summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/addons_pdf.zig3
-rw-r--r--test/panes.zig48
-rw-r--r--test/session.zig15
3 files changed, 24 insertions, 42 deletions
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index af194a5b..cf5c8009 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -273,8 +273,9 @@ test "addons: a PDF whose file changes on disk while a page of it renders: the p
try std.testing.expect((try shown(&s, n)).len >= 1);
// A page drawn again (another tint), its render done on a worker but
// not yet answered as the file changes and the pane opens it again.
- s.hold_jobs = true;
+ s.holdJobs();
try s.write(s.at("/pane/{d}/ctl", .{n}), "PdfTint full\n");
+ _ = try shown(&s, n);
s.runJobs();
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "doc.pdf", .data = outline });
try std.testing.expect(try s.filesChanged());
diff --git a/test/panes.zig b/test/panes.zig
index d47136a5..fb8adc36 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -3783,15 +3783,12 @@ const PdfAddon = struct {
}.f,
};
- test "a client without the pdf addon shows a PDF pane as the session's frames of it, its pages by key, and its wheel goes to the session" {
+ test "a client without the pdf addon shows its PDF pane as a line, its page in its tag, and its wheel goes to the session" {
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();
- var screens: R.Screens = .init(gpa);
- defer screens.deinit(a.core);
- const peer = try screens.addPeer();
const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false);
defer r.deinit();
const Land = struct {
@@ -3802,61 +3799,30 @@ const PdfAddon = struct {
}
};
const land: Land = .{ .a = a, .r = r };
- 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 } });
// A frontend with pictures (a terminal without them is shown the
// page's text layer).
try land.step(.{ .frontend = .{ .windowed = false, .native_images = true } });
+ const id = try opened(a, land);
try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null);
- var buf: [4096]u8 = undefined;
- const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, "docs/design.pdf", &buf);
- var line: [4200]u8 = undefined;
- try land.step(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{buf[0..real]}) });
- for (0..3) |_| {
- try land.step(.tick);
- try jobs(a.core, land);
- }
- // Its frame crosses: the replica draws the pane as the session
- // painted it, its pages placed by key, its page in its tag.
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
- const deliver = struct {
- fn f(au: *R.Authority, sc: *R.Screens, pe: u16, re: *R.Replica) !void {
- var msgs: std.ArrayListUnmanaged([]u8) = .empty;
- defer {
- for (msgs.items) |m| std.testing.allocator.free(m);
- msgs.deinit(std.testing.allocator);
- }
- try sc.flush(au.core, pe, re.view, &msgs);
- for (msgs.items) |m| if (re.screen(m)) |reply| {
- _ = try sc.take(au.core, pe, reply);
- };
- }
- }.f;
_ = try a.core.render(arena.allocator());
- // (A kind's prefix is its last frame's, and the tag a step's: a
- // Shadow's is the authority's last step's.)
try land.step(.tick);
- try deliver(a, &screens, peer, r);
- const id = for (r.core().panes, 0..) |slot, i| {
- if (slot) |pane| if (pane.addon != null) break i;
- } else return error.NoPdfPane;
+ // No picture crosses: the client shows the line saying the addon
+ // does not run here, and the session's page in its tag.
const shown = try r.core().render(arena.allocator());
var placed: usize = 0;
for (shown.placements.items) |pl| placed += @intFromBool(pl.pane == id);
- try std.testing.expect(placed >= 1);
+ try std.testing.expectEqual(@as(usize, 0), placed);
try std.testing.expect(std.mem.startsWith(u8, try pardes.tagline.tagPrefix(r.core(), r.core().panes[id].?), "[1/16]"));
- // A wheel at the replica: the session's kind takes it, and the
- // replica shows where the session's strip went.
+ // A wheel at the replica: the session's kind takes it.
const before = a.core.panes[id].?.addon.?.thumb_at;
const rect = r.core().view().rects[id];
for (0..20) |_| r.confirm(try a.take(try r.input(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = rect.x + rect.w / 2, .row = rect.y + rect.h / 2 } })));
+ for (0..4) |_| try land.step(.tick);
try jobs(a.core, land);
_ = try a.core.render(arena.allocator());
try std.testing.expect(a.core.panes[id].?.addon.?.thumb_at > before);
- try deliver(a, &screens, peer, r);
r.settle();
try std.testing.expect(r.diverged == null);
}
diff --git a/test/session.zig b/test/session.zig
index 06cd3a32..cd04ecb8 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -107,6 +107,7 @@ pub const Session = struct {
pub fn deinit(s: *Session) void {
s.held.deinit(pardesOf(s).gpa);
+ if (s.hold_jobs) pardes.Kind.drawer = null;
if (s.watch_fd >= 0) {
pardes.file_watch.unwatchAll(s.watch_fd, &s.watches);
_ = std.c.close(s.watch_fd);
@@ -310,6 +311,19 @@ pub const Session = struct {
return true;
}
+ /// Kinds' jobs and draws held from now on (`hold_jobs`), until
+ /// `releaseJobs`.
+ pub fn holdJobs(s: *Session) void {
+ s.hold_jobs = true;
+ pardes.Kind.drawer = .{ .ctx = s, .go = struct {
+ fn go(ctx: ?*anyopaque, j: *pardes.host_io.KindJob) bool {
+ const ss: *Session = @ptrCast(@alignCast(ctx));
+ ss.held.append(pardesOf(ss).gpa, j) catch return false;
+ return true;
+ }
+ }.go };
+ }
+
/// The jobs held run now, as a worker runs them, their answers held
/// still: what a test does next happens while they are under way.
pub fn runJobs(s: *Session) void {
@@ -320,6 +334,7 @@ pub const Session = struct {
/// The jobs held, run now and answered as the host's workers would.
pub fn releaseJobs(s: *Session) void {
s.hold_jobs = false;
+ pardes.Kind.drawer = null;
for (s.held.items, 0..) |j, i| {
if (i >= s.ran) j.run();
j.land(pardesOf(s));