summaryrefslogtreecommitdiffstats
path: root/test/src/test-datamodel.cpp
blob: 773fe7fcf66ef20f6bd9d54b900a4fda90819ceb (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
#include "uscxml/URL.h"
#include "uscxml/Message.h"
#include "uscxml/Interpreter.h"
#include "uscxml/server/HTTPServer.h"

#include <SAX/helpers/InputSourceResolver.hpp>

#include <assert.h>
#include <boost/algorithm/string.hpp>
#include <iostream>

using namespace uscxml;
using namespace boost;


int main(int argc, char** argv) {
#ifdef _WIN32
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif

	Interpreter interpreter = Interpreter::fromXML("<scxml></scxml>");
	DataModel dm(Factory::getInstance()->createDataModel("ecmascript", interpreter.getImpl().get()));
	dm.evalAsString("var foo = 12");

	{
		std::string content = "$";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 0);
		std::cout << content << std::endl;
		assert(boost::equals(content, "$"));
	}

	{
		std::string content = "$sadf ${foo}";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 1);
		std::cout << content << std::endl;
		assert(boost::equals(content, "$sadf 12"));
	}

	{
		std::string content = "${";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 0);
		std::cout << content << std::endl;
		assert(boost::equals(content, "${"));
	}

	{
		std::string content = "${foo}";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 1);
		std::cout << content << std::endl;
		assert(boost::equals(content, "12"));
	}

	{
		std::string content = "${bar}";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 0);
		std::cout << content << std::endl;
		assert(boost::equals(content, "${bar}"));
	}

	{
		std::string content = "There are ${bar} monkeys! Really ${foo} monkeys!";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 1);
		std::cout << content << std::endl;
		assert(boost::equals(content, "There are ${bar} monkeys! Really 12 monkeys!"));
	}

	{
		std::string content = "There are ${foo} monkeys! Really ${foo} monkeys!";
		int rplc = dm.replaceExpressions(content);
		assert(rplc == 2);
		std::cout << content << std::endl;
		assert(boost::equals(content, "There are 12 monkeys! Really 12 monkeys!"));
	}
}