Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

test(x11): check ZRLE decoding against real Xvnc output

ExTv2362087fec51
diff --git a/app/src/test/java/com/excp/podroid/x11/ZrleFixtureTest.kt b/app/src/test/java/com/excp/podroid/x11/ZrleFixtureTest.kt
new file mode 100644
index 0000000..4cecaaa
--- /dev/null
+++ b/app/src/test/java/com/excp/podroid/x11/ZrleFixtureTest.kt
@@ -0,0 +1,58 @@
+/*
+ * Podroid - Rootless Podman for Android
+ * Copyright (C) 2024-2026 Podroid contributors
+ */
+package com.excp.podroid.x11
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+import org.junit.Test
+import java.io.ByteArrayInputStream
+import java.nio.ByteBuffer
+import java.security.MessageDigest
+
+/**
+ * Decodes real Xvnc ZRLE captures through [VncClient.readFramebufferUpdate] and checks
+ * the region against the SHA-256 of the same region decoded from a Raw capture.
+ * Fixture format and hash layout are described in resources/x11/manifest.txt.
+ */
+class ZrleFixtureTest {
+
+ private fun resource(name: String): ByteArray =
+ requireNotNull(javaClass.getResourceAsStream("/x11/$name")) { "missing test resource x11/$name" }
+ .use { it.readBytes() }
+
+ private fun regionSha256(fb: IntArray, stride: Int, x: Int, y: Int, w: Int, h: Int): String {
+ val md = MessageDigest.getInstance("SHA-256")
+ val px = ByteBuffer.allocate(4)
+ for (row in y until y + h) for (col in x until x + w) {
+ px.clear(); px.putInt(fb[row * stride + col]); md.update(px.array())
+ }
+ return md.digest().joinToString("") { "%02x".format(it) }
+ }
+
+ @Test fun `every ZRLE fixture decodes to the Raw capture's pixels`() {
+ val entries = resource("manifest.txt").toString(Charsets.UTF_8).lines()
+ .filter { it.isNotBlank() && !it.startsWith("#") }
+ assertTrue("manifest lists no fixtures", entries.isNotEmpty())
+ for (entry in entries) {
+ val fields = entry.split(' ')
+ val file = fields[0]
+ val expected = fields.first { it.startsWith("sha256=") }.removePrefix("sha256=")
+
+ val bytes = resource(file)
+ assertEquals("$file magic", "PDRF", String(bytes, 0, 4, Charsets.US_ASCII))
+ val hdr = ByteBuffer.wrap(bytes, 4, 12)
+ val fbW = hdr.short.toInt() and 0xFFFF; val fbH = hdr.short.toInt() and 0xFFFF
+ val rx = hdr.short.toInt() and 0xFFFF; val ry = hdr.short.toInt() and 0xFFFF
+ val rw = hdr.short.toInt() and 0xFFFF; val rh = hdr.short.toInt() and 0xFFFF
+
+ val fb = IntArray(fbW * fbH)
+ val inp = ByteArrayInputStream(bytes, 16, bytes.size - 16)
+ val zrle = ZrleDecoder()
+ while (inp.available() > 0) VncClient.readFramebufferUpdate(inp, fb, fbW, zrle)
+
+ assertEquals("$file region hash", expected, regionSha256(fb, fbW, rx, ry, rw, rh))
+ }
+ }
+}
diff --git a/app/src/test/resources/x11/desktop_0_0_1280x720.zrle.bin b/app/src/test/resources/x11/desktop_0_0_1280x720.zrle.bin
new file mode 100644
index 0000000..9fc706c
Binary files /dev/null and b/app/src/test/resources/x11/desktop_0_0_1280x720.zrle.bin differ
diff --git a/app/src/test/resources/x11/desktop_0_0_256x256.zrle.bin b/app/src/test/resources/x11/desktop_0_0_256x256.zrle.bin
new file mode 100644
index 0000000..b8733f4
Binary files /dev/null and b/app/src/test/resources/x11/desktop_0_0_256x256.zrle.bin differ
diff --git a/app/src/test/resources/x11/desktop_0_232_256x256.zrle.bin b/app/src/test/resources/x11/desktop_0_232_256x256.zrle.bin
new file mode 100644
index 0000000..8e46fb1
Binary files /dev/null and b/app/src/test/resources/x11/desktop_0_232_256x256.zrle.bin differ
diff --git a/app/src/test/resources/x11/desktop_0_464_256x256.zrle.bin b/app/src/test/resources/x11/desktop_0_464_256x256.zrle.bin
new file mode 100644
index 0000000..812047f
Binary files /dev/null and b/app/src/test/resources/x11/desktop_0_464_256x256.zrle.bin differ
diff --git a/app/src/test/resources/x11/image_0_0_256x256.zrle.bin b/app/src/test/resources/x11/image_0_0_256x256.zrle.bin
new file mode 100644
index 0000000..9a460d9
Binary files /dev/null and b/app/src/test/resources/x11/image_0_0_256x256.zrle.bin differ
diff --git a/app/src/test/resources/x11/image_824_853_256x256.zrle.bin b/app/src/test/resources/x11/image_824_853_256x256.zrle.bin
new file mode 100644
index 0000000..fbe6b14
Binary files /dev/null and b/app/src/test/resources/x11/image_824_853_256x256.zrle.bin differ
diff --git a/app/src/test/resources/x11/manifest.txt b/app/src/test/resources/x11/manifest.txt
new file mode 100644
index 0000000..197aa7b
--- /dev/null
+++ b/app/src/test/resources/x11/manifest.txt
@@ -0,0 +1,19 @@
+# ZRLE regression fixtures captured from TigerVNC Xvnc in the Podroid guest.
+#
+# Each .zrle.bin file: magic "PDRF", then big-endian u16 fbW, fbH, regionX, regionY,
+# regionW, regionH, then every server byte after ServerInit (FramebufferUpdate
+# messages) for a fresh connection advertising [ZRLE, Raw] with the 32bpp depth-24
+# little-endian R16 G8 B0 pixel format.
+#
+# sha256 is over the region's ARGB pixels (alpha 0xFF), row-major, each pixel as a
+# 4-byte big-endian int, decoded from the matching Raw capture of the same static
+# scene. subenc lists the ZRLE tile subencodings present in the file.
+#
+# <file> sha256=<hex> subenc=<kinds>
+desktop_0_0_1280x720.zrle.bin sha256=ff176be288d56f0d581d0631be7e9f77708106899560da92091116fc126cee41 subenc=raw,packed5-16
+desktop_0_0_256x256.zrle.bin sha256=449dc9f63fb939c136f6b6a78e0ce2ad6f48b67bd901e05ff718785e32125b1e subenc=raw
+desktop_0_232_256x256.zrle.bin sha256=33aa77243cdb8559e7f8e1388721f850efea376fd2d2c23a2faa4fd392f995f3 subenc=paletteRle
+desktop_0_464_256x256.zrle.bin sha256=acf823b0fca19f0055d8123b91f0898ec04bcfa46d91d9c18673424fa9f1e6ab subenc=packed5-16
+image_0_0_256x256.zrle.bin sha256=3d70f10083404abd81dadcc5c2bd30b8d518647a805489989e1761861d2e8117 subenc=solid
+image_824_853_256x256.zrle.bin sha256=da79e4667db048aa95dfdefa8bc731ee2823a41f77140138b8929c7c198c7754 subenc=raw,packed5-16,paletteRle
+settings_824_853_256x256.zrle.bin sha256=d843a3c50e2b8e73123dd8ec727536b5ae1e3a3e5a4c189e05bfec5062db1277 subenc=raw,packed3-4,paletteRle
diff --git a/app/src/test/resources/x11/settings_824_853_256x256.zrle.bin b/app/src/test/resources/x11/settings_824_853_256x256.zrle.bin
new file mode 100644
index 0000000..e851333
Binary files /dev/null and b/app/src/test/resources/x11/settings_824_853_256x256.zrle.bin differ