]> git.draconx.ca Git - upkg.git/blobdiff - tests/libupkg-index-decode.sh
tests: Test some corner cases of upkg_decode_index.
[upkg.git] / tests / libupkg-index-decode.sh
diff --git a/tests/libupkg-index-decode.sh b/tests/libupkg-index-decode.sh
new file mode 100644 (file)
index 0000000..b82bbc9
--- /dev/null
@@ -0,0 +1,54 @@
+#!/bin/sh
+#
+# Check various corner cases of upkg_decode_index.
+# Copyright © 2012 Nick Bowler
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+decodeindex=test/decodeindex$EXEEXT
+scriptname=$0
+
+test_index() {
+       decode_cmd=`exec 3>&1
+               { $decodeindex "$1" 3>&-
+                       echo decode_status=$? >&3
+               } | { read val 3>&-
+                       echo decode_val=$val >&3
+               }`
+       eval "$decode_cmd"
+
+       case $# in
+       2)
+               (exit $decode_status) || return 1
+               if test x"$decode_val" != x"$2"; then
+                       printf '%s: result (%d) does not match expected (%d)\n' \
+                               "$scriptname" "$decode_val" "$2"
+                       return 1
+               fi
+               ;;
+       1)
+               if (exit $decode_status); then
+                       printf '%s: false positive on (%s), got (%d)\n' \
+                               "$scriptname" "$1" "$decode_val"
+                       return 1
+               fi
+               ;;
+       esac
+}
+
+test_index 00 0
+test_index 4000 0
+test_index 408000 0
+test_index 40808000 0
+test_index 4080808000 0
+
+# False positives
+test_index ''
+test_index 40
+test_index 4080
+test_index 408080
+test_index 40808080
+test_index 4080808080
+test_index 408080808000