324.1.1
by Mats Kindahl
Adding specification of a simple protobuf-based binary log format, |
1 |
#!/bin/sh
|
2 |
||
3 |
failed=0 |
|
4 |
||
685.1.31
by Monty Taylor
Updated check_length.sh to work with VPATH. |
5 |
if test -z $BINDIR ; then |
6 |
BINDIR=. |
|
7 |
fi
|
|
8 |
||
324.1.1
by Mats Kindahl
Adding specification of a simple protobuf-based binary log format, |
9 |
check_encode () { |
685.1.31
by Monty Taylor
Updated check_length.sh to work with VPATH. |
10 |
bytes=`${BINDIR}/length --hex --encode $1` |
324.1.1
by Mats Kindahl
Adding specification of a simple protobuf-based binary log format, |
11 |
shift
|
12 |
expected="$@" |
|
13 |
if test "$bytes" != "$expected"; then |
|
14 |
failed=`expr $failed + 1` |
|
15 |
echo "Got '$bytes' but expected '$expected'" |
|
16 |
fi
|
|
17 |
}
|
|
18 |
||
19 |
check_invertible () { |
|
685.1.31
by Monty Taylor
Updated check_length.sh to work with VPATH. |
20 |
bytes=`${BINDIR}/length --encode $value` |
21 |
result=`${BINDIR}/length --decode $bytes` |
|
324.1.1
by Mats Kindahl
Adding specification of a simple protobuf-based binary log format, |
22 |
if test $result -ne $value; then |
23 |
failed=`expr $failed + 1` |
|
24 |
echo "Got $result but expected $value" |
|
25 |
fi
|
|
26 |
}
|
|
27 |
||
28 |
# check that the encoding is correct
|
|
29 |
check_encode 2 0x2
|
|
30 |
check_encode 255 0xff
|
|
31 |
check_encode 256 0x0 0x0 0x1
|
|
32 |
check_encode 65535 0x0 0xff 0xff
|
|
33 |
||
34 |
# Check that we can decode what we have encoded
|
|
35 |
for value in 2 255 256 65535 65536 \ |
|
36 |
`expr 16 "*" 65536` \ |
|
37 |
`expr 16 "*" 65536 + 255` |
|
38 |
do
|
|
39 |
check_invertible $value
|
|
40 |
done
|
|
41 |
||
685.1.31
by Monty Taylor
Updated check_length.sh to work with VPATH. |
42 |
exit $failed |