diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/fonts.c | 78 | ||||
| -rw-r--r-- | test/kill.script | 5 | ||||
| -rw-r--r-- | test/killed.script | 6 | ||||
| -rw-r--r-- | test/manual.script | 131 | ||||
| -rw-r--r-- | test/past.script | 8 | ||||
| -rw-r--r-- | test/past_diverged.script | 6 | ||||
| -rw-r--r-- | test/past_replay.script | 12 | ||||
| -rw-r--r-- | test/reload.script | 2 | ||||
| -rw-r--r-- | test/same_sessions.zig | 66 | ||||
| -rw-r--r-- | test/scene_compiled.script | 2 | ||||
| -rw-r--r-- | test/scene_live.script | 21 | ||||
| -rw-r--r-- | test/scene_morph.script | 46 | ||||
| -rw-r--r-- | test/scene_morph.zig | 25 | ||||
| -rw-r--r-- | test/session_export.script | 3 | ||||
| -rw-r--r-- | test/session_import.script | 13 | ||||
| -rw-r--r-- | test/svg/image.svg | 9 | ||||
| -rw-r--r-- | test/svg/typst-image.typ | 6 | ||||
| -rw-r--r-- | test/talk.script | 104 | ||||
| -rw-r--r-- | test/text.script | 8 | ||||
| -rw-r--r-- | test/text.zig | 9 | ||||
| -rw-r--r-- | test/voices.script | 29 | ||||
| -rw-r--r-- | test/voices.zig | 26 |
22 files changed, 528 insertions, 87 deletions
diff --git a/test/fonts.c b/test/fonts.c deleted file mode 100644 index 87a47bb..0000000 --- a/test/fonts.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Standalone Linux font regression/specimen. See vendor/fonts/README.md. */ -#include "../vendor/text.c" -#include <assert.h> -#include <stdio.h> - -static unsigned glyphs(PangoLayout *layout) { - unsigned count = 0; - PangoLayoutIter *it = pango_layout_get_iter(layout); - do { - PangoLayoutRun *run = pango_layout_iter_get_run_readonly(it); - if (run) count += run->glyphs->num_glyphs; - } while (pango_layout_iter_next_run(it)); - pango_layout_iter_free(it); - return count; -} -int main(int argc, char **argv) { - assert(SDL_Init(0)); - SDL_Surface *surface = SDL_CreateSurface(1440, 820, SDL_PIXELFORMAT_ARGB8888); - SDL_Renderer *r = SDL_CreateSoftwareRenderer(surface); - assert(r); - SDL_SetRenderDrawColor(r, 17, 21, 27, 255); SDL_RenderClear(r); - sk_text_begin_frame(r); - const char *samples[] = { - "Go Mono / native shaped text", - "Pardes / 46.8M accesses / 3.97M calls", - "0123456789 0x7ffed849acf0 () [] {} <> -> != ==", - "Latin: cafe\xcc\x81 / café / naïve / fi fl ffi", - "Greek / Cyrillic: λ → Ω Привет мир", - "Japanese fallback: 日本語 ひらがな カタカナ", - "Arabic shaping: العربية لا السلام عليكم", - "Hebrew bidi: שלום עולם | English 123", - "Symbols / emoji: ✓ ⌘ ⌥ ⌫ ⌜ ⌟ 😀 ★ ♥", - "draw.render → body_layer.renderBody → TerminalImages.draw" - }; - for (unsigned i=0; i<sizeof(samples)/sizeof(*samples); ++i) { - assert(sk_text_draw(r, 30, 25 + 53*i, i==0?2.2f:1.6f, samples[i], strlen(samples[i]), - i==0?228:165,i==0?234:178,i==0?242:195,255)); - TextCache *c=cache_for(r); - assert(pango_layout_get_unknown_glyphs_count(c->layout)==0); - } - TextCache *c=cache_for(r); - assert(sk_text_draw(r,30,575,1.0f,"e\xcc\x81",3,228,234,242,255)); - PangoRectangle combining, plain; - pango_layout_get_pixel_extents(c->layout,NULL,&combining); - assert(sk_text_draw(r,50,575,1.0f,"e",1,228,234,242,255)); - pango_layout_get_pixel_extents(c->layout,NULL,&plain); - assert(combining.width==plain.width); - assert(sk_text_draw(r,70,575,1.0f,"لا",strlen("لا"),228,234,242,255)); - assert(glyphs(c->layout)==1); - assert(sk_text_draw(r,120,575,1.0f,"0123456789",10,228,234,242,255)); - PangoRectangle bounds; pango_layout_get_pixel_extents(c->layout,NULL,&bounds); - assert(bounds.width>=75 && bounds.width<=85 && bounds.height>=13); - printf("scale 1: 10-digit advance %dpx, line box %dpx\n",bounds.width,bounds.height); - SDL_Rect clip={30,620,400,30}; SDL_SetRenderClipRect(r,&clip); - assert(sk_text_draw(r,30,617,1.6f,"Clipping preserves the baseline and glyph edges outside this box",strlen("Clipping preserves the baseline and glyph edges outside this box"),112,183,255,255)); - SDL_SetRenderClipRect(r,NULL); - assert(SDL_RenderPresent(r)); - if(argc>1) assert(SDL_SavePNG(surface,argv[1])); - assert(SDL_SetRenderLogicalPresentation(r,720,410,SDL_LOGICAL_PRESENTATION_LETTERBOX)); - assert(fabsf(density(r)-2)<0.01f); - assert(sk_text_draw(r,10,10,1.0f,"0123456789",10,228,234,242,255)); - pango_layout_get_pixel_extents(c->layout,NULL,&bounds); - assert(bounds.width>=150 && bounds.width<=170); - /* Eviction across frames and exhaustion inside one frame both stay bounded. */ - for(unsigned i=0;i<800;i++) { - if(i%100==0) sk_text_begin_frame(r); - char text[32]; int n=snprintf(text,sizeof(text),"cache %u",i); - assert(sk_text_draw(r,0,0,1,text,(size_t)n,255,255,255,255)); - assert(c->bytes<=CACHE_BYTES); - } - for(unsigned i=0;i<600;i++) { - char text[32]; int n=snprintf(text,sizeof(text),"transient %u",i); - assert(sk_text_draw(r,0,0,1,text,(size_t)n,255,255,255,255)); - assert(c->bytes<=CACHE_BYTES); - } - SDL_DestroyRenderer(r); SDL_DestroySurface(surface); SDL_Quit(); - puts("Go Mono, fallback, combining marks, Arabic shaping, 2x DPI, clipping and bounded cache passed"); -} diff --git a/test/kill.script b/test/kill.script new file mode 100644 index 0000000..824b741 --- /dev/null +++ b/test/kill.script @@ -0,0 +1,5 @@ +# A run without --fresh records to a file; it dies by SIGKILL after 255 +# frames, the last 15 of them not yet committed (test/killed.script). +move 100 80 +frames 254 +kill diff --git a/test/killed.script b/test/killed.script new file mode 100644 index 0000000..7d0899c --- /dev/null +++ b/test/killed.script @@ -0,0 +1,6 @@ +# After test/kill.script: its session kept the four commits of 60 frames it +# made before it was killed, and says it crashed; this run starts from them, +# replayed. +expect updates 240 +console sessions +expect-log frames 240 (crashed) diff --git a/test/manual.script b/test/manual.script new file mode 100644 index 0000000..707e5cc --- /dev/null +++ b/test/manual.script @@ -0,0 +1,131 @@ +# The manual example (examples/manual.zig) on Vol. 2 of the Intel SDM: +# Figure 2-1, then ADD's row 80 /0 ib becoming SUB's 80 /5 ib, stepped +# through in the stock player, and exported twice. Built only when the PDF +# is there (-Dmanual). +frames 150 +expect deck.waiting true +expect deck.log.len 0 +screenshot .zig-cache/manual/page.png +# The page on its paper, the whole of it in view. +expect-pixel .zig-cache/manual/page.png 400 650 255 255 255 255 2 +# Onto the figure; the rest of the page greys. +key space +await deck.waiting true +screenshot .zig-cache/manual/figure.png +expect-pixel .zig-cache/manual/figure.png 460 160 255 255 255 255 2 +# Each field in turn, tinted: the third is ModR/M. +key space +await deck.waiting true +key space +await deck.waiting true +key space +await deck.waiting true +expect deck.log.len 4 +screenshot .zig-cache/manual/modrm.png +expect-pixel .zig-cache/manual/modrm.png 460 160 192 233 242 255 3 +expect-pixel .zig-cache/manual/modrm.png 300 160 255 255 255 255 2 +# Back a step: Opcode's tint again, ModR/M's gone. +key page_up +expect deck.log.len 3 +frames 2 +screenshot .zig-cache/manual/opcode.png +expect-pixel .zig-cache/manual/opcode.png 460 160 255 255 255 255 2 +expect-pixel .zig-cache/manual/opcode.png 300 160 192 233 242 255 3 +key space +await deck.waiting true +key space +await deck.waiting true +key space +await deck.waiting true +key space +await deck.waiting true +# 83 C0 01 written below, where the footnotes were. +key space +await deck.waiting true +screenshot .zig-cache/manual/bytes.png +# Into their fields: ModR/M's label gives way to C0. +key space +await deck.waiting true +screenshot .zig-cache/manual/flown.png +expect-different-screenshot .zig-cache/manual/bytes.png .zig-cache/manual/flown.png 440 140 180 90 +# C0 down into its boxes as bits, then split over Mod, Reg and R/M. +key space +await deck.waiting true +screenshot .zig-cache/manual/bits.png +expect-pixel .zig-cache/manual/bits.png 527 185 255 255 255 255 2 +key space +await deck.waiting true +screenshot .zig-cache/manual/split.png +expect-different-screenshot .zig-cache/manual/bits.png .zig-cache/manual/split.png 280 420 310 70 +expect deck.log.len 11 +# Back to the page, filled in: the end of slide 1. +key space +await deck.waiting true +expect deck.log.len 12 +expect deck.slide 1 +screenshot .zig-cache/manual/end.png +expect-different-screenshot .zig-cache/manual/page.png .zig-cache/manual/end.png 470 260 340 120 +# Slide 2: ADD's page, its opcode table out of it. +key space +await deck.waiting true +expect deck.slide 2 +expect deck.log.len 13 +screenshot .zig-cache/manual/add.png +expect-pixel .zig-cache/manual/add.png 640 300 255 255 255 255 2 +# The table, written in row by row. +key space +await deck.waiting true +screenshot .zig-cache/manual/table.png +expect-different-screenshot .zig-cache/manual/add.png .zig-cache/manual/table.png 415 90 445 310 +# Onto the row 80 /0 ib, then its opcode cell tinted. +key space +await deck.waiting true +screenshot .zig-cache/manual/row.png +expect-pixel .zig-cache/manual/row.png 230 362 255 255 255 255 2 +key space +await deck.waiting true +screenshot .zig-cache/manual/cell.png +expect-pixel .zig-cache/manual/cell.png 230 362 192 233 242 255 3 +# The digit after the slash becomes SUB's 5, closer in; back a step is the +# picture before it (the bar under it aside: it shows the time). +key space +await deck.waiting true +expect deck.log.len 17 +screenshot .zig-cache/manual/digit.png +expect-different-screenshot .zig-cache/manual/cell.png .zig-cache/manual/digit.png 0 0 1280 680 +key page_up +expect deck.log.len 16 +frames 2 +screenshot .zig-cache/manual/undone.png +expect-same-screenshot .zig-cache/manual/cell.png .zig-cache/manual/undone.png 2 0 0 1280 680 +key space +await deck.waiting true +expect deck.log.len 17 +# The rest of the row follows, on SUB's page. +key space +await deck.waiting true +screenshot .zig-cache/manual/sub.png +expect-different-screenshot .zig-cache/manual/digit.png .zig-cache/manual/sub.png 0 0 1280 680 +# ADD's row over SUB's, what differs marked: the end of the talk. +key space +frames 240 +expect deck.log.len 19 +expect deck.waiting false +screenshot .zig-cache/manual/rows.png +expect-pixel .zig-cache/manual/rows.png 75 300 251 236 183 255 3 +expect-pixel .zig-cache/manual/rows.png 962 357 251 236 183 255 3 +# Exported ({a}, {b}: 10 fps, half size), each step held 1.5 s: the same +# frames twice, and the talk moves through them (Figure 2-1 at 4, 20 and +# 34 s; ADD's table being written at 45, its digit morphing at 56.5, the two +# rows at the end, 66). +expect-same-screenshot {a}/000040.png {b}/000040.png +expect-same-screenshot {a}/000200.png {b}/000200.png +expect-same-screenshot {a}/000340.png {b}/000340.png +expect-same-screenshot {a}/000450.png {b}/000450.png +expect-same-screenshot {a}/000565.png {b}/000565.png +expect-same-screenshot {a}/000660.png {b}/000660.png +expect-different-screenshot {a}/000040.png {a}/000200.png +expect-different-screenshot {a}/000200.png {a}/000340.png +expect-different-screenshot {a}/000340.png {a}/000450.png +expect-different-screenshot {a}/000450.png {a}/000565.png +expect-different-screenshot {a}/000565.png {a}/000660.png diff --git a/test/past.script b/test/past.script new file mode 100644 index 0000000..8ac9c25 --- /dev/null +++ b/test/past.script @@ -0,0 +1,8 @@ +# Session 0 of test-past (see build.zig): pointer driven, a mark at frame +# 30, a jump (`set`) at frame 60, 300 frames in all. +move 300 200 +frames 29 +console save probe +frames 29 +console set velocity[0] 5 +frames 240 diff --git a/test/past_diverged.script b/test/past_diverged.script new file mode 100644 index 0000000..6d275a2 --- /dev/null +++ b/test/past_diverged.script @@ -0,0 +1,6 @@ +# Session 0, replayed by a build whose pointer chase differs: it diverges +# before the mark and is put back on it. +console play session 0 +expect-log was built from +frames 40 +expect-log diverged before frame 30 diff --git a/test/past_replay.script b/test/past_replay.script new file mode 100644 index 0000000..0f11c64 --- /dev/null +++ b/test/past_replay.script @@ -0,0 +1,12 @@ +# Session 0 again, by the same build: from its start, half a second in is +# the mark's State exactly; two seconds in, from the jump's keyframe, is +# frame 120's. +console play session 0 +console seek 499 +expect-snapshot probe +expect-no-log diverged +console play session 0 at 2 +expect updates 121 +console pause +frames 30 +expect-no-log diverged diff --git a/test/reload.script b/test/reload.script index d2b2b36..72d1571 100644 --- a/test/reload.script +++ b/test/reload.script @@ -17,7 +17,9 @@ expect clicks 2 expect label warm console snapshot 3 console save +console set retired 3.5 load {v2} +expect-key before_reload retired 3.5 expect clicks 2 expect label warm expect streak 7 ~0.5 diff --git a/test/same_sessions.zig b/test/same_sessions.zig new file mode 100644 index 0000000..af13be0 --- /dev/null +++ b/test/same_sessions.zig @@ -0,0 +1,66 @@ +//! test-same (build.zig): `same_sessions A B` exits 0 when two sessions +//! databases hold the same values apart from the wall clock's (a session's +//! `started` and `ended`), and otherwise names the first that differs. +const std = @import("std"); +const Sessions = @import("Sessions"); +const DB = Sessions.Disk; +const Cursor = DB.Cursor(.read_only); + +pub fn main(init: std.process.Init) !void { + const io = init.io; + const gpa = init.arena.allocator(); + var args = init.minimal.args.iterate(); + _ = args.skip(); + var dbs: [2]DB = undefined; + var buffers: [2]std.Io.Writer.Allocating = undefined; + for (&dbs, &buffers) |*db, *buffer| { + const file = try std.Io.Dir.cwd().openFile(io, args.next() orelse return error.Usage, .{}); + buffer.* = .init(gpa); + db.* = try DB.init(io, .{ .file = file, .buffer = buffer, .fsync = false }); + } + if (!try same(gpa, dbs[0].rootCursor().readOnly(), dbs[1].rootCursor().readOnly(), "root")) std.process.exit(1); +} + +fn same(gpa: std.mem.Allocator, a: Cursor, b: Cursor, at: []const u8) anyerror!bool { + const tag = (try a.slot()).tag; + if (tag != (try b.slot()).tag) return differ(at, "kinds"); + switch (tag) { + .uint => if (try a.readUint() != try b.readUint()) return differ(at, "numbers"), + .bytes, .short_bytes => { + if (!std.mem.eql(u8, try a.readBytesAlloc(gpa, null), try b.readBytesAlloc(gpa, null))) return differ(at, "bytes"); + }, + .array_list => { + if (try a.count() != try b.count()) return differ(at, "lengths"); + var ia = try a.iterator(); + var ib = try b.iterator(); + var i: usize = 0; + while (try ia.next()) |ca| : (i += 1) { + if (!try same(gpa, ca, (try ib.next()).?, try std.fmt.allocPrint(gpa, "{s}[{d}]", .{ at, i }))) return false; + } + }, + .hash_map => { + const mb = try DB.HashMap(.read_only).init(b); + var n: usize = 0; + var ia = try a.iterator(); + while (try ia.next()) |kv_cursor| { + const kv = try kv_cursor.readKeyValuePair(); + n += 1; + const name = if (std.enums.fromInt(Sessions.K, kv.hash)) |k| @tagName(k) else "?"; + const there = try std.fmt.allocPrint(gpa, "{s}.{s}", .{ at, name }); + const cb = try mb.getCursor(kv.hash) orelse return differ(there, "presence"); + if (std.mem.eql(u8, name, "started") or std.mem.eql(u8, name, "ended")) continue; + if (!try same(gpa, kv.value_cursor, cb, there)) return false; + } + var ib = try b.iterator(); + while (try ib.next()) |_| n -%= 1; + if (n != 0) return differ(at, "fields"); + }, + else => return differ(at, "kinds (unknown)"), + } + return true; +} + +fn differ(at: []const u8, what: []const u8) bool { + std.debug.print("same_sessions: the databases' {s} differ at {s}\n", .{ what, at }); + return false; +} diff --git a/test/scene_compiled.script b/test/scene_compiled.script index 3c9ef44..df2d62f 100644 --- a/test/scene_compiled.script +++ b/test/scene_compiled.script @@ -2,7 +2,7 @@ # 30 fps, 640x360, so half size, played once without the player's controls). frames 30 screenshot .zig-cache/anim/compiled-written.png -console set t 1.5 +console set deck.t 1.5 frames 1 screenshot .zig-cache/anim/compiled-morph.png # Frame 68 is 2.27 s in: the dot over the panel's corner, at half size. diff --git a/test/scene_live.script b/test/scene_live.script index 30b2087..e480d8d 100644 --- a/test/scene_live.script +++ b/test/scene_live.script @@ -1,6 +1,9 @@ -# The live test scene, through the player. It holds at the pause. +# The live test scene, through the player. At the pause it waits for a +# click, time running on and nothing after the pause starting. frames 150 -expect t 2 +expect deck.waiting true +expect deck.t 2.5 ~0.02 +expect deck.log.len 0 screenshot .zig-cache/anim/live.png # The custom panel is over the circle added before it, expect-pixel .zig-cache/anim/live.png 600 330 32 64 96 255 1 @@ -11,23 +14,25 @@ expect-pixel .zig-cache/anim/live.png 725 400 131 193 103 255 1 expect-pixel .zig-cache/anim/live.png 600 390 240 172 95 255 1 expect-pixel .zig-cache/anim/live.png 680 390 32 64 96 255 1 # Half way through its move it is half way. -console set playing false -console set t 1.5 +console set deck.playing false +console set deck.t 1.5 screenshot .zig-cache/anim/live-moving.png expect-pixel .zig-cache/anim/live-moving.png 400 330 32 64 96 255 1 expect-pixel .zig-cache/anim/live-moving.png 600 330 252 98 85 255 1 # The CPU renderer layers the same way. -console set t 2 +console set deck.t 2 key b expect backend cpu screenshot .zig-cache/anim/live-cpu.png expect-pixel .zig-cache/anim/live-cpu.png 600 330 32 64 96 255 1 expect-pixel .zig-cache/anim/live-cpu.png 725 400 131 193 103 255 1 key b -# A click continues: the camera zooms to 2 and the panel fades to half, -# over the background where it now reaches. +# A click opens the pause and plays on: the camera zooms to 2 and the +# panel fades to half, over the background where it now reaches. click 640 360 -expect playing true +expect deck.playing true +expect deck.log.len 1 +expect deck.waiting false frames 70 screenshot .zig-cache/anim/live-zoom.png expect-pixel .zig-cache/anim/live-zoom.png 800 300 30 46 64 255 2 diff --git a/test/scene_morph.script b/test/scene_morph.script new file mode 100644 index 0000000..0da4670 --- /dev/null +++ b/test/scene_morph.script @@ -0,0 +1,46 @@ +# Holes through morphs (test/scene_morph.zig), a quarter, half and three +# quarters of the way, on the GPU and then on the CPU: the middle of each +# hole is the background, the ring around it drawn (the 0 into the 5 while +# its hole is half its size or more); at the end the disc fills it. +console set deck.playing false +console set deck.t 1 +screenshot .zig-cache/anim/morph-1.png +expect-pixel .zig-cache/anim/morph-1.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-1.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-1.png 640 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-1.png 1040 360 28 28 31 255 1 +console set deck.t 2 +screenshot .zig-cache/anim/morph-2.png +expect-pixel .zig-cache/anim/morph-2.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-2.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-2.png 640 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-2.png 1040 360 28 28 31 255 1 +console set deck.t 3 +screenshot .zig-cache/anim/morph-3.png +expect-pixel .zig-cache/anim/morph-3.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-3.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-3.png 1040 360 28 28 31 255 1 +key b +expect backend cpu +console set deck.t 1 +screenshot .zig-cache/anim/morph-cpu-1.png +expect-pixel .zig-cache/anim/morph-cpu-1.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-cpu-1.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-cpu-1.png 640 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-cpu-1.png 1040 360 28 28 31 255 1 +console set deck.t 2 +screenshot .zig-cache/anim/morph-cpu-2.png +expect-pixel .zig-cache/anim/morph-cpu-2.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-cpu-2.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-cpu-2.png 640 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-cpu-2.png 1040 360 28 28 31 255 1 +console set deck.t 3 +screenshot .zig-cache/anim/morph-cpu-3.png +expect-pixel .zig-cache/anim/morph-cpu-3.png 300 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-cpu-3.png 240 360 28 28 31 255 1 +expect-pixel .zig-cache/anim/morph-cpu-3.png 1040 360 28 28 31 255 1 +console set deck.t 4 +screenshot .zig-cache/anim/morph-cpu-4.png +expect-pixel .zig-cache/anim/morph-cpu-4.png 240 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-cpu-4.png 640 360 255 255 255 255 1 +expect-pixel .zig-cache/anim/morph-cpu-4.png 1040 360 28 28 31 255 1 diff --git a/test/scene_morph.zig b/test/scene_morph.zig new file mode 100644 index 0000000..fbde51d --- /dev/null +++ b/test/scene_morph.zig @@ -0,0 +1,25 @@ +//! Holes through a morph (vector/morph.zig), for test/scene_morph.script: +//! a ring into a disc, a 0 into a 5, and a 0 whose path has its hole first +//! into a ring, side by side, together over 4 s at a steady pace. +const anim = @import("anim"); + +pub const scene = anim.Scene(construct); + +const disc = "M 40 0 C 40 22 22 40 0 40 C -22 40 -40 22 -40 0 C -40 -22 -22 -40 0 -40 C 22 -40 40 -22 40 0 Z "; +const ring_hole = "M 20 0 C 20 -11 11 -20 0 -20 C -11 -20 -20 -11 -20 0 C -20 11 -11 20 0 20 C 11 20 20 11 20 0 Z "; +const zero = "M 0 -45 C 25 -45 30 -20 30 0 C 30 20 25 45 0 45 C -25 45 -30 20 -30 0 C -30 -20 -25 -45 0 -45 Z "; +const zero_hole = "M 0 -25 C -12 -25 -14 -12 -14 0 C -14 12 -12 25 0 25 C 12 25 14 12 14 0 C 14 -12 12 -25 0 -25 Z "; +const five = "M -25 -45 H 25 V -33 H -13 V -8 H 5 L 20 -3 L 28 10 V 25 L 20 40 L 5 45 H -25 V 33 H 5 L 14 25 V 10 L 5 4 H -25 Z "; + +const head = "<svg viewBox=\"-50 -50 100 100\" width=\"100\" height=\"100\"><path fill=\"white\" d=\""; +const tail = "\"/></svg>"; + +fn construct(s: *anim.Builder) void { + const pairs = .{ .{ disc ++ ring_hole, disc, -400 }, .{ zero ++ zero_hole, five, 0 }, .{ zero_hole ++ zero, disc ++ ring_hole, 400 } }; + var morphs: [pairs.len]anim.Animation = undefined; + inline for (pairs, &morphs) |p, *m| { + const from = s.svg(head ++ p[0] ++ tail, .{ .x = p[2], .scale = 2, .visible = true }); + m.* = from.transformInto(s.svg(head ++ p[1] ++ tail, .{ .x = p[2], .scale = 2 })); + } + s.play(morphs, .{ .seconds = 4, .ease = anim.ease.linear }); +} diff --git a/test/session_export.script b/test/session_export.script new file mode 100644 index 0000000..a90587e --- /dev/null +++ b/test/session_export.script @@ -0,0 +1,3 @@ +# test-import (see build.zig): session 0 of test/past.script's database, +# written to a file of its own, as a playtester would send it. +console export-session 0 {file} diff --git a/test/session_import.script b/test/session_import.script new file mode 100644 index 0000000..bcc3126 --- /dev/null +++ b/test/session_import.script @@ -0,0 +1,13 @@ +# test-import: the session test/session_export.script wrote, imported into +# another database as its session 1, plays there as it did where it was +# recorded: half a second in is the mark's State exactly (the mark came +# with it, renamed), two seconds in is frame 120's. +console import {file} +console sessions +expect-log import one.xitdb +console play session 1 +console seek 499 +expect-snapshot [email protected] +expect-no-log diverged +console play session 1 at 2 +expect updates 121 diff --git a/test/svg/image.svg b/test/svg/image.svg new file mode 100644 index 0000000..f5a5d8e --- /dev/null +++ b/test/svg/image.svg @@ -0,0 +1,9 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 100" width="200" height="100"> + <!-- SVG documents as data-URI images (how Typst places an SVG or a PDF + page): placed, stretched or fitted into their boxes, with their own ids + and gradients, and an id the outer document also uses. --> + <defs><radialGradient id="g"><stop offset="0" stop-color="#58c4dd"/><stop offset="1" stop-color="#9a72ac"/></radialGradient></defs> + <rect x="150" y="10" width="40" height="80" fill="url(#g)"/> + <image x="10" y="10" width="40" height="80" xlink:href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNDAgNDAiIHdpZHRoPSI0MHB0IiBoZWlnaHQ9IjQwcHQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgo8ZGVmcz48cmFkaWFsR3JhZGllbnQgaWQ9ImciPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2Y3ZDk2ZiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2ZjNjI1NSIvPjwvcmFkaWFsR3JhZGllbnQ+CjxzeW1ib2wgaWQ9ImxlYWYiIG92ZXJmbG93PSJ2aXNpYmxlIj48cGF0aCBkPSJNMCAwIEM4IC04IDE2IC04IDIwIDAgQzE2IDggOCA4IDAgMFoiLz48L3N5bWJvbD48L2RlZnM+CjxjaXJjbGUgY3g9IjIwIiBjeT0iMjAiIHI9IjE4IiBmaWxsPSJ1cmwoI2cpIi8+Cjx1c2UgeGxpbms6aHJlZj0iI2xlYWYiIHg9IjEwIiB5PSIyMCIgZmlsbD0iIzgzYzE2NyIvPgo8L3N2Zz4="/> + <image x="55" y="20" width="90" height="60" preserveAspectRatio="none" href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNDAgNDAiIHdpZHRoPSI0MHB0IiBoZWlnaHQ9IjQwcHQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPgo8ZGVmcz48cmFkaWFsR3JhZGllbnQgaWQ9ImciPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2Y3ZDk2ZiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI2ZjNjI1NSIvPjwvcmFkaWFsR3JhZGllbnQ+CjxzeW1ib2wgaWQ9ImxlYWYiIG92ZXJmbG93PSJ2aXNpYmxlIj48cGF0aCBkPSJNMCAwIEM4IC04IDE2IC04IDIwIDAgQzE2IDggOCA4IDAgMFoiLz48L3N5bWJvbD48L2RlZnM+CjxjaXJjbGUgY3g9IjIwIiBjeT0iMjAiIHI9IjE4IiBmaWxsPSJ1cmwoI2cpIi8+Cjx1c2UgeGxpbms6aHJlZj0iI2xlYWYiIHg9IjEwIiB5PSIyMCIgZmlsbD0iIzgzYzE2NyIvPgo8L3N2Zz4=" transform="rotate(10 100 50)"/> +</svg> diff --git a/test/svg/typst-image.typ b/test/svg/typst-image.typ new file mode 100644 index 0000000..2c88207 --- /dev/null +++ b/test/svg/typst-image.typ @@ -0,0 +1,6 @@ +// An SVG placed by Typst: an <image> with the document as a data URI. +#set page(width: auto, height: auto, margin: 6pt, fill: none) +#stack(dir: ltr, spacing: 8pt, + image("use.svg", width: 120pt), + image("gradients.svg", width: 80pt, height: 60pt, fit: "stretch"), +) diff --git a/test/talk.script b/test/talk.script new file mode 100644 index 0000000..e123d59 --- /dev/null +++ b/test/talk.script @@ -0,0 +1,104 @@ +# The talk example (examples/talk.zig): a Deck in the sketch's own State, +# stepped by the clicks and keys the sketch turns into asks. +frames 90 +expect deck.waiting false +expect deck.slide 1 +# Slide 2 lies after the choice, which has not been made. +expect deck.slides 1 +# A click during the first step finishes it: held at the first pause. +click 100 100 +expect deck.t 2.5 ~0.0001 +expect deck.waiting true +expect deck.log.len 0 +# The mass bobs while the deck waits. +screenshot .zig-cache/talk/bob-a.png +frames 14 +screenshot .zig-cache/talk/bob-b.png +expect-different-screenshot .zig-cache/talk/bob-a.png .zig-cache/talk/bob-b.png +# The next click opens the pause where it lands: the slider comes in, and +# the deck waits at the choice. +click 100 100 +expect deck.log.len 1 +expect deck.log.buffer[0].wait 0.2833 ~0.001 +await deck.waiting true +frames 5 +# Reloaded mid-wait, the first step retimed from 2 s to 3: the same step, +# as far into it, a second later. +console set deck.playing false +expect deck.t 3.4833 ~0.001 +load {v2} +expect deck.t 4.4833 ~0.001 +expect deck.waiting true +expect deck.log.len 1 +expect deck.log.buffer[0].wait 0.2833 ~0.001 +console set deck.playing true +# A click on the slider is the slider's: zeta goes there, the deck stays. +click 790 580 +expect app.zeta 1.5 ~0.01 +expect deck.log.len 1 +expect deck.waiting true +# So is a drag along it, let go and all. +down 640 580 +move 400 580 +up 400 580 +expect app.zeta 0.2 ~0.01 +expect app.dragging false +expect deck.log.len 1 +expect deck.waiting true +# Going on chooses by the slider: under 1, it rings; slide 2 is laid. +key space +expect deck.log.len 2 +expect deck.log.buffer[1].value 0 +expect deck.slides 2 +frames 90 +screenshot .zig-cache/talk/rings.png +# Back: held at the choice again; over 1, it creeps. +key page_up +expect deck.log.len 1 +expect deck.waiting true +click 840 580 +expect app.zeta 1.667 ~0.01 +key space +expect deck.log.len 2 +expect deck.log.buffer[1].value 1 +frames 90 +screenshot .zig-cache/talk/creeps.png +expect-different-screenshot .zig-cache/talk/rings.png .zig-cache/talk/creeps.png +# Slide 2 at rest: it holds no pause, so its end. +key right_bracket +expect deck.slide 2 +expect deck.log.len 3 +expect deck.waiting false +# Back a slide: slide 1 at rest, held at its first pause (3 s of writing +# in this build, then the mass). +key left_bracket +expect deck.slide 1 +expect deck.log.len 0 +expect deck.t 3.5 ~0.0001 +expect deck.waiting true +# Recorded, clicks, the slider and keys replay to the same State: the deck +# opens gates in update, from events and State alone. +console record 0 +click 100 100 +frames 40 +click 790 580 +key space +frames 30 +key page_up +key right_bracket +frames 10 +console save 2 +console play 0 +frames 120 +expect-snapshot 2 +console stop +# Exported ({a}, {b}: 30 fps, half size), each gate holds 2 s: the mass +# bobs through the first hold (to 4.5 s), nothing moves at the choice +# (5.1 to 7.1 s), and the verdict writes after it. Twice, the same frames. +expect-different-screenshot {a}/000080.png {a}/000090.png +expect-different-screenshot {a}/000130.png {a}/000170.png +expect-same-screenshot {a}/000170.png {a}/000200.png +expect-different-screenshot {a}/000200.png {a}/000230.png +expect-same-screenshot {a}/000080.png {b}/000080.png +expect-same-screenshot {a}/000230.png {b}/000230.png +expect-same-screenshot {a}/000350.png {b}/000350.png diff --git a/test/text.script b/test/text.script index 776cc41..2ed0b29 100644 --- a/test/text.script +++ b/test/text.script @@ -19,3 +19,11 @@ expect-pixel .zig-cache/text/native.png 127 256 16 16 16 255 # ligatures: twelve characters at scale 2 are 192 px, on its own taller line. expect-pixel .zig-cache/text/native.png 200 275 32 64 96 255 expect-pixel .zig-cache/text/native.png 206 290 16 16 16 255 +# A paragraph (sk.text) wrapped at 200 and centred: three lines, the last +# with "twice" at twice the size, 16 + 16 + 31 px tall from y 175; the caret +# its Layout gives before "twice" is that line's height, at x 440. +expect-pixel .zig-cache/text/native.png 425 237 32 64 96 255 +expect-pixel .zig-cache/text/native.png 425 238 16 16 16 255 +expect-pixel .zig-cache/text/native.png 440 207 255 255 0 255 +expect-pixel .zig-cache/text/native.png 440 237 255 255 0 255 +expect-pixel .zig-cache/text/native.png 440 206 32 64 96 255 diff --git a/test/text.zig b/test/text.zig index d0e0eea..f60f13a 100644 --- a/test/text.zig +++ b/test/text.zig @@ -36,4 +36,13 @@ pub fn draw(f: *sk.Frame) void { if (line.raster > 0) f.textScaled(line.face, 10 * k, y, line.scale * k, line.raster * k, line.text, 0xffffff) else f.textIn(line.face, 10 * k, y, line.scale * k, line.text, 0xffffff); y += size[1] + 6 * k; } + // A paragraph (sk.text): wrapped at 200, centred, a span in red and + // one twice the size, its box from sk.text.layout and a caret drawn + // before "twice" from the Layout it returns. + const words = "Centred, wrapped at spaces, in red and twice the size."; + const p: sk.text.Paragraph = .{ .width = 200 * k, .@"align" = .center, .scale = k, .spans = &.{ .{ .start = 31, .color = .{ .r = 255, .g = 80, .b = 80 } }, .{ .start = 35 }, .{ .start = 39, .scale = 2 * k }, .{ .start = 44 } }, .caret = 39 }; + const l = sk.text.layout(words, p); + f.fill(sk.Rect{ .x = 420 * k, .y = 175 * k, .w = 200 * k, .h = l.h }, 0x204060); + const drawn = f.paragraph(420 * k, 175 * k, words, p); + f.fill(sk.Rect{ .x = drawn.caret.x, .y = drawn.caret.y, .w = k, .h = drawn.caret.h }, 0xffff00); } diff --git a/test/voices.script b/test/voices.script new file mode 100644 index 0000000..4b444d0 --- /dev/null +++ b/test/voices.script @@ -0,0 +1,29 @@ +# A sound made with host.newSound is a voice like a loaded one: it sounds +# once for its serial, a replay that keeps declaring that serial does not +# sound it again, and a new serial does. +frames 3 +expect-no-audio 1 +key space +expect coins 1 +expect-audio 1 +frames 10 +expect-no-audio 1 +# Recorded while the blip is declared but finished, then played back, +# stepped and seeked over: the same serial all along, so it stays silent. +console record 0 +frames 20 +console stop +console play 0 +frames 30 +expect-no-audio 1 +console seek start +console step 5 +console seek end +expect-no-audio 1 +console stop +# A new serial starts it again. +key space +expect coins 2 +expect-audio 1 +frames 10 +expect-no-audio 1 diff --git a/test/voices.zig b/test/voices.zig new file mode 100644 index 0000000..141e562 --- /dev/null +++ b/test/voices.zig @@ -0,0 +1,26 @@ +//! A sound the sketch made itself, played as a voice: space bumps the +//! serial that starts it (test/voices.script). The README's sfxr blip. +const sk = @import("sketch"); + +pub const name = "voices"; +pub const width = 160; +pub const height = 120; + +pub const State = struct { coins: u32 = 0 }; +pub const Session = struct { blip: sk.Audio = .none }; + +pub fn update(s: *State, in: *const sk.Input) void { + if (in.pressed(sk.Key.space)) s.coins += 1; +} + +pub fn draw(s: *const State, ss: *Session, f: *sk.Frame) void { + f.clear(0x202020); + // About 1300 samples: shorter than the host's lead (2048), so the first + // frame that declares it mixes all of it. + if (ss.blip == .none) { + var buf: [4096]f32 = undefined; + const n = sk.sfxr.render(.{ .freq = 0.5, .sustain = 0.05, .decay = 0.1 }, f.in.sample_rate, &buf); + ss.blip = f.host.newSound(buf[0..n]); + } + if (s.coins != 0) f.voice(.{ .key = 1, .audio = ss.blip, .serial = s.coins }); +} |
