[a0a02d]: test / script.cpp  Maximize  Restore  History

Download this file

251 lines (207 with data), 6.0 kB

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

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks