update copyright date
[gnash.git] / extensions / dejagnu / dejagnu.cpp
blob488818339b857516d3f2aa743dce33aa494685e8
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 // 2011 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 #include <map>
24 #include <iostream>
25 #include <string>
26 #include "log.h"
27 #include "dejagnu.h"
28 #include "fn_call.h"
29 #include "as_object.h"
30 #include "as_function.h"
31 #include "Global_as.h"
33 using namespace std;
35 namespace gnash
38 as_value dejagnu_pass(const fn_call& fn);
39 as_value dejagnu_fail(const fn_call& fn);
40 as_value dejagnu_totals(const fn_call& fn);
42 class DejaGnu : public Relay
44 public:
45 DejaGnu();
46 ~DejaGnu();
47 const char *pass (const char *msg);
48 const char *fail (const char *msg);
49 const char *xpass (const char *msg);
50 const char *xfail (const char *msg);
51 void totals ();
52 private:
53 int passed;
54 int failed;
55 int xpassed;
56 int xfailed;
59 static void
60 attachInterface(as_object& obj)
62 Global_as& gl = getGlobal(obj);
64 obj.init_member("pass", gl.createFunction(dejagnu_pass));
65 obj.init_member("fail", gl.createFunction(dejagnu_fail));
66 obj.init_member("totals", gl.createFunction(dejagnu_totals));
69 static as_value
70 dejagnu_ctor(const fn_call& fn)
72 as_object* obj = ensure<ValidThis>(fn);
73 obj->setRelay(new DejaGnu());
74 return as_value();
78 DejaGnu::DejaGnu()
79 : passed(0), failed(0), xpassed(0), xfailed(0)
81 // GNASH_REPORT_FUNCTION;
84 DejaGnu::~DejaGnu()
86 // GNASH_REPORT_FUNCTION;
89 const char *
90 DejaGnu::pass (const char *msg)
92 passed++;
93 log_debug("PASSED: %s\n", msg);
94 return NULL;
97 const char *
98 DejaGnu::fail (const char *msg)
100 failed++;
101 log_debug("FAILED: %s\n", msg);
102 return NULL;
105 as_value
106 dejagnu_pass(const fn_call& fn)
108 // GNASH_REPORT_FUNCTION;
109 DejaGnu* ptr = ensure<ThisIsNative<DejaGnu> >(fn);
111 if (fn.nargs > 0) {
112 string text = fn.arg(0).to_string();
113 return as_value(ptr->pass(text.c_str()));
116 return as_value();
119 as_value
120 dejagnu_fail(const fn_call& fn)
122 // GNASH_REPORT_FUNCTION;
123 DejaGnu* ptr = ensure<ThisIsNative<DejaGnu> >(fn);
125 if (fn.nargs > 0) {
126 string text = fn.arg(0).to_string();
127 return as_value(ptr->fail(text.c_str()));
130 return as_value();
133 as_value
134 dejagnu_totals(const fn_call& fn)
136 DejaGnu* ptr = ensure<ThisIsNative<DejaGnu> >(fn);
138 ptr->totals();
139 return as_value(true);
143 extern "C" {
144 void
145 dejagnu_class_init(as_object &obj)
147 Global_as& gl = getGlobal(obj);
148 as_object* proto = createObject(gl);
149 attachInterface(*proto);
151 as_object* cl = gl.createClass(&dejagnu_ctor, proto);
153 obj.init_member("DejaGnu", cl);
155 } // end of extern C
158 } // end of gnash namespace
160 // Local Variables:
161 // mode: C++
162 // indent-tabs-mode: t
163 // End: