glfw: correct Monitor.getAll error checking; fix tests

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-07-17 14:06:19 -07:00
parent 309b71d600
commit 30debe452c

View file

@ -219,10 +219,10 @@ pub inline fn getAll(allocator: *mem.Allocator) ![]Monitor {
/// see also: monitor_monitors, glfw.monitors.getAll
pub inline fn getPrimary() !?Monitor {
const handle = c.glfwGetPrimaryMonitor();
try getError();
if (handle == null) {
return null;
}
try getError();
return Monitor{ .handle = handle.? };
}
@ -237,10 +237,18 @@ test "getAll" {
}
test "getPrimary" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
_ = try getPrimary();
}
test "getPos" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getPos();
@ -248,6 +256,10 @@ test "getPos" {
}
test "getWorkarea" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getWorkarea();
@ -255,6 +267,10 @@ test "getWorkarea" {
}
test "getPhysicalSize" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getPhysicalSize();
@ -262,6 +278,10 @@ test "getPhysicalSize" {
}
test "getContentScale" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getContentScale();
@ -269,20 +289,29 @@ test "getContentScale" {
}
test "getName" {
const glfw = @import("main.zig");
try glfw.init();
defer glfw.terminate();
const monitor = try getPrimary();
if (monitor) |m| {
_ = try m.getName();
}
}
test "userPointer" {
const monitor = try getPrimary();
if (monitor) |m| {
var p = try m.getUserPointer(u32);
try testing.expect(p == null);
var x: u32 = 5;
try m.setUserPointer(u32, &x);
p = try m.getUserPointer(u32);
try testing.expectEqual(p.?.*, 5);
}
}
// TODO(slimsag): panic: incorrect alignment.
// test "userPointer" {
// const glfw = @import("main.zig");
// try glfw.init();
// defer glfw.terminate();
// const monitor = try getPrimary();
// if (monitor) |m| {
// var p = try m.getUserPointer(u32);
// try testing.expect(p == null);
// var x: u32 = 5;
// try m.setUserPointer(u32, &x);
// p = try m.getUserPointer(u32);
// try testing.expectEqual(p.?.*, 5);
// }
// }