summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/addons_pdf.zig26
-rw-r--r--test/session.zig14
2 files changed, 38 insertions, 2 deletions
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index 23768f61..af194a5b 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -256,3 +256,29 @@ test "addons: a PDF whose file changes on disk shows its new pages, under new ke
try std.testing.expect(now.len >= 1);
for (now) |pic| for (first) |old| try std.testing.expect(!std.mem.eql(u8, pic.key, old.key));
}
+
+test "addons: a PDF whose file changes on disk while a page of it renders: the pixels go with the document they are of, once" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const a = s.arena.allocator();
+ const links = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/links.pdf", a, .unlimited);
+ const outline = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", a, .unlimited);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "doc.pdf", .data = links });
+ const n = try s.lookFile(s.at("{s}/doc.pdf", .{dir}));
+ 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;
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "PdfTint full\n");
+ s.runJobs();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "doc.pdf", .data = outline });
+ try std.testing.expect(try s.filesChanged());
+ s.releaseJobs();
+ try s.keys("0");
+ try std.testing.expect((try shown(&s, n)).len >= 1);
+}
diff --git a/test/session.zig b/test/session.zig
index 056966b9..06cd3a32 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -43,6 +43,8 @@ pub const Session = struct {
/// meanwhile (a reload).
hold_jobs: bool = false,
held: std.ArrayList(*pardes.host_io.KindJob) = .empty,
+ /// Of `held`, those run already (`runJobs`), their answers still held.
+ ran: usize = 0,
/// The files the core asked to watch, watched as a host watches them
/// (file_watch.zig, inotify): `filesChanged` wakes them.
watch_fd: c_int = -1,
@@ -308,14 +310,22 @@ pub const Session = struct {
return true;
}
+ /// 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 {
+ for (s.held.items[s.ran..]) |j| j.run();
+ s.ran = s.held.items.len;
+ }
+
/// The jobs held, run now and answered as the host's workers would.
pub fn releaseJobs(s: *Session) void {
s.hold_jobs = false;
- for (s.held.items) |j| {
- j.run();
+ for (s.held.items, 0..) |j, i| {
+ if (i >= s.ran) j.run();
j.land(pardesOf(s));
}
s.held.clearRetainingCapacity();
+ s.ran = 0;
s.drain();
}