Merge "added FONT_SIZE_SCALE("fontSizeScale") DevelProperty into TextLabel, TextField...
[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] test-files
5 Options:
6   none    retrieve TC names with corresponding startup and cleanup functions
7   -f      retrieve 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
50
51 function tc_names {
52     if [[ -z "$1" ]]; then
53         exit
54     fi
55
56     awk '
57     BEGIN {
58         OFS = ",";
59         start_fun = "NULL";
60         clean_fun = "NULL";
61         err_flag = 0;
62         tc_list = "";
63     }
64     BEGINFILE {
65         start_fun = "NULL";
66         clean_fun = "NULL";
67     }
68     /^void .*startup\(void\)/ {
69         gsub(/^void /, "");
70         gsub(/\(void\)$/,"");
71         start_fun = $0
72     }
73     /^void .*cleanup\(void\)/ {
74         gsub(/^void /, "");
75         gsub(/\(void\)$/,"");
76         clean_fun = $0
77     }
78     /^int .*\(\)/ {
79         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
80         err_flag = 1;
81     }
82     /^int .*\(void\)/ {
83         gsub(/^int /, "");
84         gsub(/\(void\).*/,"");
85         if (tc_list != "") tc_list = tc_list "\n";
86         tc_list = tc_list $0 OFS start_fun OFS clean_fun
87     }
88     END {
89         if (err_flag) {
90             exit 1
91         } else {
92             print tc_list
93         }
94     }
95     ' $*
96 }
97
98 function tc_anum {
99     awk '
100     BEGIN {
101         count = 0;
102         err_flag = 0;
103     }
104     /^int .*\(\)/ {
105         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
106         err_flag = 1;
107     }
108     /^int .*\(void\)$/ {
109         count++;
110     }
111     END {
112         if (err_flag) {
113             exit 1
114         } else {
115             print count
116         }
117     }
118     ' $*
119 }
120
121 function tc_mnum {
122     # TODO: fix this hardcoded value
123     echo 0
124 }
125
126 function tc_fullinfo {
127     awk '
128     BEGIN {
129         OFS=",";
130         purpose = "";
131         set = "default";
132         err_flag = 0;
133         tc_list = "";
134     }
135     /^\/\/& set:/ {
136         set = $3;
137         next;
138     }
139     /^\/\/& purpose:/ {
140         purpose = $3;
141         for (i = 4; i <= NF; i++) {
142             purpose = purpose " " $i;
143         }
144         next;
145     }
146     /^int .*\(\)/ {
147         print "Warning: function with empty argument list -- \"" $0 "\" in " FILENAME ":" FNR;
148         err_flag = 1;
149     }
150     /^int .*\(void\)$/ {
151         gsub(/^int /, "");
152         gsub(/\(void\)$/,"");
153         if (tc_list != "") tc_list = tc_list "\n";
154         tc_list = tc_list $0 OFS set OFS purpose;
155         purpose = "";
156         next
157     }
158     END {
159         if (err_flag) {
160             exit 1
161         } else {
162             print tc_list
163         }
164     }
165     ' $*
166 }
167
168 TEMP=`getopt -o f::,a:,m: --long full::,anum:,mnum: \
169      -n 'retriever.sh' -- "$@"`
170
171 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
172
173 # Note the quotes around `$TEMP': they are essential!
174 eval set -- "$TEMP"
175
176 opt_full=false
177 opt_full_dir=
178 opt_anum=
179 opt_mnum=
180
181 while true ; do
182     case "$1" in
183         -f|--full) opt_full_dir="$2" ; opt_full="true" ; shift 2 ;;
184         -a|--anum) opt_anum="$2" ; shift 2 ;;
185         -m|--mnum) opt_mnum="$2" ; shift 2 ;;
186         --) shift ; break ;;
187         *) echo -e $USAGE ; exit 1 ;;
188     esac
189 done
190
191 #echo "###Retriever" >& 2
192 #echo opt_full: {$opt_full} >& 2
193 #echo opt_full_dir: {$opt_full_dir} >& 2
194
195 DIR=.
196 if [ -n "$opt_anum" ] ; then
197     DIR=$opt_anum
198     echo opt_anum: DIR=$DIR >& 2
199 elif [ -n "$opt_mnum" ] ; then
200     DIR=$opt_mnum
201     echo opt_mnum: DIR=$DIR >& 2
202 elif [ "$opt_full" == "true" ] ; then
203     if [ -n $opt_full_dir ] ; then
204         DIR=$opt_full_dir
205         echo opt_full: DIR=$DIR >& 2
206     fi
207 fi
208
209
210 # get filename from first argument
211 if [[ $# == 1 && -f $DIR/$1 ]] ; then
212     FILE=$1
213     shift;
214 fi
215
216 #echo "Dir: $DIR  File: $FILE" >& 2
217
218 # populate $TC_FILES with files declared in CMakeLists.txt
219 if [[ -z $FILE ]]; then
220     if [[ ! $DIR == "." || $# == 0 ]] ; then
221         #echo Get tc files: DIR=$DIR >& 2
222         get_tc_files $DIR
223     else
224         TC_FILES=$(
225             for i in $* ; do
226                 echo $DIR/$i
227             done
228             )
229     fi
230     if [ $? != 0 ]; then
231         exit 1
232     fi
233     echo "Got all files in `pwd`" >& 2
234     #echo "TC_FILES: $TC_FILES" >& 2
235 else
236     TC_FILES="$DIR/$FILE"
237     echo "TC_FILES: $TC_FILES" >& 2
238 fi
239
240
241
242 # run appropriate subcommand
243 if [ "$opt_full" == "true" ] ; then
244     tc_fullinfo $TC_FILES
245 elif [ -n "$opt_anum" ] ; then
246     tc_anum $TC_FILES
247 elif [ -n "$opt_mnum" ] ; then
248     tc_mnum $TC_FILES
249 else
250     tc_names $TC_FILES
251 fi