Debian Codegraph @

tests/API/CPE/name/test_api_cpe_uri.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Copyright 2009 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5 #
6 # OpenScap CPE URI Module Test Suite.
7 #
8 # Authors:
9 # Ondrej Moris <[email protected]>
10
11 . $builddir/tests/test_common.sh
12
13 CPE_URIS=(`grep "cpe:" $srcdir/dict.xml | \
14 xsed 's/^.*cpe:/cpe:/g' | xsed 's/".*$//g' | tr '\n' ' '`)
15
16 # Test cases.
17
18 function test_api_cpe_uri_smoke {
19 ./test_api_cpe_uri --smoke-test
20 }
21
22 function test_api_cpe_uri_parse {
23 require "grep" || return 255
24 local ret_val=0
25 for URI in ${CPE_URIS[@]}; do
26 ./test_api_cpe_uri --parsing $URI parsing.out >/dev/null
27 if [ $? -eq 0 ]; then
28 if [ ! "`cat parsing.out`X" == "${URI}X" ]; then
29 echo "`cat parsing.out`X != ${URI}X"
30 ret_val=1
31 fi
32 else
33 echo "Parsing failed!"
34 ret_val=1
35 fi
36 done
37 return $ret_val
38 }
39
40 function test_api_cpe_uri_create {
41 require "grep" || return 255
42 local ret_val=0
43 for URI in ${CPE_URIS[@]}; do
44 ./test_api_cpe_uri --parsing $URI parsing.out > parsing.out.1
45 if [ $? -eq 0 ]; then
46 if [ "`cat parsing.out`X" == "${URI}X" ]; then
47 xsed 's/^\s*//g' parsing.out.1 > parsing.out.sed-tmp ; mv parsing.out.sed-tmp parsing.out.1
48 xsed 's/(null)//g' parsing.out.1 > parsing.out.sed-tmp ; mv parsing.out.sed-tmp parsing.out.1
49
50 case $(uname) in
51 FreeBSD)
52 cat parsing.out.1 | gxargs -d '\n' ./test_api_cpe_uri --creation > creation.out
53 ;;
54 *)
55 cat parsing.out.1 | xargs -d '\n' ./test_api_cpe_uri --creation > creation.out
56 ;;
57 esac
58
59 if [ ! $? -eq 0 ] || [ "${URI}X" != "`cat creation.out`X" ]; then
60 echo "${URI}X != `cat creation.out`X"
61 ret_val=1;
62 fi
63 else
64 echo "`cat parsing.out`X != ${URI}X"
65 ret_val=1
66 fi
67 else
68 echo "Parsing failed!"
69 ret_val=1
70 fi
71 done
72 return $ret_val
73 }
74
75 function test_api_cpe_uri_match {
76 require "grep" || return 255
77 local ret_val=0
78 for URI in ${CPE_URIS[@]}; do
79 ./test_api_cpe_uri --parsing $URI parsing.out
80 if [ $? -eq 0 ]; then
81 if [ "`cat parsing.out`X" == "${URI}X" ]; then
82 CPE=(`cat parsing.out | xsed 's/(null)//g' | \
83 xsed 's/^\s*//g' | tr '\n' ' '`)
84 ./test_api_cpe_uri --matching $URI " " >matching.out
85 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
86 echo "Cannot match URI \"$URI\"!"
87 ret_val=1;
88 fi
89 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
90 ./test_api_cpe_uri --matching $URI "cpe:/:::::::" > matching.out
91 echo "Cannot match URI \"$URI\"!"
92 ret_val=1;
93 fi
94 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
95 ./test_api_cpe_uri --matching $URI "cpe:/:foo" > matching.out
96 echo "Cannot match URI \"$URI\"!"
97 ret_val=1;
98 fi
99 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
100 ./test_api_cpe_uri --matching $URI "cpe:/foo" > matching.out
101 echo "Cannot match URI \"$URI\"!"
102 ret_val=1;
103 fi
104
105 OTHER_URIS=(`echo ${CPE_URIS[@]} | tr ' ' '\n' | grep -v $URI | \
106 tr '\n' ' '`)
107
108 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
109 ./test_api_cpe_uri --matching $URI ${OTHER_URIS[@]} > matching.out
110 echo "Cannot match URI \"$URI\"!"
111 ret_val=1;
112 fi
113 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
114 ./test_api_cpe_uri --matching $URI $URI > matching.out
115 echo "Cannot match URI \"$URI\"!"
116 ret_val=1;
117 fi
118 if [ ! $? -eq 0 ] || ! grep "Mismatch" matching.out > /dev/null; then
119 ./test_api_cpe_uri --matching $URI ${CPE_URIS[@]} > matching.out
120 echo "Cannot match URI \"$URI\"!"
121 ret_val=1;
122 fi
123 else
124 ret_val=1
125 echo "Parsing failed!"
126 fi
127 else
128 ret_val=1
129 echo "Parsing failed!"
130 fi
131 done
132 return $ret_val
133 }
134
135 # Testing.
136
137 test_init
138
139 if [ -z ${CUSTOM_OSCAP+x} ] ; then
140 test_run "test_api_cpe_uri_smoke" test_api_cpe_uri_smoke
141 test_run "test_api_cpe_uri_parse" test_api_cpe_uri_parse
142 test_run "test_api_cpe_uri_create" test_api_cpe_uri_create
143 test_run "test_api_cpe_uri_match" test_api_cpe_uri_match
144 fi
145
146 test_exit