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
|
#define protected public
#include "uscxml/Interpreter.h"
#undef protected
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Expected path to test-predicates.scxml" << std::endl;
exit(EXIT_FAILURE);
}
using namespace uscxml;
using namespace Arabica::DOM;
using namespace Arabica::XPath;
Interpreter* interpreter = Interpreter::fromURI(argv[1]);
assert(interpreter);
Node<std::string> atomicState = interpreter->getState("atomic");
assert(Interpreter::isAtomic(atomicState));
assert(!Interpreter::isParallel(atomicState));
assert(!Interpreter::isCompound(atomicState));
Node<std::string> compoundState = interpreter->getState("compound");
assert(!Interpreter::isAtomic(compoundState));
assert(!Interpreter::isParallel(compoundState));
assert(Interpreter::isCompound(compoundState));
Node<std::string> parallelState = interpreter->getState("parallel");
assert(!Interpreter::isAtomic(parallelState));
assert(Interpreter::isParallel(parallelState));
assert(!Interpreter::isCompound(parallelState)); // parallel states are not compound!
NodeSet<std::string> initialState = interpreter->getInitialStates();
assert(initialState[0] == atomicState);
NodeSet<std::string> childs = interpreter->getChildStates(compoundState);
Node<std::string> compundChild1 = interpreter->getState("compundChild1");
Node<std::string> compundChild2 = interpreter->getState("compundChild2");
assert(childs.size() > 0);
assert(Interpreter::isMember(compundChild1, childs));
assert(Interpreter::isMember(compundChild2, childs));
assert(!Interpreter::isMember(compoundState, childs));
assert(Interpreter::isDescendant(compundChild1, compoundState));
std::string transEvents;
transEvents = "error";
assert(Interpreter::nameMatch(transEvents, "error"));
assert(!Interpreter::nameMatch(transEvents, "foo"));
transEvents = "error foo";
assert(Interpreter::nameMatch(transEvents, "error"));
assert(Interpreter::nameMatch(transEvents, "error.send"));
assert(Interpreter::nameMatch(transEvents, "error.send.failed"));
assert(Interpreter::nameMatch(transEvents, "foo"));
assert(Interpreter::nameMatch(transEvents, "foo.bar"));
assert(!Interpreter::nameMatch(transEvents, "errors.my.custom"));
assert(!Interpreter::nameMatch(transEvents, "errorhandler.mistake"));
assert(!Interpreter::nameMatch(transEvents, "errOr.send"));
assert(!Interpreter::nameMatch(transEvents, "foobar"));
}
|