summaryrefslogtreecommitdiffstats
path: root/test/src/test-cmdline-parsing.cpp
blob: 9ff094ad9d77f27e8772e33a5f2c07d4cf271601 (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
#include "uscxml/config.h"
#include "uscxml/Interpreter.h"
#include <glog/logging.h>

int main(int argc, char** argv) {
	using namespace uscxml;

	if (true) {
		int testArgc = 11;
		const char* testArgv[] = {
			"test-cmdline-parsing",
			"--verbose",
			"--dot",
			"--port=80",
			"--ssl-port=8080",
			"--certificate=/foo/bar.pem",
			"--private-key=/foo/bar.priv",
			"--public-key=/foo/bar.pub",
			"--plugin-path=/foo/plugins",
			"--loglevel=10",
			"--disable-http",
			0
		};
		InterpreterOptions options = InterpreterOptions::fromCmdLine(testArgc, (char **)testArgv);
		assert(options.verbose);
		assert(options.useDot);
		assert(options.httpPort == 80);
		assert(options.httpsPort == 8080);
		assert(boost::equals(options.certificate, "/foo/bar.pem"));
		assert(boost::equals(options.privateKey, "/foo/bar.priv"));
		assert(boost::equals(options.publicKey, "/foo/bar.pub"));
		assert(boost::equals(options.pluginPath, "/foo/plugins"));
		assert(options.logLevel == 10);
		assert(!options.withHTTP);
		assert(!options); // invalid as no SCXML document is given
		
		optind = 0;
	}

	if (true) {
		int testArgc = 3;
		const char* testArgv[] = {
			"test-cmdline-parsing",
			"--verbose",
			"/foo/bar.scxml",
			0
		};
		InterpreterOptions options = InterpreterOptions::fromCmdLine(testArgc, (char **)testArgv);
		assert(options);
		assert(options.verbose);
		assert(options.interpreters.size() == 1);
		assert(options.interpreters.find("/foo/bar.scxml") != options.interpreters.end());

		optind = 0;
	}

	if (true) {
		int testArgc = 7;
		const char* testArgv[] = {
			"test-cmdline-parsing",
			"--port=80",
			"/foo/bar1.scxml",
			"--disable-http",
			"/foo/bar2.scxml",
			"/foo/bar3.scxml",
			"--disable-http",
			0
		};
		InterpreterOptions options = InterpreterOptions::fromCmdLine(testArgc, (char **)testArgv);
		assert(options);
		assert(options.httpPort == 80);
		assert(options.interpreters.size() == 3);
		assert(options.interpreters.find("/foo/bar1.scxml") != options.interpreters.end());
		assert(options.interpreters.find("/foo/bar2.scxml") != options.interpreters.end());
		assert(options.interpreters.find("/foo/bar3.scxml") != options.interpreters.end());
		assert(!options.interpreters["/foo/bar1.scxml"]->withHTTP);
		assert(options.interpreters["/foo/bar2.scxml"]->withHTTP);
		assert(!options.interpreters["/foo/bar3.scxml"]->withHTTP);

		optind = 0;
	}

	if (true) {
		int testArgc = 5;
		const char* testArgv[] = {
			"test-cmdline-parsing",
			"--port=80",
			"/foo/bar1.scxml",
			"--vrml-path=/foo/bar.test",
			"--tmp-path=/foo/bar.test",
			0
		};
		InterpreterOptions options = InterpreterOptions::fromCmdLine(testArgc, (char **)testArgv);
		assert(options);
		assert(options.httpPort == 80);
		assert(options.interpreters.size() == 1);
		assert(options.interpreters.find("/foo/bar1.scxml") != options.interpreters.end());
		assert(options.interpreters["/foo/bar1.scxml"]->additionalParameters.find("vrml-path") != options.interpreters["/foo/bar1.scxml"]->additionalParameters.end());
		assert(options.interpreters["/foo/bar1.scxml"]->additionalParameters.find("tmp-path") != options.interpreters["/foo/bar1.scxml"]->additionalParameters.end());
		
		optind = 0;
	}

	return EXIT_SUCCESS;
}