#!/bin/sh
set -e

cd "$AUTOPKGTEST_TMP"

for python in $(py3versions -s); do
	"$python" - <<'PY'
import vtracer
import struct
import zlib

assert callable(vtracer.Config)
assert callable(vtracer.convert_file)
assert callable(vtracer.convert_bytes)
assert callable(vtracer.convert_pixels)

width = height = 4
rows = []
for y in range(height):
    pixels = []
    for x in range(width):
        pixels.extend((0, 0, 0, 255) if 1 <= x <= 2 and 1 <= y <= 2
                      else (255, 255, 255, 255))
    rows.append(b"\x00" + bytes(pixels))

raw = b"".join(rows)

def chunk(kind, data):
    return (struct.pack(">I", len(data)) + kind + data +
            struct.pack(">I", zlib.crc32(kind + data) & 0xffffffff))

png = (b"\x89PNG\r\n\x1a\n" +
       chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 6, 0, 0, 0)) +
       chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b""))
svg = vtracer.Config.bw().convert_bytes(png, format="png")
assert "<svg" in svg
assert "</svg>" in svg
PY
done
