~ubuntu-branches/ubuntu/saucy/nettle/saucy-proposed

« back to all changes in this revision

Viewing changes to testsuite/sexp-conv-test

  • Committer: Bazaar Package Importer
  • Author(s): Marek Habersack
  • Date: 2004-05-04 15:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20040504155602-7jbhw5mabvwksl3j
Tags: upstream-1.10
ImportĀ upstreamĀ versionĀ 1.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
 
 
3
if [ -z "$srcdir" ] ; then
 
4
  srcdir=`pwd`
 
5
fi
 
6
 
 
7
# echo -n is not portable
 
8
 
 
9
if [ "`echo -n ''`" = "" ]; then
 
10
    n='-n'; c=''
 
11
elif [ "`echo '\c'`" = "" ]; then
 
12
    n=''; c='\c'
 
13
else
 
14
    echo >&2 'Neither echo -n nor echo \c seems to work.'
 
15
    exit 1
 
16
fi
 
17
 
 
18
# Doesn't work if $1 contains 
 
19
print_raw () {
 
20
    echo $n "$1$c" > "$2"
 
21
}
 
22
 
 
23
# Using a here-document seems more robust. However, I don't know how
 
24
# to get rid of the final newline, so we can't use it exclusively.
 
25
print_nl () {
 
26
    cat >"$2" <<EOF
 
27
$1
 
28
EOF
 
29
}
 
30
 
 
31
test_advanced () {
 
32
    print_raw "$1" test.in
 
33
    if ../tools/sexp-conv -s advanced <test.in >test1.out ; then
 
34
        true
 
35
    else
 
36
        exit 1
 
37
    fi
 
38
    print_nl "$2" test2.out
 
39
 
 
40
    if cmp test1.out test2.out ; then
 
41
        true
 
42
    else
 
43
        exit 1;
 
44
    fi
 
45
}
 
46
 
 
47
test_advanced_hex () {
 
48
    print_raw "$1" test.in
 
49
    if ../tools/sexp-conv -s hex <test.in >test1.out ; then
 
50
        true
 
51
    else
 
52
        exit 1
 
53
    fi
 
54
    print_nl "$2" test2.out
 
55
 
 
56
    if cmp test1.out test2.out ; then
 
57
        true
 
58
    else
 
59
        exit 1;
 
60
    fi
 
61
}
 
62
 
 
63
test_transport () {
 
64
    print_raw "$1" test.in
 
65
    if ../tools/sexp-conv -s transport <test.in >test1.out ; then
 
66
        true
 
67
    else
 
68
        exit 1
 
69
    fi
 
70
    print_nl "$2" test2.out
 
71
 
 
72
    if cmp test1.out test2.out ; then
 
73
        true
 
74
    else
 
75
        exit 1;
 
76
    fi
 
77
}
 
78
 
 
79
test_canonical () {
 
80
    print_raw "$1" test.in
 
81
    if ../tools/sexp-conv -s canonical <test.in >test1.out ; then
 
82
        true
 
83
    else
 
84
        exit 1
 
85
    fi
 
86
    print_raw "$2" test2.out
 
87
 
 
88
    if cmp test1.out test2.out ; then
 
89
        true
 
90
    else
 
91
        exit 1;
 
92
    fi
 
93
}
 
94
 
 
95
test_advanced '0:' '""'
 
96
test_advanced '3:foo' 'foo'
 
97
test_advanced '12:fooooooooooo' 'fooooooooooo'
 
98
test_advanced '10:fooooooooo' 'fooooooooo'
 
99
test_advanced '4:3des' '"3des"' 
 
100
test_advanced '"foo"' 'foo' 
 
101
test_advanced '4:foo
 
102
' '"foo\n"'
 
103
# Having the string end with a \ breaks with sysv echo. \x seems harmless.
 
104
test_advanced '3:"\x' '"\"\\x"' 
 
105
test_advanced '()' '()' 
 
106
test_advanced '(foo bar baz)' '(foo bar
 
107
     baz)' 
 
108
test_advanced '; comment
 
109
()' '()' 
 
110
 
 
111
test_advanced '(foo[bar]foo)' '(foo [bar]foo)'
 
112
 
 
113
test_advanced '(#aabb#)' '(|qrs=|)'
 
114
test_advanced '(|qrs=|)' '(|qrs=|)'
 
115
test_advanced_hex '(|qrs=|)' '(#aabb#)'
 
116
test_advanced_hex '(#aabb#)' '(#aabb#)'
 
117
test_advanced_hex '{MToR}' '#11#'
 
118
test_advanced_hex '|EQ==|' '#11#'
 
119
 
 
120
test_transport '0:' '{MDo=}'
 
121
test_transport '()' '{KCk=}'
 
122
test_transport '1:A' '{MTpB}'
 
123
test_transport 'foo' '{Mzpmb28=}'
 
124
test_transport '(foo bar baz)' '{KDM6Zm9vMzpiYXIzOmJheik=}'
 
125
 
 
126
test_canonical '""' '0:'
 
127
test_canonical '{MDo=}' '0:'
 
128
test_canonical '{KCk=}' '()'
 
129
test_canonical '{MTpB}' '1:A'
 
130
test_canonical 'foo' '3:foo'
 
131
test_canonical 'fooooooooooo' '12:fooooooooooo'
 
132
test_canonical 'fooooooooo' '10:fooooooooo'
 
133
test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)' 
 
134
test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)' 
 
135
 
 
136
exit 0