Fix broken test

This also involved closing windows from previous tests.
This commit is contained in:
Brandon Dyck 2022-01-09 15:50:07 -07:00
parent 172baf2ef8
commit 48cf77be08

View File

@ -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,