Merge "Notify the IMF when backspace/cut empties the TextField" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / scripts / retriever.sh
1 #!/bin/bash
2
3 USAGE=$(cat <<EOF
4 Usage note: retriever.sh [option] [directory]
5 Options:
6   none    retrieve TC names with corresponding startup and cleanup functions
7   -f      retrieveve TC name with corresponding "set" and "purpose" clauses
8   -anum   retrieve automatic TC number
9   -mnum   retrieve manual TC number
10
11 In case of TC in form of "int tc_name()" script will abort.
12 ("int tc_name(void)" is a proper function signature)
13 EOF
14 )
15
16 function get_tc_files {
17     CMAKE_FILE="$DIR/CMakeLists.txt"
18     if [ ! -e $CMAKE_FILE ]; then
19         echo "File $CMAKE_FILE not found. Aborting..."
20         exit 1
21     fi
22
23     TC_FILES=$(cat $CMAKE_FILE | awk -vDIR="$DIR" '
24     BEGIN {
25         flag = 0;
26         files = "";
27     }
28     /^SET\(TC_SOURCES/ {
29         flag = 1;
30         next;
31     }
32     /\)/ {
33         if (flag == 1)
34             exit;
35     }
36     !/^ *#/ {
37         if (flag == 1) {
38             if (files == "")
39                 files = DIR "/" $1;
40             else
41                 files = files " " DIR "/" $1;
42         }
43     }
44     END {
45         print files;
46     }')
47 }
48
49 function tc_names {
50     if [[ -z "$1" ]]; then
51         exit
52     fi
53
54     awk '
55     BEGIN {
56         OFS = ",";
57         start_fun = "NULL";
58         clean_fun = "NULL";
59         err_flag = 0;
60         tc_list = "";
61     }
62     /^void .*startup\(void\)/ {
63         gsub(/^void /, "");
64         gsub(/\(void\)$/,"");
65         start_fun = $0
66     }
67     /^void .*cleanup\(void\)/ {
68         gsub(/^void /, "");
69         gsub(/\(void\)$/,"");
70         clean_fun = $0
71     }
72     /^int .*\(\)/ {
73         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
74         err_flag = 1;
75     }
76     /^int .*\(void\)/ {
77         gsub(/^int /, "");
78         gsub(/\(void\).*/,"");
79         if (tc_list != "") tc_list = tc_list "\n";
80         tc_list = tc_list $0 OFS start_fun OFS clean_fun
81     }
82     END {
83         if (err_flag) {
84             exit 1
85         } else {
86             print tc_list
87         }
88     }
89     ' $*
90 }
91
92 function tc_anum {
93     awk '
94     BEGIN {
95         count = 0;
96         err_flag = 0;
97     }
98     /^int .*\(\)/ {
99         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
100         err_flag = 1;
101     }
102     /^int .*\(void\)$/ {
103         count++;
104     }
105     END {
106         if (err_flag) {
107             exit 1
108         } else {
109             print count
110         }
111     }
112     ' $*
113 }
114
115 function tc_mnum {
116     # TODO: fix this hardcoded value
117     echo 0
118 }
119
120 function tc_fullinfo {
121     awk '
122     BEGIN {
123         OFS=",";
124         purpose = "";
125         set = "default";
126         err_flag = 0;
127         tc_list = "";
128     }
129     /^\/\/& set:/ {
130         set = $3;
131         next;
132     }
133     /^\/\/& purpose:/ {
134         purpose = $3;
135         for (i = 4; i <= NF; i++) {
136             purpose = purpose " " $i;
137         }
138         next;
139     }
140     /^int .*\(\)/ {
141         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
142         err_flag = 1;
143     }
144     /^int .*\(void\)$/ {
145         gsub(/^int /, "");
146         gsub(/\(void\)$/,"");
147         if (tc_list != "") tc_list = tc_list "\n";
148         tc_list = tc_list $0 OFS set OFS purpose;
149         purpose = "";
150         next
151     }
152     END {
153         if (err_flag) {
154             exit 1
155         } else {
156             print tc_list
157         }
158     }
159     ' $*
160 }
161
162
163 # usage note and exit:
164 # - argument begin with '-' but is not recognised or number of arguments is > 3,
165 # - argument doesn't begin with '-' and number of arguments is > 2
166 if [[ ( "$1" == -* && ( ! "$1" =~ ^-(anum|mnum|f)$ || $# > 3 ) ) || ( "$1" != -* && $# > 2 ) ]]; then
167     echo -e "$USAGE"
168     exit 1
169 fi
170
171 # get directory from last argument (or assume current one)
172 if [[ ! "$1" =~ ^-(anum|mnum|f)$ ]]; then
173     DIR=${1:-.}
174 else
175     DIR=${2:-.}
176 fi
177
178 # get filename from last argument
179 if [[ $# == 3 && -f $DIR/$3 ]] ; then
180     FILE=$3
181 elif [[ $# == 2 && -f $DIR/$2 ]] ; then
182     FILE=$2
183 fi
184
185 #echo "Dir: $DIR  File: $FILE" >& 2
186
187
188 # populate $TC_FILES with files declared in CMakeLists.txt
189 if [[ -z $FILE ]]; then
190     get_tc_files $DIR
191     if [ $? != 0 ]; then
192         exit 1
193     fi
194     echo "Got all files" >& 2
195 else
196     TC_FILES="$DIR/$FILE"
197     echo "TC_FILES: $TC_FILES" >& 2
198 fi
199
200
201
202 # run appropriate subcommand
203 case "$1" in
204     -anum)
205         tc_anum $TC_FILES ;;
206     -mnum)
207         tc_mnum $TC_FILES ;;
208     -f)
209         tc_fullinfo $TC_FILES ;;
210     *)
211         tc_names $TC_FILES ;;
212 esac