From 48cf77be089c17cc37ee08ab29c349d24da3e417 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 9 Jan 2022 15:50:07 -0700 Subject: [PATCH] Fix broken test This also involved closing windows from previous tests. --- lib/minifb/src/minifb.zig | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/minifb/src/minifb.zig b/lib/minifb/src/minifb.zig index 1029489..cfad8ff 100644 --- a/lib/minifb/src/minifb.zig +++ b/lib/minifb/src/minifb.zig @@ -57,6 +57,10 @@ pub fn Window(comptime TUserData: type) type { } } + pub fn close(self: Window(TUserData)) void { + c.mfb_close(self.cwin); + } + pub fn waitSync(self: Window(TUserData)) bool { return c.mfb_wait_sync(self.cwin); } @@ -99,12 +103,14 @@ pub fn Window(comptime TUserData: type) type { test "user data is null if never set" { const win = try Window(u64).open("abc", 100, 100, .{}); + defer win.close(); const data = win.getUserData(); try testing.expectEqual(@as(?*u64, null), data); } test "user data is not null if previously set" { const win = try Window(u64).open("abc", 100, 100, .{}); + defer win.close(); var data: u64 = 42; win.setUserData(&data); const expected: u64 = 42; @@ -113,6 +119,7 @@ test "user data is not null if previously set" { test "also works with smaller user data" { const win = try Window(u8).open("abc", 100, 100, .{}); + defer win.close(); var data: u8 = 42; win.setUserData(&data); const expected: u8 = 42; @@ -127,15 +134,15 @@ pub fn setTargetFPS(fps: u32) void { c.mfb_set_target_fps(fps); } -// TODO Figure out how to run this once I have Internet access. -// test "set and get target FPS" { -// const max = 40; -// var fps: u32 = 30; -// while (fps < max) { -// setTargetFPS(fps); -// try std.testing.expectEqual(fps, getTargetFPS()); -// } -// } +test "set and get target FPS" { + const max = 40; + var fps: u32 = 30; + while (fps < max) { + setTargetFPS(fps); + try std.testing.expectEqual(fps, getTargetFPS()); + fps += 1; + } +} pub const Timer = extern struct { ctimer: *c.mfb_timer,