Update with current status
[gnash.git] / testsuite / misc-haxe.all / classes.all / gen-as3-test.sh
blob1f81edda73ffdfb508b1af01075a5066b8aa00de
1 #!/bin/sh
3 # Copyright (C) 2009, 2010 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # This script generates header file and C++ source file templates
21 # for an ActionScript class. It depends on the doc/C/NOTES file for
22 # data. It takes a single argument, which is the name of the class,
23 # like "./gen-files.sh Camera".
25 # This script is only of use to developers, so it's "as is". Your
26 # mileage may vary.
28 if test x"$1" = "x"; then
29 echo "Usage: $0 <classname>" >&2
30 exit 1
33 # Top level path
34 # Add some newlines to make sed;ing and greping easier.
35 nspace="`basename $PWD`"
36 class="`basename $1 | sed -e 's:.html::'`"
37 sed -e "s/<tr/\n<tr/g" $1 > tmp.html
38 dos2unix -q tmp.html
39 # extract the properties from the web page
40 rm props.tmp
41 grep -v "hideInheritedProperty" tmp.html | sed -e '/th colspan=.*Property/,/th colspan=.*Method/w props.tmp' > /dev/null
42 properties="`grep signatureLink props.tmp | sed -e 's:<div class="summaryTableDescription.*::' -e 's:^.*signatureLink\">::' -e 's:<.*\">:_:' -e 's:<.*::'`"
44 # extract the methods from the web page
45 rm methods.tmp
46 grep -v "hideInheritedMethod" tmp.html | sed -e '/th colspan=.*Method/,/th colspan=.*Event/w methods.tmp' > /dev/null
47 allmethods="`grep signatureLink methods.tmp | sed -e 's:<div class="summaryTableDescription.*::' -e 's:^.*signatureLink\">::' -e 's:<.*\">:_:' -e 's:<.*::'`"
49 # extract the methods from the web page
50 # events="`sed -e '1,/eventDetail/ d' -e '/(propertyDetail|Property Detail)/,$d' tmp.html | grep "detailHeaderName" | sed -e 's:^.*detailHeaderName">::' -e 's:<.*::' | tr -s '\n' ' '`"
52 # ignore the package-detail files
53 if test x"${class}" = x"package-detail" -o x"${class}" = x"package"; then
54 exit
58 # split up the list of data in pairs into an array so we can have a crude
59 # association between the porterty and the data type it returns.
61 i=0
62 for item in $properties; do
63 name="`echo $item | cut -d '_' -f 1`"
64 type="`echo $item | cut -d '_' -f 2`"
65 pargs[$i]="$type"
66 props[$i]="$name"
67 i=`eval expr $i + 1`
68 done
70 # display what we found
71 echo "Class: $class"
72 i=0
73 props_blanks=`echo $props | tr -d ' '`
74 echo -n " Properties: "
75 if test x"$props_blanks" != x; then
76 for item in $properties; do
77 echo -n " \"${props[$i]}\" \"${pargs[$i]}\","
78 i=`eval expr $i + 1`
79 done
80 else
81 echo "none"
83 echo ""
86 # split up the list of data in pairs into an array so we can have a crude
87 # association between the porterty and the data type it returns.
89 i=0
90 for item in $allmethods; do
91 name="`echo $item | cut -d '_' -f 1`"
92 type="`echo $item | cut -d '_' -f 2`"
93 margs[$i]="$type"
94 methods[$i]="$name"
95 i=`eval expr $i + 1`
96 done
98 # display what we found
99 i=0
100 meth_blanks=`echo $allmethods | tr -d ' '`
101 echo -n " Methods: "
102 if test x"$meth_blanks" != x; then
103 for item in $allmethods; do
104 echo -n " \"${methods[$i]}\" \"${margs[$i]}\","
105 i=`eval expr $i + 1`
106 done
107 else
108 echo "none"
110 echo ""
113 # We're done making lists of things, do some real work.
115 asname=${class}
116 lowname=`echo ${asname} | tr '[A-Z]' '[a-z]'`
117 upname=`echo ${asname} | tr '[a-z]' '[A-Z]'`
118 outname=${asname}_as3.hx
120 if test -f ${outname}; then
121 echo ${outname} exists!
122 mv -f ${outname} ${outname}.orig
123 # exit 1;
126 ###############################################################
127 # Start by generating the header file for this class
129 now=`date "+%Y%m%d"`
130 rm -f ${outname}
131 cat <<EOF>${outname}
132 // ${outname}: ActionScript 3 "${asname}" class, for Gnash.
134 // Generated by gen-as3.sh on: ${now} by "${USER}". Remove this
135 // after any hand editing loosing changes.
137 // Copyright (C) 2009, 2010 Free Software Foundation, Inc.
139 // This program is free software; you can redistribute it and/or modify
140 // it under the terms of the GNU General Public License as published by
141 // the Free Software Foundation; either version 3 of the License, or
142 // (at your option) any later version.
144 // This program is distributed in the hope that it will be useful,
145 // but WITHOUT ANY WARRANTY; without even the implied warranty of
146 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147 // GNU General Public License for more details.
149 // You should have received a copy of the GNU General Public License
150 // along with this program; if not, write to the Free Software
151 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
154 // This test case must be processed by CPP before compiling to include the
155 // DejaGnu.hx header file for the testing framework support.
157 #if flash9
158 import flash.${nspace}.${asname};
159 import flash.display.MovieClip;
160 #else
161 import flash.${asname};
162 import flash.MovieClip;
163 #end
164 import flash.Lib;
165 import Type;
167 // import our testing API
168 import DejaGnu;
170 // Class must be named with the _as3 suffix, as that's the same name as the file.
171 class ${asname}_as3 {
172 static function main() {
173 var x1:${asname} = new ${asname}();
175 // Make sure we actually get a valid class
176 if (x1 != null) {
177 DejaGnu.pass("${asname} class exists");
178 } else {
179 DejaGnu.fail("${asname} class doesn't exist");
184 if test x"$props_blanks" != x; then
185 cat <<EOF>>${outname}
186 // Tests to see if all the properties exist. All these do is test for
187 // existance of a property, and don't test the functionality at all. This
188 // is primarily useful only to test completeness of the API implementation.
192 # Add tests to see if all the properties exist
195 if test x"$props_blanks" != x; then
196 for item in $properties; do
197 name=${props[$i]}
198 type=${pargs[$i]}
199 case "${type}" in
200 "Number") result=0 ;;
201 "int") result=0 ;;
202 "String") result="null" ;;
203 "Boolean") result=false ;;
204 "Array") result=0 ;;
205 *) result=${type} ;;
206 esac
207 # echo "PROPS[$i]: ${name} : ${type}"
208 lines[$j]=" if (x1.${name} == $result) {"
209 j=`eval expr $j + 1`
210 lines[$j]=" DejaGnu.pass(\"${asname}.${name} property exists\");"
211 j=`eval expr $j + 1`
212 lines[$j]=" } else {"
213 j=`eval expr $j + 1`
214 lines[$j]=" DejaGnu.fail(\"${asname}.${name} property doesn't exist\");"
215 j=`eval expr $j + 1`
216 lines[$j]=" }"
217 j=`eval expr $j + 1`
218 lines[$j]=""
219 i=`eval expr $i + 1`
220 done
221 else
222 echo "none"
226 while test $k -le $j; do
227 echo "${lines[$k]}" >> ${outname}
228 k=`eval expr $k + 1`
229 done
231 if test x"$meth_blanks" != x; then
232 cat <<EOF>>${outname}
233 // Tests to see if all the methods exist. All these do is test for
234 // existance of a method, and don't test the functionality at all. This
235 // is primarily useful only to test completeness of the API implementation.
239 # Add tests to see if all the methods exist
242 if test x"$props_blanks" != x; then
243 for item in $allmethods; do
244 name=${methods[$i]}
245 type=${margs[$i]}
246 case "${type}" in
247 "Number") result=0 ;;
248 "uint") result=0 ;;
249 "int") result=0 ;;
250 "String") result="null" ;;
251 "Boolean") result=false ;;
252 "void") result=null ;;
253 "Array") result=0 ;;
254 *) result=${type} ;;
255 esac
256 # echo "PROPS[$i]: ${name} : ${type}"
257 lines[$j]=" if (x1.${name} == $result) {"
258 j=`eval expr $j + 1`
259 lines[$j]=" DejaGnu.pass(\"${asname}::${name}() method exists\");"
260 j=`eval expr $j + 1`
261 lines[$j]=" } else {"
262 j=`eval expr $j + 1`
263 lines[$j]=" DejaGnu.fail(\"${asname}::${name}() method doesn't exist\");"
264 j=`eval expr $j + 1`
265 lines[$j]=" }"
266 j=`eval expr $j + 1`
267 lines[$j]=""
268 i=`eval expr $i + 1`
269 done
270 else
271 echo "none"
275 while test $k -le $j; do
276 echo "${lines[$k]}" >> ${outname}
277 k=`eval expr $k + 1`
278 done
284 cat <<EOF>>${outname}
285 // Call this after finishing all tests. It prints out the totals.
286 DejaGnu.done();
290 // local Variables:
291 // mode: C++
292 // indent-tabs-mode: t
293 // End:
297 # cleanup after ourselves
298 rm -f tmp.html
299 rm -f *.tmp