Skip to content

Commit 3134cf4

Browse files
committed
force cast pointer to pointers in mock framework
1 parent 10f8ced commit 3134cf4

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/mock.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const ArgMatcher = struct {
191191
stored.* = value;
192192

193193
return ArgMatcher{
194-
.value_ptr = stored,
194+
.value_ptr = @ptrCast(stored),
195195
.match = ValueHolder.matchFn,
196196
.deinit = ValueHolder.deinitFn,
197197
};

tests/mock_object.zig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const IShape = interface.ConstructCountingInterface(struct {
3939
return interface.CountingInterfaceVirtualCall(self, "allocate_some", .{}, void);
4040
}
4141

42+
pub fn pass_string(self: *Self, s: []const u8) void {
43+
return interface.CountingInterfaceVirtualCall(self, "pass_string", .{s}, void);
44+
}
45+
4246
// do not forget about virtual destructor
4347
pub fn delete(self: *Self) void {
4448
interface.CountingInterfaceDestructorCall(self);
@@ -180,3 +184,21 @@ test "mock can invoke callback function" {
180184

181185
obj.interface.set_size(999);
182186
}
187+
188+
test "mock can handle string arguments" {
189+
var mock = try ShapeMock.create(std.testing.allocator);
190+
defer mock.delete();
191+
var obj = mock.get_interface();
192+
defer obj.interface.delete();
193+
194+
_ = mock
195+
.expectCall("pass_string")
196+
.withArgs(.{interface.mock.any{}});
197+
198+
_ = mock
199+
.expectCall("pass_string")
200+
.withArgs(.{"hello, world"});
201+
202+
obj.interface.pass_string("hello, world");
203+
obj.interface.pass_string("another string");
204+
}

0 commit comments

Comments
 (0)