]> git.draconx.ca Git - upkg.git/blob - tests/libupkg-index-decode.sh
libupkg: Make decodeindex test accept an empty string.
[upkg.git] / tests / libupkg-index-decode.sh
1 #!/bin/sh
2 #
3 # Check various corner cases of upkg_decode_index.
4 # Copyright © 2012 Nick Bowler
5 #
6 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
7 # This is free software: you are free to do what the fuck you want to.
8 # There is NO WARRANTY, to the extent permitted by law.
9
10 decodeindex=test/decodeindex$EXEEXT
11 scriptname=$0
12
13 test_index() {
14         decode_cmd=`exec 3>&1
15                 { $decodeindex "$1" 3>&-
16                         echo decode_status=$? >&3
17                 } | { read val 3>&-
18                         echo decode_val=$val >&3
19                 }`
20         eval "$decode_cmd"
21
22         case $# in
23         2)
24                 (exit $decode_status) || return 1
25                 if test x"$decode_val" != x"$2"; then
26                         printf '%s: result (%d) does not match expected (%d)\n' \
27                                 "$scriptname" "$decode_val" "$2"
28                         return 1
29                 fi
30                 ;;
31         1)
32                 if (exit $decode_status); then
33                         printf '%s: false positive on (%s), got (%d)\n' \
34                                 "$scriptname" "$1" "$decode_val"
35                         return 1
36                 fi
37                 ;;
38         esac
39 }
40
41 test_index 00 0         || exit 1
42 test_index 4000 0       || exit 1
43 test_index 408000 0     || exit 1
44 test_index 40808000 0   || exit 1
45 test_index 4080808000 0 || exit 1
46
47 # False positives
48 test_index ''           || exit 1
49 test_index 40           || exit 1
50 test_index 4080         || exit 1
51 test_index 408080       || exit 1
52 test_index 40808080     || exit 1
53 test_index 4080808080   || exit 1
54 test_index 408080808000 || exit 1