summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/daemon.py6
-rw-r--r--test/panes.zig148
-rw-r--r--test/pdf_scroll_bench.zig6
-rw-r--r--test/replicas.zig2
4 files changed, 157 insertions, 5 deletions
diff --git a/test/daemon.py b/test/daemon.py
index 051297a8..5bdf1fc4 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -649,9 +649,9 @@ def pdf_window(binary, gui_binary):
"""A PDF in a terminal's detached session (the pdf addon its prefix
installs, `<prefix>/lib/pardes/addons/pdf.so`), a window client attached
and its wheel turned over the PDF: the session's page moves, the
- window's digest is the session's, and the window, which runs no addon
- code, draws the session's frames of it. Skipped when the build has no
- pdf.so."""
+ window's digest is the session's, and the window, which runs the
+ addon's code itself (its state is plain: PA_PLAIN), draws its own
+ pages from the file. Skipped when the build has no pdf.so."""
lib = Path(binary).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so'
if not lib.exists():
print(f'daemon: no {lib}: the PDF window case skipped')
diff --git a/test/panes.zig b/test/panes.zig
index fb8adc36..de9d3aea 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3937,7 +3937,7 @@ const PdfAddon = struct {
else
try std.testing.expectEqualDeep(@field(s, name), @field(t, name));
}
- // Its place: what its kind says, and the Shadow's copy of it.
+ // Its place: what its kind says, and the loaded copy of it.
var here: [32]u8 = undefined;
var there: [32]u8 = undefined;
try std.testing.expectEqualStrings(pardes.Kind.where(s, &here), pardes.Kind.where(t, &there));
@@ -4178,6 +4178,152 @@ const PdfAddon = struct {
try std.testing.expect(notch > 0 and first > at[0] and first < at[1]);
try std.testing.expectApproxEqRel(notch / 4, at[2] - at[1], 0.05);
}
+
+ test "a window client the size of its session's window shows a PDF's pages where the session's window shows them, a fraction of a pixel scrolled and all" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const win = try R.Replica.init(gpa, 2, try a.unit(0, 0), false);
+ defer win.deinit();
+ const land = struct {
+ a: *R.Authority,
+ r: *R.Replica,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.r.confirm(try l.a.local(ev));
+ }
+ }{ .a = a, .r = win };
+ // The session's window, and the client's of its size on a view of its own.
+ const window: pardes.Event = .{ .frontend = .{ .windowed = true, .native_images = true } };
+ try land.step(window);
+ // The client has the addon (a test's replica finds no library of
+ // its own: it is handed the session's, loaded in this process).
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
+ const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
+ try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ const kind = a.core.kinds.n - 1;
+ win.core().kinds.ops[kind] = a.core.kinds.ops[kind];
+ const id = try opened(a, land);
+ const k = try a.openView(2);
+ win.confirm(k.unit);
+ win.view = k.view;
+ win.confirm(try a.take(try win.input(window)));
+ try land.step(.tick);
+ // A touchpad's 0.6 of a notch in the client: its view's top a
+ // fraction of a pixel past a row (as a glide's half steps leave it).
+ const r = win.core().view().rects[id];
+ win.confirm(try a.take(try win.input(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = r.x + 4, .row = r.y + r.h - 2, .amount = 0.6 } })));
+ for (0..2) |_| {
+ try land.step(.tick);
+ try jobs(a.core, land);
+ }
+ win.settle();
+ try std.testing.expect(win.diverged == null);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var at: [2][8][4]u32 = @splat(@splat(@splat(0)));
+ for ([_]*Pardes{ a.core, win.core() }, [_]u8{ 0, k.view }, &at) |core, view, *rows| {
+ core.toView(view);
+ var n: usize = 0;
+ for ((try core.render(arena.allocator())).placements.items) |pl| if (pl.pane == id and pl.raster.w > 1 and n < rows.len) {
+ rows[n] = if (pl.at) |x| .{ x.y, x.h, pl.src.y, pl.src.h } else .{ 0, 0, pl.src.y, pl.src.h };
+ n += 1;
+ };
+ try std.testing.expect(n > 0);
+ }
+ try std.testing.expectEqualSlices([4]u32, &at[0], &at[1]);
+ }
+
+ /// A session with design.pdf open and a client on a view of its own
+ /// (`frontend`'s), which runs the kind as the session does: handed the
+ /// session's library (a test's replica finds none of its own).
+ fn clientOf(a: *pardes.replica.Authority, win: *pardes.replica.Replica, frontend: pardes.Event) !struct { id: usize, view: u8 } {
+ const land = Confirmed{ .a = a, .r = win };
+ try land.step(.{ .frontend = .{ .windowed = true, .native_images = true } });
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
+ const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why);
+ try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } });
+ const kind = a.core.kinds.n - 1;
+ win.core().kinds.ops[kind] = a.core.kinds.ops[kind];
+ const id = try opened(a, land);
+ const k = try a.openView(2);
+ win.confirm(k.unit);
+ win.view = k.view;
+ win.confirm(try a.take(try win.input(frontend)));
+ try land.step(.tick);
+ try jobs(a.core, land);
+ return .{ .id = id, .view = k.view };
+ }
+
+ const Confirmed = struct {
+ a: *pardes.replica.Authority,
+ r: *pardes.replica.Replica,
+ fn step(l: @This(), ev: pardes.Event) !void {
+ l.r.confirm(try l.a.local(ev));
+ }
+ };
+
+ test "a terminal's client shows a PDF's page as its text, the session's page's lines from its first" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const win = try R.Replica.init(gpa, 2, try a.unit(0, 0), false);
+ defer win.deinit();
+ const c = try clientOf(a, win, .{ .frontend = .{ .windowed = false, .native_images = false } });
+ try (Confirmed{ .a = a, .r = win }).step(.tick);
+ try jobs(a.core, Confirmed{ .a = a, .r = win });
+ // The page's text (its body) as the session reads it: its first line
+ // is the client pane's first row.
+ const text = try pardes.Kind.body(a.core.panes[c.id].?, gpa);
+ defer gpa.free(text);
+ const first = std.mem.trim(u8, text[0 .. std.mem.indexOfScalar(u8, text, '\n') orelse text.len], " ");
+ try std.testing.expect(first.len > 0);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ win.core().toView(c.view);
+ const s = try win.core().render(arena.allocator());
+ const r = win.core().view().rects[c.id];
+ var row: [512]u8 = undefined;
+ var n: usize = 0;
+ for (r.x..r.x + r.w) |x| {
+ const g = s.at(@intCast(x), r.y + win.core().panes[c.id].?.tag_rows).grapheme();
+ if (n + g.len > row.len) break;
+ @memcpy(row[n..][0..g.len], g);
+ n += g.len;
+ }
+ try std.testing.expect(std.mem.indexOf(u8, row[0..n], first[0..@min(first.len, 20)]) != null);
+ var placed: usize = 0;
+ for (s.placements.items) |pl| placed += @intFromBool(pl.pane == c.id);
+ try std.testing.expectEqual(@as(usize, 0), placed);
+ }
+
+ test "a PDF pane a client closes waits for the session's order (its kind's close is never guessed), then is gone in both" {
+ if (!addons.has_pdf) return error.SkipZigTest;
+ const R = pardes.replica;
+ const gpa = std.testing.allocator;
+ const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }, false);
+ defer a.deinit();
+ const win = try R.Replica.init(gpa, 2, try a.unit(0, 0), false);
+ defer win.deinit();
+ const c = try clientOf(a, win, .{ .frontend = .{ .windowed = true, .native_images = true } });
+ // The client's click in the PDF: its pane the client's own view's.
+ const r = win.core().view().rects[c.id];
+ for ([_]pardes.Mouse.Kind{ .press, .release }) |kind| win.confirm(try a.take(try win.input(.{ .mouse = .{ .button = .left, .kind = kind, .col = r.x + 4, .row = r.y + r.h - 2 } })));
+ win.settle();
+ const stopped = win.stats.stopped;
+ const sent = try win.input(.{ .command = "Del" });
+ try std.testing.expect(win.core().panes[c.id] != null);
+ try std.testing.expectEqual(stopped + 1, win.stats.stopped);
+ win.confirm(try a.take(sent));
+ win.settle();
+ try std.testing.expect(a.core.panes[c.id] == null and win.core().panes[c.id] == null);
+ try std.testing.expect(win.diverged == null);
+ }
};
test {
diff --git a/test/pdf_scroll_bench.zig b/test/pdf_scroll_bench.zig
index bb4640f7..595037ae 100644
--- a/test/pdf_scroll_bench.zig
+++ b/test/pdf_scroll_bench.zig
@@ -277,9 +277,15 @@ fn measure(config: Config, plan: Plan) !Result {
var visual: u64 = 0x7061_7264_6573_5343;
var shown: u64 = 0;
var total: u64 = 0;
+ // The core's clock a frame on at each, as a shell's loop moves it
+ // (its glide and a fling are on that clock).
+ var now: u64 = std.time.ns_per_s;
+ core.advance(now);
for (0..plan.frames) |frame| {
const button: pardes.Mouse.Button = if (plan.scenario == .fling_reverse and frame >= plan.down_frames) .wheel_up else .wheel_down;
const started = nowNs();
+ now += pardes.frame_ns;
+ core.advance(now);
for (0..ticks) |_| core.update(.{ .mouse = .{ .button = button, .kind = .press, .col = rect.x + rect.w / 2, .row = rect.y + rect.h / 2, .amount = config.turn } });
_ = arena.reset(.retain_capacity);
const surface = try core.render(arena.allocator());
diff --git a/test/replicas.zig b/test/replicas.zig
index 8d4b2e38..aea6ef7f 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -1239,7 +1239,7 @@ fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void {
fn flushAll(sc: *replica.Screens, core: *pardes.Pardes, ps: []const u16, list: *std.ArrayListUnmanaged([]u8), q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, now: u64, dl: []Link, rnd: std.Random, ow: u64, jt: u64, vs: *std.AutoHashMapUnmanaged(u64, u64), tot: *Totals) !void {
for (ps, 0..) |peer, c| {
list.clearRetainingCapacity();
- // No pane of a kind here: the view a Shadow is painted for is moot.
+ // Terminals alone cross: the view is not read.
try sc.flush(core, peer, 0, list);
for (list.items) |bytes| {
tot.deltas += 1;