summaryrefslogtreecommitdiff
path: root/test/kitty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/kitty.zig')
-rw-r--r--test/kitty.zig56
1 files changed, 55 insertions, 1 deletions
diff --git a/test/kitty.zig b/test/kitty.zig
index ad70f453..ac407e1a 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -66,7 +66,7 @@ const Rig = struct {
fn init(shells: u8) !Rig {
// f=100 decodes through wuffs, its resize through stb_image_resize,
// which the shells start at launch.
- pardes.TerminalImages.start(std.testing.io, gpa);
+ pardes.TerminalImages.start(gpa);
// ghostty warns of every refused command; the refusals are the point.
std.testing.log_level = .err;
// A core boots one shell or the classic three.
@@ -211,6 +211,60 @@ test "kitty: quiet levels: q=1 drops the OK, q=2 the errors too" {
}
}
+/// A one-row, one-bit grayscale PNG `width` pixels wide, its row stored
+/// uncompressed: a few hundred bytes however wide.
+fn widePng(arena: std.mem.Allocator, width: u32) ![]const u8 {
+ var out: std.ArrayList(u8) = .empty;
+ try out.appendSlice(arena, "\x89PNG\r\n\x1a\n");
+ const chunk = struct {
+ fn add(list: *std.ArrayList(u8), a: std.mem.Allocator, kind: *const [4]u8, data: []const u8) !void {
+ var word: [4]u8 = undefined;
+ std.mem.writeInt(u32, &word, @intCast(data.len), .big);
+ try list.appendSlice(a, &word);
+ const from = list.items.len;
+ try list.appendSlice(a, kind);
+ try list.appendSlice(a, data);
+ std.mem.writeInt(u32, &word, std.hash.Crc32.hash(list.items[from..]), .big);
+ try list.appendSlice(a, &word);
+ }
+ }.add;
+ var ihdr: [13]u8 = .{ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0 };
+ std.mem.writeInt(u32, ihdr[0..4], width, .big);
+ try chunk(&out, arena, "IHDR", &ihdr);
+ // The filter byte and the row, in one stored deflate block.
+ const row = try arena.alloc(u8, 1 + (width + 7) / 8);
+ @memset(row, 0);
+ var idat: std.ArrayList(u8) = .empty;
+ try idat.appendSlice(arena, &.{ 0x78, 0x01, 0x01 });
+ var len: [2]u8 = undefined;
+ std.mem.writeInt(u16, &len, @intCast(row.len), .little);
+ try idat.appendSlice(arena, &len);
+ std.mem.writeInt(u16, &len, ~@as(u16, @intCast(row.len)), .little);
+ try idat.appendSlice(arena, &len);
+ try idat.appendSlice(arena, row);
+ var sum: [4]u8 = undefined;
+ std.mem.writeInt(u32, &sum, std.hash.Adler32.hash(row), .big);
+ try idat.appendSlice(arena, &sum);
+ try chunk(&out, arena, "IDAT", idat.items);
+ try chunk(&out, arena, "IEND", "");
+ return out.items;
+}
+
+test "kitty: a PNG longer than 1280 pixels on a side is kept at 1280" {
+ var r = try Rig.init(1);
+ defer r.deinit();
+ const arena = r.frame.allocator();
+ const png = try widePng(arena, 1300);
+ const payload = try arena.alloc(u8, std.base64.standard.Encoder.calcSize(png.len));
+ _ = std.base64.standard.Encoder.encode(payload, png);
+ r.feed(0, try std.fmt.allocPrint(arena, "\x1b_Ga=T,i=1,f=100,c=2,r=1;{s}\x1b\\", .{payload}));
+ try std.testing.expectEqualStrings(reply("i=1", "OK"), try r.take(0));
+ // Decoded by wuffs at 1300, brought down by stb_image_resize (zstbi).
+ const img = r.storage(0).imageById(1) orelse return error.NotStored;
+ try std.testing.expectEqual(@as(u32, 1280), img.width);
+ try std.testing.expectEqual(@as(u32, 1), img.height);
+}
+
test "kitty: RGB, RGBA, PNG and zlib-compressed RGB all draw the same pixels" {
const Case = struct { control: []const u8, payload: []const u8 };
const cases = [_]Case{