Fix compile-time warning.
[pwmd.git] / tests / store.test
blobe06bfd09fa9a1c6ec731273396fff115630ff725
1 #!/bin/bash
2 source common.sh
3 source import-common.sh
5 do_import datafile
7 cat > config << EOF
8 [global]
9 log_level=9
10 #enable_logging=true
11 [datafile]
12 passphrase_file=`pwd`/datafile.key
13 [datafile.tmp]
14 passphrase_file=`pwd`/datafile.key
15 EOF
17 launch_pwmd datafile
18 begin_test
20 echo "Test 1. An element with the same value as the element name."
21 cp -f data/datafile data/datafile.tmp
22 echo -ne 'a\ta' | pwmc $PWMC_ARGS --inquire STORE -S \
23 --key-file $WDIR/datafile.key datafile.tmp
24 echo -ne 'GET a' | pwmc $PWMC_ARGS datafile.tmp > result
26 cmp store.result1 result
27 rm -f result
29 echo
30 echo "Test 2. Empty content (fail)."
31 cp -f data/datafile data/datafile.tmp
32 echo -ne 'a\t' | pwmc $PWMC_ARGS --inquire STORE -S \
33 --key-file $WDIR/datafile.key datafile.tmp
34 set +o errexit
35 echo -ne 'GET a' | pwmc $PWMC_ARGS datafile.tmp > result
36 if [ ${PIPESTATUS[1]} == 0 ]; then
37 echo "The previous command should have failed. Stopping."
38 exit 1
41 set -e
43 cmp store.result2 result
44 rm -f result
46 echo
47 echo "Test 3. Child element content."
48 echo -ne 'a\tb\ta b value' | pwmc $PWMC_ARGS --inquire STORE -S datafile
49 echo -ne 'GET a\tb' | pwmc $PWMC_ARGS datafile > result
50 cmp store.result3 result
51 rm -f result
53 echo
54 echo "Test 4. Root targets."
55 echo -ne 'ATTR SET target b a' | pwmc $PWMC_ARGS -S datafile
56 echo -ne 'GET b\tb' | pwmc $PWMC_ARGS datafile > result
57 cmp store.result4 result
58 rm -f result
60 echo
61 echo "Test 5. Literal content."
62 echo -ne '!b\tb value' | pwmc $PWMC_ARGS --inquire STORE -S datafile
63 echo -ne 'GET !b' | pwmc $PWMC_ARGS datafile > result
64 cmp store.result5 result
65 rm -f result
67 echo
68 echo "Test 6. Target, empty content (fail)."
69 echo -ne 'b\tb\t' | pwmc $PWMC_ARGS --inquire STORE -S datafile
70 set +o errexit
71 echo -ne 'GET b\tb' | pwmc $PWMC_ARGS datafile > result
72 if [ ${PIPESTATUS[1]} == 0 ]; then
73 echo "The previous command should have failed. Stopping."
74 exit 1
77 set -e
78 cmp store.result6 result
79 rm -f result
81 echo
82 echo "Test 7. Target content."
83 echo -ne 'b\tb\ta b value' | pwmc $PWMC_ARGS --inquire STORE -S datafile
84 echo -ne 'GET b\tb' | pwmc $PWMC_ARGS datafile > result
85 cmp store.result7 result
86 rm -f result
88 echo "Test 8. Invalid syntax, too many '!' (fail)."
89 set +o errexit
90 echo -ne '!!b\tb value' | pwmc $PWMC_ARGS --inquire STORE -S datafile
91 if [ ${PIPESTATUS[1]} == 0 ]; then
92 echo "The previous command should have failed. Stopping."
93 exit 1
96 set -e
98 echo
99 echo "Test 9. Recursion loop (fail)."
100 cp -f data/datafile data/datafile.tmp
101 echo -ne 'ATTR SET target a b' | pwmc $PWMC_ARGS -S \
102 --key-file $WDIR/datafile.key datafile.tmp
103 set +o errexit
104 echo -ne 'GET b\tb' | pwmc $PWMC_ARGS datafile.tmp > result
105 if [ ${PIPESTATUS[1]} == 0 ]; then
106 echo "The previous command should have failed. Stopping."
107 exit 1
110 set -e
112 echo
113 echo "Test 10. Recursion loop, retrieve literal value."
114 cp -f data/datafile data/datafile.tmp
115 echo -ne 'ATTR SET target a b' | pwmc $PWMC_ARGS -S \
116 --key-file $WDIR/datafile.key datafile.tmp
117 echo -ne 'GET !a\tb' | pwmc $PWMC_ARGS datafile.tmp > result
118 cmp store.result10 result
119 rm -f result
121 echo
122 echo "Test 11. Recursion loop, store literal value."
123 cp -f data/datafile data/datafile.tmp
124 echo -ne 'ATTR SET target a b' | pwmc $PWMC_ARGS -S \
125 --key-file $WDIR/datafile.key datafile.tmp
126 echo -ne '!a\tb\ta b value' | pwmc $PWMC_ARGS --inquire STORE -S \
127 datafile
128 echo -ne 'GET !a\tb' | pwmc $PWMC_ARGS datafile.tmp > result
129 cmp store.result11 result
130 rm -f result
132 echo
133 echo "Test 12. Recursion to parent (fail)."
134 cp -f data/datafile data/datafile.tmp
135 echo -ne 'ATTR SET target a b' | pwmc $PWMC_ARGS -S \
136 --key-file $WDIR/datafile.key datafile.tmp
137 set +o errexit
138 echo -ne 'ATTR SET target !a\tb a' | pwmc $PWMC_ARGS -S \
139 --key-file $WDIR/datafile.key datafile.tmp
140 if [ ${PIPESTATUS[1]} == 0 ]; then
141 echo "The previous command should have failed. Stopping."
142 exit 1
145 set -e
147 echo
148 echo "Test 13. Literal recursion to parent (fail)."
149 cp -f data/datafile data/datafile.tmp
150 echo -ne 'ATTR SET target a b' | pwmc $PWMC_ARGS -S \
151 --key-file $WDIR/datafile.key datafile.tmp
152 set +o errexit
153 echo -ne 'ATTR SET target !a\tb !a' | pwmc $PWMC_ARGS -S \
154 --key-file $WDIR/datafile.key datafile.tmp
155 if [ ${PIPESTATUS[1]} == 0 ]; then
156 echo "The previous command should have failed. Stopping."
157 exit 1
160 set -e
162 echo
163 echo "Test 14. Target to child (fail)."
164 cp -f data/datafile data/datafile.tmp
165 set +o errexit
166 echo -ne 'ATTR SET target a a\tb' | pwmc $PWMC_ARGS -S \
167 --key-file $WDIR/datafile.key datafile.tmp
168 if [ ${PIPESTATUS[1]} == 0 ]; then
169 echo "The previous command should have failed. Stopping."
170 exit 1
173 set -e
175 echo
176 echo "Test 15. Target to literal self."
177 cp -f data/datafile data/datafile.tmp
178 echo -ne 'ATTR SET target a !a' | pwmc $PWMC_ARGS -S \
179 --key-file $WDIR/datafile.key datafile.tmp
180 echo -ne 'GET a' | pwmc $PWMC_ARGS datafile.tmp > result
181 cmp store.result15 result
182 rm -f result
184 test_success