[Title] Add packaging/nettle.spec to build nettle on OBS system
[external/nettle.git] / testsuite / sexp-conv-test
1 #! /bin/sh
2
3 if [ -z "$srcdir" ] ; then
4   srcdir=`pwd`
5 fi
6
7 print_raw () {
8     printf "%s" "$1" > "$2"
9 }
10
11 print_nl () {
12     printf "%s\n" "$1" > "$2"
13 }
14
15 test_advanced () {
16     print_raw "$1" test.in
17     if ../tools/sexp-conv -s advanced <test.in >test1.out ; then
18         true
19     else
20         exit 1
21     fi
22     print_nl "$2" test2.out
23
24     if cmp test1.out test2.out ; then
25         true
26     else
27         exit 1;
28     fi
29 }
30
31 test_advanced_hex () {
32     print_raw "$1" test.in
33     if ../tools/sexp-conv -s hex <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_transport () {
48     print_raw "$1" test.in
49     if ../tools/sexp-conv -s transport <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_canonical () {
64     print_raw "$1" test.in
65     if ../tools/sexp-conv -s canonical <test.in >test1.out ; then
66         true
67     else
68         exit 1
69     fi
70     print_raw "$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_advanced '0:' '""'
80 test_advanced '3:foo' 'foo'
81 test_advanced '12:fooooooooooo' 'fooooooooooo'
82 test_advanced '10:fooooooooo' 'fooooooooo'
83 test_advanced '4:3des' '"3des"' 
84 test_advanced '"foo"' 'foo' 
85 test_advanced '4:foo
86 ' '"foo\n"'
87 # Having the string end with a \ breaks with sysv echo. \x seems harmless.
88 test_advanced '3:"\x' '"\"\\x"' 
89 test_advanced '()' '()' 
90 test_advanced '(foo bar baz)' '(foo bar
91      baz)' 
92 test_advanced '; comment
93 ()' '; comment
94 ()' 
95 test_advanced '(foo ; gazonk
96 bar)' '(foo ; gazonk
97      bar)'
98
99 test_advanced '(foo[bar]foo)' '(foo [bar]foo)'
100
101 test_advanced '(#aabb#)' '(|qrs=|)'
102 test_advanced '(|qrs=|)' '(|qrs=|)'
103 test_advanced_hex '(|qrs=|)' '(#aabb#)'
104 test_advanced_hex '(#aabb#)' '(#aabb#)'
105 test_advanced_hex '{MToR}' '#11#'
106 test_advanced_hex '|EQ==|' '#11#'
107
108 test_transport '0:' '{MDo=}'
109 test_transport '()' '{KCk=}'
110 test_transport '1:A' '{MTpB}'
111 test_transport 'foo' '{Mzpmb28=}'
112 test_transport '(foo bar baz)' '{KDM6Zm9vMzpiYXIzOmJheik=}'
113
114 test_canonical '""' '0:'
115 test_canonical '{MDo=}' '0:'
116 test_canonical '{KCk=}' '()'
117 test_canonical '{MTpB}' '1:A'
118 test_canonical 'foo' '3:foo'
119 test_canonical 'fooooooooooo' '12:fooooooooooo'
120 test_canonical 'fooooooooo' '10:fooooooooo'
121 test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)' 
122 test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)' 
123
124 exit 0