diff options
Diffstat (limited to 'linden/indra/test/llmessageconfig_tut.cpp')
-rw-r--r-- | linden/indra/test/llmessageconfig_tut.cpp | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/linden/indra/test/llmessageconfig_tut.cpp b/linden/indra/test/llmessageconfig_tut.cpp new file mode 100644 index 0000000..07e8e72 --- /dev/null +++ b/linden/indra/test/llmessageconfig_tut.cpp | |||
@@ -0,0 +1,227 @@ | |||
1 | /** | ||
2 | * @file llmessageconfig_tut.cpp | ||
3 | * @date March 2007 | ||
4 | * @brief LLMessageConfig unit tests | ||
5 | * | ||
6 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include <tut/tut.h> | ||
31 | #include "lltut.h" | ||
32 | #include "llmessageconfig.h" | ||
33 | #include "llsdserialize.h" | ||
34 | #include "llfile.h" | ||
35 | #include "lltimer.h" | ||
36 | #include "llframetimer.h" | ||
37 | |||
38 | namespace tut | ||
39 | { | ||
40 | ///var/tmp/babbage/dev/message-liberation/etc | ||
41 | static const char file_name[] = "/tmp/message.xml"; | ||
42 | static const F32 refreshRate = 6.0*1000.0; // milliseconds | ||
43 | |||
44 | struct LLMessageConfigTestData { | ||
45 | |||
46 | LLSD getCurrentConfig() | ||
47 | { | ||
48 | LLSD data; | ||
49 | // store aside the current config to overwrite the test ones | ||
50 | // when the test finishes | ||
51 | llifstream in_file(file_name); | ||
52 | if (in_file.is_open()) | ||
53 | { | ||
54 | LLSDSerialize::fromXML(data, in_file); | ||
55 | } | ||
56 | return data; | ||
57 | } | ||
58 | |||
59 | void writeConfigFile(const LLSD& config) | ||
60 | { | ||
61 | LLMessageConfig::initClass("simulator", "/tmp"); | ||
62 | llofstream file(file_name); | ||
63 | if (file.is_open()) | ||
64 | { | ||
65 | LLSDSerialize::toPrettyXML(config, file); | ||
66 | } | ||
67 | file.close(); | ||
68 | ms_sleep(refreshRate); | ||
69 | LLFrameTimer::updateFrameTime(); | ||
70 | } | ||
71 | }; | ||
72 | |||
73 | typedef test_group<LLMessageConfigTestData> LLMessageConfigTestGroup; | ||
74 | typedef LLMessageConfigTestGroup::object LLMessageConfigTestObject; | ||
75 | LLMessageConfigTestGroup llMessageConfigTestGroup("LLMessageConfig"); | ||
76 | |||
77 | template<> template<> | ||
78 | void LLMessageConfigTestObject::test<1>() | ||
79 | // tests server defaults | ||
80 | { | ||
81 | LLSD config_backup = getCurrentConfig(); | ||
82 | LLSD config; | ||
83 | config["serverDefaults"]["simulator"] = "template"; | ||
84 | writeConfigFile(config); | ||
85 | ensure_equals("Ensure server default is not llsd", | ||
86 | LLMessageConfig::isServerDefaultBuilderLLSD(), | ||
87 | false); | ||
88 | ensure_equals("Ensure server default is template", | ||
89 | LLMessageConfig::isServerDefaultBuilderTemplate(), | ||
90 | true); | ||
91 | writeConfigFile(config_backup); | ||
92 | } | ||
93 | |||
94 | template<> template<> | ||
95 | void LLMessageConfigTestObject::test<2>() | ||
96 | // tests message builders | ||
97 | { | ||
98 | LLSD config_backup = getCurrentConfig(); | ||
99 | LLSD config; | ||
100 | config["serverDefaults"]["simulator"] = "template"; | ||
101 | config["messages"]["msg1"]["builder"] = "template"; | ||
102 | config["messages"]["msg2"]["builder"] = "llsd"; | ||
103 | writeConfigFile(config); | ||
104 | ensure_equals("Ensure msg template builder not llsd", | ||
105 | LLMessageConfig::isMessageBuiltLLSD("msg1"), | ||
106 | false); | ||
107 | ensure_equals("Ensure msg template builder", | ||
108 | LLMessageConfig::isMessageBuiltTemplate("msg1"), | ||
109 | true); | ||
110 | ensure_equals("Ensure msg llsd builder", | ||
111 | LLMessageConfig::isMessageBuiltLLSD("msg2"), | ||
112 | true); | ||
113 | ensure_equals("Ensure msg llsd builder not template", | ||
114 | LLMessageConfig::isMessageBuiltTemplate("msg2"), | ||
115 | false); | ||
116 | writeConfigFile(config_backup); | ||
117 | } | ||
118 | |||
119 | template<> template<> | ||
120 | void LLMessageConfigTestObject::test<4>() | ||
121 | // tests message builder defaults | ||
122 | { | ||
123 | LLSD config_backup = getCurrentConfig(); | ||
124 | LLSD config; | ||
125 | config["serverDefaults"]["simulator"] = "llsd"; | ||
126 | config["messages"]["msg1"]["trusted-sender"] = true; | ||
127 | writeConfigFile(config); | ||
128 | ensure_equals("Ensure missing message defaults to server builder, not template", | ||
129 | LLMessageConfig::isMessageBuiltTemplate("Test"), | ||
130 | false); | ||
131 | ensure_equals("Ensure missing message default to server builder llsd", | ||
132 | LLMessageConfig::isMessageBuiltLLSD("Test"), | ||
133 | true); | ||
134 | ensure_equals("Ensure missing builder defaults to server builder, not template", | ||
135 | LLMessageConfig::isMessageBuiltTemplate("msg1"), | ||
136 | false); | ||
137 | ensure_equals("Ensure missing builder default to server builder llsd", | ||
138 | LLMessageConfig::isMessageBuiltLLSD("msg1"), | ||
139 | true); | ||
140 | |||
141 | ensure_equals("Ensure server default is not llsd", | ||
142 | LLMessageConfig::isServerDefaultBuilderLLSD(), | ||
143 | true); | ||
144 | ensure_equals("Ensure server default is template", | ||
145 | LLMessageConfig::isServerDefaultBuilderTemplate(), | ||
146 | false); | ||
147 | |||
148 | writeConfigFile(config_backup); | ||
149 | } | ||
150 | |||
151 | template<> template<> | ||
152 | void LLMessageConfigTestObject::test<3>() | ||
153 | // tests trusted/untrusted senders | ||
154 | { | ||
155 | LLSD config_backup = getCurrentConfig(); | ||
156 | LLSD config; | ||
157 | config["serverDefaults"]["simulator"] = "template"; | ||
158 | config["messages"]["msg1"]["builder"] = "llsd"; | ||
159 | config["messages"]["msg1"]["trusted-sender"] = false; | ||
160 | config["messages"]["msg2"]["builder"] = "llsd"; | ||
161 | config["messages"]["msg2"]["trusted-sender"] = true; | ||
162 | writeConfigFile(config); | ||
163 | ensure_equals("Ensure untrusted is not trusted", | ||
164 | LLMessageConfig::isMessageTrusted("msg1"), | ||
165 | false); | ||
166 | ensure_equals("Ensure untrusted is untrusted", | ||
167 | LLMessageConfig::isValidUntrustedMessage("msg1"), | ||
168 | true); | ||
169 | ensure_equals("Ensure trusted is trusted", | ||
170 | LLMessageConfig::isMessageTrusted("msg2"), | ||
171 | true); | ||
172 | ensure_equals("Ensure trusted is not untrusted", | ||
173 | LLMessageConfig::isValidUntrustedMessage("msg2"), | ||
174 | false); | ||
175 | writeConfigFile(config_backup); | ||
176 | } | ||
177 | |||
178 | template<> template<> | ||
179 | void LLMessageConfigTestObject::test<5>() | ||
180 | // tests trusted/untrusted without flag, only builder | ||
181 | { | ||
182 | LLSD config_backup = getCurrentConfig(); | ||
183 | LLSD config; | ||
184 | config["serverDefaults"]["simulator"] = "template"; | ||
185 | config["messages"]["msg1"]["builder"] = "llsd"; | ||
186 | writeConfigFile(config); | ||
187 | ensure_equals("Ensure missing trusted is not trusted", | ||
188 | LLMessageConfig::isMessageTrusted("msg1"), | ||
189 | false); | ||
190 | ensure_equals("Ensure missing trusted is not untrusted", | ||
191 | LLMessageConfig::isValidUntrustedMessage("msg1"), | ||
192 | false); | ||
193 | writeConfigFile(config_backup); | ||
194 | } | ||
195 | |||
196 | template<> template<> | ||
197 | void LLMessageConfigTestObject::test<6>() | ||
198 | // tests message builder defaults | ||
199 | { | ||
200 | LLSD config_backup = getCurrentConfig(); | ||
201 | LLSD config; | ||
202 | config["serverDefaults"]["simulator"] = "template"; | ||
203 | config["messages"]["msg1"]["trusted-sender"] = true; | ||
204 | writeConfigFile(config); | ||
205 | ensure_equals("Ensure missing message defaults to server builder, not template", | ||
206 | LLMessageConfig::isMessageBuiltTemplate("Test"), | ||
207 | true); | ||
208 | ensure_equals("Ensure missing message default to server builder llsd", | ||
209 | LLMessageConfig::isMessageBuiltLLSD("Test"), | ||
210 | false); | ||
211 | ensure_equals("Ensure missing builder defaults to server builder, not template", | ||
212 | LLMessageConfig::isMessageBuiltTemplate("msg1"), | ||
213 | true); | ||
214 | ensure_equals("Ensure missing builder default to server builder llsd", | ||
215 | LLMessageConfig::isMessageBuiltLLSD("msg1"), | ||
216 | false); | ||
217 | |||
218 | ensure_equals("Ensure server default is not llsd", | ||
219 | LLMessageConfig::isServerDefaultBuilderLLSD(), | ||
220 | false); | ||
221 | ensure_equals("Ensure server default is template", | ||
222 | LLMessageConfig::isServerDefaultBuilderTemplate(), | ||
223 | true); | ||
224 | |||
225 | writeConfigFile(config_backup); | ||
226 | } | ||
227 | } | ||