summaryrefslogtreecommitdiffstats
path: root/test/src/test-apache-commons.cpp
blob: 9ac4442d7b0474fedc7a9e16f9ad9d515f48d7ec (plain)
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
#include "uscxml/Interpreter.h"
#include <glog/logging.h>

using namespace uscxml;
using namespace Arabica::DOM;
using namespace Arabica::XPath;

static std::string path;

bool testEvents1() {
	LOG(INFO) << "---- testEvent1 ";
	Interpreter* interpreter = Interpreter::fromURI(path + "/eventdata-01.xml");
	interpreter->start();
	interpreter->waitForStabilization();
	assert(interpreter->getConfiguration().size() == 1);
	assert(Interpreter::isMember(interpreter->getState("state1"), interpreter->getConfiguration()));

	Event eventFoo;
	eventFoo.name = "event.foo";
	eventFoo.atom = "3";
	interpreter->receive(eventFoo);
	interpreter->waitForStabilization();
	assert(interpreter->getConfiguration().size() == 1);
	assert(Interpreter::isMember(interpreter->getState("state3"), interpreter->getConfiguration()));

	Event eventBar;
	eventBar.name = "event.bar";
	eventBar.atom = "6";
	interpreter->receive(eventBar);
	interpreter->waitForStabilization();
	assert(interpreter->getConfiguration().size() == 1);
	assert(Interpreter::isMember(interpreter->getState("state6"), interpreter->getConfiguration()));

	Event eventBaz;
	eventBaz.name = "event.baz";
	eventBaz.atom = "7";
	interpreter->receive(eventBaz);

	delete interpreter;
	return true;
}

bool testEvents2() {
	LOG(INFO) << "---- testEvent2 ";
	Interpreter* interpreter = Interpreter::fromURI(path + "/eventdata-02.xml");
	interpreter->start();
	interpreter->waitForStabilization();
	assert(interpreter->getConfiguration().size() == 1);
	assert(Interpreter::isMember(interpreter->getState("state0"), interpreter->getConfiguration()));

	Event eventConnAlert;
	eventConnAlert.name = "connection.alerting";
	eventConnAlert.atom = "'line2'";
	interpreter->receive(eventConnAlert);
	interpreter->waitForStabilization();
	assert(interpreter->getConfiguration().size() == 1);
	assert(Interpreter::isMember(interpreter->getState("state2"), interpreter->getConfiguration()));

	Event eventConnAlert2;
	eventConnAlert2.name = "connection.alerting";
	eventConnAlert2.compound["line"] = Data(std::string("4"));
	interpreter->receive(eventConnAlert2);

	delete interpreter;
	return true;
}

//bool testEvents3() {
//  LOG(INFO) << "---- testEvent3 ";
//  Interpreter* Interpreter = new Interpreter(path + "/eventdata-03.xml");
//  interpreter->start();
//  interpreter->waitForStabilization();
//  Thread::sleepMs(200);
//  assert(interpreter->getConfiguration().size() == 1);
//  assert(Interpreter::isMember(interpreter->getState("state0"), interpreter->getConfiguration()));
//
//  Event eventConnAlert;
//  eventConnAlert.name = "connection.alerting";
//  eventConnAlert.atom = "'line2'";
//  interpreter->receive(eventConnAlert);
//  Thread::sleepMs(200);
//  assert(interpreter->getConfiguration().size() == 1);
//  assert(Interpreter::isMember(interpreter->getState("state2"), interpreter->getConfiguration()));
//
//  Event eventConnAlert2;
//  eventConnAlert2.name = "connection.alerting";
//  eventConnAlert2.compound["line"] = Data(std::string("4"));
//  interpreter->receive(eventConnAlert2);
//  Thread::sleepMs(200);
//  assert(interpreter->getConfiguration().size() == 1);
//  assert(Interpreter::isMember(interpreter->getState("state4"), interpreter->getConfiguration()));
//
//  delete Interpreter;
//  return true;
//}


int main(int argc, char** argv) {
	if (argc != 2) {
		std::cerr << "Expected path to scxml file from apache commons distribution" << std::endl;
		exit(EXIT_FAILURE);
	}

	path = "file://";
	path += argv[1];

	if (!testEvents1())
		return EXIT_FAILURE;
	if (!testEvents2())
		return EXIT_FAILURE;
//  if (!testEvents3())
//    return EXIT_FAILURE;

//
//  Interpreter* scxmlInterpreter = new Interpreter(path + "/tie-breaker-01.xml");
//  SCXMLRunner* scxmlRun = new SCXMLRunner(scxmlInterpreter);
//  scxmlRun->start();
//
//  Thread::sleepMs(100);
//  assert(Interpreter::isMember(scxmlinterpreter->getState("ten"), scxmlinterpreter->getConfiguration()));
//
//  boost::shared_ptr<Event> event = boost::shared_ptr<Event>(new Event());
//  event->name = "ten.done";
//  scxmlinterpreter->receive(event);
//  scxmlRun->join();
//  scxmlinterpreter->receive(event);

}