// SPDX-FileCopyrightText: © 2025 Jeffrey C. Ollie // SPDX-License-Identifier: MIT pub const CorsairGalleonK100 = @import("devices/CorsairGalleonK100.zig"); pub const ElgatoStreamDeckMini = @import("devices/ElgatoStreamDeckMini.zig"); pub const ElgatoStreamDeckMiniMK2 = @import("devices/ElgatoStreamDeckMiniMK2.zig"); pub const ElgatoStreamDeckMK2 = @import("devices/ElgatoStreamDeckMK2.zig"); pub const ElgatoStreamDeckMK2Scissor = @import("devices/ElgatoStreamDeckMK2Scissor.zig"); pub const ElgatoStreamDeckMiniDiscord = @import("devices/ElgatoStreamDeckMiniDiscord.zig"); pub const ElgatoStreamDeckModule15 = @import("devices/ElgatoStreamDeckModule15.zig"); pub const ElgatoStreamDeckModule32 = @import("devices/ElgatoStreamDeckModule32.zig"); pub const ElgatoStreamDeckModule6 = @import("devices/ElgatoStreamDeckModule6.zig"); pub const ElgatoStreamDeckNeo = @import("devices/ElgatoStreamDeckNeo.zig"); pub const ElgatoStreamDeckOriginal = @import("devices/ElgatoStreamDeckOriginal.zig"); pub const ElgatoStreamDeckOriginalV2 = @import("devices/ElgatoStreamDeckOriginalV2.zig"); pub const ElgatoStreamDeckPedal = @import("devices/ElgatoStreamDeckPedal.zig"); pub const ElgatoStreamDeckPlus = @import("devices/ElgatoStreamDeckPlus.zig"); pub const ElgatoStreamDeckPlusXL = @import("devices/ElgatoStreamDeckPlusXL.zig"); pub const ElgatoStreamDeckStudio = @import("devices/ElgatoStreamDeckStudio.zig"); pub const ElgatoStreamDeckXL = @import("devices/ElgatoStreamDeckXL.zig"); pub const ElgatoStreamDeckXLV2 = @import("devices/ElgatoStreamDeckXLV2.zig"); const std = @import("std"); const ImageFormat = @import("root.zig").ImageFormat; const KeyFeature = @import("Keys.zig").KeyFeature; const StreamDeck = @import("StreamDeck.zig"); /// Every model's module in one list, so that a test can say something /// about all of them at once rather than naming them one at a time and /// silently missing the next one added. pub const all = &[_]type{ CorsairGalleonK100, ElgatoStreamDeckMini, ElgatoStreamDeckMiniMK2, ElgatoStreamDeckMK2, ElgatoStreamDeckMK2Scissor, ElgatoStreamDeckMiniDiscord, ElgatoStreamDeckModule15, ElgatoStreamDeckModule32, ElgatoStreamDeckModule6, ElgatoStreamDeckNeo, ElgatoStreamDeckOriginal, ElgatoStreamDeckOriginalV2, ElgatoStreamDeckPedal, ElgatoStreamDeckPlus, ElgatoStreamDeckPlusXL, ElgatoStreamDeckStudio, ElgatoStreamDeckXL, ElgatoStreamDeckXLV2, }; test "every model is in `all`" { // `all` is written out by hand, so this is what keeps it honest // when a model is added: `StreamDeck.Type` is the list the rest of // the library switches over, and the two have to agree. try std.testing.expectEqual(std.meta.fields(StreamDeck.Type).len, all.len); inline for (std.meta.fields(StreamDeck.Type)) |f| { const device = @field(@This(), f.name); comptime var found = false; inline for (all) |d| { if (d == device) found = true; } if (!found) { @compileError("model " ++ f.name ++ " is missing from `devices.all`"); } } } test "key counts add up" { inline for (all) |device| { try std.testing.expectEqual( @as(u8, device.keys.cols) * device.keys.rows + device.keys.touch, device.keys.count, ); } } test "every key up to the count has a feature, and none beyond it" { inline for (all) |device| { for (0..device.keys.count) |key| { try std.testing.expect(device.keys.getFeature(@intCast(key)) != null); } // One past the end, and the top of the range, since `getFeature` // takes a `u8` and the switches in it are written out by hand. try std.testing.expectEqual(null, device.keys.getFeature(device.keys.count)); try std.testing.expectEqual(null, device.keys.getFeature(255)); } } test "the touch keys are the ones numbered after the grid" { // `Keys.setTouchKeyColor` decides whether a key takes a color by // asking `getFeature` for it, so which keys report `touchled` has // to line up with the `touch` count that `Keys.touch` reports. inline for (all) |device| { const grid = @as(u8, device.keys.cols) * device.keys.rows; for (0..grid) |key| { const feature = device.keys.getFeature(@intCast(key)).?; try std.testing.expect(feature != .touchled); } for (grid..device.keys.count) |key| { const feature = device.keys.getFeature(@intCast(key)).?; try std.testing.expectEqual(KeyFeature.touchled, feature); } } } test "every image key has a usable size" { inline for (all) |device| { for (0..device.keys.count) |key| { switch (device.keys.getFeature(@intCast(key)).?) { .image => |i| { try std.testing.expect(i.width > 0); try std.testing.expect(i.height > 0); }, .none, .touchled => {}, } } } } test { inline for (all) |device| { std.testing.refAllDecls(device); std.testing.refAllDecls(device.keys); } } test "the models that share a key table agree about it" { // The modules and the special editions are the same electronics in // a different shell, and their tables are shared rather than // copied. This says which is which, so that a copy made by mistake // later shows up here. const shared = .{ .{ ElgatoStreamDeckMK2Scissor, ElgatoStreamDeckMK2 }, .{ ElgatoStreamDeckMiniDiscord, ElgatoStreamDeckMini }, .{ ElgatoStreamDeckModule6, ElgatoStreamDeckMini }, .{ ElgatoStreamDeckModule15, ElgatoStreamDeckMK2 }, .{ ElgatoStreamDeckModule32, ElgatoStreamDeckXL }, }; inline for (shared) |pair| { const module, const base = pair; try std.testing.expectEqual(base.keys.cols, module.keys.cols); try std.testing.expectEqual(base.keys.rows, module.keys.rows); try std.testing.expectEqual(base.keys.touch, module.keys.touch); try std.testing.expectEqual(base.keys.count, module.keys.count); for (0..base.keys.count) |key| { try std.testing.expectEqual( base.keys.getFeature(@intCast(key)), module.keys.getFeature(@intCast(key)), ); } } } test "the older models send BMP and the newer ones JPEG" { // The image format follows the header format: a v1 header goes // with BMP and a v2 header with JPEG. The Mini MK.2 used to be // down as v1 and JPEG, which is a combination no model has. inline for (all) |device| { for (0..device.keys.count) |key| { switch (device.keys.getFeature(@intCast(key)).?) { .image => |i| switch (i.header_format) { .v1 => try std.testing.expectEqual(ImageFormat.BMP, i.image_format), .v2 => try std.testing.expectEqual(ImageFormat.JPEG, i.image_format), }, .none, .touchled => {}, } } } }