sexp-conv-test 2.41 KB
Newer Older
1
2
3
4
5
6
#! /bin/sh

if [ -z "$srcdir" ] ; then
  srcdir=`pwd`
fi

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
19
20
21
	true
    else
	exit 1
    fi
22
    print_nl "$2" test2.out
23
24
25
26
27
28
29
30

    if cmp test1.out test2.out ; then
	true
    else
	exit 1;
    fi
}

31
test_advanced_hex () {
32
    print_raw "$1" test.in
33
34
35
36
37
    if ../tools/sexp-conv -s hex <test.in >test1.out ; then
	true
    else
	exit 1
    fi
38
    print_nl "$2" test2.out
39
40
41
42
43
44
45
46

    if cmp test1.out test2.out ; then
	true
    else
	exit 1;
    fi
}

47
test_transport () {
48
    print_raw "$1" test.in
49
    if ../tools/sexp-conv -s transport <test.in >test1.out ; then
50
51
52
53
	true
    else
	exit 1
    fi
54
    print_nl "$2" test2.out
55
56
57
58
59
60
61
62
63

    if cmp test1.out test2.out ; then
	true
    else
	exit 1;
    fi
}

test_canonical () {
64
    print_raw "$1" test.in
65
    if ../tools/sexp-conv -s canonical <test.in >test1.out ; then
66
67
68
69
	true
    else
	exit 1
    fi
70
    print_raw "$2" test2.out
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

    if cmp test1.out test2.out ; then
	true
    else
	exit 1;
    fi
}

test_advanced '0:' '""'
test_advanced '3:foo' 'foo'
test_advanced '12:fooooooooooo' 'fooooooooooo'
test_advanced '10:fooooooooo' 'fooooooooo'
test_advanced '4:3des' '"3des"' 
test_advanced '"foo"' 'foo' 
test_advanced '4:foo
86
87
88
' '"foo\n"'
# Having the string end with a \ breaks with sysv echo. \x seems harmless.
test_advanced '3:"\x' '"\"\\x"' 
89
90
91
92
test_advanced '()' '()' 
test_advanced '(foo bar baz)' '(foo bar
     baz)' 
test_advanced '; comment
93
94
95
96
97
()' '; comment
()' 
test_advanced '(foo ; gazonk
bar)' '(foo ; gazonk
     bar)'
98
99
100

test_advanced '(foo[bar]foo)' '(foo [bar]foo)'

101
102
103
104
test_advanced '(#aabb#)' '(|qrs=|)'
test_advanced '(|qrs=|)' '(|qrs=|)'
test_advanced_hex '(|qrs=|)' '(#aabb#)'
test_advanced_hex '(#aabb#)' '(#aabb#)'
105
106
test_advanced_hex '{MToR}' '#11#'
test_advanced_hex '|EQ==|' '#11#'
107

108
109
test_transport '0:' '{MDo=}'
test_transport '()' '{KCk=}'
110
test_transport '1:A' '{MTpB}'
111
112
113
114
test_transport 'foo' '{Mzpmb28=}'
test_transport '(foo bar baz)' '{KDM6Zm9vMzpiYXIzOmJheik=}'

test_canonical '""' '0:'
115
116
117
test_canonical '{MDo=}' '0:'
test_canonical '{KCk=}' '()'
test_canonical '{MTpB}' '1:A'
118
119
120
121
122
123
124
test_canonical 'foo' '3:foo'
test_canonical 'fooooooooooo' '12:fooooooooooo'
test_canonical 'fooooooooo' '10:fooooooooo'
test_canonical '(foo bar baz)' '(3:foo3:bar3:baz)' 
test_canonical '{KDM6Zm9vMzpiYXIzOmJheik=}' '(3:foo3:bar3:baz)' 

exit 0