blob: 37aace05076f7dd97ab258eb4cd2ebdda82a5767 (
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
|
#include "uscxml/config.h"
#include "uscxml/Interpreter.h"
#include "uscxml/plugins/Factory.h"
#include "uscxml/plugins/DataModelImpl.h"
#include <iostream>
#include <cassert>
/*
#define WITH_DM_ECMA_V8
#define WITH_DM_ECMA_JSC
#define WITH_DM_LUA
#define WITH_DM_PYTHON
#define WITH_DM_C89
#define WITH_DM_PROMELA
*/
using namespace uscxml;
class TestDataModelCallbacks : public DataModelCallbacks {
public:
std::string _name = "name";
std::string _sessionId = "sessionId";
std::map<std::string, IOProcessor> _ioProcs;
std::map<std::string, Invoker> _invokers;
const std::string& getName() {
return _name;
}
const std::string& getSessionId() {
return _sessionId;
}
const std::map<std::string, IOProcessor>& getIOProcessors() {
return _ioProcs;
}
virtual bool isInState(const std::string& stateId) {
return true;
}
XERCESC_NS::DOMDocument* getDocument() const {
return NULL;
}
const std::map<std::string, Invoker>& getInvokers() {
return _invokers;
}
Logger getLogger() {
return Logger::getDefault();
}
};
TestDataModelCallbacks dmCallbacks;
std::list<std::string> datamodels;
bool testSimpleJSON() {
for (auto dmName : datamodels) {
std::cout << "** " << dmName << ":" << std::endl;
DataModel dm = Factory::getInstance()->createDataModel(dmName, &dmCallbacks);
Data json = Data::fromJSON("{\"ü\": \"ä\"}");
dm.init("foo", json);
Data json2 = dm.evalAsData("foo");
std::cout << json << std::endl;
std::cout << json2 << std::endl;
assert(json == json2);
dm.init("bar", Data("ö", Data::VERBATIM));
bool cmp = dm.evalAsBool("bar == \"ö\"");
std::cout << dm.evalAsData("bar") << std::endl;
assert(cmp);
}
return true;
}
int main(int argc, char** argv) {
#ifdef WITH_DM_LUA
datamodels.push_back("lua");
#endif
#ifdef WITH_DM_PROMELA
// datamodels.push_back("promela");
#endif
#if (defined WITH_DM_ECMA_V8 || defined WITH_DM_ECMA_JSC)
datamodels.push_back("ecmascript");
#endif
testSimpleJSON();
return EXIT_SUCCESS;
}
|