summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/deck/replay.zig69
1 files changed, 66 insertions, 3 deletions
diff --git a/test/deck/replay.zig b/test/deck/replay.zig
index 90f46486..9cf829d6 100644
--- a/test/deck/replay.zig
+++ b/test/deck/replay.zig
@@ -14,7 +14,7 @@ const Tally = struct {
click_down: [3]u32 = @splat(0), // indexed by deck.Click
click_up: [3]u32 = @splat(0),
wheel: i32 = 0,
- keys: [4]u32 = @splat(0), // indexed by deck.Keytap
+ keys: [5]u32 = @splat(0), // indexed by deck.Keytap
rumbles: u32 = 0,
};
@@ -32,10 +32,10 @@ fn replay(src: [:0]const u8) !Tally {
.down => .down,
.motion => .motion,
.up => .up,
- }, .x = t.x, .y = t.y } },
+ }, .x = t.x, .y = t.y, .pressure = t.pressure } },
else => continue,
};
- var acts: [2]deck.Action = undefined;
+ var acts: [3]deck.Action = undefined;
for (acts[0..d.feed(in, &acts)]) |act| switch (act) {
.move => |mv| {
tally.moves += 1;
@@ -69,6 +69,9 @@ test "right-pad drag moves the pointer, fresh touches don't jump" {
// and no single motion teleports the cursor
try std.testing.expect(t.max_step < 0.05 * deck.POINTER_SCALE);
try std.testing.expectEqual(0, t.wheel);
+ // a light-touch drag stays well under the click threshold — no phantom
+ // select clicks (nor their rumble)
+ try std.testing.expectEqual(0, t.click_down[@intFromEnum(deck.Click.select)]);
try std.testing.expectEqual(0, t.rumbles);
}
@@ -95,9 +98,69 @@ test "left-pad swipe scrolls" {
// which must be ignored — and the left pad must never move the pointer.
try std.testing.expectEqual(5, t.wheel);
try std.testing.expectEqual(0, t.moves);
+ // the swipe presses lightly — no phantom look clicks
+ try std.testing.expectEqual(0, t.click_down[@intFromEnum(deck.Click.look)]);
try std.testing.expectEqual(0, t.rumbles);
}
+test "pad press-and-release clicks: right pad=select, left pad=look, both rumble" {
+ // no capture of a real firm press exists yet, so drive the pressure
+ // directly: a hard press (>PAD_CLICK_PRESS) then release (<RELEASE).
+ var d: deck.Deck = .{};
+ var acts: [3]deck.Action = undefined;
+ const cases = [_]struct { pad: u8, which: deck.Click }{
+ .{ .pad = deck.PAD_RIGHT, .which = .select },
+ .{ .pad = deck.PAD_LEFT, .which = .look },
+ };
+ for (cases) |cse| {
+ var down: u32 = 0;
+ var up: u32 = 0;
+ var rumbles: u32 = 0;
+ const steps = [_]struct { phase: enum { down, motion, up }, p: f32 }{
+ .{ .phase = .down, .p = 0.01 }, // land light: no click yet
+ .{ .phase = .motion, .p = 0.5 }, // press hard: click down + rumble
+ .{ .phase = .motion, .p = 0.5 }, // held: no repeat
+ .{ .phase = .up, .p = 0.0 }, // lift: click up
+ };
+ for (steps) |s| {
+ const in: deck.Input = .{ .touch = .{
+ .pad = cse.pad,
+ .phase = switch (s.phase) {
+ .down => .down,
+ .motion => .motion,
+ .up => .up,
+ },
+ .x = 0.5,
+ .y = 0.5,
+ .pressure = s.p,
+ } };
+ for (acts[0..d.feed(in, &acts)]) |act| switch (act) {
+ .click => |ck| {
+ try std.testing.expectEqual(cse.which, ck.which);
+ if (ck.down) down += 1 else up += 1;
+ },
+ .rumble => rumbles += 1,
+ else => {},
+ };
+ }
+ try std.testing.expectEqual(1, down);
+ try std.testing.expectEqual(1, up);
+ try std.testing.expectEqual(1, rumbles);
+ }
+}
+
+test "back paddles L4/R4/L5/R5 each toggle the terminal, release is inert" {
+ // the back paddles aren't in the recorded sweeps, so drive them directly.
+ var d: deck.Deck = .{};
+ var acts: [3]deck.Action = undefined;
+ for ([_]u8{ deck.BTN_L4, deck.BTN_R4, deck.BTN_L5, deck.BTN_R5 }) |idx| {
+ try std.testing.expectEqual(1, d.feed(.{ .button = .{ .idx = idx, .down = true } }, &acts));
+ try std.testing.expect(acts[0] == .key);
+ try std.testing.expectEqual(deck.Keytap.tty_toggle, acts[0].key);
+ try std.testing.expectEqual(0, d.feed(.{ .button = .{ .idx = idx, .down = false } }, &acts));
+ }
+}
+
test "buttons: dpad n/N, A Enter, Y Tab, L1 look + rumble" {
const t = try replay(@embedFile("buttons.zon"));
// every button press of a real all-buttons sweep: dpad-down x1,