~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/check_length.sh

  • Committer: Brian Aker
  • Date: 2008-12-15 19:32:58 UTC
  • mfrom: (677.1.2 devel)
  • Revision ID: brian@tangent.org-20081215193258-fsvc1sh9h7a9sb1t
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
failed=0
 
4
 
 
5
check_encode () {
 
6
    bytes=`./length --hex --encode $1`
 
7
    shift
 
8
    expected="$@"
 
9
    if test "$bytes" != "$expected"; then
 
10
        failed=`expr $failed + 1`
 
11
        echo "Got '$bytes' but expected '$expected'"
 
12
    fi
 
13
}
 
14
 
 
15
check_invertible () {
 
16
    bytes=`./length --encode $value`
 
17
    result=`./length --decode $bytes`
 
18
    if test $result -ne $value; then
 
19
        failed=`expr $failed + 1`
 
20
        echo "Got $result but expected $value"
 
21
    fi
 
22
}
 
23
 
 
24
# check that the encoding is correct
 
25
check_encode 2     0x2
 
26
check_encode 255   0xff
 
27
check_encode 256   0x0 0x0 0x1
 
28
check_encode 65535 0x0 0xff 0xff
 
29
 
 
30
# Check that we can decode what we have encoded
 
31
for value in 2 255 256 65535 65536 \
 
32
    `expr 16 "*" 65536` \
 
33
    `expr 16 "*" 65536 + 255`
 
34
do
 
35
    check_invertible $value
 
36
done
 
37
 
 
38
exit `test $failed -gt 0`