Fix a few 'gcc -fanalyzer' warnings.
[pwmd.git] / tests / store.test
blobec2254f164fdcae69d704f9b47d2339d163732cf
1 #!/bin/sh
3 # Tests for the STORE protocol command.
5 MAX_TESTS=10
7 . $AM_SRCDIR/common.sh
8 . $AM_SRCDIR/import-common.sh
10 init_tests() {
11 do_import datafile
12 cat >$OUTDIR/config << EOF
13 [global]
14 log_level=9
15 #enable_logging=true
16 invoking_user=$USER
17 [datafile]
18 passphrase_file=$WDIR/passphrase.key
19 [datafile.tmp]
20 passphrase_file=$WDIR/passphrase.key
21 EOF
22 launch_pwmd datafile
25 test_1() {
26 cp -f data/datafile data/datafile.tmp || bail_out "Could not copy data/datafile."
27 run_pwmc "--inquire STORE --inquire-line 'a a' -S datafile.tmp" $DEVNULL <<EOF
28 EOF
29 e=$?
30 if [ $e -eq 0 ]; then
31 run_pwmc "datafile.tmp" >result $DEVNULL <<EOF
32 GET a
33 EOF
34 e=$?
36 test_result $test_n $e store "Element with same value as element name."
39 test_2() {
40 cp -f data/datafile data/datafile.tmp || bail_out "Could not copy data/datafile."
41 run_pwmc "--inquire STORE --inquire-line 'a ' -S datafile.tmp" $DEVNULL <<EOF
42 EOF
43 e=$?
44 if [ $e -eq 0 ]; then
45 run_pwmc "datafile.tmp" >result $DEVNULL <<EOF
46 GET a
47 EOF
48 e=$?
50 test_failure $test_n $e 536870970 "Remove element content."
53 test_3() {
54 run_pwmc "--inquire STORE --inquire-line 'a b a b value' -S datafile" $DEVNULL <<EOF
55 EOF
56 e=$?
57 if [ $e -eq 0 ]; then
58 run_pwmc "datafile" >result $DEVNULL <<EOF
59 GET a b
60 EOF
61 e=$?
63 test_result $test_n $e store "Write element content."
66 test_4() {
67 run_pwmc "-S datafile" $DEVNULL <<EOF
68 ATTR SET _target b a
69 EOF
70 e=$?
71 if [ $e -eq 0 ]; then
72 run_pwmc "datafile" >result $DEVNULL <<EOF
73 GET b b
74 EOF
75 e=$?
77 test_result $test_n $e store "ATTR: Set root target to root."
80 test_5() {
81 run_pwmc "--inquire STORE --inquire-line 'b b a b value' -S datafile" $DEVNULL <<EOF
82 EOF
83 e=$?
84 if [ $e -eq 0 ]; then
85 run_pwmc "datafile" >result $DEVNULL <<EOF
86 GET b b
87 EOF
88 e=$?
90 test_result $test_n $e store "Overwrite target content."
93 test_6() {
94 cp -f data/datafile data/datafile.tmp || bail_out "Could not copy data/datafile."
95 run_pwmc "-S datafile.tmp" $DEVNULL <<EOF
96 ATTR SET _target a b
97 EOF
98 list_recurse datafile.tmp
99 test_result $test_n $? store "ATTR: Set target to recursion loop."
102 test_7() {
103 run_pwmc "-S datafile.tmp" $DEVNULL <<EOF
104 ATTR SET _target a b a
106 test_failure $test_n $? 536903743 "Fail to set target to parent element."
110 test_8() {
111 cp -f data/datafile data/datafile.tmp || bail_out "Could not copy data/datafile.tmp."
112 run_pwmc "-S datafile.tmp" $DEVNULL <<EOF
113 ATTR SET _target a a b
115 list_recurse datafile.tmp
116 test_result $test_n $? store "ATTR: Set target to child."
119 test_9() {
120 run_pwmc "-S datafile" $DEVNULL <<EOF
121 ATTR SET _target a b b
123 e=$?
124 if [ $e -eq 0 ]; then
125 run_pwmc "--inquire STORE -S datafile" $DEVNULL <<EOF
126 a b c
128 e=$?
130 test_failure $test_n $e 536903743 "Fail to create element at element with recursion loop."
133 test_10() {
134 run_pwmc "--inquire STORE -S datafile" $DEVNULL <<EOF
135 a b content
137 test_failure $test_n $e 536903743 "Fail to create content at element with recursion loop."
140 run_tests $@