Make automated FSCommand invocation tests show player-side output.
[gnash.git] / testsuite / libcore.all / AsValueTest.cpp
blob56e5f408b7181de06acd260002f32748fb802a59
1 //
2 // Copyright (C) 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
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.
9 //
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.
14 //
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
19 #ifdef HAVE_CONFIG_H
20 #include "gnashconfig.h"
21 #endif
23 #ifdef HAVE_DEJAGNU_H
25 #include "VM.h"
26 #include "DummyMovieDefinition.h"
27 #include "ManualClock.h"
28 #include "movie_definition.h"
29 #include "dejagnu.h"
30 #include "as_value.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"
38 #include <string>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <iostream>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <fcntl.h>
46 #include <log.h>
47 #include <iostream>
48 #include <string>
50 #include "check.h"
52 using namespace gnash;
53 using namespace std;
55 static void usage (void);
57 static void test_isnan();
58 static void test_conversion();
60 TestState runtest;
61 LogFile& dbglogfile = LogFile::getDefaultInstance();
62 RcInitFile& rcfile = RcInitFile::getDefaultInstance();
64 TRYMAIN(_runtest);
65 int
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;
77 exit(EXIT_FAILURE);
80 for( int i = 0; i < parser.arguments(); ++i ) {
81 const int code = parser.code(i);
82 try {
83 switch( code ) {
84 case 'h':
85 usage ();
86 exit(EXIT_SUCCESS);
87 case 'v':
88 dbglogfile.setVerbosity();
89 // This happens once per 'v' flag
90 log_debug(_("Verbose output turned on"));
91 break;
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;
105 const URL url("");
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);
112 ManualClock clock;
114 movie_root stage(clock, runResources);
116 MovieClip::MovieVariables v;
117 stage.init(md, v);
119 // run the tests
120 test_isnan();
121 test_conversion();
123 return 0;
126 void
127 test_bool(as_value boolval)
129 if (boolval.is_bool()) {
130 runtest.pass("as_value(bool)");
131 } else {
132 runtest.fail("as_value(bool)");
136 void
137 test_int(as_value val)
139 if (val.is_number()) {
140 runtest.pass("as_value(int)");
141 } else {
142 runtest.fail("as_value(int)");
146 void
147 test_string(as_value val)
149 if (val.is_string()) {
150 runtest.pass("as_value(string)");
151 } else {
152 runtest.fail("as_value(string)");
157 typedef enum {
158 ONE = 0,
159 TWO = 1,
160 THREE = 2
161 } enumbers;
163 void
164 test_conversion()
166 test_bool(true);
167 test_bool(false);
168 test_int(5);
169 test_int(1);
170 test_int(double(0));
171 test_int(0.0);
173 test_int(THREE);
174 test_int(ONE);
175 test_int(TWO);
177 test_string(std::string("lar"));
179 test_string("lar");
185 void
186 test_isnan()
188 float num = 0;
190 if(!isNaN(num)) {
191 runtest.pass("isNaN(0)");
192 } else {
193 runtest.fail("isNaN(0)");
196 num /= 9999999;
198 if(!isNaN(num)) {
199 runtest.pass("isNaN(9999999)");
200 } else {
201 runtest.fail("isNaN(9999999)");
203 if(isFinite(num)) {
204 runtest.pass("isFinite(9999999)");
205 } else {
206 runtest.fail("isFinite(9999999)");
209 num = std::numeric_limits<float>::quiet_NaN();
211 if(isNaN(num)) {
212 runtest.pass("isNaN(quiet_NaN)");
213 } else {
214 runtest.fail("isNaN(quiet_NaN)");
216 if(!isFinite(num)) {
217 runtest.pass("isFinite(quiet_NaN)");
218 } else {
219 runtest.fail("isFinite(quiet_NaN)");
222 num = std::numeric_limits<float>::infinity();
224 if(!isNaN(num)) {
225 runtest.pass("isNaN(infinity)");
226 } else {
227 runtest.fail("isNaN(infinity)");
229 if(!isFinite(num)) {
230 runtest.pass("isFinite(infinity)");
231 } else {
232 runtest.fail("isFinite(infinity)");
235 num = 1.0 / 0.0;
237 if(!isNaN(num)) {
238 runtest.pass("isNaN(1.0/0.0)");
239 } else {
240 runtest.fail("isNaN(1.0/0.0)");
242 if(!isFinite(num)) {
243 runtest.pass("isFinite(1.0/0.0)");
244 } else {
245 runtest.fail("isFinite(1.0/0.0)");
248 int intgr = num;
250 num = intgr;
252 if(!isNaN(num)) {
253 runtest.pass("isNaN(int)");
254 } else {
255 runtest.fail("isNaN(int)");
257 if(isFinite(num)) {
258 runtest.pass("isFinite(int)");
259 } else {
260 runtest.fail("isFinite(int)");
264 static void
265 usage (void)
267 cerr << "This program tests the as_value class." << endl
268 << endl
269 << _("Usage: AsValue [options...]") << endl
270 << _(" -h, --help Print this help and exit") << endl
271 << _(" -v, --verbose Output verbose debug info") << endl
272 << endl;
275 #else
278 main(int /*argc*/, char /* *argv[]*/)
280 // nop
281 return 0;
284 #endif