diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 708c44db..3afed53b 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -130,13 +130,32 @@ Additionally, if a `.gb` file exists, the output of RGBFIX must match the `.gb`.
### RGBGFX
+There are three kinds of test.
+
+#### Simple tests
+
Each `.png` file corresponds to one test.
RGBGFX will be invoked on the file.
If a `.flags` file exists, it will be used as part of the RGBGFX invocation (@<file>.flags).
+If `.out.1bpp`, `.out.2bpp`, `.out.pal`, `.out.tilemap`, `.out.attrmap`, or `.out.palmap` files exist, RGBGFX will create the corresponding kind of output, which must match the file's contents.
+Multiple kinds of output may be tested for the same input.
+
If no `.err` file exists, RGBGFX is simply expected to be able to process the file normally.
If one *does* exist, RGBGFX's return status is ignored, but its output **must** match the `.err` file's contents.
+#### Reverse tests
+
+Each `.1bpp` or `.2bpp` file corresponds to one test.
+RGBGFX will be invoked on the file with `-r 1` for reverse mode, then invoked on the output without `-r 1`.
+The round-trip output must match the input file's contents.
+If a `.flags` file exists, it will be used as part of the RGBGFX invocation (@<file>.flags).
+
+#### Random seed tests
+
+Each `seed*.bin` file corresponds to one test.
+Each one is a binary RNG file which is passed to the `rgbgfx_test` program.
+
### Downstream projects
1. Make sure the downstream project supports make <target> RGBDS=<path/to/RGBDS/>.
diff --git a/test/gfx/.gitignore b/test/gfx/.gitignore
index 8bc59604..9e948c34 100644
--- a/test/gfx/.gitignore
+++ b/test/gfx/.gitignore
@@ -3,10 +3,11 @@
/rgbgfx_test
# Generated by randtilegen
/out*.png
-/*.rng
-# Generated by the test program
-/result.2bpp
-/result.tilemap
-/result.pal
-/result.attrmap
+# Generated by tests
/result.png
+/result.1bpp
+/result.2bpp
+/result.pal
+/result.tilemap
+/result.attrmap
+/result.palmap
diff --git a/test/gfx/crop.out.2bpp b/test/gfx/crop.out.2bpp
new file mode 100644
index 00000000..362c4da2
Binary files /dev/null and b/test/gfx/crop.out.2bpp differ
diff --git a/test/gfx/crop.out.pal b/test/gfx/crop.out.pal
new file mode 100644
index 00000000..d2d5c908
--- /dev/null
+++ b/test/gfx/crop.out.pal
@@ -0,0 +1 @@
+ÿUÿÿÿÿ
\ No newline at end of file
diff --git a/test/gfx/empty_lines.out.2bpp b/test/gfx/empty_lines.out.2bpp
new file mode 100644
index 00000000..d7ee4c70
Binary files /dev/null and b/test/gfx/empty_lines.out.2bpp differ
diff --git a/test/gfx/empty_lines.out.pal b/test/gfx/empty_lines.out.pal
new file mode 100644
index 00000000..ca034125
--- /dev/null
+++ b/test/gfx/empty_lines.out.pal
@@ -0,0 +1 @@
+ŠlUÿÿÿ
\ No newline at end of file
diff --git a/test/gfx/full_gpl.out.2bpp b/test/gfx/full_gpl.out.2bpp
new file mode 100644
index 00000000..f9610191
Binary files /dev/null and b/test/gfx/full_gpl.out.2bpp differ
diff --git a/test/gfx/full_gpl.out.attrmap b/test/gfx/full_gpl.out.attrmap
new file mode 100644
index 00000000..cb1ce59c
Binary files /dev/null and b/test/gfx/full_gpl.out.attrmap differ
diff --git a/test/gfx/full_gpl.out.pal b/test/gfx/full_gpl.out.pal
new file mode 100644
index 00000000..820ff240
Binary files /dev/null and b/test/gfx/full_gpl.out.pal differ
diff --git a/test/gfx/full_gpl.out.tilemap b/test/gfx/full_gpl.out.tilemap
new file mode 100644
index 00000000..6cf04740
Binary files /dev/null and b/test/gfx/full_gpl.out.tilemap differ
diff --git a/test/gfx/full_hex.out.2bpp b/test/gfx/full_hex.out.2bpp
new file mode 100644
index 00000000..971f04f4
Binary files /dev/null and b/test/gfx/full_hex.out.2bpp differ
diff --git a/test/gfx/full_hex.out.attrmap b/test/gfx/full_hex.out.attrmap
new file mode 100644
index 00000000..4ffd3e60
Binary files /dev/null and b/test/gfx/full_hex.out.attrmap differ
diff --git a/test/gfx/full_hex.out.pal b/test/gfx/full_hex.out.pal
new file mode 100644
index 00000000..4c41e8ff
Binary files /dev/null and b/test/gfx/full_hex.out.pal differ
diff --git a/test/gfx/full_hex.out.tilemap b/test/gfx/full_hex.out.tilemap
new file mode 100644
index 00000000..6cf04740
Binary files /dev/null and b/test/gfx/full_hex.out.tilemap differ
diff --git a/test/gfx/multiple_manual_pals.out.2bpp b/test/gfx/multiple_manual_pals.out.2bpp
new file mode 100644
index 00000000..df01f20b
--- /dev/null
+++ b/test/gfx/multiple_manual_pals.out.2bpp
@@ -0,0 +1 @@
+.]ºtéÒ/¥_K¿
\ No newline at end of file
diff --git a/test/gfx/multiple_manual_pals.out.pal b/test/gfx/multiple_manual_pals.out.pal
new file mode 100644
index 00000000..73c1db78
Binary files /dev/null and b/test/gfx/multiple_manual_pals.out.pal differ
diff --git a/test/gfx/none_round_trip.flags b/test/gfx/none_round_trip.flags
new file mode 100644
index 00000000..9928b9ec
--- /dev/null
+++ b/test/gfx/none_round_trip.flags
@@ -0,0 +1 @@
+-c#none,#fff,#000
diff --git a/test/gfx/test.sh b/test/gfx/test.sh
index 7bd4a47f..8de74318 100755
--- a/test/gfx/test.sh
+++ b/test/gfx/test.sh
@@ -7,7 +7,7 @@ errtmp="$(mktemp)"
# Immediate expansion is the desired behavior.
# shellcheck disable=SC2064
-trap "rm -f ${errtmp@Q}" EXIT
+trap "rm -f ${errtmp@Q} result.{png,1bpp,2bpp,pal,tilemap,attrmap,palmap} out*.png" EXIT
tests=0
failed=0
@@ -37,37 +37,47 @@ failTest () {
echo "${bold}${red}Test ${cmdline} failed!${1:+ (RC=$1)}${rescolors}${resbold}"
}
+checkOutput () {
+ out_rc=0
+ for ext in 1bpp 2bpp pal tilemap attrmap palmap; do
+ if [[ -e "$1.out.$ext" ]]; then
+ cmp "$1.out.$ext" "result.$ext"
+ (( out_rc = out_rc || $? ))
+ fi
+ done
+ return $out_rc
+}
# Draw a random tile offset and VRAM0 size
# Neither should change anything to how the image is displayed
while [[ "$ofs" -eq 0 ]]; do (( ofs = RANDOM % 256 )); done
while [[ "$size" -eq 0 ]]; do (( size = RANDOM % 256 )); done
-for f in *.bin; do
+for f in seed*.bin; do
for flags in ""{," -b $ofs"}{," -N $size,256"}; do
newTest ./rgbgfx_test "$f" $flags
runTest || failTest $?
done
done
-# Test round-tripping '-r' with '-c #none'
-reverse_cmd="$RGBGFX -c#none,#fff,#000 -o none_round_trip.2bpp -r 1 out.png"
-reconvert_cmd="$RGBGFX -c#none,#fff,#000 -o result.2bpp out.png"
-compare_cmd="cmp none_round_trip.2bpp result.2bpp"
-newTest "$reverse_cmd && $reconvert_cmd && $compare_cmd"
-runTest || failTest $?
-
-# Remove temporaries (also ignored by Git) created by the above tests
-rm -f out*.png result.png result.2bpp
-
for f in *.png; do
+ # Do not process outputs of other tests as test inputs themselves
+ if [[ "$f" = result.png ]]; then
+ continue
+ fi
+
flags="$([[ -e "${f%.png}.flags" ]] && echo "@${f%.png}.flags")"
+ for f_ext in o_1bpp o_2bpp p_pal t_tilemap a_attrmap q_palmap; do
+ if [[ -e "${f%.png}.out.${f_ext#*_}" ]]; then
+ flags="$flags -${f_ext%_*} result.${f_ext#*_}"
+ fi
+ done
newTest "$RGBGFX" $flags "$f"
if [[ -e "${f%.png}.err" ]]; then
runTest 2>"$errtmp"
diff -u --strip-trailing-cr "${f%.png}.err" "$errtmp" || failTest
else
- runTest || failTest $?
+ runTest && checkOutput "${f%.png}" || failTest $?
fi
newTest "$RGBGFX" $flags - "<$f"
@@ -75,10 +85,22 @@ for f in *.png; do
runTest 2>"$errtmp"
diff -u --strip-trailing-cr <(sed "s/$f//g" "${f%.png}.err") "$errtmp" || failTest
else
- runTest || failTest $?
+ runTest && checkOutput "${f%.png}" || failTest $?
fi
done
+for f in *.[12]bpp; do
+ # Do not process outputs or sample outputs of other tests as test inputs themselves
+ if [[ "$f" = result.[12]bpp ]] || [[ "$f" = *.out.[12]bpp ]]; then
+ continue
+ fi
+
+ flags="$([[ -e "${f%.[12]bpp}.flags" ]] && echo "@${f%.[12]bpp}.flags")"
+
+ newTest "$RGBGFX $flags -o $f -r 1 result.png && $RGBGFX $flags -o result.2bpp result.png"
+ runTest && cmp "$f" result.2bpp || failTest $?
+done
+
if [[ "$failed" -eq 0 ]]; then
echo "${bold}${green}All ${tests} tests passed!${rescolors}${resbold}"
else