1 // Copyright (C) 1995-1999 David Sugar, Tycho Softworks.
2 // Copyright (C) 1999-2005 Open Source Telecom Corp.
3 // Copyright (C) 2005-2010 David Sugar, Tycho Softworks.
4 //
5 // This file is part of GNU uCommon C++.
6 //
7 // GNU uCommon C++ is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // GNU uCommon C++ is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
19
20 #include <config.h>
22
24 using namespace UCOMMON_NAMESPACE;
25
26 static unsigned checks = 0;
27 static unsigned exchecks = 0;
28 static unsigned refchecks = 0;
29 static unsigned mainchecks = 0;
30 static unsigned debugcount = 0;
31 static unsigned printcount = 0;
32 static unsigned eventchecks = 0;
33 static unsigned loopingchecks = 0;
34 static unsigned manipchecks = 0;
35
37 {
38 public:
40
42
43 virtual void print(void);
44 };
45
47 {
48 public:
49 bool scrCheck(void);
50 bool scrCheckExit(void);
51 bool scrCheckMain(void);
52 bool scrCheckEvent(void);
53 bool scrCheckLoop(void);
54 bool scrCheckRefs(void);
55 bool scrArgs(void);
56 bool scrSleep(void);
57 bool scrCheckManip(void);
58 };
59
61 {
62 ++debugcount;
63 flag = NULL;
64 }
65
67 {
68 if(flag)
69 printf("%s", flag);
70 else
71 ++printcount;
72 }
73
75 {
76 ++manipchecks;
77 skip();
78 return true;
79 }
80
82 {
83 ++eventchecks;
84 skip();
85 return true;
86 }
87
89 {
90 ++refchecks;
91 skip();
92 return true;
93 }
94
96 {
97 ++mainchecks;
99 if(scriptEvent("event"))
100 return false;
101 skip();
102 return true;
103 }
104
106 {
107 ++loopingchecks;
108 skip();
109 return true;
110 }
111
112
114 {
115 ++exchecks;
116 skip();
117 return true;
118 }
119
121 {
122 ++checks;
123 skip();
124 return true;
125 }
126
128 {
129 unsigned index = 0;
130 Script::line_t *line = stack[frame].line;
131
132 while(index < line->argc) {
133 const char *cp = getContent(line->argv[index]);
134 printf(" ARG %d %s <%s>\n", index, line->argv[index], cp);
135 ++index;
136 }
137 skip();
138 return false;
139 }
140
142 {
143 Thread::sleep(500);
144 skip();
145 return true;
146 }
147
148 int main(
int argc,
char **argv)
149 {
151 unsigned errors;
152
153 static Script::keyword_t keywords[] = {
161 {"ignore", (Script::method_t)&Script::methods::scrNop, &Script::checks::chkIgnore},
164 {NULL}};
165
166 const char *filename = "testscript.scr";
167 const char *mergename = "mergescript.scr";
168
169 if(argc > 3) {
170 fprintf(stderr, "use: testscript [scrname]\n");
171 exit(-1);
172 }
173
174 if(argc == 2) {
175 mergename = NULL;
176 filename = argv[1];
177 }
178
179 Script::init();
180 Script::assign(keywords);
181
182 Script *image;
183
184 if(mergename) {
185 image = Script::compile(mergename);
186 image = Script::append(image, filename);
187 }
188 else
189 image = Script::compile(filename);
190
191 if(!image) {
192 fprintf(stderr, "*** failed to load %s\n", filename);
193 exit(-1);
194 }
195
196 errors = image->getErrors();
197 if(errors) {
198 fprintf(stderr, "*** %d total errors in %s\n", errors, filename);
199 linked_pointer<Script::error> ep = image->getListing();
200 while(is(ep)) {
201 fprintf(stderr, "*** %s(%d): %s\n", image->getFilename(), ep->errline, ep->errmsg);
202 ep.next();
203 }
204 delete image;
205 exit(-1);
206 }
207
208 interp.initialize();
209
210 if(!interp.attach(image)) {
211 fprintf(stderr, "*** no main section in %s\n", filename);
212 exit(-1);
213 }
214 while(interp.step()) {
215 Thread::yield();
216 }
217 interp.detach();
218
219 if(argc < 2) {
220 // enter correct generic number of "checks"
221 assert(checks == 3);
222
223 // enter validation of defined call by ref
224 assert(refchecks == 1);
225
226 // @exit handler called, and only once...
227 assert(exchecks == 1);
228
229 // @main handler called
230 assert(mainchecks == 1);
231
232 // @main ^event handler called
233 assert(eventchecks == 1);
234
235 // check looping operation
236 assert(loopingchecks == 3);
237
238 // in multiple inheritence base class initialized successfully
239 assert(debugcount == 1);
240
241 // in multiple inheritence, method call this* has combined class
242 assert(printcount == 1);
243
244 // check manipulations
245 assert(manipchecks == 8);
246 }
247
248 exit(0);
249 }
250
#define BAYONNE_NAMESPACE
GNU Bayonne library namespace.
int main(int argc, char **argv)