tests: Test some corner cases of upkg_decode_index.
[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
42 test_index 4000 0
43 test_index 408000 0
44 test_index 40808000 0
45 test_index 4080808000 0
46
47 # False positives
48 test_index ''
49 test_index 40
50 test_index 4080
51 test_index 408080
52 test_index 40808080
53 test_index 4080808080
54 test_index 408080808000