~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/check_length.sh

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env bash
 
2
 
 
3
failed=0
 
4
 
 
5
if test -z $BINDIR ; then
 
6
  BINDIR=drizzled/message
 
7
fi
 
8
 
 
9
check_encode () {
 
10
    bytes=`${BINDIR}/length --hex --encode $1`
 
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 () {
 
20
    bytes=`${BINDIR}/length --encode $value`
 
21
    result=`${BINDIR}/length --decode $bytes`
 
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
 
 
42
exit $failed