summaryrefslogtreecommitdiff
path: root/indra/test/llmessageconfig_tut.cpp
blob: f7eede73a3bc6ca6c74f2e155c67a2224e275e08 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/** 
 * @file llmessageconfig_tut.cpp
 * @date   March 2007
 * @brief LLMessageConfig unit tests
 *
 * Copyright (c) 2006-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#include <tut/tut.h>
#include "lltut.h"
#include "llmessageconfig.h"
#include "llsdserialize.h"
#include "llfile.h"
#include "lltimer.h"
#include "llframetimer.h"

namespace tut
{
	///var/tmp/babbage/dev/message-liberation/etc
	static const char file_name[] = "/tmp/message.xml";
	static const long refreshRateMillis = 6000;
	
	struct LLMessageConfigTestData {

		LLSD getCurrentConfig()
		{
			LLSD data;
			// store aside the current config to overwrite the test ones
			// when the test finishes
			llifstream in_file(file_name);
			if (in_file.is_open())
			{
				LLSDSerialize::fromXML(data, in_file);
			}
			return data;
		}

		void writeConfigFile(const LLSD& config)
		{
			LLMessageConfig::initClass("simulator", "/tmp");
			llofstream file(file_name);
			if (file.is_open())
			{
				LLSDSerialize::toPrettyXML(config, file);
			}
			file.close();
			ms_sleep(refreshRateMillis);
			LLFrameTimer::updateFrameTime();
		}
	};
	
	typedef test_group<LLMessageConfigTestData> LLMessageConfigTestGroup;
	typedef LLMessageConfigTestGroup::object LLMessageConfigTestObject;
	LLMessageConfigTestGroup llMessageConfigTestGroup("LLMessageConfig");
	
	template<> template<>
	void LLMessageConfigTestObject::test<1>()
		// tests server defaults
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "template";
		writeConfigFile(config);
		ensure_equals("Ensure server default is not llsd",
					  LLMessageConfig::isServerDefaultBuilderLLSD(),
					  false);
		ensure_equals("Ensure server default is template",
					  LLMessageConfig::isServerDefaultBuilderTemplate(),
					  true);
		writeConfigFile(config_backup);
	}

	template<> template<>
	void LLMessageConfigTestObject::test<2>()
		// tests message builders
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "template";
		config["messages"]["msg1"]["builder"] = "template";
		config["messages"]["msg2"]["builder"] = "llsd";
		writeConfigFile(config);
		ensure_equals("Ensure msg template builder not llsd",
					  LLMessageConfig::isMessageBuiltLLSD("msg1"),
					  false);
		ensure_equals("Ensure msg template builder",
					  LLMessageConfig::isMessageBuiltTemplate("msg1"),
					  true);
		ensure_equals("Ensure msg llsd builder",
					  LLMessageConfig::isMessageBuiltLLSD("msg2"),
					  true);
		ensure_equals("Ensure msg llsd builder not template",
					  LLMessageConfig::isMessageBuiltTemplate("msg2"),
					  false);
		writeConfigFile(config_backup);
	}

	template<> template<>
	void LLMessageConfigTestObject::test<4>()
		// tests message builder defaults
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "llsd";
		config["messages"]["msg1"]["trusted-sender"] = true;
		writeConfigFile(config);
		ensure_equals("Ensure missing message defaults to server builder, not template",
					  LLMessageConfig::isMessageBuiltTemplate("Test"),
					  false);
		ensure_equals("Ensure missing message default to server builder llsd",
					  LLMessageConfig::isMessageBuiltLLSD("Test"),
					  true);
		ensure_equals("Ensure missing builder defaults to server builder, not template",
					  LLMessageConfig::isMessageBuiltTemplate("msg1"),
					  false);
		ensure_equals("Ensure missing builder default to server builder llsd",
					  LLMessageConfig::isMessageBuiltLLSD("msg1"),
					  true);

		ensure_equals("Ensure server default is not llsd",
					  LLMessageConfig::isServerDefaultBuilderLLSD(),
					  true);
		ensure_equals("Ensure server default is template",
					  LLMessageConfig::isServerDefaultBuilderTemplate(),
					  false);

		writeConfigFile(config_backup);
	}

	template<> template<>
	void LLMessageConfigTestObject::test<3>()
		// tests trusted/untrusted senders
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "template";
		config["messages"]["msg1"]["builder"] = "llsd";
		config["messages"]["msg1"]["trusted-sender"] = false;
		config["messages"]["msg2"]["builder"] = "llsd";
		config["messages"]["msg2"]["trusted-sender"] = true;
		writeConfigFile(config);
		ensure_equals("Ensure untrusted is not trusted",
					  LLMessageConfig::isMessageTrusted("msg1"),
					  false);
		ensure_equals("Ensure untrusted is untrusted",
					  LLMessageConfig::isValidUntrustedMessage("msg1"),
					  true);
		ensure_equals("Ensure trusted is trusted",
					  LLMessageConfig::isMessageTrusted("msg2"),
					  true);
		ensure_equals("Ensure trusted is not untrusted",
					  LLMessageConfig::isValidUntrustedMessage("msg2"),
					  false);
		writeConfigFile(config_backup);
	}
	
	template<> template<>
	void LLMessageConfigTestObject::test<5>()
		// tests trusted/untrusted without flag, only builder
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "template";
		config["messages"]["msg1"]["builder"] = "llsd";
		writeConfigFile(config);
		ensure_equals("Ensure missing trusted is not trusted",
					  LLMessageConfig::isMessageTrusted("msg1"),
					  false);
		ensure_equals("Ensure missing trusted is not untrusted",
					  LLMessageConfig::isValidUntrustedMessage("msg1"),
					  false);
		writeConfigFile(config_backup);
	}

	template<> template<>
	void LLMessageConfigTestObject::test<6>()
		// tests message builder defaults
	{
		LLSD config_backup = getCurrentConfig();
		LLSD config;
		config["serverDefaults"]["simulator"] = "template";
		config["messages"]["msg1"]["trusted-sender"] = true;
		writeConfigFile(config);
		ensure_equals("Ensure missing message defaults to server builder, not template",
					  LLMessageConfig::isMessageBuiltTemplate("Test"),
					  true);
		ensure_equals("Ensure missing message default to server builder llsd",
					  LLMessageConfig::isMessageBuiltLLSD("Test"),
					  false);
		ensure_equals("Ensure missing builder defaults to server builder, not template",
					  LLMessageConfig::isMessageBuiltTemplate("msg1"),
					  true);
		ensure_equals("Ensure missing builder default to server builder llsd",
					  LLMessageConfig::isMessageBuiltLLSD("msg1"),
					  false);

		ensure_equals("Ensure server default is not llsd",
					  LLMessageConfig::isServerDefaultBuilderLLSD(),
					  false);
		ensure_equals("Ensure server default is template",
					  LLMessageConfig::isServerDefaultBuilderTemplate(),
					  true);

		writeConfigFile(config_backup);
	}
}