2 // Copyright (C) 2008, 2009, 2010, 2011, 2012
3 // 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 3 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 #include "gnashconfig.h"
26 #include "DummyMovieDefinition.h"
27 #include "ManualClock.h"
28 #include "movie_definition.h"
31 #include "StreamProvider.h"
32 #include "as_object.h"
33 #include "arg_parser.h"
34 #include "Global_as.h"
35 #include "GnashNumeric.h"
36 #include "movie_root.h"
37 #include "RunResources.h"
39 #include <sys/types.h>
43 #include <sys/types.h>
52 using namespace gnash
;
55 static void usage (void);
57 static void test_isnan();
58 static void test_conversion();
61 LogFile
& dbglogfile
= LogFile::getDefaultInstance();
62 RcInitFile
& rcfile
= RcInitFile::getDefaultInstance();
66 trymain(int argc
, char *argv
[])
67 { const Arg_parser::Option opts
[] =
69 { 'h', "help", Arg_parser::no
},
70 { 'v', "verbose", Arg_parser::no
},
71 { 'd', "dump", Arg_parser::no
},
74 Arg_parser
parser(argc
, argv
, opts
);
75 if( ! parser
.error().empty() ) {
76 cout
<< parser
.error() << endl
;
80 for( int i
= 0; i
< parser
.arguments(); ++i
) {
81 const int code
= parser
.code(i
);
88 dbglogfile
.setVerbosity();
89 // This happens once per 'v' flag
90 log_debug(_("Verbose output turned on"));
95 catch (Arg_parser::ArgParserException
&e
) {
96 cerr
<< _("Error parsing command line options: ") << e
.what() << endl
;
97 cerr
<< _("This is a Gnash bug.") << endl
;
101 // Initialize gnash lib
103 RunResources runResources
;
106 runResources
.setStreamProvider(
107 std::shared_ptr
<StreamProvider
>(new StreamProvider(url
, url
)));
109 // Create a bogus movie with swf version 7 support
110 movie_definition
* md
= new DummyMovieDefinition(runResources
, 7);
114 movie_root
stage(clock
, runResources
);
116 MovieClip::MovieVariables v
;
127 test_bool(as_value boolval
)
129 if (boolval
.is_bool()) {
130 runtest
.pass("as_value(bool)");
132 runtest
.fail("as_value(bool)");
137 test_int(as_value val
)
139 if (val
.is_number()) {
140 runtest
.pass("as_value(int)");
142 runtest
.fail("as_value(int)");
147 test_string(as_value val
)
149 if (val
.is_string()) {
150 runtest
.pass("as_value(string)");
152 runtest
.fail("as_value(string)");
177 test_string(std::string("lar"));
191 runtest
.pass("isNaN(0)");
193 runtest
.fail("isNaN(0)");
199 runtest
.pass("isNaN(9999999)");
201 runtest
.fail("isNaN(9999999)");
204 runtest
.pass("isFinite(9999999)");
206 runtest
.fail("isFinite(9999999)");
209 num
= std::numeric_limits
<float>::quiet_NaN();
212 runtest
.pass("isNaN(quiet_NaN)");
214 runtest
.fail("isNaN(quiet_NaN)");
217 runtest
.pass("isFinite(quiet_NaN)");
219 runtest
.fail("isFinite(quiet_NaN)");
222 num
= std::numeric_limits
<float>::infinity();
225 runtest
.pass("isNaN(infinity)");
227 runtest
.fail("isNaN(infinity)");
230 runtest
.pass("isFinite(infinity)");
232 runtest
.fail("isFinite(infinity)");
238 runtest
.pass("isNaN(1.0/0.0)");
240 runtest
.fail("isNaN(1.0/0.0)");
243 runtest
.pass("isFinite(1.0/0.0)");
245 runtest
.fail("isFinite(1.0/0.0)");
253 runtest
.pass("isNaN(int)");
255 runtest
.fail("isNaN(int)");
258 runtest
.pass("isFinite(int)");
260 runtest
.fail("isFinite(int)");
267 cerr
<< "This program tests the as_value class." << endl
269 << _("Usage: AsValue [options...]") << endl
270 << _(" -h, --help Print this help and exit") << endl
271 << _(" -v, --verbose Output verbose debug info") << endl
278 main(int /*argc*/, char /* *argv[]*/)