diff options
Diffstat (limited to 'linden/indra/test')
37 files changed, 8485 insertions, 213 deletions
diff --git a/linden/indra/test/MacTester.xcodeproj/project.pbxproj b/linden/indra/test/MacTester.xcodeproj/project.pbxproj index 76bdc0a..1aad040 100644 --- a/linden/indra/test/MacTester.xcodeproj/project.pbxproj +++ b/linden/indra/test/MacTester.xcodeproj/project.pbxproj | |||
@@ -241,7 +241,7 @@ | |||
241 | 38A8BF620A18C31D00814862 /* metaproperty.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = metaproperty.cpp; sourceTree = "<group>"; }; | 241 | 38A8BF620A18C31D00814862 /* metaproperty.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = metaproperty.cpp; sourceTree = "<group>"; }; |
242 | 38A8BF690A18C38800814862 /* reflective.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = reflective.h; sourceTree = "<group>"; }; | 242 | 38A8BF690A18C38800814862 /* reflective.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = reflective.h; sourceTree = "<group>"; }; |
243 | 38A8BF740A18C42900814862 /* reflective.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = reflective.cpp; sourceTree = "<group>"; }; | 243 | 38A8BF740A18C42900814862 /* reflective.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = reflective.cpp; sourceTree = "<group>"; }; |
244 | 8DD76F6C0486A84900D96B5E /* MacTester */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MacTester; sourceTree = BUILT_PRODUCTS_DIR; }; | 244 | 8DD76F6C0486A84900D96B5E /* MacTester */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = MacTester; sourceTree = BUILT_PRODUCTS_DIR; }; |
245 | 91469E7F0B4486F20009E8F9 /* llmime.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = llmime.cpp; sourceTree = "<group>"; }; | 245 | 91469E7F0B4486F20009E8F9 /* llmime.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = llmime.cpp; sourceTree = "<group>"; }; |
246 | 91469E800B4486F20009E8F9 /* llmime.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = llmime.h; sourceTree = "<group>"; }; | 246 | 91469E800B4486F20009E8F9 /* llmime.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = llmime.h; sourceTree = "<group>"; }; |
247 | 91469E830B44870B0009E8F9 /* llmime_tut.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = llmime_tut.cpp; sourceTree = "<group>"; }; | 247 | 91469E830B44870B0009E8F9 /* llmime_tut.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = llmime_tut.cpp; sourceTree = "<group>"; }; |
diff --git a/linden/indra/test/blowfish.pl b/linden/indra/test/blowfish.pl index 7940d87..30f41dc 100755 --- a/linden/indra/test/blowfish.pl +++ b/linden/indra/test/blowfish.pl | |||
@@ -1,4 +1,9 @@ | |||
1 | #!/usr/bin/perl | 1 | #!/usr/bin/perl |
2 | # | ||
3 | # Test Perl Crypt::CBC Blowfish algorithm and initial parameter settings | ||
4 | # for compatibility with OpenSSL's Blowfish algorithm/settings. | ||
5 | # | ||
6 | # Used by outbound LSL email (openssl C library) and mailglue (Perl library) | ||
2 | use strict; | 7 | use strict; |
3 | use warnings; | 8 | use warnings; |
4 | 9 | ||
diff --git a/linden/indra/test/files.lst b/linden/indra/test/files.lst index 74f8879..8063bfd 100644 --- a/linden/indra/test/files.lst +++ b/linden/indra/test/files.lst | |||
@@ -4,24 +4,45 @@ test/io.cpp | |||
4 | test/llapp_tut.cpp | 4 | test/llapp_tut.cpp |
5 | test/llbase64_tut.cpp | 5 | test/llbase64_tut.cpp |
6 | test/llblowfish_tut.cpp | 6 | test/llblowfish_tut.cpp |
7 | test/llbuffer_tut.cpp | ||
8 | test/lldate_tut.cpp | ||
7 | test/llerror_tut.cpp | 9 | test/llerror_tut.cpp |
10 | test/llhost_tut.cpp | ||
8 | test/llhttpclient_tut.cpp | 11 | test/llhttpclient_tut.cpp |
9 | test/llhttpnode_tut.cpp | 12 | test/llhttpnode_tut.cpp |
10 | test/llinventoryparcel_tut.cpp | 13 | test/llinventoryparcel_tut.cpp |
11 | test/lliohttpserver_tut.cpp | 14 | test/lliohttpserver_tut.cpp |
15 | test/lljoint_tut.cpp | ||
12 | test/llmime_tut.cpp | 16 | test/llmime_tut.cpp |
13 | test/llmessageconfig_tut.cpp | 17 | test/llmessageconfig_tut.cpp |
18 | test/llmessagetemplateparser_tut.cpp | ||
19 | test/llnamevalue_tut.cpp | ||
20 | test/llpermissions_tut.cpp | ||
14 | test/llpipeutil.cpp | 21 | test/llpipeutil.cpp |
22 | test/llquaternion_tut.cpp | ||
15 | test/llrandom_tut.cpp | 23 | test/llrandom_tut.cpp |
24 | test/llsaleinfo_tut.cpp | ||
16 | test/llsdmessagebuilder_tut.cpp | 25 | test/llsdmessagebuilder_tut.cpp |
17 | test/llsdmessagereader_tut.cpp | 26 | test/llsdmessagereader_tut.cpp |
18 | test/llsd_new_tut.cpp | 27 | test/llsd_new_tut.cpp |
19 | test/llsdserialize_tut.cpp | 28 | test/llsdserialize_tut.cpp |
29 | test/llsdutil_tut.cpp | ||
20 | test/llservicebuilder_tut.cpp | 30 | test/llservicebuilder_tut.cpp |
31 | test/llstreamtools_tut.cpp | ||
32 | test/lltemplatemessagebuilder_tut.cpp | ||
21 | test/lltiming_tut.cpp | 33 | test/lltiming_tut.cpp |
22 | test/lltut.cpp | 34 | test/lltut.cpp |
23 | test/lluri_tut.cpp | 35 | test/lluri_tut.cpp |
36 | test/lluuidhashmap_tut.cpp | ||
24 | test/llxfer_tut.cpp | 37 | test/llxfer_tut.cpp |
25 | test/math.cpp | 38 | test/math.cpp |
39 | test/message_tut.cpp | ||
26 | test/reflection_tut.cpp | 40 | test/reflection_tut.cpp |
27 | test/test.cpp | 41 | test/test.cpp |
42 | test/v2math_tut.cpp | ||
43 | test/v3color_tut.cpp | ||
44 | test/v3dmath_tut.cpp | ||
45 | test/v3math_tut.cpp | ||
46 | test/v4color_tut.cpp | ||
47 | test/v4coloru_tut.cpp | ||
48 | test/v4math_tut.cpp | ||
diff --git a/linden/indra/test/inventory.cpp b/linden/indra/test/inventory.cpp index 0539910..944647f 100644 --- a/linden/indra/test/inventory.cpp +++ b/linden/indra/test/inventory.cpp | |||
@@ -28,12 +28,6 @@ | |||
28 | * COMPLETENESS OR PERFORMANCE. | 28 | * COMPLETENESS OR PERFORMANCE. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /** | ||
32 | * | ||
33 | * THOROUGH_DESCRIPTION of inventory.cpp | ||
34 | * | ||
35 | */ | ||
36 | |||
37 | #include "linden_common.h" | 31 | #include "linden_common.h" |
38 | #include "lltut.h" | 32 | #include "lltut.h" |
39 | #include "llinventory.h" | 33 | #include "llinventory.h" |
@@ -102,67 +96,438 @@ namespace tut | |||
102 | typedef inventory_test::object inventory_object; | 96 | typedef inventory_test::object inventory_object; |
103 | tut::inventory_test inv("llinventory"); | 97 | tut::inventory_test inv("llinventory"); |
104 | 98 | ||
99 | //***class LLInventoryType***// | ||
100 | |||
101 | |||
105 | template<> template<> | 102 | template<> template<> |
106 | void inventory_object::test<1>() | 103 | void inventory_object::test<1>() |
107 | { | 104 | { |
105 | LLInventoryType::EType retType = LLInventoryType::lookup("sound"); | ||
106 | ensure("1.LLInventoryType::lookup(char*) failed", retType == LLInventoryType::IT_SOUND); | ||
107 | |||
108 | retType = LLInventoryType::lookup("snapshot"); | ||
109 | ensure("2.LLInventoryType::lookup(char*) failed", retType == LLInventoryType::IT_SNAPSHOT); | ||
110 | } | ||
111 | |||
112 | template<> template<> | ||
113 | void inventory_object::test<2>() | ||
114 | { | ||
115 | const char* retType = LLInventoryType::lookup(LLInventoryType::IT_CALLINGCARD); | ||
116 | ensure("1.LLInventoryType::lookup(EType) failed", 0 == strcmp(retType, "callcard")); | ||
117 | |||
118 | retType = LLInventoryType::lookup(LLInventoryType::IT_LANDMARK); | ||
119 | ensure("2.LLInventoryType::lookup(EType) failed", 0 == strcmp(retType, "landmark")); | ||
120 | |||
121 | } | ||
122 | |||
123 | template<> template<> | ||
124 | void inventory_object::test<3>() | ||
125 | { | ||
126 | static const char* retType = LLInventoryType::lookupHumanReadable(LLInventoryType::IT_CALLINGCARD); | ||
127 | ensure("1.LLInventoryType::lookupHumanReadable(EType) failed", 0 == strcmp(retType, "calling card")); | ||
128 | |||
129 | retType = LLInventoryType::lookupHumanReadable(LLInventoryType::IT_LANDMARK); | ||
130 | ensure("2.LLInventoryType::lookupHumanReadable(EType) failed", 0 == strcmp(retType, "landmark")); | ||
131 | } | ||
132 | |||
133 | template<> template<> | ||
134 | void inventory_object::test<4>() | ||
135 | { | ||
136 | static LLInventoryType::EType retType = LLInventoryType::defaultForAssetType(LLAssetType::AT_TEXTURE); | ||
137 | ensure("1.LLInventoryType::defaultForAssetType(LLAssetType EType) failed", retType == LLInventoryType::IT_TEXTURE); | ||
138 | |||
139 | retType = LLInventoryType::defaultForAssetType(LLAssetType::AT_LANDMARK); | ||
140 | ensure("2.LLInventoryType::defaultForAssetType(LLAssetType EType) failed", retType == LLInventoryType::IT_LANDMARK); | ||
141 | } | ||
142 | |||
143 | //*****class LLInventoryItem*****// | ||
144 | |||
145 | template<> template<> | ||
146 | void inventory_object::test<5>() | ||
147 | { | ||
108 | LLPointer<LLInventoryItem> src = create_random_inventory_item(); | 148 | LLPointer<LLInventoryItem> src = create_random_inventory_item(); |
109 | LLSD sd = ll_create_sd_from_inventory_item(src); | 149 | LLSD sd = ll_create_sd_from_inventory_item(src); |
110 | //llinfos << "sd: " << *sd << llendl; | 150 | //llinfos << "sd: " << *sd << llendl; |
111 | LLPointer<LLInventoryItem> dst; | 151 | LLPointer<LLInventoryItem> dst = ll_create_item_from_sd(sd); |
152 | ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src->getUUID()); | ||
153 | ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID()); | ||
154 | ensure_equals("3.name::getName() failed", dst->getName(), src->getName()); | ||
155 | ensure_equals("4.type::getType() failed", dst->getType(), src->getType()); | ||
156 | |||
157 | ensure_equals("5.permissions::getPermissions() failed", dst->getPermissions(), src->getPermissions()); | ||
158 | ensure_equals("6.description::getDescription() failed", dst->getDescription(), src->getDescription()); | ||
159 | ensure_equals("7.sale type::getSaleType() failed", dst->getSaleInfo().getSaleType(), src->getSaleInfo().getSaleType()); | ||
160 | ensure_equals("8.sale price::getSalePrice() failed", dst->getSaleInfo().getSalePrice(), src->getSaleInfo().getSalePrice()); | ||
161 | ensure_equals("9.asset id::getAssetUUID() failed", dst->getAssetUUID(), src->getAssetUUID()); | ||
162 | ensure_equals("10.inventory type::getInventoryType() failed", dst->getInventoryType(), src->getInventoryType()); | ||
163 | ensure_equals("11.flags::getFlags() failed", dst->getFlags(), src->getFlags()); | ||
164 | ensure_equals("12.creation::getCreationDate() failed", dst->getCreationDate(), src->getCreationDate()); | ||
165 | |||
166 | LLUUID new_item_id, new_parent_id; | ||
167 | new_item_id.generate(); | ||
168 | src->setUUID(new_item_id); | ||
169 | |||
170 | new_parent_id.generate(); | ||
171 | src->setParent(new_parent_id); | ||
172 | |||
173 | LLString new_name = "LindenLab"; | ||
174 | src->rename(new_name); | ||
175 | |||
176 | src->setType(LLAssetType::AT_SOUND); | ||
177 | |||
178 | LLUUID new_asset_id; | ||
179 | new_asset_id.generate(); | ||
180 | |||
181 | src->setAssetUUID(new_asset_id); | ||
182 | LLString new_desc = "SecondLife Testing"; | ||
183 | src->setDescription(new_desc); | ||
184 | |||
185 | S32 new_price = rand(); | ||
186 | LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price); | ||
187 | src->setSaleInfo(new_sale_info); | ||
188 | |||
189 | U32 new_flags = rand(); | ||
190 | S32 new_creation = time(NULL); | ||
191 | |||
192 | LLPermissions new_perm; | ||
193 | |||
194 | LLUUID new_creator_id; | ||
195 | new_creator_id.generate(); | ||
196 | |||
197 | LLUUID new_owner_id; | ||
198 | new_owner_id.generate(); | ||
199 | |||
200 | LLUUID last_owner_id; | ||
201 | last_owner_id.generate(); | ||
202 | |||
203 | LLUUID new_group_id; | ||
204 | new_group_id.generate(); | ||
205 | new_perm.init(new_creator_id, new_owner_id, last_owner_id, new_group_id); | ||
206 | new_perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY); | ||
207 | src->setPermissions(new_perm); | ||
208 | |||
209 | src->setInventoryType(LLInventoryType::IT_SOUND); | ||
210 | src->setFlags(new_flags); | ||
211 | src->setCreationDate(new_creation); | ||
212 | |||
213 | sd = ll_create_sd_from_inventory_item(src); | ||
214 | //llinfos << "sd: " << *sd << llendl; | ||
112 | dst = ll_create_item_from_sd(sd); | 215 | dst = ll_create_item_from_sd(sd); |
113 | ensure_equals("item id", dst->getUUID(), src->getUUID()); | 216 | ensure_equals("13.item id::getUUID() failed", dst->getUUID(), src->getUUID()); |
114 | ensure_equals("parent", dst->getParentUUID(), src->getParentUUID()); | 217 | ensure_equals("14.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID()); |
115 | ensure_equals("name", dst->getName(), src->getName()); | 218 | ensure_equals("15.name::getName() failed", dst->getName(), src->getName()); |
116 | ensure_equals("type", dst->getType(), src->getType()); | 219 | ensure_equals("16.type::getType() failed", dst->getType(), src->getType()); |
117 | ensure_equals( | 220 | |
118 | "permissions", | 221 | ensure_equals("17.permissions::getPermissions() failed", dst->getPermissions(), src->getPermissions()); |
119 | dst->getPermissions(), | 222 | ensure_equals("18.description::getDescription() failed", dst->getDescription(), src->getDescription()); |
120 | src->getPermissions()); | 223 | ensure_equals("19.sale type::getSaleType() failed type", dst->getSaleInfo().getSaleType(), src->getSaleInfo().getSaleType()); |
121 | ensure_equals( | 224 | ensure_equals("20.sale price::getSalePrice() failed price", dst->getSaleInfo().getSalePrice(), src->getSaleInfo().getSalePrice()); |
122 | "description", | 225 | ensure_equals("21.asset id::getAssetUUID() failed id", dst->getAssetUUID(), src->getAssetUUID()); |
123 | dst->getDescription(), | 226 | ensure_equals("22.inventory type::getInventoryType() failed type", dst->getInventoryType(), src->getInventoryType()); |
124 | src->getDescription()); | 227 | ensure_equals("23.flags::getFlags() failed", dst->getFlags(), src->getFlags()); |
125 | ensure_equals( | 228 | ensure_equals("24.creation::getCreationDate() failed", dst->getCreationDate(), src->getCreationDate()); |
126 | "sale type", | 229 | |
127 | dst->getSaleInfo().getSaleType(), | ||
128 | src->getSaleInfo().getSaleType()); | ||
129 | ensure_equals( | ||
130 | "sale price", | ||
131 | dst->getSaleInfo().getSalePrice(), | ||
132 | src->getSaleInfo().getSalePrice()); | ||
133 | ensure_equals("asset id", dst->getAssetUUID(), src->getAssetUUID()); | ||
134 | ensure_equals( | ||
135 | "inventory type", | ||
136 | dst->getInventoryType(), | ||
137 | src->getInventoryType()); | ||
138 | ensure_equals("flags", dst->getFlags(), src->getFlags()); | ||
139 | ensure_equals( | ||
140 | "creation", | ||
141 | dst->getCreationDate(), | ||
142 | src->getCreationDate()); | ||
143 | } | 230 | } |
144 | 231 | ||
145 | template<> template<> | 232 | template<> template<> |
146 | void inventory_object::test<2>() | 233 | void inventory_object::test<6>() |
234 | { | ||
235 | LLPointer<LLInventoryItem> src = create_random_inventory_item(); | ||
236 | |||
237 | LLUUID new_item_id, new_parent_id; | ||
238 | new_item_id.generate(); | ||
239 | src->setUUID(new_item_id); | ||
240 | |||
241 | new_parent_id.generate(); | ||
242 | src->setParent(new_parent_id); | ||
243 | |||
244 | LLString new_name = "LindenLab"; | ||
245 | src->rename(new_name); | ||
246 | |||
247 | src->setType(LLAssetType::AT_SOUND); | ||
248 | |||
249 | LLUUID new_asset_id; | ||
250 | new_asset_id.generate(); | ||
251 | |||
252 | src->setAssetUUID(new_asset_id); | ||
253 | LLString new_desc = "SecondLife Testing"; | ||
254 | src->setDescription(new_desc); | ||
255 | |||
256 | S32 new_price = rand(); | ||
257 | LLSaleInfo new_sale_info(LLSaleInfo::FS_COPY, new_price); | ||
258 | src->setSaleInfo(new_sale_info); | ||
259 | |||
260 | U32 new_flags = rand(); | ||
261 | S32 new_creation = time(NULL); | ||
262 | |||
263 | LLPermissions new_perm; | ||
264 | |||
265 | LLUUID new_creator_id; | ||
266 | new_creator_id.generate(); | ||
267 | |||
268 | LLUUID new_owner_id; | ||
269 | new_owner_id.generate(); | ||
270 | |||
271 | LLUUID last_owner_id; | ||
272 | last_owner_id.generate(); | ||
273 | |||
274 | LLUUID new_group_id; | ||
275 | new_group_id.generate(); | ||
276 | new_perm.init(new_creator_id, new_owner_id, last_owner_id, new_group_id); | ||
277 | new_perm.initMasks(PERM_ALL, PERM_ALL, PERM_COPY, PERM_COPY, PERM_MODIFY | PERM_COPY); | ||
278 | src->setPermissions(new_perm); | ||
279 | |||
280 | src->setInventoryType(LLInventoryType::IT_SOUND); | ||
281 | src->setFlags(new_flags); | ||
282 | src->setCreationDate(new_creation); | ||
283 | |||
284 | LLSD sd = ll_create_sd_from_inventory_item(src); | ||
285 | LLPointer<LLInventoryItem> dst = ll_create_item_from_sd(sd); | ||
286 | |||
287 | |||
288 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
289 | src1->copy(src); | ||
290 | src1->clone(src); | ||
291 | |||
292 | ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src1->getUUID()); | ||
293 | ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src1->getParentUUID()); | ||
294 | ensure_equals("3.name::getName() failed", dst->getName(), src1->getName()); | ||
295 | ensure_equals("4.type::getType() failed", dst->getType(), src1->getType()); | ||
296 | |||
297 | ensure_equals("5.permissions::getPermissions() failed", dst->getPermissions(), src1->getPermissions()); | ||
298 | ensure_equals("6.description::getDescription() failed", dst->getDescription(), src1->getDescription()); | ||
299 | ensure_equals("7.sale type::getSaleType() failed type", dst->getSaleInfo().getSaleType(), src1->getSaleInfo().getSaleType()); | ||
300 | ensure_equals("8.sale price::getSalePrice() failed price", dst->getSaleInfo().getSalePrice(), src1->getSaleInfo().getSalePrice()); | ||
301 | ensure_equals("9.asset id::getAssetUUID() failed id", dst->getAssetUUID(), src1->getAssetUUID()); | ||
302 | ensure_equals("10.inventory type::getInventoryType() failed type", dst->getInventoryType(), src1->getInventoryType()); | ||
303 | ensure_equals("11.flags::getFlags() failed", dst->getFlags(), src1->getFlags()); | ||
304 | ensure_equals("12.creation::getCreationDate() failed", dst->getCreationDate(), src1->getCreationDate()); | ||
305 | |||
306 | LLPointer<LLInventoryItem> src2; | ||
307 | src1->clone(src2); | ||
308 | |||
309 | ensure_not_equals("13.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
310 | ensure_equals("14.parent::getParentUUID() failed", src2->getParentUUID(), src1->getParentUUID()); | ||
311 | ensure_equals("15.name::getName() failed", src2->getName(), src1->getName()); | ||
312 | ensure_equals("16.type::getType() failed", src2->getType(), src1->getType()); | ||
313 | |||
314 | ensure_equals("17.permissions::getPermissions() failed", src2->getPermissions(), src1->getPermissions()); | ||
315 | ensure_equals("18.description::getDescription() failed", src2->getDescription(), src1->getDescription()); | ||
316 | ensure_equals("19.sale type::getSaleType() failed type", src2->getSaleInfo().getSaleType(), src1->getSaleInfo().getSaleType()); | ||
317 | ensure_equals("20.sale price::getSalePrice() failed price", src2->getSaleInfo().getSalePrice(), src1->getSaleInfo().getSalePrice()); | ||
318 | ensure_equals("21.asset id::getAssetUUID() failed id", src2->getAssetUUID(), src1->getAssetUUID()); | ||
319 | ensure_equals("22.inventory type::getInventoryType() failed type", src2->getInventoryType(), src1->getInventoryType()); | ||
320 | ensure_equals("23.flags::getFlags() failed", src2->getFlags(), src1->getFlags()); | ||
321 | ensure_equals("24.creation::getCreationDate() failed", src2->getCreationDate(), src1->getCreationDate()); | ||
322 | |||
323 | |||
324 | } | ||
325 | |||
326 | template<> template<> | ||
327 | void inventory_object::test<7>() | ||
328 | { | ||
329 | FILE* fp = fopen("linden_file.dat","w+"); | ||
330 | if(!fp) | ||
331 | { | ||
332 | llerrs << "file could not be opened\n" << llendl; | ||
333 | return; | ||
334 | } | ||
335 | |||
336 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
337 | src1->exportFile(fp, TRUE); | ||
338 | fclose(fp); | ||
339 | |||
340 | LLPointer<LLInventoryItem> src2 = new LLInventoryItem(); | ||
341 | fp = fopen("linden_file.dat","r+"); | ||
342 | if(!fp) | ||
343 | { | ||
344 | llerrs << "file could not be opened\n" << llendl; | ||
345 | return; | ||
346 | } | ||
347 | |||
348 | src2->importFile(fp); | ||
349 | fclose(fp); | ||
350 | |||
351 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
352 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
353 | ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions()); | ||
354 | ensure_equals("4.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice()); | ||
355 | ensure_equals("5.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID()); | ||
356 | ensure_equals("6.type::getType() failed", src1->getType(), src2->getType()); | ||
357 | ensure_equals("7.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType()); | ||
358 | ensure_equals("8.name::getName() failed", src1->getName(), src2->getName()); | ||
359 | ensure_equals("9.description::getDescription() failed", src1->getDescription(), src2->getDescription()); | ||
360 | ensure_equals("10.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate()); | ||
361 | |||
362 | } | ||
363 | |||
364 | template<> template<> | ||
365 | void inventory_object::test<8>() | ||
366 | { | ||
367 | |||
368 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
369 | |||
370 | std::ostringstream ostream; | ||
371 | src1->exportLegacyStream(ostream, TRUE); | ||
372 | |||
373 | std::istringstream istream(ostream.str()); | ||
374 | LLPointer<LLInventoryItem> src2 = new LLInventoryItem(); | ||
375 | src2->importLegacyStream(istream); | ||
376 | |||
377 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
378 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
379 | ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions()); | ||
380 | ensure_equals("4.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice()); | ||
381 | ensure_equals("5.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID()); | ||
382 | ensure_equals("6.type::getType() failed", src1->getType(), src2->getType()); | ||
383 | ensure_equals("7.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType()); | ||
384 | ensure_equals("8.name::getName() failed", src1->getName(), src2->getName()); | ||
385 | ensure_equals("9.description::getDescription() failed", src1->getDescription(), src2->getDescription()); | ||
386 | ensure_equals("10.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate()); | ||
387 | |||
388 | |||
389 | } | ||
390 | |||
391 | template<> template<> | ||
392 | void inventory_object::test<9>() | ||
393 | { | ||
394 | // exportFileXML seg-faults for some reason. LLXMLNode is teh suck. | ||
395 | #if 0 | ||
396 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
397 | LLXMLNode* x_node = src1->exportFileXML(TRUE); | ||
398 | |||
399 | LLPointer<LLInventoryItem> src2 = new LLInventoryItem(); | ||
400 | src2->importXML(x_node); | ||
401 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
402 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
403 | ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions()); | ||
404 | ensure_equals("4.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice()); | ||
405 | ensure_equals("5.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID()); | ||
406 | ensure_equals("6.type::getType() failed", src1->getType(), src2->getType()); | ||
407 | ensure_equals("7.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType()); | ||
408 | ensure_equals("8.name::getName() failed", src1->getName(), src2->getName()); | ||
409 | ensure_equals("9.description::getDescription() failed", src1->getDescription(), src2->getDescription()); | ||
410 | ensure_equals("10.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate()); | ||
411 | #endif | ||
412 | } | ||
413 | |||
414 | template<> template<> | ||
415 | void inventory_object::test<10>() | ||
416 | { | ||
417 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
418 | U8* bin_bucket = new U8[300]; | ||
419 | S32 bin_bucket_size = src1->packBinaryBucket(bin_bucket, NULL); | ||
420 | |||
421 | LLPointer<LLInventoryItem> src2 = new LLInventoryItem(); | ||
422 | src2->unpackBinaryBucket(bin_bucket, bin_bucket_size); | ||
423 | |||
424 | ensure_equals("1.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice()); | ||
425 | ensure_equals("2.sale type::getSaleType() failed type", src1->getSaleInfo().getSaleType(), src2->getSaleInfo().getSaleType()); | ||
426 | ensure_equals("3.type::getType() failed", src1->getType(), src2->getType()); | ||
427 | ensure_equals("4.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType()); | ||
428 | ensure_equals("5.name::getName() failed", src1->getName(), src2->getName()); | ||
429 | ensure_equals("6.description::getDescription() failed", src1->getDescription(), src2->getDescription()); | ||
430 | ensure_equals("7.flags::getFlags() failed", src1->getFlags(), src2->getFlags()); | ||
431 | |||
432 | } | ||
433 | |||
434 | template<> template<> | ||
435 | void inventory_object::test<11>() | ||
436 | { | ||
437 | LLPointer<LLInventoryItem> src1 = create_random_inventory_item(); | ||
438 | LLSD retSd = src1->asLLSD(); | ||
439 | LLPointer<LLInventoryItem> src2 = new LLInventoryItem(); | ||
440 | src2->fromLLSD(retSd); | ||
441 | |||
442 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
443 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
444 | ensure_equals("3.permissions::getPermissions() failed", src1->getPermissions(), src2->getPermissions()); | ||
445 | ensure_equals("4.asset id::getAssetUUID() failed id", src1->getAssetUUID(), src2->getAssetUUID()); | ||
446 | ensure_equals("5.type::getType() failed", src1->getType(), src2->getType()); | ||
447 | ensure_equals("6.inventory type::getInventoryType() failed type", src1->getInventoryType(), src2->getInventoryType()); | ||
448 | ensure_equals("7.flags::getFlags() failed", src1->getFlags(), src2->getFlags()); | ||
449 | ensure_equals("8.sale type::getSaleType() failed type", src1->getSaleInfo().getSaleType(), src2->getSaleInfo().getSaleType()); | ||
450 | ensure_equals("9.sale price::getSalePrice() failed price", src1->getSaleInfo().getSalePrice(), src2->getSaleInfo().getSalePrice()); | ||
451 | ensure_equals("10.name::getName() failed", src1->getName(), src2->getName()); | ||
452 | ensure_equals("11.description::getDescription() failed", src1->getDescription(), src2->getDescription()); | ||
453 | |||
454 | |||
455 | skip_fail("12.creation::getCreationDate()"); | ||
456 | ensure_equals("12.creation::getCreationDate() failed", src1->getCreationDate(), src2->getCreationDate()); | ||
457 | } | ||
458 | |||
459 | //******class LLInventoryCategory*******// | ||
460 | |||
461 | template<> template<> | ||
462 | void inventory_object::test<12>() | ||
147 | { | 463 | { |
148 | LLPointer<LLInventoryCategory> src = create_random_inventory_cat(); | 464 | LLPointer<LLInventoryCategory> src = create_random_inventory_cat(); |
149 | LLSD sd = ll_create_sd_from_inventory_category(src); | 465 | LLSD sd = ll_create_sd_from_inventory_category(src); |
150 | LLPointer<LLInventoryCategory> dst = ll_create_category_from_sd(sd); | 466 | LLPointer<LLInventoryCategory> dst = ll_create_category_from_sd(sd); |
151 | ensure_equals("item id", dst->getUUID(), src->getUUID()); | 467 | |
152 | ensure_equals("parent", dst->getParentUUID(), src->getParentUUID()); | 468 | ensure_equals("1.item id::getUUID() failed", dst->getUUID(), src->getUUID()); |
153 | ensure_equals("name", dst->getName(), src->getName()); | 469 | ensure_equals("2.parent::getParentUUID() failed", dst->getParentUUID(), src->getParentUUID()); |
154 | ensure_equals("type", dst->getType(), src->getType()); | 470 | ensure_equals("3.name::getName() failed", dst->getName(), src->getName()); |
155 | ensure_equals( | 471 | ensure_equals("4.type::getType() failed", dst->getType(), src->getType()); |
156 | "preferred type", | 472 | ensure_equals("5.preferred type::getPreferredType() failed", dst->getPreferredType(), src->getPreferredType()); |
157 | dst->getPreferredType(), | 473 | |
158 | src->getPreferredType()); | 474 | src->setPreferredType( LLAssetType::AT_TEXTURE); |
475 | sd = ll_create_sd_from_inventory_category(src); | ||
476 | dst = ll_create_category_from_sd(sd); | ||
477 | ensure_equals("6.preferred type::getPreferredType() failed", dst->getPreferredType(), src->getPreferredType()); | ||
478 | |||
479 | |||
159 | } | 480 | } |
160 | 481 | ||
161 | /* | ||
162 | template<> template<> | 482 | template<> template<> |
163 | void inventory_object::test<3>() | 483 | void inventory_object::test<13>() |
484 | { | ||
485 | FILE* fp = fopen("linden_file.dat","w"); | ||
486 | if(!fp) | ||
487 | { | ||
488 | llerrs << "file coudnt be opened\n" << llendl; | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | LLPointer<LLInventoryCategory> src1 = create_random_inventory_cat(); | ||
493 | src1->exportFile(fp, TRUE); | ||
494 | fclose(fp); | ||
495 | |||
496 | LLPointer<LLInventoryCategory> src2 = new LLInventoryCategory(); | ||
497 | fp = fopen("linden_file.dat","r"); | ||
498 | if(!fp) | ||
499 | { | ||
500 | llerrs << "file coudnt be opened\n" << llendl; | ||
501 | return; | ||
502 | } | ||
503 | |||
504 | src2->importFile(fp); | ||
505 | fclose(fp); | ||
506 | |||
507 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
508 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
509 | ensure_equals("3.type::getType() failed", src1->getType(), src2->getType()); | ||
510 | ensure_equals("4.preferred type::getPreferredType() failed", src1->getPreferredType(), src2->getPreferredType()); | ||
511 | ensure_equals("5.name::getName() failed", src1->getName(), src2->getName()); | ||
512 | } | ||
513 | |||
514 | template<> template<> | ||
515 | void inventory_object::test<14>() | ||
164 | { | 516 | { |
517 | LLPointer<LLInventoryCategory> src1 = create_random_inventory_cat(); | ||
518 | |||
519 | std::ostringstream ostream; | ||
520 | src1->exportLegacyStream(ostream, TRUE); | ||
521 | |||
522 | std::istringstream istream(ostream.str()); | ||
523 | LLPointer<LLInventoryCategory> src2 = new LLInventoryCategory(); | ||
524 | src2->importLegacyStream(istream); | ||
525 | |||
526 | ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); | ||
527 | ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); | ||
528 | ensure_equals("3.type::getType() failed", src1->getType(), src2->getType()); | ||
529 | ensure_equals("4.preferred type::getPreferredType() failed", src1->getPreferredType(), src2->getPreferredType()); | ||
530 | ensure_equals("5.name::getName() failed", src1->getName(), src2->getName()); | ||
165 | 531 | ||
166 | } | 532 | } |
167 | */ | ||
168 | } | 533 | } |
diff --git a/linden/indra/test/llbitpack_tut.cpp b/linden/indra/test/llbitpack_tut.cpp index 1040a96..71e4a4d 100644 --- a/linden/indra/test/llbitpack_tut.cpp +++ b/linden/indra/test/llbitpack_tut.cpp | |||
@@ -1,11 +1,12 @@ | |||
1 | /** | 1 | /** |
2 | * @file llbitpack_tut.cpp | 2 | * @file llbitpack_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date February 2007 | 4 | * @date 2007-02 |
5 | * @brief llstreamtools test cases. | 5 | * @brief llstreamtools test cases. |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
diff --git a/linden/indra/test/llbuffer_tut.cpp b/linden/indra/test/llbuffer_tut.cpp new file mode 100644 index 0000000..bf58abb --- /dev/null +++ b/linden/indra/test/llbuffer_tut.cpp | |||
@@ -0,0 +1,270 @@ | |||
1 | /** | ||
2 | * @file llbuffer_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief llbuffer test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "llbuffer.h" | ||
34 | #include "llmemtype.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct buffer | ||
39 | { | ||
40 | }; | ||
41 | |||
42 | typedef test_group<buffer> buffer_t; | ||
43 | typedef buffer_t::object buffer_object_t; | ||
44 | tut::buffer_t tut_buffer("buffer"); | ||
45 | |||
46 | template<> template<> | ||
47 | void buffer_object_t::test<1>() | ||
48 | { | ||
49 | LLChannelDescriptors channelDescriptors; | ||
50 | ensure("in() and out() functions Failed", (0 == channelDescriptors.in() && 1 == channelDescriptors.out())); | ||
51 | |||
52 | S32 val = 50; | ||
53 | LLChannelDescriptors channelDescriptors1(val); | ||
54 | ensure("LLChannelDescriptors in() and out() functions Failed", (50 == channelDescriptors1.in() && 51 == channelDescriptors1.out())); | ||
55 | } | ||
56 | |||
57 | template<> template<> | ||
58 | void buffer_object_t::test<2>() | ||
59 | { | ||
60 | LLSegment segment; | ||
61 | ensure("LLSegment get functions failed", (0 == segment.getChannel() && NULL == segment.data() && 0 == segment.size())); | ||
62 | segment.setChannel(50); | ||
63 | ensure_equals("LLSegment setChannel() function failed", segment.getChannel(), 50); | ||
64 | ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(50))); | ||
65 | } | ||
66 | |||
67 | template<> template<> | ||
68 | void buffer_object_t::test<3>() | ||
69 | { | ||
70 | S32 channel = 30; | ||
71 | const char str[] = "SecondLife"; | ||
72 | S32 len = sizeof(str); | ||
73 | LLSegment segment(channel, (U8*)str, len); | ||
74 | ensure("LLSegment get functions failed", (30 == segment.getChannel() && len == segment.size() && (U8*)str == segment.data())); | ||
75 | ensure_memory_matches("LLSegment::data() failed", segment.data(), segment.size(), (U8*)str, len); | ||
76 | ensure("LLSegment isOnChannel() function failed", (TRUE == segment.isOnChannel(channel))); | ||
77 | } | ||
78 | |||
79 | template<> template<> | ||
80 | void buffer_object_t::test<4>() | ||
81 | { | ||
82 | S32 channel = 50; | ||
83 | S32 bigSize = 16384*2; | ||
84 | char str[] = "SecondLife"; | ||
85 | S32 smallSize = sizeof(str); | ||
86 | |||
87 | LLSegment segment; | ||
88 | LLHeapBuffer buf; // use default size of DEFAULT_HEAP_BUFFER_SIZE = 16384 | ||
89 | |||
90 | S32 requestSize; | ||
91 | |||
92 | requestSize = 16384-1; | ||
93 | ensure("1. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); | ||
94 | // second request for remainign 1 byte | ||
95 | |||
96 | requestSize = 1; | ||
97 | ensure("2. LLHeapBuffer createSegment failed", (TRUE == buf.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); | ||
98 | |||
99 | // it should fail now. | ||
100 | requestSize = 1; | ||
101 | ensure("3. LLHeapBuffer createSegment failed", (FALSE == buf.createSegment(channel, requestSize, segment))); | ||
102 | |||
103 | LLHeapBuffer buf1(bigSize); | ||
104 | |||
105 | // requst for more than default size but less than total sizeit should fail now. | ||
106 | requestSize = 16384 + 1; | ||
107 | ensure("4. LLHeapBuffer createSegment failed", (TRUE == buf1.createSegment(channel, requestSize, segment)) && segment.size() == requestSize); | ||
108 | |||
109 | LLHeapBuffer buf2((U8*) str, smallSize); | ||
110 | requestSize = smallSize; | ||
111 | ensure("5. LLHeapBuffer createSegment failed", (TRUE == buf2.createSegment(channel, requestSize, segment)) && segment.size() == requestSize && memcmp(segment.data(), (U8*) str, requestSize) == 0); | ||
112 | requestSize = smallSize+1; | ||
113 | ensure("6. LLHeapBuffer createSegment failed", (FALSE == buf2.createSegment(channel, requestSize, segment))); | ||
114 | } | ||
115 | |||
116 | //makeChannelConsumer() | ||
117 | template<> template<> | ||
118 | void buffer_object_t::test<5>() | ||
119 | { | ||
120 | LLChannelDescriptors inchannelDescriptors(20); | ||
121 | LLChannelDescriptors outchannelDescriptors = LLBufferArray::makeChannelConsumer(inchannelDescriptors); | ||
122 | ensure("LLBufferArray::makeChannelConsumer() function Failed", (21 == outchannelDescriptors.in())); | ||
123 | } | ||
124 | |||
125 | template<> template<> | ||
126 | void buffer_object_t::test<6>() | ||
127 | { | ||
128 | LLBufferArray bufferArray; | ||
129 | const char array[] = "SecondLife"; | ||
130 | S32 len = strlen(array); | ||
131 | LLChannelDescriptors channelDescriptors = bufferArray.nextChannel(); | ||
132 | bufferArray.append(channelDescriptors.in(), (U8*)array, len); | ||
133 | S32 count = bufferArray.countAfter(channelDescriptors.in(), NULL); | ||
134 | ensure_equals("Appended size is:", count, len); | ||
135 | } | ||
136 | |||
137 | //append() and prepend() | ||
138 | template<> template<> | ||
139 | void buffer_object_t::test<7>() | ||
140 | { | ||
141 | LLBufferArray bufferArray; | ||
142 | const char array[] = "SecondLife"; | ||
143 | S32 len = strlen(array); | ||
144 | const char array1[] = "LindenLabs"; | ||
145 | S32 len1 = strlen(array1); | ||
146 | |||
147 | std::string str(array1); | ||
148 | str.append(array); | ||
149 | |||
150 | LLChannelDescriptors channelDescriptors = bufferArray.nextChannel(); | ||
151 | bufferArray.append(channelDescriptors.in(), (U8*)array, len); | ||
152 | bufferArray.prepend(channelDescriptors.in(), (U8*)array1, len1); | ||
153 | char buf[100]; | ||
154 | S32 len2 = 20; | ||
155 | bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2); | ||
156 | ensure_equals("readAfter length failed", len2, 20); | ||
157 | |||
158 | buf[len2] = '\0'; | ||
159 | ensure_equals("readAfter/prepend/append failed", buf, str); | ||
160 | } | ||
161 | |||
162 | //append() | ||
163 | template<> template<> | ||
164 | void buffer_object_t::test<8>() | ||
165 | { | ||
166 | LLBufferArray bufferArray; | ||
167 | const char array[] = "SecondLife"; | ||
168 | S32 len = strlen(array); | ||
169 | const char array1[] = "LindenLabs"; | ||
170 | S32 len1 = strlen(array1); | ||
171 | |||
172 | std::string str(array); | ||
173 | str.append(array1); | ||
174 | |||
175 | LLChannelDescriptors channelDescriptors = bufferArray.nextChannel(); | ||
176 | bufferArray.append(channelDescriptors.in(), (U8*)array, len); | ||
177 | bufferArray.append(channelDescriptors.in(), (U8*)array1, len1); | ||
178 | char buf[100]; | ||
179 | S32 len2 = 20; | ||
180 | bufferArray.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2); | ||
181 | ensure_equals("readAfter length failed", len2, 20); | ||
182 | |||
183 | buf[len2] = '\0'; | ||
184 | ensure_equals("readAfter/append/append failed", buf, str); | ||
185 | } | ||
186 | |||
187 | template<> template<> | ||
188 | void buffer_object_t::test<9>() | ||
189 | { | ||
190 | LLBufferArray bufferArray; | ||
191 | const char array[] = "SecondLife"; | ||
192 | S32 len = strlen(array) + 1; | ||
193 | std::string str(array); | ||
194 | LLChannelDescriptors channelDescriptors = bufferArray.nextChannel(); | ||
195 | bufferArray.append(channelDescriptors.in(), (U8*)array, len); | ||
196 | LLBufferArray bufferArray1; | ||
197 | ensure("Contents are not copied and the source buffer is not empty", (1 == bufferArray1.takeContents(bufferArray))); | ||
198 | |||
199 | char buf[100]; | ||
200 | S32 len2 = len; | ||
201 | bufferArray1.readAfter(channelDescriptors.in(), NULL, (U8*)buf, len2); | ||
202 | ensure_equals("takeContents failed to copy", buf, str); | ||
203 | } | ||
204 | |||
205 | //seek() | ||
206 | template<> template<> | ||
207 | void buffer_object_t::test<10>() | ||
208 | { | ||
209 | const char array[] = "SecondLife is a Virtual World"; | ||
210 | S32 len = strlen(array); | ||
211 | LLBufferArray bufferArray; | ||
212 | bufferArray.append(0, (U8*)array, len); | ||
213 | |||
214 | char buf[255]; | ||
215 | S32 len1 = 16; | ||
216 | U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1); | ||
217 | buf[len1] = '\0'; | ||
218 | last = bufferArray.seek(0, last, -2); | ||
219 | |||
220 | len1 = 15; | ||
221 | last = bufferArray.readAfter(0, last, (U8*)buf, len1); | ||
222 | buf[len1] = '\0'; | ||
223 | std::string str(buf); | ||
224 | ensure_equals("Seek does'nt worked", str, std::string("a Virtual World")); | ||
225 | } | ||
226 | |||
227 | template<> template<> | ||
228 | void buffer_object_t::test<11>() | ||
229 | { | ||
230 | const char array[] = "SecondLife is a Virtual World"; | ||
231 | S32 len = strlen(array); | ||
232 | LLBufferArray bufferArray; | ||
233 | bufferArray.append(0, (U8*)array, len); | ||
234 | |||
235 | char buf[255]; | ||
236 | S32 len1 = 10; | ||
237 | U8* last = bufferArray.readAfter(0, 0, (U8*)buf, len1); | ||
238 | bufferArray.splitAfter(last); | ||
239 | LLBufferArray::segment_iterator_t iterator = bufferArray.beginSegment(); | ||
240 | ++iterator; | ||
241 | std::string str(((char*)(*iterator).data()), (*iterator).size()); | ||
242 | ensure_equals("Strings are not equal;splitAfter() operation failed", str, std::string(" is a Virtual World")); | ||
243 | } | ||
244 | |||
245 | //makeSegment()->eraseSegment() | ||
246 | template<> template<> | ||
247 | void buffer_object_t::test<12>() | ||
248 | { | ||
249 | LLBufferArray bufferArray; | ||
250 | LLChannelDescriptors channelDescriptors; | ||
251 | LLBufferArray::segment_iterator_t it; | ||
252 | S32 length = 1000; | ||
253 | it = bufferArray.makeSegment(channelDescriptors.out(), length); | ||
254 | ensure("makeSegment() function failed", (it != bufferArray.endSegment())); | ||
255 | ensure("eraseSegment() function failed", bufferArray.eraseSegment(it)); | ||
256 | ensure("eraseSegment() begin/end should now be same", bufferArray.beginSegment() == bufferArray.endSegment()); | ||
257 | } | ||
258 | |||
259 | // constructSegmentAfter() | ||
260 | template<> template<> | ||
261 | void buffer_object_t::test<13>() | ||
262 | { | ||
263 | LLBufferArray bufferArray; | ||
264 | LLBufferArray::segment_iterator_t it; | ||
265 | LLSegment segment; | ||
266 | LLBufferArray::segment_iterator_t end = bufferArray.endSegment(); | ||
267 | it = bufferArray.constructSegmentAfter(NULL, segment); | ||
268 | ensure("constructSegmentAfter() function failed", (it == end)); | ||
269 | } | ||
270 | } | ||
diff --git a/linden/indra/test/lldatapacker_tut.cpp b/linden/indra/test/lldatapacker_tut.cpp index 71def35..1c2a10e 100644 --- a/linden/indra/test/lldatapacker_tut.cpp +++ b/linden/indra/test/lldatapacker_tut.cpp | |||
@@ -1,11 +1,12 @@ | |||
1 | /** | 1 | /** |
2 | * @file lldatapacker_tut.cpp | 2 | * @file lldatapacker_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date February 2007 | 4 | * @date 2007-02 |
5 | * @brief LLDataPacker test cases. | 5 | * @brief LLDataPacker test cases. |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
diff --git a/linden/indra/test/lldate_tut.cpp b/linden/indra/test/lldate_tut.cpp new file mode 100644 index 0000000..f8813e3 --- /dev/null +++ b/linden/indra/test/lldate_tut.cpp | |||
@@ -0,0 +1,206 @@ | |||
1 | /** | ||
2 | * @file lldate_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief LLDate test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "linden_common.h" | ||
33 | #include "lldate.h" | ||
34 | |||
35 | #define VALID_DATE "2003-04-30T04:00:00Z" | ||
36 | #define VALID_DATE_LEAP "2004-02-29T04:00:00Z" | ||
37 | #define VALID_DATE_HOUR_BOUNDARY "2003-04-30T23:59:59Z" | ||
38 | |||
39 | // invalid format | ||
40 | #define INVALID_DATE_MISSING_YEAR "-04-30T22:59:59Z" | ||
41 | #define INVALID_DATE_MISSING_MONTH "1900-0430T22:59:59Z" | ||
42 | #define INVALID_DATE_MISSING_DATE "1900-0430-T22:59:59Z" | ||
43 | #define INVALID_DATE_MISSING_T "1900-04-30-22:59:59Z" | ||
44 | #define INVALID_DATE_MISSING_HOUR "1900-04-30T:59:59Z" | ||
45 | #define INVALID_DATE_MISSING_MIN "1900-04-30T01::59Z" | ||
46 | #define INVALID_DATE_MISSING_SEC "1900-04-30T01:59Z" | ||
47 | #define INVALID_DATE_MISSING_Z "1900-04-30T01:59:23" | ||
48 | #define INVALID_DATE_EMPTY "" | ||
49 | |||
50 | // invalid values | ||
51 | // apr 1.1.1 seems to not care about constraining the date to valid | ||
52 | // dates. Put these back when the parser checks. | ||
53 | #define LL_DATE_PARSER_CHECKS_BOUNDARY 0 | ||
54 | //#define INVALID_DATE_24HOUR_BOUNDARY "2003-04-30T24:00:00Z" | ||
55 | //#define INVALID_DATE_LEAP "2003-04-29T04:00:00Z" | ||
56 | //#define INVALID_DATE_HOUR "2003-04-30T24:59:59Z" | ||
57 | //#define INVALID_DATE_MIN "2003-04-30T22:69:59Z" | ||
58 | //#define INVALID_DATE_SEC "2003-04-30T22:59:69Z" | ||
59 | //#define INVALID_DATE_YEAR "0-04-30T22:59:59Z" | ||
60 | //#define INVALID_DATE_MONTH "2003-13-30T22:59:59Z" | ||
61 | //#define INVALID_DATE_DAY "2003-04-35T22:59:59Z" | ||
62 | |||
63 | namespace tut | ||
64 | { | ||
65 | struct date_test | ||
66 | { | ||
67 | |||
68 | }; | ||
69 | typedef test_group<date_test> date_test_t; | ||
70 | typedef date_test_t::object date_test_object_t; | ||
71 | tut::date_test_t tut_date_test("date_test"); | ||
72 | |||
73 | /* format validation */ | ||
74 | template<> template<> | ||
75 | void date_test_object_t::test<1>() | ||
76 | { | ||
77 | LLDate date(VALID_DATE); | ||
78 | std::string expected_string; | ||
79 | bool result; | ||
80 | expected_string = VALID_DATE; | ||
81 | ensure_equals("Valid Date failed" , expected_string, date.asString()); | ||
82 | |||
83 | result = date.fromString(VALID_DATE_LEAP); | ||
84 | expected_string = VALID_DATE_LEAP; | ||
85 | ensure_equals("VALID_DATE_LEAP failed" , expected_string, date.asString()); | ||
86 | |||
87 | result = date.fromString(VALID_DATE_HOUR_BOUNDARY); | ||
88 | expected_string = VALID_DATE_HOUR_BOUNDARY; | ||
89 | ensure_equals("VALID_DATE_HOUR_BOUNDARY failed" , expected_string, date.asString()); | ||
90 | |||
91 | result = date.fromString(INVALID_DATE_MISSING_YEAR); | ||
92 | ensure_equals("INVALID_DATE_MISSING_YEAR should have failed" , result, false); | ||
93 | |||
94 | result = date.fromString(INVALID_DATE_MISSING_MONTH); | ||
95 | ensure_equals("INVALID_DATE_MISSING_MONTH should have failed" , result, false); | ||
96 | |||
97 | result = date.fromString(INVALID_DATE_MISSING_DATE); | ||
98 | ensure_equals("INVALID_DATE_MISSING_DATE should have failed" , result, false); | ||
99 | |||
100 | result = date.fromString(INVALID_DATE_MISSING_T); | ||
101 | ensure_equals("INVALID_DATE_MISSING_T should have failed" , result, false); | ||
102 | |||
103 | result = date.fromString(INVALID_DATE_MISSING_HOUR); | ||
104 | ensure_equals("INVALID_DATE_MISSING_HOUR should have failed" , result, false); | ||
105 | |||
106 | result = date.fromString(INVALID_DATE_MISSING_MIN); | ||
107 | ensure_equals("INVALID_DATE_MISSING_MIN should have failed" , result, false); | ||
108 | |||
109 | result = date.fromString(INVALID_DATE_MISSING_SEC); | ||
110 | ensure_equals("INVALID_DATE_MISSING_SEC should have failed" , result, false); | ||
111 | |||
112 | result = date.fromString(INVALID_DATE_MISSING_Z); | ||
113 | ensure_equals("INVALID_DATE_MISSING_Z should have failed" , result, false); | ||
114 | |||
115 | result = date.fromString(INVALID_DATE_EMPTY); | ||
116 | ensure_equals("INVALID_DATE_EMPTY should have failed" , result, false); | ||
117 | } | ||
118 | |||
119 | /* Invalid Value Handling */ | ||
120 | template<> template<> | ||
121 | void date_test_object_t::test<2>() | ||
122 | { | ||
123 | #if LL_DATE_PARSER_CHECKS_BOUNDARY | ||
124 | LLDate date; | ||
125 | std::string expected_string; | ||
126 | bool result; | ||
127 | |||
128 | result = date.fromString(INVALID_DATE_24HOUR_BOUNDARY); | ||
129 | ensure_equals("INVALID_DATE_24HOUR_BOUNDARY should have failed" , result, false); | ||
130 | ensure_equals("INVALID_DATE_24HOUR_BOUNDARY date still set to old value on failure!" , date.secondsSinceEpoch(), 0); | ||
131 | |||
132 | result = date.fromString(INVALID_DATE_LEAP); | ||
133 | ensure_equals("INVALID_DATE_LEAP should have failed" , result, false); | ||
134 | |||
135 | result = date.fromString(INVALID_DATE_HOUR); | ||
136 | ensure_equals("INVALID_DATE_HOUR should have failed" , result, false); | ||
137 | |||
138 | result = date.fromString(INVALID_DATE_MIN); | ||
139 | ensure_equals("INVALID_DATE_MIN should have failed" , result, false); | ||
140 | |||
141 | result = date.fromString(INVALID_DATE_SEC); | ||
142 | ensure_equals("INVALID_DATE_SEC should have failed" , result, false); | ||
143 | |||
144 | result = date.fromString(INVALID_DATE_YEAR); | ||
145 | ensure_equals("INVALID_DATE_YEAR should have failed" , result, false); | ||
146 | |||
147 | result = date.fromString(INVALID_DATE_MONTH); | ||
148 | ensure_equals("INVALID_DATE_MONTH should have failed" , result, false); | ||
149 | |||
150 | result = date.fromString(INVALID_DATE_DAY); | ||
151 | ensure_equals("INVALID_DATE_DAY should have failed" , result, false); | ||
152 | #endif | ||
153 | } | ||
154 | |||
155 | /* API checks */ | ||
156 | template<> template<> | ||
157 | void date_test_object_t::test<3>() | ||
158 | { | ||
159 | LLDate date; | ||
160 | std::istringstream stream(VALID_DATE); | ||
161 | std::string expected_string = VALID_DATE; | ||
162 | date.fromStream(stream); | ||
163 | ensure_equals("fromStream failed", date.asString(), expected_string); | ||
164 | } | ||
165 | |||
166 | template<> template<> | ||
167 | void date_test_object_t::test<4>() | ||
168 | { | ||
169 | LLDate date1(VALID_DATE); | ||
170 | LLDate date2(date1); | ||
171 | ensure_equals("LLDate(const LLDate& date) constructor failed", date1.asString(), date2.asString()); | ||
172 | } | ||
173 | |||
174 | template<> template<> | ||
175 | void date_test_object_t::test<5>() | ||
176 | { | ||
177 | LLDate date1(VALID_DATE); | ||
178 | LLDate date2(date1.secondsSinceEpoch()); | ||
179 | ensure_equals("secondsSinceEpoch not equal",date1.secondsSinceEpoch(), date2.secondsSinceEpoch()); | ||
180 | ensure_equals("LLDate created using secondsSinceEpoch not equal", date1.asString(), date2.asString()); | ||
181 | } | ||
182 | |||
183 | template<> template<> | ||
184 | void date_test_object_t::test<6>() | ||
185 | { | ||
186 | LLDate date(VALID_DATE); | ||
187 | std::ostringstream stream; | ||
188 | stream << date; | ||
189 | std::string expected_str = VALID_DATE; | ||
190 | ensure_equals("ostringstream failed", expected_str, stream.str()); | ||
191 | } | ||
192 | |||
193 | template<> template<> | ||
194 | void date_test_object_t::test<7>() | ||
195 | { | ||
196 | LLDate date; | ||
197 | std::istringstream stream(VALID_DATE); | ||
198 | stream >> date; | ||
199 | std::string expected_str = VALID_DATE; | ||
200 | std::ostringstream out_stream; | ||
201 | out_stream << date; | ||
202 | |||
203 | ensure_equals("<< failed", date.asString(),expected_str); | ||
204 | ensure_equals("<< to >> failed", stream.str(),out_stream.str()); | ||
205 | } | ||
206 | } | ||
diff --git a/linden/indra/test/llhost_tut.cpp b/linden/indra/test/llhost_tut.cpp new file mode 100644 index 0000000..01f3079 --- /dev/null +++ b/linden/indra/test/llhost_tut.cpp | |||
@@ -0,0 +1,237 @@ | |||
1 | /** | ||
2 | * @file llhost_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief llhost test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llhost.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct host_data | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<host_data> host_test; | ||
42 | typedef host_test::object host_object; | ||
43 | tut::host_test host_testcase("llhost"); | ||
44 | |||
45 | |||
46 | template<> template<> | ||
47 | void host_object::test<1>() | ||
48 | { | ||
49 | LLHost host; | ||
50 | ensure("IP address is not NULL", (0 == host.getAddress()) && (0 == host.getPort()) && !host.isOk()); | ||
51 | } | ||
52 | template<> template<> | ||
53 | void host_object::test<2>() | ||
54 | { | ||
55 | U32 ip_addr = 0xc098017d; | ||
56 | U32 port = 8080; | ||
57 | LLHost host(ip_addr, port); | ||
58 | ensure("IP address is invalid", ip_addr == host.getAddress()); | ||
59 | ensure("Port Number is invalid", port == host.getPort()); | ||
60 | ensure("IP address and port number both should be ok", host.isOk()); | ||
61 | } | ||
62 | |||
63 | template<> template<> | ||
64 | void host_object::test<3>() | ||
65 | { | ||
66 | const char* str = "192.168.1.1"; | ||
67 | U32 port = 8080; | ||
68 | LLHost host(str, port); | ||
69 | ensure("IP address could not be processed", (host.getAddress() == ip_string_to_u32(str))); | ||
70 | ensure("Port Number is invalid", (port == host.getPort())); | ||
71 | } | ||
72 | |||
73 | template<> template<> | ||
74 | void host_object::test<4>() | ||
75 | { | ||
76 | U32 ip = ip_string_to_u32("192.168.1.1"); | ||
77 | U32 port = 22; | ||
78 | U64 ip_port = (((U64) ip) << 32) | port; | ||
79 | LLHost host(ip_port); | ||
80 | ensure("IP address is invalid", ip == host.getAddress()); | ||
81 | ensure("Port Number is invalid", port == host.getPort()); | ||
82 | } | ||
83 | |||
84 | template<> template<> | ||
85 | void host_object::test<5>() | ||
86 | { | ||
87 | std::string ip_port_string = "192.168.1.1:8080"; | ||
88 | U32 ip = ip_string_to_u32("192.168.1.1"); | ||
89 | U32 port = 8080; | ||
90 | |||
91 | LLHost host(ip_port_string.c_str()); | ||
92 | ensure("IP address from IP:port is invalid", ip == host.getAddress()); | ||
93 | ensure("Port Number from from IP:port is invalid", port == host.getPort()); | ||
94 | } | ||
95 | |||
96 | template<> template<> | ||
97 | void host_object::test<6>() | ||
98 | { | ||
99 | U32 ip = 0xc098017d, port = 8080; | ||
100 | LLHost host; | ||
101 | host.set(ip,port); | ||
102 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
103 | ensure("Port Number is invalid", (port == host.getPort())); | ||
104 | } | ||
105 | |||
106 | template<> template<> | ||
107 | void host_object::test<7>() | ||
108 | { | ||
109 | const char* str = "192.168.1.1"; | ||
110 | U32 port = 8080, ip; | ||
111 | LLHost host; | ||
112 | host.set(str,port); | ||
113 | ip = ip_string_to_u32(str); | ||
114 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
115 | ensure("Port Number is invalid", (port == host.getPort())); | ||
116 | |||
117 | str = "64.233.187.99"; | ||
118 | ip = ip_string_to_u32(str); | ||
119 | host.setAddress(str); | ||
120 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
121 | |||
122 | ip = 0xc098017b; | ||
123 | host.setAddress(ip); | ||
124 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
125 | // should still use the old port | ||
126 | ensure("Port Number is invalid", (port == host.getPort())); | ||
127 | |||
128 | port = 8084; | ||
129 | host.setPort(port); | ||
130 | ensure("Port Number is invalid", (port == host.getPort())); | ||
131 | // should still use the old address | ||
132 | ensure("IP address is invalid", (ip == host.getAddress())); | ||
133 | } | ||
134 | |||
135 | template<> template<> | ||
136 | void host_object::test<8>() | ||
137 | { | ||
138 | char buffer[50]; | ||
139 | char buffer1[50]; | ||
140 | const char* str = "192.168.1.1"; | ||
141 | U32 port = 8080; | ||
142 | LLHost host; | ||
143 | host.set(str,port); | ||
144 | host.getString(buffer, 50); | ||
145 | ensure("Function Failed", (0 == strcmp("192.168.1.1:8080", buffer))); | ||
146 | |||
147 | host.getIPString(buffer1, 50); | ||
148 | ensure("Function Failed", (0 == strcmp(str, buffer1))); | ||
149 | |||
150 | std::string ip_string = host.getIPString(); | ||
151 | ensure("Function Failed", (0 == strcmp(str, buffer1))); | ||
152 | |||
153 | std::string ip_string_port = host.getIPandPort(); | ||
154 | ensure("Function Failed", (0 == strcmp("192.168.1.1:8080", buffer))); | ||
155 | } | ||
156 | |||
157 | |||
158 | // getHostName() and setHostByName | ||
159 | template<> template<> | ||
160 | void host_object::test<9>() | ||
161 | { | ||
162 | std::string hostStr = "google.com"; | ||
163 | char buffer[50] = {0}; | ||
164 | LLHost host; | ||
165 | host.setHostByName(hostStr.c_str()); | ||
166 | host.getHostName(buffer, 50); | ||
167 | // reverse DNS will likely result in appending of some | ||
168 | // sub-domain to the main hostname. so look for | ||
169 | // the main domain name and not do the exact compare | ||
170 | ensure("getHostName failed", (NULL != strstr(buffer, hostStr.c_str()))); | ||
171 | |||
172 | LLString hostname = host.getHostName(); | ||
173 | ensure("getHostName failed", (NULL != strstr(hostname.c_str(), hostStr.c_str()))); | ||
174 | } | ||
175 | |||
176 | // setHostByName for dotted IP | ||
177 | template<> template<> | ||
178 | void host_object::test<10>() | ||
179 | { | ||
180 | std::string hostStr = "64.233.167.99"; | ||
181 | LLHost host; | ||
182 | host.setHostByName(hostStr.c_str()); | ||
183 | ensure("SetHostByName for dotted IP Address failed", host.getAddress() == ip_string_to_u32(hostStr.c_str())); | ||
184 | } | ||
185 | |||
186 | template<> template<> | ||
187 | void host_object::test<11>() | ||
188 | { | ||
189 | LLHost host1(0xc098017d, 8080); | ||
190 | LLHost host2 = host1; | ||
191 | ensure("Both IP addresses are not same", (host1.getAddress() == host2.getAddress())); | ||
192 | ensure("Both port numbers are not same", (host1.getPort() == host2.getPort())); | ||
193 | } | ||
194 | |||
195 | template<> template<> | ||
196 | void host_object::test<12>() | ||
197 | { | ||
198 | LLHost host1("192.168.1.1", 8080); | ||
199 | std::string str1 = "192.168.1.1:8080"; | ||
200 | std::ostringstream stream; | ||
201 | stream << host1; | ||
202 | ensure("Operator << failed", ( stream.str()== str1)); | ||
203 | |||
204 | // There is no istream >> llhost operator. | ||
205 | //std::istringstream is(stream.str()); | ||
206 | //LLHost host2; | ||
207 | //is >> host2; | ||
208 | //ensure("Operator >> failed. Not compatible with <<", host1 == host2); | ||
209 | } | ||
210 | |||
211 | // operators ==, !=, < | ||
212 | template<> template<> | ||
213 | void host_object::test<13>() | ||
214 | { | ||
215 | U32 ip_addr = 0xc098017d; | ||
216 | U32 port = 8080; | ||
217 | LLHost host1(ip_addr, port); | ||
218 | LLHost host2(ip_addr, port); | ||
219 | ensure("operator== failed", host1 == host2); | ||
220 | |||
221 | // change port | ||
222 | host2.setPort(7070); | ||
223 | ensure("operator!= failed", host1 != host2); | ||
224 | |||
225 | // set port back to 8080 and change IP address now | ||
226 | host2.setPort(8080); | ||
227 | host2.setAddress(ip_addr+10); | ||
228 | ensure("operator!= failed", host1 != host2); | ||
229 | |||
230 | ensure("operator< failed", host1 < host2); | ||
231 | |||
232 | // set IP address back to same value and change port | ||
233 | host2.setAddress(ip_addr); | ||
234 | host2.setPort(host1.getPort() + 10); | ||
235 | ensure("operator< failed", host1 < host2); | ||
236 | } | ||
237 | } | ||
diff --git a/linden/indra/test/lljoint_tut.cpp b/linden/indra/test/lljoint_tut.cpp new file mode 100644 index 0000000..5be81ae --- /dev/null +++ b/linden/indra/test/lljoint_tut.cpp | |||
@@ -0,0 +1,244 @@ | |||
1 | /** | ||
2 | * @file lljoint_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007=-03 | ||
5 | * @brief lljoint test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #ifdef THIS_DOESNT_LINK | ||
32 | // THIS DOESN'T LINK! | ||
33 | |||
34 | #include <tut/tut.h> | ||
35 | #include "lltut.h" | ||
36 | #include "linden_common.h" | ||
37 | #include "m4math.h" | ||
38 | #include "v3math.h" | ||
39 | #include "lljoint.h" | ||
40 | |||
41 | |||
42 | namespace tut | ||
43 | { | ||
44 | struct lljoint_data | ||
45 | { | ||
46 | }; | ||
47 | typedef test_group<lljoint_data> lljoint_test; | ||
48 | typedef lljoint_test::object lljoint_object; | ||
49 | tut::lljoint_test lljoint_testcase("lljoint"); | ||
50 | |||
51 | template<> template<> | ||
52 | void lljoint_object::test<1>() | ||
53 | { | ||
54 | LLJoint lljoint; | ||
55 | LLJoint* jnt = lljoint.getParent(); | ||
56 | ensure("getParent() failed ", (NULL == jnt)); | ||
57 | ensure("getRoot() failed ", (&lljoint == lljoint.getRoot())); | ||
58 | } | ||
59 | |||
60 | template<> template<> | ||
61 | void lljoint_object::test<2>() | ||
62 | { | ||
63 | std::string str = "LLJoint"; | ||
64 | LLJoint parent(str), child; | ||
65 | child.setup(str, &parent); | ||
66 | LLJoint* jnt = child.getParent(); | ||
67 | ensure("setup() failed ", (&parent == jnt)); | ||
68 | } | ||
69 | |||
70 | template<> template<> | ||
71 | void lljoint_object::test<3>() | ||
72 | { | ||
73 | LLJoint parent, child; | ||
74 | std::string str = "LLJoint"; | ||
75 | child.setup(str, &parent); | ||
76 | LLJoint* jnt = parent.findJoint(str); | ||
77 | ensure("findJoint() failed ", (&child == jnt)); | ||
78 | } | ||
79 | |||
80 | template<> template<> | ||
81 | void lljoint_object::test<4>() | ||
82 | { | ||
83 | LLJoint parent; | ||
84 | std::string str1 = "LLJoint", str2; | ||
85 | parent.setName(str1); | ||
86 | str2 = parent.getName(); | ||
87 | ensure("setName() failed ", (str1 == str2)); | ||
88 | } | ||
89 | |||
90 | template<> template<> | ||
91 | void lljoint_object::test<5>() | ||
92 | { | ||
93 | LLJoint lljoint; | ||
94 | LLVector3 vec3(2.3f,30.f,10.f); | ||
95 | lljoint.setPosition(vec3); | ||
96 | LLVector3 pos = lljoint.getPosition(); | ||
97 | ensure("setPosition()/getPosition() failed ", (vec3 == pos)); | ||
98 | } | ||
99 | |||
100 | template<> template<> | ||
101 | void lljoint_object::test<6>() | ||
102 | { | ||
103 | LLJoint lljoint; | ||
104 | LLVector3 vec3(2.3f,30.f,10.f); | ||
105 | lljoint.setWorldPosition(vec3); | ||
106 | LLVector3 pos = lljoint.getWorldPosition(); | ||
107 | ensure("1:setWorldPosition()/getWorldPosition() failed ", (vec3 == pos)); | ||
108 | LLVector3 lastPos = lljoint.getLastWorldPosition(); | ||
109 | ensure("2:getLastWorldPosition failed ", (vec3 == lastPos)); | ||
110 | } | ||
111 | |||
112 | template<> template<> | ||
113 | void lljoint_object::test<7>() | ||
114 | { | ||
115 | LLJoint lljoint("LLJoint"); | ||
116 | LLQuaternion q(2.3f,30.f,10.f,1.f); | ||
117 | lljoint.setRotation(q); | ||
118 | LLQuaternion rot = lljoint.getRotation(); | ||
119 | ensure("setRotation()/getRotation() failed ", (q == rot)); | ||
120 | } | ||
121 | template<> template<> | ||
122 | void lljoint_object::test<8>() | ||
123 | { | ||
124 | LLJoint lljoint("LLJoint"); | ||
125 | LLQuaternion q(2.3f,30.f,10.f,1.f); | ||
126 | lljoint.setWorldRotation(q); | ||
127 | LLQuaternion rot = lljoint.getWorldRotation(); | ||
128 | ensure("1:setWorldRotation()/getWorldRotation() failed ", (q == rot)); | ||
129 | LLQuaternion lastRot = lljoint.getLastWorldRotation(); | ||
130 | ensure("2:getLastWorldRotation failed ", (q == lastRot)); | ||
131 | } | ||
132 | |||
133 | template<> template<> | ||
134 | void lljoint_object::test<9>() | ||
135 | { | ||
136 | LLJoint lljoint; | ||
137 | LLVector3 vec3(2.3f,30.f,10.f); | ||
138 | lljoint.setScale(vec3); | ||
139 | LLVector3 scale = lljoint.getScale(); | ||
140 | ensure("setScale()/getScale failed ", (vec3 == scale)); | ||
141 | } | ||
142 | |||
143 | template<> template<> | ||
144 | void lljoint_object::test<10>() | ||
145 | { | ||
146 | LLJoint lljoint("LLJoint"); | ||
147 | LLMatrix4 mat; | ||
148 | mat.identity(); | ||
149 | lljoint.setWorldMatrix(mat);//giving warning setWorldMatrix not correctly implemented; | ||
150 | LLMatrix4 mat4 = lljoint.getWorldMatrix(); | ||
151 | ensure("setWorldMatrix()/getWorldMatrix failed ", (mat4 == mat)); | ||
152 | } | ||
153 | |||
154 | template<> template<> | ||
155 | void lljoint_object::test<11>() | ||
156 | { | ||
157 | LLJoint lljoint("parent"); | ||
158 | S32 joint_num = 12; | ||
159 | lljoint.setJointNum(joint_num); | ||
160 | S32 jointNum = lljoint.getJointNum(); | ||
161 | ensure("setJointNum()/getJointNum failed ", (jointNum == joint_num)); | ||
162 | } | ||
163 | |||
164 | template<> template<> | ||
165 | void lljoint_object::test<12>() | ||
166 | { | ||
167 | LLJoint lljoint; | ||
168 | LLVector3 vec3(2.3f,30.f,10.f); | ||
169 | lljoint.setSkinOffset(vec3); | ||
170 | LLVector3 offset = lljoint.getSkinOffset(); | ||
171 | ensure("1:setSkinOffset()/getSkinOffset() failed ", (vec3 == offset)); | ||
172 | } | ||
173 | |||
174 | template<> template<> | ||
175 | void lljoint_object::test<13>() | ||
176 | { | ||
177 | LLJoint lljointgp("gparent"); | ||
178 | LLJoint lljoint("parent"); | ||
179 | LLJoint lljoint1("child1"); | ||
180 | lljoint.addChild(&lljoint1); | ||
181 | LLJoint lljoint2("child2"); | ||
182 | lljoint.addChild(&lljoint2); | ||
183 | LLJoint lljoint3("child3"); | ||
184 | lljoint.addChild(&lljoint3); | ||
185 | |||
186 | LLJoint* jnt = NULL; | ||
187 | jnt = lljoint2.getParent(); | ||
188 | ensure("addChild() failed ", (&lljoint == jnt)); | ||
189 | LLJoint* jnt1 = lljoint.findJoint("child3"); | ||
190 | ensure("findJoint() failed ", (&lljoint3 == jnt1)); | ||
191 | lljoint.removeChild(&lljoint3); | ||
192 | LLJoint* jnt2 = lljoint.findJoint("child3"); | ||
193 | ensure("removeChild() failed ", (NULL == jnt2)); | ||
194 | |||
195 | lljointgp.addChild(&lljoint); | ||
196 | ensure("GetParent() failed ", (&lljoint== lljoint2.getParent())); | ||
197 | ensure("getRoot() failed ", (&lljointgp == lljoint2.getRoot())); | ||
198 | |||
199 | ensure("getRoot() failed ", &lljoint1 == lljoint.findJoint("child1")); | ||
200 | |||
201 | lljointgp.removeAllChildren(); | ||
202 | // parent removed from grandparent - so should not be able to locate child | ||
203 | ensure("removeAllChildren() failed ", (NULL == lljointgp.findJoint("child1"))); | ||
204 | // it should still exist in parent though | ||
205 | ensure("removeAllChildren() failed ", (&lljoint1 == lljoint.findJoint("child1"))); | ||
206 | } | ||
207 | |||
208 | template<> template<> | ||
209 | void lljoint_object::test<14>() | ||
210 | { | ||
211 | LLJoint lljointgp("gparent"); | ||
212 | |||
213 | LLJoint llparent1("parent1"); | ||
214 | LLJoint llparent2("parent2"); | ||
215 | |||
216 | LLJoint llchild("child1"); | ||
217 | LLJoint lladoptedchild("child2"); | ||
218 | llparent1.addChild(&llchild); | ||
219 | llparent1.addChild(&lladoptedchild); | ||
220 | |||
221 | llparent2.addChild(&lladoptedchild); | ||
222 | ensure("1. addChild failed to remove prior parent", lladoptedchild.getParent() == &llparent2); | ||
223 | ensure("2. addChild failed to remove prior parent", llparent1.findJoint("child2") == NULL); | ||
224 | } | ||
225 | |||
226 | |||
227 | //* | ||
228 | Test cases for the following not added. They perform operations | ||
229 | on underlying LLXformMatrix and LLVector3 elements which have | ||
230 | been unit tested separately. | ||
231 | Unit Testing these functions will basically require re-implementing | ||
232 | logic of these function in the test case itself | ||
233 | |||
234 | 1) void WorldMatrixChildren(); | ||
235 | 2) void updateWorldMatrixParent(); | ||
236 | 3) void updateWorldPRSParent(); | ||
237 | 4) void updateWorldMatrix(); | ||
238 | 5) LLXformMatrix *getXform() { return &mXform; } | ||
239 | 6) void setConstraintSilhouette(LLDynamicArray<LLVector3>& silhouette); | ||
240 | 7) void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot); | ||
241 | |||
242 | //* | ||
243 | } | ||
244 | #endif // THIS_DOESNT_LINK | ||
diff --git a/linden/indra/test/llmessageconfig_tut.cpp b/linden/indra/test/llmessageconfig_tut.cpp index 1d11cbf..cc2a0a2 100644 --- a/linden/indra/test/llmessageconfig_tut.cpp +++ b/linden/indra/test/llmessageconfig_tut.cpp | |||
@@ -32,41 +32,46 @@ | |||
32 | #include "llmessageconfig.h" | 32 | #include "llmessageconfig.h" |
33 | #include "llsdserialize.h" | 33 | #include "llsdserialize.h" |
34 | #include "llfile.h" | 34 | #include "llfile.h" |
35 | #include "lldir.h" | ||
35 | #include "lltimer.h" | 36 | #include "lltimer.h" |
36 | #include "llframetimer.h" | 37 | #include "llframetimer.h" |
37 | 38 | ||
38 | namespace tut | 39 | namespace tut |
39 | { | 40 | { |
40 | ///var/tmp/babbage/dev/message-liberation/etc | ||
41 | static const char file_name[] = "/tmp/message.xml"; | ||
42 | static const long refreshRateMillis = 6000; | ||
43 | |||
44 | struct LLMessageConfigTestData { | 41 | struct LLMessageConfigTestData { |
42 | std::string mTestConfigDir; | ||
45 | 43 | ||
46 | LLSD getCurrentConfig() | 44 | LLMessageConfigTestData() |
47 | { | 45 | { |
48 | LLSD data; | 46 | // generate temp dir |
49 | // store aside the current config to overwrite the test ones | 47 | mTestConfigDir = "/tmp/llmessage-config-test"; |
50 | // when the test finishes | 48 | LLFile::mkdir(mTestConfigDir.c_str()); |
51 | llifstream in_file(file_name); | 49 | |
52 | if (in_file.is_open()) | 50 | LLMessageConfig::initClass("simulator", mTestConfigDir); |
53 | { | 51 | } |
54 | LLSDSerialize::fromXML(data, in_file); | 52 | |
55 | } | 53 | ~LLMessageConfigTestData() |
56 | return data; | 54 | { |
55 | // rm contents of temp dir | ||
56 | gDirUtilp->deleteFilesInDir(mTestConfigDir, "*"); | ||
57 | // rm temp dir | ||
58 | LLFile::rmdir(mTestConfigDir.c_str()); | ||
57 | } | 59 | } |
58 | 60 | ||
61 | void reloadConfig(const LLSD& config) | ||
62 | { | ||
63 | LLMessageConfig::useConfig(config); | ||
64 | } | ||
65 | |||
59 | void writeConfigFile(const LLSD& config) | 66 | void writeConfigFile(const LLSD& config) |
60 | { | 67 | { |
61 | LLMessageConfig::initClass("simulator", "/tmp"); | 68 | std::string configFile = mTestConfigDir + "/message.xml"; |
62 | llofstream file(file_name); | 69 | llofstream file(configFile.c_str()); |
63 | if (file.is_open()) | 70 | if (file.is_open()) |
64 | { | 71 | { |
65 | LLSDSerialize::toPrettyXML(config, file); | 72 | LLSDSerialize::toPrettyXML(config, file); |
66 | } | 73 | } |
67 | file.close(); | 74 | file.close(); |
68 | ms_sleep(refreshRateMillis); | ||
69 | LLFrameTimer::updateFrameTime(); | ||
70 | } | 75 | } |
71 | }; | 76 | }; |
72 | 77 | ||
@@ -78,150 +83,116 @@ namespace tut | |||
78 | void LLMessageConfigTestObject::test<1>() | 83 | void LLMessageConfigTestObject::test<1>() |
79 | // tests server defaults | 84 | // tests server defaults |
80 | { | 85 | { |
81 | LLSD config_backup = getCurrentConfig(); | ||
82 | LLSD config; | 86 | LLSD config; |
83 | config["serverDefaults"]["simulator"] = "template"; | 87 | config["serverDefaults"]["simulator"] = "template"; |
84 | writeConfigFile(config); | 88 | reloadConfig(config); |
85 | ensure_equals("Ensure server default is not llsd", | 89 | ensure_equals("Ensure server default is not template", |
86 | LLMessageConfig::isServerDefaultBuilderLLSD(), | 90 | LLMessageConfig::getServerDefaultFlavor(), |
87 | false); | 91 | LLMessageConfig::TEMPLATE_FLAVOR); |
88 | ensure_equals("Ensure server default is template", | ||
89 | LLMessageConfig::isServerDefaultBuilderTemplate(), | ||
90 | true); | ||
91 | writeConfigFile(config_backup); | ||
92 | } | 92 | } |
93 | 93 | ||
94 | template<> template<> | 94 | template<> template<> |
95 | void LLMessageConfigTestObject::test<2>() | 95 | void LLMessageConfigTestObject::test<2>() |
96 | // tests message builders | 96 | // tests message flavors |
97 | { | 97 | { |
98 | LLSD config_backup = getCurrentConfig(); | ||
99 | LLSD config; | 98 | LLSD config; |
100 | config["serverDefaults"]["simulator"] = "template"; | 99 | config["serverDefaults"]["simulator"] = "template"; |
101 | config["messages"]["msg1"]["builder"] = "template"; | 100 | config["messages"]["msg1"]["flavor"] = "template"; |
102 | config["messages"]["msg2"]["builder"] = "llsd"; | 101 | config["messages"]["msg2"]["flavor"] = "llsd"; |
103 | writeConfigFile(config); | 102 | reloadConfig(config); |
104 | ensure_equals("Ensure msg template builder not llsd", | 103 | ensure_equals("Ensure msg template flavor", |
105 | LLMessageConfig::isMessageBuiltLLSD("msg1"), | 104 | LLMessageConfig::getMessageFlavor("msg1"), |
106 | false); | 105 | LLMessageConfig::TEMPLATE_FLAVOR); |
107 | ensure_equals("Ensure msg template builder", | 106 | ensure_equals("Ensure msg llsd flavor", |
108 | LLMessageConfig::isMessageBuiltTemplate("msg1"), | 107 | LLMessageConfig::getMessageFlavor("msg2"), |
109 | true); | 108 | LLMessageConfig::LLSD_FLAVOR); |
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 | } | 109 | } |
118 | 110 | ||
119 | template<> template<> | 111 | template<> template<> |
120 | void LLMessageConfigTestObject::test<4>() | 112 | void LLMessageConfigTestObject::test<4>() |
121 | // tests message builder defaults | 113 | // tests message flavor defaults |
122 | { | 114 | { |
123 | LLSD config_backup = getCurrentConfig(); | ||
124 | LLSD config; | 115 | LLSD config; |
125 | config["serverDefaults"]["simulator"] = "llsd"; | 116 | config["serverDefaults"]["simulator"] = "llsd"; |
126 | config["messages"]["msg1"]["trusted-sender"] = true; | 117 | config["messages"]["msg1"]["trusted-sender"] = true; |
127 | writeConfigFile(config); | 118 | reloadConfig(config); |
128 | ensure_equals("Ensure missing message defaults to server builder, not template", | 119 | ensure_equals("Ensure missing message gives no flavor", |
129 | LLMessageConfig::isMessageBuiltTemplate("Test"), | 120 | LLMessageConfig::getMessageFlavor("Test"), |
130 | false); | 121 | LLMessageConfig::NO_FLAVOR); |
131 | ensure_equals("Ensure missing message default to server builder llsd", | 122 | ensure_equals("Ensure missing flavor is NO_FLAVOR even with sender trustedness set", |
132 | LLMessageConfig::isMessageBuiltLLSD("Test"), | 123 | LLMessageConfig::getMessageFlavor("msg1"), |
133 | true); | 124 | LLMessageConfig::NO_FLAVOR); |
134 | ensure_equals("Ensure missing builder defaults to server builder, not template", | 125 | ensure_equals("Ensure server default is llsd", |
135 | LLMessageConfig::isMessageBuiltTemplate("msg1"), | 126 | LLMessageConfig::getServerDefaultFlavor(), |
136 | false); | 127 | LLMessageConfig::LLSD_FLAVOR); |
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 | } | 128 | } |
150 | 129 | ||
151 | template<> template<> | 130 | template<> template<> |
152 | void LLMessageConfigTestObject::test<3>() | 131 | void LLMessageConfigTestObject::test<3>() |
153 | // tests trusted/untrusted senders | 132 | // tests trusted/untrusted senders |
154 | { | 133 | { |
155 | LLSD config_backup = getCurrentConfig(); | ||
156 | LLSD config; | 134 | LLSD config; |
157 | config["serverDefaults"]["simulator"] = "template"; | 135 | config["serverDefaults"]["simulator"] = "template"; |
158 | config["messages"]["msg1"]["builder"] = "llsd"; | 136 | config["messages"]["msg1"]["flavor"] = "llsd"; |
159 | config["messages"]["msg1"]["trusted-sender"] = false; | 137 | config["messages"]["msg1"]["trusted-sender"] = false; |
160 | config["messages"]["msg2"]["builder"] = "llsd"; | 138 | config["messages"]["msg2"]["flavor"] = "llsd"; |
161 | config["messages"]["msg2"]["trusted-sender"] = true; | 139 | config["messages"]["msg2"]["trusted-sender"] = true; |
162 | writeConfigFile(config); | 140 | reloadConfig(config); |
163 | ensure_equals("Ensure untrusted is not trusted", | ||
164 | LLMessageConfig::isMessageTrusted("msg1"), | ||
165 | false); | ||
166 | ensure_equals("Ensure untrusted is untrusted", | 141 | ensure_equals("Ensure untrusted is untrusted", |
167 | LLMessageConfig::isValidUntrustedMessage("msg1"), | 142 | LLMessageConfig::getSenderTrustedness("msg1"), |
168 | true); | 143 | LLMessageConfig::UNTRUSTED); |
169 | ensure_equals("Ensure trusted is trusted", | 144 | ensure_equals("Ensure trusted is trusted", |
170 | LLMessageConfig::isMessageTrusted("msg2"), | 145 | LLMessageConfig::getSenderTrustedness("msg2"), |
171 | true); | 146 | LLMessageConfig::TRUSTED); |
172 | ensure_equals("Ensure trusted is not untrusted", | 147 | ensure_equals("Ensure missing trustedness is NOT_SET", |
173 | LLMessageConfig::isValidUntrustedMessage("msg2"), | 148 | LLMessageConfig::getSenderTrustedness("msg3"), |
174 | false); | 149 | LLMessageConfig::NOT_SET); |
175 | writeConfigFile(config_backup); | ||
176 | } | 150 | } |
177 | 151 | ||
178 | template<> template<> | 152 | template<> template<> |
179 | void LLMessageConfigTestObject::test<5>() | 153 | void LLMessageConfigTestObject::test<5>() |
180 | // tests trusted/untrusted without flag, only builder | 154 | // tests trusted/untrusted without flag, only flavor |
181 | { | 155 | { |
182 | LLSD config_backup = getCurrentConfig(); | ||
183 | LLSD config; | 156 | LLSD config; |
184 | config["serverDefaults"]["simulator"] = "template"; | 157 | config["serverDefaults"]["simulator"] = "template"; |
185 | config["messages"]["msg1"]["builder"] = "llsd"; | 158 | config["messages"]["msg1"]["flavor"] = "llsd"; |
186 | writeConfigFile(config); | 159 | reloadConfig(config); |
187 | ensure_equals("Ensure missing trusted is not trusted", | 160 | ensure_equals("Ensure msg1 exists, has llsd flavor", |
188 | LLMessageConfig::isMessageTrusted("msg1"), | 161 | LLMessageConfig::getMessageFlavor("msg1"), |
189 | false); | 162 | LLMessageConfig::LLSD_FLAVOR); |
190 | ensure_equals("Ensure missing trusted is not untrusted", | 163 | ensure_equals("Ensure missing trusted is not set", |
191 | LLMessageConfig::isValidUntrustedMessage("msg1"), | 164 | LLMessageConfig::getSenderTrustedness("msg1"), |
192 | false); | 165 | LLMessageConfig::NOT_SET); |
193 | writeConfigFile(config_backup); | ||
194 | } | 166 | } |
195 | 167 | ||
196 | template<> template<> | 168 | template<> template<> |
197 | void LLMessageConfigTestObject::test<6>() | 169 | void LLMessageConfigTestObject::test<6>() |
198 | // tests message builder defaults | ||
199 | { | 170 | { |
200 | LLSD config_backup = getCurrentConfig(); | ||
201 | LLSD config; | 171 | LLSD config; |
202 | config["serverDefaults"]["simulator"] = "template"; | 172 | config["capBans"]["MapLayer"] = true; |
203 | config["messages"]["msg1"]["trusted-sender"] = true; | 173 | config["capBans"]["MapLayerGod"] = false; |
204 | writeConfigFile(config); | 174 | reloadConfig(config); |
205 | ensure_equals("Ensure missing message defaults to server builder, not template", | 175 | ensure_equals("Ensure cap ban true MapLayer", |
206 | LLMessageConfig::isMessageBuiltTemplate("Test"), | 176 | LLMessageConfig::isCapBanned("MapLayer"), |
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); | 177 | true); |
214 | ensure_equals("Ensure missing builder default to server builder llsd", | 178 | ensure_equals("Ensure cap ban false", |
215 | LLMessageConfig::isMessageBuiltLLSD("msg1"), | 179 | LLMessageConfig::isCapBanned("MapLayerGod"), |
216 | false); | 180 | false); |
181 | } | ||
217 | 182 | ||
218 | ensure_equals("Ensure server default is not llsd", | 183 | template<> template<> |
219 | LLMessageConfig::isServerDefaultBuilderLLSD(), | 184 | void LLMessageConfigTestObject::test<7>() |
220 | false); | 185 | // tests that config changes are picked up/refreshed periodically |
221 | ensure_equals("Ensure server default is template", | 186 | { |
222 | LLMessageConfig::isServerDefaultBuilderTemplate(), | 187 | LLSD config; |
223 | true); | 188 | config["serverDefaults"]["simulator"] = "llsd"; |
189 | writeConfigFile(config); | ||
224 | 190 | ||
225 | writeConfigFile(config_backup); | 191 | // wait for it to reload after N seconds |
192 | ms_sleep(6*1000); | ||
193 | LLFrameTimer::updateFrameTime(); | ||
194 | ensure_equals("Ensure reload after 6 seconds", | ||
195 | LLMessageConfig::getServerDefaultFlavor(), | ||
196 | LLMessageConfig::LLSD_FLAVOR); | ||
226 | } | 197 | } |
227 | } | 198 | } |
diff --git a/linden/indra/test/llmessagetemplateparser_tut.cpp b/linden/indra/test/llmessagetemplateparser_tut.cpp new file mode 100644 index 0000000..74b4c55 --- /dev/null +++ b/linden/indra/test/llmessagetemplateparser_tut.cpp | |||
@@ -0,0 +1,370 @@ | |||
1 | /** | ||
2 | * @file llmessagetemplateparser_tut.cpp | ||
3 | * @date April 2007 | ||
4 | * @brief LLMessageTemplateParser 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 "llmessagetemplateparser.h" | ||
33 | |||
34 | namespace tut | ||
35 | { | ||
36 | struct LLMessageTemplateParserTestData { | ||
37 | LLMessageTemplateParserTestData() : mMessage("unset message") | ||
38 | { | ||
39 | } | ||
40 | |||
41 | ~LLMessageTemplateParserTestData() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | void ensure_next(LLTemplateTokenizer & tokens, | ||
46 | std::string value, | ||
47 | U32 line) | ||
48 | { | ||
49 | std::string next = tokens.next(); | ||
50 | ensure_equals(mMessage + " token matches", next, value); | ||
51 | ensure_equals(mMessage + " line matches", tokens.line(), line); | ||
52 | } | ||
53 | |||
54 | char * prehash(const char * name) | ||
55 | { | ||
56 | return gMessageStringTable.getString(name); | ||
57 | } | ||
58 | |||
59 | void ensure_block_attributes(std::string identifier, | ||
60 | const LLMessageTemplate * message, | ||
61 | const char * name, | ||
62 | EMsgBlockType type, | ||
63 | S32 number, | ||
64 | S32 total_size) | ||
65 | { | ||
66 | const LLMessageBlock * block = message->getBlock(prehash(name)); | ||
67 | identifier = identifier + ":" + message->mName + ":" + name + " block"; | ||
68 | ensure(identifier + " exists", block != NULL); | ||
69 | ensure_equals(identifier + " name", block->mName, prehash(name)); | ||
70 | ensure_equals(identifier + " type", block->mType, type); | ||
71 | ensure_equals(identifier + " number", block->mNumber, number); | ||
72 | ensure_equals(identifier + " total size", block->mTotalSize, total_size); | ||
73 | } | ||
74 | |||
75 | void ensure_variable_attributes(std::string identifier, | ||
76 | const LLMessageBlock * block, | ||
77 | const char * name, | ||
78 | EMsgVariableType type, | ||
79 | S32 size) | ||
80 | { | ||
81 | const LLMessageVariable * var = block->getVariable(prehash(name)); | ||
82 | identifier = identifier + ":" + block->mName + ":" + name + " variable"; | ||
83 | ensure(identifier + " exists", var != NULL); | ||
84 | ensure_equals( | ||
85 | identifier + " name", var->getName(), prehash(name)); | ||
86 | ensure_equals( | ||
87 | identifier + " type", var->getType(), type); | ||
88 | ensure_equals(identifier + " size", var->getSize(), size); | ||
89 | } | ||
90 | |||
91 | std::string mMessage; | ||
92 | |||
93 | }; | ||
94 | |||
95 | typedef test_group<LLMessageTemplateParserTestData> LLMessageTemplateParserTestGroup; | ||
96 | typedef LLMessageTemplateParserTestGroup::object LLMessageTemplateParserTestObject; | ||
97 | LLMessageTemplateParserTestGroup llMessageTemplateParserTestGroup("LLMessageTemplateParser"); | ||
98 | |||
99 | template<> template<> | ||
100 | void LLMessageTemplateParserTestObject::test<1>() | ||
101 | // tests tokenizer constructor and next methods | ||
102 | { | ||
103 | mMessage = "test method 1 walkthrough"; | ||
104 | LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth"); | ||
105 | ensure_next(tokens, "first", 1); | ||
106 | ensure_next(tokens, "line", 1); | ||
107 | ensure_next(tokens, "next", 2); | ||
108 | ensure_next(tokens, "line", 2); | ||
109 | ensure_next(tokens, "fourth", 4); | ||
110 | |||
111 | tokens = LLTemplateTokenizer("\n\t{ \t Test1 Fixed \n 523 }\n\n"); | ||
112 | ensure(tokens.want("{")); | ||
113 | ensure_next(tokens, "Test1", 2); | ||
114 | ensure_next(tokens, "Fixed", 2); | ||
115 | ensure_next(tokens, "523", 3); | ||
116 | ensure(tokens.want("}")); | ||
117 | |||
118 | tokens = LLTemplateTokenizer("first line\nnext\t line\n\nfourth"); | ||
119 | ensure(tokens.want("first")); | ||
120 | ensure_next(tokens, "line", 1); | ||
121 | ensure_next(tokens, "next", 2); | ||
122 | ensure_next(tokens, "line", 2); | ||
123 | ensure(tokens.want("fourth")); | ||
124 | } | ||
125 | |||
126 | template<> template<> | ||
127 | void LLMessageTemplateParserTestObject::test<2>() | ||
128 | // tests tokenizer want method | ||
129 | { | ||
130 | // *NOTE: order matters | ||
131 | LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth"); | ||
132 | ensure_equals("wants first token", tokens.want("first"), true); | ||
133 | ensure_equals("doesn't want blar token", tokens.want("blar"), false); | ||
134 | ensure_equals("wants line token", tokens.want("line"), true); | ||
135 | } | ||
136 | |||
137 | template<> template<> | ||
138 | void LLMessageTemplateParserTestObject::test<3>() | ||
139 | // tests tokenizer eof methods | ||
140 | { | ||
141 | LLTemplateTokenizer tokens("single\n\n"); | ||
142 | ensure_equals("is not at eof at beginning", tokens.atEOF(), false); | ||
143 | ensure_equals("doesn't want eof", tokens.wantEOF(), false); | ||
144 | ensure_equals("wants the first token just to consume it", | ||
145 | tokens.want("single"), true); | ||
146 | ensure_equals("is not at eof in middle", tokens.atEOF(), false); | ||
147 | ensure_equals("wants eof", tokens.wantEOF(), true); | ||
148 | ensure_equals("is at eof at end", tokens.atEOF(), true); | ||
149 | } | ||
150 | |||
151 | template<> template<> | ||
152 | void LLMessageTemplateParserTestObject::test<4>() | ||
153 | // tests variable parsing method | ||
154 | { | ||
155 | LLTemplateTokenizer tokens(std::string("{ Test0 \n\t\n U32 \n\n }")); | ||
156 | LLMessageVariable * var = LLTemplateParser::parseVariable(tokens); | ||
157 | |||
158 | ensure("test0 var parsed", var != 0); | ||
159 | ensure_equals("name of variable", std::string(var->getName()), std::string("Test0")); | ||
160 | ensure_equals("type of variable is U32", var->getType(), MVT_U32); | ||
161 | ensure_equals("size of variable", var->getSize(), 4); | ||
162 | |||
163 | delete var; | ||
164 | |||
165 | std::string message_string("\n\t{ \t Test1 Fixed \n 523 }\n\n"); | ||
166 | tokens = LLTemplateTokenizer(message_string); | ||
167 | var = LLTemplateParser::parseVariable(tokens); | ||
168 | |||
169 | ensure("test1 var parsed", var != 0); | ||
170 | ensure_equals("name of variable", std::string(var->getName()), std::string("Test1")); | ||
171 | ensure_equals("type of variable is Fixed", var->getType(), MVT_FIXED); | ||
172 | ensure_equals("size of variable", var->getSize(), 523); | ||
173 | |||
174 | delete var; | ||
175 | |||
176 | // *NOTE: the parsers call llerrs on invalid input, so we can't really | ||
177 | // test that :-( | ||
178 | } | ||
179 | |||
180 | template<> template<> | ||
181 | void LLMessageTemplateParserTestObject::test<5>() | ||
182 | // tests block parsing method | ||
183 | { | ||
184 | LLTemplateTokenizer tokens("{ BlockA Single { VarX F32 } }"); | ||
185 | LLMessageBlock * block = LLTemplateParser::parseBlock(tokens); | ||
186 | |||
187 | ensure("blockA block parsed", block != 0); | ||
188 | ensure_equals("name of block", std::string(block->mName), std::string("BlockA")); | ||
189 | ensure_equals("type of block is Single", block->mType, MBT_SINGLE); | ||
190 | ensure_equals("total size of block", block->mTotalSize, 4); | ||
191 | ensure_equals("number of block defaults to 1", block->mNumber, 1); | ||
192 | ensure_equals("variable type of VarX is F32", | ||
193 | block->getVariableType(prehash("VarX")), MVT_F32); | ||
194 | ensure_equals("variable size of VarX", | ||
195 | block->getVariableSize(prehash("VarX")), 4); | ||
196 | |||
197 | delete block; | ||
198 | |||
199 | tokens = LLTemplateTokenizer("{ Stuff Variable { Id LLUUID } }"); | ||
200 | block = LLTemplateParser::parseBlock(tokens); | ||
201 | |||
202 | ensure("stuff block parsed", block != 0); | ||
203 | ensure_equals("name of block", std::string(block->mName), std::string("Stuff")); | ||
204 | ensure_equals("type of block is Multiple", block->mType, MBT_VARIABLE); | ||
205 | ensure_equals("total size of block", block->mTotalSize, 16); | ||
206 | ensure_equals("number of block defaults to 1", block->mNumber, 1); | ||
207 | ensure_equals("variable type of Id is LLUUID", | ||
208 | block->getVariableType(prehash("Id")), MVT_LLUUID); | ||
209 | ensure_equals("variable size of Id", | ||
210 | block->getVariableSize(prehash("Id")), 16); | ||
211 | |||
212 | delete block; | ||
213 | |||
214 | tokens = LLTemplateTokenizer("{ Stuff2 Multiple 45 { Shid LLVector3d } }"); | ||
215 | block = LLTemplateParser::parseBlock(tokens); | ||
216 | |||
217 | ensure("stuff2 block parsed", block != 0); | ||
218 | ensure_equals("name of block", std::string(block->mName), std::string("Stuff2")); | ||
219 | ensure_equals("type of block is Multiple", block->mType, MBT_MULTIPLE); | ||
220 | ensure_equals("total size of block", block->mTotalSize, 24); | ||
221 | ensure_equals("number of blocks", block->mNumber, 45); | ||
222 | ensure_equals("variable type of Shid is Vector3d", | ||
223 | block->getVariableType(prehash("Shid")), MVT_LLVector3d); | ||
224 | ensure_equals("variable size of Shid", | ||
225 | block->getVariableSize(prehash("Shid")), 24); | ||
226 | |||
227 | delete block; | ||
228 | } | ||
229 | |||
230 | template<> template<> | ||
231 | void LLMessageTemplateParserTestObject::test<6>() | ||
232 | // tests message parsing method on a simple message | ||
233 | { | ||
234 | std::string message_skel( | ||
235 | "{\n" | ||
236 | "TestMessage Low 1 NotTrusted Zerocoded\n" | ||
237 | "// comment \n" | ||
238 | " {\n" | ||
239 | "TestBlock1 Single\n" | ||
240 | " { Test1 U32 }\n" | ||
241 | " }\n" | ||
242 | " {\n" | ||
243 | " NeighborBlock Multiple 4\n" | ||
244 | " { Test0 U32 }\n" | ||
245 | " { Test1 U32 }\n" | ||
246 | " { Test2 U32 }\n" | ||
247 | " }\n" | ||
248 | "}"); | ||
249 | LLTemplateTokenizer tokens(message_skel); | ||
250 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
251 | |||
252 | ensure("simple message parsed", message != 0); | ||
253 | ensure_equals("name of message", std::string(message->mName), std::string("TestMessage")); | ||
254 | ensure_equals("frequency is Low", message->mFrequency, MFT_LOW); | ||
255 | ensure_equals("trust is untrusted", message->mTrust, MT_NOTRUST); | ||
256 | ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 1)); | ||
257 | ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); | ||
258 | ensure_equals("message deprecation is notdeprecated", message->mDeprecation, MD_NOTDEPRECATED); | ||
259 | |||
260 | LLMessageBlock * block = message->getBlock(prehash("NonexistantBlock")); | ||
261 | ensure("Nonexistant block does not exist", block == 0); | ||
262 | |||
263 | delete message; | ||
264 | } | ||
265 | |||
266 | template<> template<> | ||
267 | void LLMessageTemplateParserTestObject::test<7>() | ||
268 | // tests message parsing method on a deprecated message | ||
269 | { | ||
270 | std::string message_skel( | ||
271 | "{\n" | ||
272 | "TestMessageDeprecated High 34 Trusted Unencoded Deprecated\n" | ||
273 | " {\n" | ||
274 | "TestBlock2 Single\n" | ||
275 | " { Test2 S32 }\n" | ||
276 | " }\n" | ||
277 | "}"); | ||
278 | LLTemplateTokenizer tokens(message_skel); | ||
279 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
280 | |||
281 | ensure("deprecated message parsed", message != 0); | ||
282 | ensure_equals("name of message", std::string(message->mName), std::string("TestMessageDeprecated")); | ||
283 | ensure_equals("frequency is High", message->mFrequency, MFT_HIGH); | ||
284 | ensure_equals("trust is trusted", message->mTrust, MT_TRUST); | ||
285 | ensure_equals("message number", message->mMessageNumber, (U32)34); | ||
286 | ensure_equals("message encoding is unencoded", message->mEncoding, ME_UNENCODED); | ||
287 | ensure_equals("message deprecation is deprecated", message->mDeprecation, MD_DEPRECATED); | ||
288 | |||
289 | delete message; | ||
290 | } | ||
291 | |||
292 | void LLMessageTemplateParserTestObject::test<8>() | ||
293 | // tests message parsing on RezMultipleAttachmentsFromInv, a possibly-faulty message | ||
294 | { | ||
295 | std::string message_skel( | ||
296 | "{\n\ | ||
297 | RezMultipleAttachmentsFromInv Low 452 NotTrusted Zerocoded\n\ | ||
298 | {\n\ | ||
299 | AgentData Single\n\ | ||
300 | { AgentID LLUUID }\n\ | ||
301 | { SessionID LLUUID }\n\ | ||
302 | } \n\ | ||
303 | {\n\ | ||
304 | HeaderData Single\n\ | ||
305 | { CompoundMsgID LLUUID } // All messages a single \"compound msg\" must have the same id\n\ | ||
306 | { TotalObjects U8 }\n\ | ||
307 | { FirstDetachAll BOOL }\n\ | ||
308 | }\n\ | ||
309 | {\n\ | ||
310 | ObjectData Variable // 1 to 4 of these per packet\n\ | ||
311 | { ItemID LLUUID }\n\ | ||
312 | { OwnerID LLUUID }\n\ | ||
313 | { AttachmentPt U8 } // 0 for default\n\ | ||
314 | { ItemFlags U32 }\n\ | ||
315 | { GroupMask U32 }\n\ | ||
316 | { EveryoneMask U32 }\n\ | ||
317 | { NextOwnerMask U32 }\n\ | ||
318 | { Name Variable 1 }\n\ | ||
319 | { Description Variable 1 }\n\ | ||
320 | }\n\ | ||
321 | }\n\ | ||
322 | "); | ||
323 | LLTemplateTokenizer tokens(message_skel); | ||
324 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
325 | |||
326 | ensure("RezMultipleAttachmentsFromInv message parsed", message != 0); | ||
327 | ensure_equals("name of message", message->mName, prehash("RezMultipleAttachmentsFromInv")); | ||
328 | ensure_equals("frequency is low", message->mFrequency, MFT_LOW); | ||
329 | ensure_equals("trust is not trusted", message->mTrust, MT_NOTRUST); | ||
330 | ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 452)); | ||
331 | ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); | ||
332 | |||
333 | ensure_block_attributes( | ||
334 | "RMAFI", message, "AgentData", MBT_SINGLE, 1, 16+16); | ||
335 | LLMessageBlock * block = message->getBlock(prehash("AgentData")); | ||
336 | ensure_variable_attributes("RMAFI", | ||
337 | block, "AgentID", MVT_LLUUID, 16); | ||
338 | ensure_variable_attributes("RMAFI", | ||
339 | block, "SessionID", MVT_LLUUID, 16); | ||
340 | |||
341 | ensure_block_attributes( | ||
342 | "RMAFI", message, "HeaderData", MBT_SINGLE, 1, 16+1+1); | ||
343 | block = message->getBlock(prehash("HeaderData")); | ||
344 | ensure_variable_attributes( | ||
345 | "RMAFI", block, "CompoundMsgID", MVT_LLUUID, 16); | ||
346 | ensure_variable_attributes( | ||
347 | "RMAFI", block, "TotalObjects", MVT_U8, 1); | ||
348 | ensure_variable_attributes( | ||
349 | "RMAFI", block, "FirstDetachAll", MVT_BOOL, 1); | ||
350 | |||
351 | |||
352 | ensure_block_attributes( | ||
353 | "RMAFI", message, "ObjectData", MBT_VARIABLE, 1, -1); | ||
354 | block = message->getBlock(prehash("ObjectData")); | ||
355 | ensure_variable_attributes("RMAFI", block, "ItemID", MVT_LLUUID, 16); | ||
356 | ensure_variable_attributes("RMAFI", block, "OwnerID", MVT_LLUUID, 16); | ||
357 | ensure_variable_attributes("RMAFI", block, "AttachmentPt", MVT_U8, 1); | ||
358 | ensure_variable_attributes("RMAFI", block, "ItemFlags", MVT_U32, 4); | ||
359 | ensure_variable_attributes("RMAFI", block, "GroupMask", MVT_U32, 4); | ||
360 | ensure_variable_attributes("RMAFI", block, "EveryoneMask", MVT_U32, 4); | ||
361 | ensure_variable_attributes("RMAFI", block, "NextOwnerMask", MVT_U32, 4); | ||
362 | ensure_variable_attributes("RMAFI", block, "Name", MVT_VARIABLE, 1); | ||
363 | ensure_variable_attributes("RMAFI", block, "Description", MVT_VARIABLE, 1); | ||
364 | |||
365 | delete message; | ||
366 | } | ||
367 | |||
368 | |||
369 | |||
370 | } | ||
diff --git a/linden/indra/test/llnamevalue_tut.cpp b/linden/indra/test/llnamevalue_tut.cpp new file mode 100644 index 0000000..77e5ff2 --- /dev/null +++ b/linden/indra/test/llnamevalue_tut.cpp | |||
@@ -0,0 +1,848 @@ | |||
1 | /** | ||
2 | * @file llnamevalue_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief LLNameValue unit test | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include "lltut.h" | ||
32 | #include "linden_common.h" | ||
33 | #include "llnamevalue.h" | ||
34 | #include "llsdserialize.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct namevalue_test | ||
39 | { | ||
40 | namevalue_test() | ||
41 | { | ||
42 | mExpectedNameValueReference.string = NULL; | ||
43 | mExpectedNameValueType = NVT_NULL; | ||
44 | mCallbackCount = 0; | ||
45 | } | ||
46 | |||
47 | ~namevalue_test() | ||
48 | { | ||
49 | reset(); | ||
50 | }; | ||
51 | |||
52 | void reset() | ||
53 | { | ||
54 | switch(mExpectedNameValueType) | ||
55 | { | ||
56 | case NVT_STRING: | ||
57 | case NVT_ASSET: | ||
58 | delete [] mExpectedNameValueReference.string; | ||
59 | mExpectedNameValueReference.string = NULL; | ||
60 | break; | ||
61 | case NVT_F32: | ||
62 | delete mExpectedNameValueReference.f32; | ||
63 | mExpectedNameValueReference.f32 = NULL; | ||
64 | break; | ||
65 | case NVT_S32: | ||
66 | delete mExpectedNameValueReference.s32; | ||
67 | mExpectedNameValueReference.s32 = NULL; | ||
68 | break; | ||
69 | case NVT_U32: | ||
70 | delete mExpectedNameValueReference.u32; | ||
71 | mExpectedNameValueReference.u32 = NULL; | ||
72 | break; | ||
73 | case NVT_VEC3: | ||
74 | delete mExpectedNameValueReference.vec3; | ||
75 | mExpectedNameValueReference.vec3 = NULL; | ||
76 | break; | ||
77 | case NVT_U64: | ||
78 | delete mExpectedNameValueReference.u64; | ||
79 | mExpectedNameValueReference.u64 = NULL; | ||
80 | default: | ||
81 | break; | ||
82 | } | ||
83 | |||
84 | mExpectedNameValueType = NVT_NULL; | ||
85 | mCallbackCount = 0; | ||
86 | } | ||
87 | |||
88 | void setExpectedResult(ENameValueType type, void* value) | ||
89 | { | ||
90 | reset(); | ||
91 | mExpectedNameValueType = type; | ||
92 | switch(type) | ||
93 | { | ||
94 | case NVT_STRING: | ||
95 | case NVT_ASSET: | ||
96 | mExpectedNameValueReference.string = new char[strlen((const char*) value)+1]; | ||
97 | strcpy(mExpectedNameValueReference.string, (const char*) value); | ||
98 | break; | ||
99 | case NVT_F32: | ||
100 | mExpectedNameValueReference.f32 = new F32(*((F32*) value)); | ||
101 | break; | ||
102 | case NVT_S32: | ||
103 | mExpectedNameValueReference.s32 = new S32(*((S32*) value)); | ||
104 | break; | ||
105 | case NVT_U32: | ||
106 | mExpectedNameValueReference.u32 = new U32(*((U32*) value)); | ||
107 | break; | ||
108 | case NVT_VEC3: | ||
109 | mExpectedNameValueReference.vec3 = new LLVector3(*((LLVector3*) value)); | ||
110 | break; | ||
111 | case NVT_U64: | ||
112 | mExpectedNameValueReference.u64 = new U64(*((U64*) value)); | ||
113 | default: | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | void verifyChange(LLNameValue* changed) | ||
119 | { | ||
120 | std::string str = ""; | ||
121 | str += "Expected Value of type: "; | ||
122 | str += NameValueTypeStrings[mExpectedNameValueType]; | ||
123 | str += "not equal"; | ||
124 | |||
125 | switch(mExpectedNameValueType) | ||
126 | { | ||
127 | case NVT_STRING: | ||
128 | ensure_memory_matches(str.c_str(), changed->getString(), strlen(changed->getString()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string)); | ||
129 | break; | ||
130 | case NVT_ASSET: | ||
131 | ensure_memory_matches(str.c_str(), changed->getAsset(), strlen(changed->getAsset()), mExpectedNameValueReference.string, strlen(mExpectedNameValueReference.string)); | ||
132 | break; | ||
133 | case NVT_F32: | ||
134 | ensure(str, *(changed->getF32()) == *mExpectedNameValueReference.f32); | ||
135 | break; | ||
136 | case NVT_S32: | ||
137 | ensure(str, *(changed->getS32()) == *mExpectedNameValueReference.s32); | ||
138 | break; | ||
139 | case NVT_U32: | ||
140 | ensure(str, *(changed->getU32()) == *mExpectedNameValueReference.u32); | ||
141 | break; | ||
142 | case NVT_VEC3: | ||
143 | ensure(str, *(changed->getVec3()) == *mExpectedNameValueReference.vec3); | ||
144 | break; | ||
145 | case NVT_U64: | ||
146 | ensure(str, *(changed->getU64()) == *mExpectedNameValueReference.u64); | ||
147 | break; | ||
148 | default: | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | void HandleCallback(LLNameValue* changed) | ||
154 | { | ||
155 | mCallbackCount++; | ||
156 | verifyChange(changed); | ||
157 | ensure("Callback called more than once", mCallbackCount == 1); | ||
158 | } | ||
159 | |||
160 | static void NameValueCallbackFunction(LLNameValue* changed, void** data) | ||
161 | { | ||
162 | namevalue_test* pNameValue = (namevalue_test*)data; | ||
163 | pNameValue->HandleCallback(changed); | ||
164 | } | ||
165 | |||
166 | ENameValueType mExpectedNameValueType; | ||
167 | UNameValueReference mExpectedNameValueReference; | ||
168 | int mCallbackCount; | ||
169 | }; | ||
170 | typedef test_group<namevalue_test> namevalue_t; | ||
171 | typedef namevalue_t::object namevalue_object_t; | ||
172 | tut::namevalue_t tut_namevalue("namevalue_test"); | ||
173 | |||
174 | |||
175 | template<> template<> | ||
176 | void namevalue_object_t::test<1>() | ||
177 | { | ||
178 | // LLNameValue() | ||
179 | LLNameValue nValue; | ||
180 | ensure("mName should have been NULL", nValue.mName == NULL); | ||
181 | ensure("getTypeEnum failed",nValue.getTypeEnum() == NVT_NULL); | ||
182 | ensure("getClassEnum failed",nValue.getClassEnum() == NVC_NULL); | ||
183 | ensure("getSendtoEnum failed",nValue.getSendtoEnum() == NVS_NULL); | ||
184 | |||
185 | LLNameValue nValue1(" SecondLife ASSET RW SIM 232324343"); | ||
186 | |||
187 | } | ||
188 | |||
189 | // LLNameValue(const char* data); | ||
190 | // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, const char* nvsendto, | ||
191 | // TNameValueCallback nvcb = NULL, void** user_data = NULL); | ||
192 | template<> template<> | ||
193 | void namevalue_object_t::test<2>() | ||
194 | { | ||
195 | LLNameValue nValue(" SecondLife ASSET RW S 232324343"); | ||
196 | ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife"))); | ||
197 | ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET); | ||
198 | ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE); | ||
199 | ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM); | ||
200 | ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343"))); | ||
201 | ensure("sendToData or sendToViewer failed", !nValue.sendToData() && !nValue.sendToViewer()); | ||
202 | |||
203 | LLNameValue nValue1("\n\r SecondLife_1 STRING READ_WRITE SIM 232324343"); | ||
204 | ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife_1"))); | ||
205 | ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING); | ||
206 | ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE); | ||
207 | ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM); | ||
208 | ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343"))); | ||
209 | ensure("1. sendToData or sendToViewer failed", !nValue1.sendToData() && !nValue1.sendToViewer()); | ||
210 | |||
211 | LLNameValue nValue2("SecondLife", "23.5", "F32", "R", "DS"); | ||
212 | ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32); | ||
213 | ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY); | ||
214 | ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_DATA_SIM); | ||
215 | ensure("2. getF32 failed", *nValue2.getF32() == 23.5f); | ||
216 | ensure("2. sendToData or sendToViewer failed", nValue2.sendToData() && !nValue2.sendToViewer()); | ||
217 | |||
218 | LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY", "SIM_SPACE"); | ||
219 | ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32); | ||
220 | ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY); | ||
221 | ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_DATA_SIM); | ||
222 | ensure("3. getS32 failed", *nValue3.getS32() == -43456787); | ||
223 | ensure("sendToData or sendToViewer failed", nValue3.sendToData() && !nValue3.sendToViewer()); | ||
224 | |||
225 | LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB", "SV"); | ||
226 | LLVector3 llvec4(1.0, 2.0, 3.0); | ||
227 | ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3); | ||
228 | ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK); | ||
229 | ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM_VIEWER); | ||
230 | ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4); | ||
231 | ensure("4. sendToData or sendToViewer failed", !nValue4.sendToData() && nValue4.sendToViewer()); | ||
232 | |||
233 | LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK", "SIM_VIEWER"); | ||
234 | LLVector3 llvec5(-1.0f, 2.4f, 3); | ||
235 | ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3); | ||
236 | ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK); | ||
237 | ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM_VIEWER); | ||
238 | ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5); | ||
239 | ensure("5. sendToData or sendToViewer failed", !nValue5.sendToData() && nValue5.sendToViewer()); | ||
240 | |||
241 | LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK", "DSV"); | ||
242 | ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32); | ||
243 | ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK); | ||
244 | ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_DATA_SIM_VIEWER); | ||
245 | ensure("6. getU32 failed", *nValue6.getU32() == 89764323); | ||
246 | ensure("6. sendToData or sendToViewer failed", nValue6.sendToData() && nValue6.sendToViewer()); | ||
247 | |||
248 | LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK", "SIM_SPACE_VIEWER"); | ||
249 | U64 u64_7 = U64L(89764323323232); | ||
250 | ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64); | ||
251 | ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK); | ||
252 | ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_DATA_SIM_VIEWER); | ||
253 | ensure("7. getU32 failed", *nValue7.getU64() == u64_7); | ||
254 | ensure("7. sendToData or sendToViewer failed", nValue7.sendToData() && nValue7.sendToViewer()); | ||
255 | } | ||
256 | |||
257 | // LLNameValue(const char* name, const char* data, const char* type, const char* nvclass, | ||
258 | // TNameValueCallback nvcb = NULL, void** user_data = NULL); | ||
259 | template<> template<> | ||
260 | void namevalue_object_t::test<3>() | ||
261 | { | ||
262 | LLNameValue nValue("SecondLife", "232324343", "ASSET", "READ_WRITE"); | ||
263 | ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife"))); | ||
264 | ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_ASSET); | ||
265 | ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE); | ||
266 | ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM); | ||
267 | ensure("getString failed", (0==strcmp(nValue.getAsset(),"232324343"))); | ||
268 | |||
269 | LLNameValue nValue1("SecondLife", "232324343", "STRING", "READ_WRITE"); | ||
270 | ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife"))); | ||
271 | ensure("1. getTypeEnum failed", nValue1.getTypeEnum() == NVT_STRING); | ||
272 | ensure("1. getClassEnum failed", nValue1.getClassEnum() == NVC_READ_WRITE); | ||
273 | ensure("1. getSendtoEnum failed", nValue1.getSendtoEnum() == NVS_SIM); | ||
274 | ensure("1. getString failed", (0==strcmp(nValue1.getString(),"232324343"))); | ||
275 | |||
276 | LLNameValue nValue2("SecondLife", "23.5", "F32", "R"); | ||
277 | ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32); | ||
278 | ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY); | ||
279 | ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM); | ||
280 | ensure("2. getF32 failed", *nValue2.getF32() == 23.5f); | ||
281 | |||
282 | LLNameValue nValue3("SecondLife", "-43456787", "S32", "READ_ONLY"); | ||
283 | ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32); | ||
284 | ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY); | ||
285 | ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM); | ||
286 | ensure("3. getS32 failed", *nValue3.getS32() == -43456787); | ||
287 | |||
288 | LLNameValue nValue4("SecondLife", "<1.0, 2.0, 3.0>", "VEC3", "CB"); | ||
289 | LLVector3 llvec4(1.0, 2.0, 3.0); | ||
290 | ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3); | ||
291 | ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK); | ||
292 | ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM); | ||
293 | ensure("4. getVec3 failed", *nValue4.getVec3() == llvec4); | ||
294 | |||
295 | LLNameValue nValue5("SecondLife", "-1.0, 2.4, 3", "VEC3", "CALLBACK"); | ||
296 | LLVector3 llvec5(-1.0f, 2.4f, 3); | ||
297 | ensure("5. getTypeEnum failed", nValue5.getTypeEnum() == NVT_VEC3); | ||
298 | ensure("5. getClassEnum failed", nValue5.getClassEnum() == NVC_CALLBACK); | ||
299 | ensure("5. getSendtoEnum failed", nValue5.getSendtoEnum() == NVS_SIM); | ||
300 | ensure("5. getVec3 failed", *nValue5.getVec3() == llvec5); | ||
301 | |||
302 | LLNameValue nValue6("SecondLife", "89764323", "U32", "CALLBACK"); | ||
303 | ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32); | ||
304 | ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK); | ||
305 | ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM); | ||
306 | ensure("6. getU32 failed", *nValue6.getU32() == 89764323); | ||
307 | |||
308 | LLNameValue nValue7("SecondLife", "89764323323232", "U64", "CALLBACK"); | ||
309 | U64 u64_7 = U64L(89764323323232); | ||
310 | ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64); | ||
311 | ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK); | ||
312 | ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM); | ||
313 | ensure("7. getU32 failed", *nValue7.getU64() == u64_7); | ||
314 | } | ||
315 | |||
316 | // LLNameValue(const char* name, const char* type, const char* nvclass, | ||
317 | // TNameValueCallback nvcb = NULL, void** user_data = NULL); | ||
318 | template<> template<> | ||
319 | void namevalue_object_t::test<4>() | ||
320 | { | ||
321 | LLNameValue nValue("SecondLife", "STRING", "READ_WRITE"); | ||
322 | ensure("mName not set correctly", (0 == strcmp(nValue.mName,"SecondLife"))); | ||
323 | ensure("getTypeEnum failed", nValue.getTypeEnum() == NVT_STRING); | ||
324 | ensure("getClassEnum failed", nValue.getClassEnum() == NVC_READ_WRITE); | ||
325 | ensure("getSendtoEnum failed", nValue.getSendtoEnum() == NVS_SIM); | ||
326 | |||
327 | LLNameValue nValue1("SecondLife", "ASSET", "READ_WRITE"); | ||
328 | ensure("1. mName not set correctly", (0 == strcmp(nValue1.mName,"SecondLife"))); | ||
329 | ensure("1. getTypeEnum for RW failed", nValue1.getTypeEnum() == NVT_ASSET); | ||
330 | ensure("1. getClassEnum for RW failed", nValue1.getClassEnum() == NVC_READ_WRITE); | ||
331 | ensure("1. getSendtoEnum for RW failed", nValue1.getSendtoEnum() == NVS_SIM); | ||
332 | |||
333 | LLNameValue nValue2("SecondLife", "F32", "READ_ONLY"); | ||
334 | ensure("2. getTypeEnum failed", nValue2.getTypeEnum() == NVT_F32); | ||
335 | ensure("2. getClassEnum failed", nValue2.getClassEnum() == NVC_READ_ONLY); | ||
336 | ensure("2. getSendtoEnum failed", nValue2.getSendtoEnum() == NVS_SIM); | ||
337 | |||
338 | LLNameValue nValue3("SecondLife", "S32", "READ_ONLY"); | ||
339 | ensure("3. getTypeEnum failed", nValue3.getTypeEnum() == NVT_S32); | ||
340 | ensure("3. getClassEnum failed", nValue3.getClassEnum() == NVC_READ_ONLY); | ||
341 | ensure("3. getSendtoEnum failed", nValue3.getSendtoEnum() == NVS_SIM); | ||
342 | |||
343 | skip_fail("NVC_CALLBACK does not parse."); | ||
344 | |||
345 | LLNameValue nValue4("SecondLife", "VEC3", "CALLBACK"); | ||
346 | ensure("4. getTypeEnum failed", nValue4.getTypeEnum() == NVT_VEC3); | ||
347 | ensure("4. getClassEnum failed", nValue4.getClassEnum() == NVC_CALLBACK); | ||
348 | ensure("4. getSendtoEnum failed", nValue4.getSendtoEnum() == NVS_SIM); | ||
349 | |||
350 | LLNameValue nValue6("SecondLife", "U32", "CALLBACK"); | ||
351 | ensure("6. getTypeEnum failed", nValue6.getTypeEnum() == NVT_U32); | ||
352 | ensure("6. getClassEnum failed", nValue6.getClassEnum() == NVC_CALLBACK); | ||
353 | ensure("6. getSendtoEnum failed", nValue6.getSendtoEnum() == NVS_SIM); | ||
354 | |||
355 | LLNameValue nValue7("SecondLife", "U64", "CALLBACK"); | ||
356 | ensure("7. getTypeEnum failed", nValue7.getTypeEnum() == NVT_U64); | ||
357 | ensure("7. getClassEnum failed", nValue7.getClassEnum() == NVC_CALLBACK); | ||
358 | ensure("7. getSendtoEnum failed", nValue7.getSendtoEnum() == NVS_SIM); | ||
359 | } | ||
360 | |||
361 | template<> template<> | ||
362 | void namevalue_object_t::test<5>() | ||
363 | { | ||
364 | skip_fail("callback will be called more than once."); | ||
365 | LLNameValue nValue("SecondLife", "This is a test", "STRING", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
366 | |||
367 | ensure("getString failed", (0 == strcmp(nValue.getString(),"This is a test"))); | ||
368 | reset(); | ||
369 | |||
370 | setExpectedResult(NVT_STRING, (void*)"New Value"); | ||
371 | nValue.setString("New Value"); | ||
372 | ensure("String nonzero failed", nValue.nonzero() == TRUE); | ||
373 | reset(); | ||
374 | setExpectedResult(NVT_STRING, (void*)""); | ||
375 | nValue.setString(""); | ||
376 | ensure("String nonzero failed", nValue.nonzero() == FALSE); | ||
377 | reset(); | ||
378 | } | ||
379 | |||
380 | template<> template<> | ||
381 | void namevalue_object_t::test<6>() | ||
382 | { | ||
383 | skip_fail("callback will be called more than once."); | ||
384 | LLNameValue nValue("SecondLife", "This is a test", "ASSET", "CALLBACK", "S", NameValueCallbackFunction, (void**) this); | ||
385 | ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test"))); | ||
386 | reset(); | ||
387 | |||
388 | setExpectedResult(NVT_ASSET, (void*)"New Value"); | ||
389 | nValue.setAsset("New Value"); | ||
390 | reset(); | ||
391 | } | ||
392 | |||
393 | template<> template<> | ||
394 | void namevalue_object_t::test<7>() | ||
395 | { | ||
396 | skip_fail("callback will be called more than once."); | ||
397 | LLNameValue nValue("SecondLife", "555555", "F32", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
398 | |||
399 | ensure("getF32 failed",*nValue.getF32() == 555555.f); | ||
400 | reset(); | ||
401 | |||
402 | F32 fVal = 0.1f; | ||
403 | setExpectedResult(NVT_F32, &fVal); | ||
404 | nValue.setF32(fVal); | ||
405 | |||
406 | fVal = -11111.1f; | ||
407 | setExpectedResult(NVT_F32, &fVal); | ||
408 | nValue.setF32(fVal); | ||
409 | ensure("F32 nonzero failed", nValue.nonzero() == TRUE); | ||
410 | reset(); | ||
411 | |||
412 | fVal = 0.; | ||
413 | setExpectedResult(NVT_F32, &fVal); | ||
414 | nValue.setF32(fVal); | ||
415 | ensure("F32 nonzero failed", nValue.nonzero() == FALSE); | ||
416 | reset(); | ||
417 | } | ||
418 | |||
419 | template<> template<> | ||
420 | void namevalue_object_t::test<8>() | ||
421 | { | ||
422 | skip_fail("callback will be called more than once."); | ||
423 | LLNameValue nValue("SecondLife", "-5555", "S32", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
424 | |||
425 | ensure("getS32 failed", *nValue.getS32() == -5555); | ||
426 | reset(); | ||
427 | |||
428 | S32 sVal = 0x7FFFFFFF; | ||
429 | setExpectedResult(NVT_S32, &sVal); | ||
430 | nValue.setS32(sVal); | ||
431 | |||
432 | sVal = -0x7FFFFFFF; | ||
433 | setExpectedResult(NVT_S32, &sVal); | ||
434 | nValue.setS32(sVal); | ||
435 | ensure("S32 nonzero failed", nValue.nonzero() == TRUE); | ||
436 | reset(); | ||
437 | |||
438 | sVal = 0; | ||
439 | setExpectedResult(NVT_S32, &sVal); | ||
440 | nValue.setS32(sVal); | ||
441 | ensure("S32 nonzero failed", nValue.nonzero() == FALSE); | ||
442 | reset(); | ||
443 | } | ||
444 | |||
445 | template<> template<> | ||
446 | void namevalue_object_t::test<9>() | ||
447 | { | ||
448 | LLNameValue nValue("SecondLife", "<-3, 2, 1>", "VEC3", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
449 | LLVector3 vecExpected(-3, 2, 1); | ||
450 | LLVector3 vec; | ||
451 | nValue.getVec3(vec); | ||
452 | ensure("getVec3 failed", vec == vecExpected); | ||
453 | reset(); | ||
454 | |||
455 | vecExpected.setVec(2, -1, 0); | ||
456 | setExpectedResult(NVT_VEC3, &vecExpected); | ||
457 | nValue.setVec3(vecExpected); | ||
458 | ensure("VEC3 nonzero failed", nValue.nonzero() == TRUE); | ||
459 | reset(); | ||
460 | |||
461 | vecExpected.setVec(0, 0, 0); | ||
462 | setExpectedResult(NVT_VEC3, &vecExpected); | ||
463 | nValue.setVec3(vecExpected); | ||
464 | ensure("VEC3 nonzero failed", nValue.nonzero() == FALSE); | ||
465 | reset(); | ||
466 | } | ||
467 | |||
468 | template<> template<> | ||
469 | void namevalue_object_t::test<10>() | ||
470 | { | ||
471 | LLNameValue nValue("SecondLife", "12345678", "U32", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
472 | |||
473 | ensure("getU32 failed",*nValue.getU32() == 12345678); | ||
474 | |||
475 | U32 val = 0xFFFFFFFF; | ||
476 | setExpectedResult(NVT_U32, &val); | ||
477 | nValue.setU32(val); | ||
478 | ensure("U32 nonzero failed", nValue.nonzero() == TRUE); | ||
479 | reset(); | ||
480 | |||
481 | val = 0; | ||
482 | setExpectedResult(NVT_U32, &val); | ||
483 | nValue.setU32(val); | ||
484 | ensure("U32 nonzero failed", nValue.nonzero() == FALSE); | ||
485 | reset(); | ||
486 | } | ||
487 | |||
488 | template<> template<> | ||
489 | void namevalue_object_t::test<11>() | ||
490 | { | ||
491 | skip_fail("incomplete support for U64."); | ||
492 | LLNameValue nValue("SecondLife", "44444444444", "U64", "CB", "SIM", NameValueCallbackFunction, (void**) this); | ||
493 | |||
494 | ensure("getU64 failed",*nValue.getU64() == U64L(44444444444)); | ||
495 | ensure("U64 nonzero failed", nValue.nonzero() == TRUE); | ||
496 | |||
497 | // there is no LLNameValue::setU64() | ||
498 | } | ||
499 | |||
500 | template<> template<> | ||
501 | void namevalue_object_t::test<12>() | ||
502 | { | ||
503 | LLNameValue nValue("SecondLife F32 RW SIM -333.337600"); | ||
504 | F32 val = nValue.magnitude(); | ||
505 | ensure_equals("F32 magnitude failed", val, 333.337600f); | ||
506 | |||
507 | LLNameValue nValue1("SecondLife STRING RW SIM 3300"); | ||
508 | val = nValue1.magnitude(); | ||
509 | ensure_equals("STRING magnitude failed",val,4.0f); | ||
510 | |||
511 | LLNameValue nValue2("SecondLife S32 RW SIM -3300"); | ||
512 | val = nValue2.magnitude(); | ||
513 | ensure_equals("S32 magnitude failed", val, 3300.); | ||
514 | |||
515 | LLNameValue nValue3("SecondLife U32 RW SIM 3300"); | ||
516 | val = nValue3.magnitude(); | ||
517 | ensure_equals("U32 magnitude failed", val, 3300.); | ||
518 | |||
519 | LLNameValue nValue4("SecondLife VEC3 RW SIM <1,2,3>"); | ||
520 | LLVector3 vec(1,2,3); | ||
521 | val = nValue4.magnitude(); | ||
522 | ensure_equals("VEC3 magnitude failed", val, vec.magVec()); | ||
523 | |||
524 | skip_fail("incomplete support for U64."); | ||
525 | LLNameValue nValue5("SecondLife U64 RW SIM 12345"); | ||
526 | val = nValue5.magnitude(); | ||
527 | ensure_equals("U62 magnitude failed", val, 12345); | ||
528 | } | ||
529 | |||
530 | template<> template<> | ||
531 | void namevalue_object_t::test<13>() | ||
532 | { | ||
533 | skip_fail("incomplete support for U64."); | ||
534 | LLNameValue nValue("SecondLife U64 RW DSV 44444444444"); | ||
535 | std::string ret_str = nValue.printNameValue(); | ||
536 | |||
537 | ensure_equals("1:printNameValue failed",ret_str,"SecondLife U64 RW DSV 44444444444"); | ||
538 | |||
539 | LLNameValue nValue1(ret_str.c_str()); | ||
540 | ensure_equals("Serialization of printNameValue failed", nValue, nValue1); | ||
541 | } | ||
542 | |||
543 | template<> template<> | ||
544 | void namevalue_object_t::test<14>() | ||
545 | { | ||
546 | LLNameValue nValue("SecondLife STRING RW DSV 44444444444"); | ||
547 | std::string ret_str = nValue.printData(); | ||
548 | ensure_equals("1:printData failed",ret_str,"44444444444"); | ||
549 | |||
550 | LLNameValue nValue1("SecondLife S32 RW DSV 44444"); | ||
551 | ret_str = nValue1.printData(); | ||
552 | ensure_equals("2:printData failed",ret_str,"44444"); | ||
553 | } | ||
554 | |||
555 | template<> template<> | ||
556 | void namevalue_object_t::test<15>() | ||
557 | { | ||
558 | LLNameValue nValue("SecodLife STRING RW SIM 22222"); | ||
559 | std::ostringstream stream1,stream2,stream3, stream4, stream5; | ||
560 | stream1 << nValue; | ||
561 | ensure_equals("STRING << failed",stream1.str(),"22222"); | ||
562 | |||
563 | LLNameValue nValue1("SecodLife F32 RW SIM 22222"); | ||
564 | stream2 << nValue1; | ||
565 | ensure_equals("F32 << failed",stream2.str(),"22222"); | ||
566 | |||
567 | LLNameValue nValue2("SecodLife S32 RW SIM 22222"); | ||
568 | stream3<< nValue2; | ||
569 | ensure_equals("S32 << failed",stream3.str(),"22222"); | ||
570 | |||
571 | LLNameValue nValue3("SecodLife U32 RW SIM 122222"); | ||
572 | stream4<< nValue3; | ||
573 | ensure_equals("U32 << failed",stream4.str(),"122222"); | ||
574 | |||
575 | skip_fail("incomplete support for U64."); | ||
576 | LLNameValue nValue4("SecodLife U64 RW SIM 22222"); | ||
577 | stream5<< nValue4; | ||
578 | ensure("U64 << failed",0 == strcmp((stream5.str()).c_str(),"22222")); | ||
579 | } | ||
580 | |||
581 | template<> template<> | ||
582 | void namevalue_object_t::test<16>() | ||
583 | { | ||
584 | LLNameValue nValue1("SecondLife STRING RW DSV 44444"); | ||
585 | LLNameValue nValue2("SecondLife STRING RW SIM 33333"); | ||
586 | LLNameValue nValue3("SecondLife"); | ||
587 | nValue3 = nValue1 + nValue2; | ||
588 | ensure("1:operator+ failed",(0==strcmp(nValue3.getString(),"4444433333"))); | ||
589 | |||
590 | LLNameValue nValue4("SecondLife F32 R DSV 44444"); | ||
591 | LLNameValue nValue5("SecondLife F32 RW SIM 33333"); | ||
592 | LLNameValue nValue6("SecondLife"); | ||
593 | nValue6 = nValue4 + nValue5; | ||
594 | ensure_equals("2:operator+ failed",*nValue6.getF32(),77777.0); | ||
595 | |||
596 | LLNameValue nValue7("SecondLife F32 R DSV 44444"); | ||
597 | LLNameValue nValue8("SecondLife S32 RW SIM 33333"); | ||
598 | LLNameValue nValue9("SecondLife F32"); | ||
599 | nValue9 = nValue7 + nValue8; | ||
600 | ensure_equals("3:operator+ failed",*nValue9.getF32(),77777.0); | ||
601 | |||
602 | LLNameValue nValue10("SecondLife VEC3 RW SIM <4, 4, 4>"); | ||
603 | LLNameValue nValue11("SecondLife VEC3 RW SV <3, 3, 3>"); | ||
604 | LLNameValue nValue12("SecondLife VEC3"); | ||
605 | nValue12 = nValue10 + nValue11; | ||
606 | LLVector3 vec(7,7,7); | ||
607 | ensure_equals("4:operator+ failed",*nValue12.getVec3(), vec); | ||
608 | } | ||
609 | |||
610 | template<> template<> | ||
611 | void namevalue_object_t::test<17>() | ||
612 | { | ||
613 | LLNameValue nValue7(" SecondLife S32 RW SIM 22222"); | ||
614 | LLNameValue nValue8(" SecondLife F32 RW SIM 33333"); | ||
615 | LLNameValue nValue9(" SecondLife F32"); | ||
616 | nValue9 = nValue7 - nValue8; | ||
617 | ensure_equals("1:operator- failed",*nValue9.getF32(),-11111.f); | ||
618 | |||
619 | LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>"); | ||
620 | LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>"); | ||
621 | LLNameValue nValue12(" SecondLife VEC3"); | ||
622 | LLVector3 vec(-1,-1,-1); | ||
623 | nValue12 = nValue10 - nValue11; | ||
624 | ensure_equals("2:operator- failed",*nValue12.getVec3(), vec); | ||
625 | } | ||
626 | |||
627 | template<> template<> | ||
628 | void namevalue_object_t::test<18>() | ||
629 | { | ||
630 | |||
631 | LLNameValue nValue1(" SecondLife F32 RW SIM 22222"); | ||
632 | LLNameValue nValue2(" SecondLife F32 RW SIM 33333"); | ||
633 | LLNameValue nValue3(" SecondLife F32"); | ||
634 | nValue3 = nValue1 * nValue2; | ||
635 | ensure_equals("1:operator* failed",*nValue3.getF32(),740725926.f); | ||
636 | |||
637 | LLNameValue nValue4(" SecondLife S32 RW SIM 22222"); | ||
638 | LLNameValue nValue5(" SecondLife F32 RW SIM 33333"); | ||
639 | LLNameValue nValue6(" SecondLife F32"); | ||
640 | nValue6 = nValue4 * nValue5; | ||
641 | ensure_equals("2:operator* failed",*nValue6.getF32(),740725926.f); | ||
642 | |||
643 | LLNameValue nValue10(" SecondLife VEC3 RW SIM <2, 2, 2>"); | ||
644 | LLNameValue nValue11(" SecondLife VEC3 RW SIM <3, 3, 3>"); | ||
645 | LLNameValue nValue12(" SecondLife F32"); | ||
646 | LLVector3 vec1(2,2,2); | ||
647 | LLVector3 vec2(3,3,3); | ||
648 | nValue12 = nValue10 * nValue11; | ||
649 | ensure_equals("2:operator* failed",*nValue12.getF32(), (vec1 * vec2)); | ||
650 | } | ||
651 | |||
652 | template<> template<> | ||
653 | void namevalue_object_t::test<19>() | ||
654 | { | ||
655 | LLNameValue nValue1(" SecondLife S32 RW SIM 22222"); | ||
656 | LLNameValue nValue2(" Virtual F32 RW SIM 44444"); | ||
657 | LLNameValue nValue3(" SecondLife F32"); | ||
658 | nValue3 = nValue1 / nValue2; | ||
659 | ensure_equals("1:operator/ failed",*nValue3.getF32(),0.5); | ||
660 | |||
661 | LLNameValue nValue4(" SecondLife F32 RW SIM 33333"); | ||
662 | LLNameValue nValue5(" SecondLife S32 RW SIM 22222"); | ||
663 | LLNameValue nValue6(" SecondLife F32"); | ||
664 | nValue6 = nValue4 / nValue5; | ||
665 | ensure_equals("2:operator/ failed",*nValue6.getF32(),1.5); | ||
666 | } | ||
667 | |||
668 | template<> template<> | ||
669 | void namevalue_object_t::test<20>() | ||
670 | { | ||
671 | LLNameValue nValue1(" SecondLife S32 RW SIM 22222"); | ||
672 | LLNameValue nValue2(" Virtual S32 RW SIM 33333"); | ||
673 | LLNameValue nValue3(" SecondLife S32"); | ||
674 | nValue3 = nValue1 % nValue2; | ||
675 | ensure_equals("1:operator% failed",*nValue3.getS32(),22222); | ||
676 | |||
677 | LLNameValue nValue4(" SecondLife U32 RW SIM 3"); | ||
678 | LLNameValue nValue5(" SecondLife S32 RW SIM 2"); | ||
679 | LLNameValue nValue6(" SecondLife S32"); | ||
680 | nValue6 = nValue4 % nValue5; | ||
681 | ensure_equals("2:operator% failed",*nValue6.getS32(),1); | ||
682 | |||
683 | LLNameValue nValue10(" SecondLife VEC3 RW SIM <4, 5, 6>"); | ||
684 | LLNameValue nValue11(" SecondLife VEC3 RW SIM <1, 2, 3>"); | ||
685 | LLNameValue nValue12(" SecondLife VEC3"); | ||
686 | LLVector3 vec1(4,5,6); | ||
687 | LLVector3 vec2(1,2,3); | ||
688 | LLVector3 vec3(vec1 % vec2); | ||
689 | nValue12 = nValue10 % nValue11; | ||
690 | ensure_equals("5:operator% failed",*nValue12.getVec3(), vec3); | ||
691 | } | ||
692 | |||
693 | template<> template<> | ||
694 | void namevalue_object_t::test<21>() | ||
695 | { | ||
696 | LLNameValue nValue1(" SecondLife STRING RW SIM 22222"); | ||
697 | LLNameValue nValue2(" Virtual STRING RW SIM 22222"); | ||
698 | ensure("1:operator== failed", nValue1 == nValue2); | ||
699 | |||
700 | LLNameValue nValue3(" SecondLife F32 RW SIM 33333"); | ||
701 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
702 | ensure("2:operator== failed",!(nValue3 == nValue4)); | ||
703 | |||
704 | LLNameValue nValue5(" SecondLife STRING RW SIM 22222"); | ||
705 | LLNameValue nValue6(" Virtual STRING RW SIM 33333"); | ||
706 | ensure("3:operator== failed",!(nValue5 == nValue6)); | ||
707 | |||
708 | LLNameValue nValue7(" SecondLife VEC3 RW SIM <2, 2, 2>"); | ||
709 | LLNameValue nValue8(" Virtual VEC3 RW SIM <2, 2, 2>"); | ||
710 | ensure("4:operator== failed",(nValue7 == nValue8)); | ||
711 | } | ||
712 | |||
713 | template<> template<> | ||
714 | void namevalue_object_t::test<22>() | ||
715 | { | ||
716 | LLNameValue nValue1(" SecondLife STRING RW SIM 22222"); | ||
717 | LLNameValue nValue2(" Virtual STRING RW SIM 33333"); | ||
718 | bool b_ret = (nValue1 <= nValue2) ? 1 : 0; | ||
719 | ensure("1:operator<= failed",(1==b_ret)); | ||
720 | |||
721 | LLNameValue nValue3(" SecondLife F32 RW SIM 33333"); | ||
722 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
723 | b_ret = (nValue3 <= nValue4) ? 1 : 0; | ||
724 | ensure("2:operator<= failed",(0==b_ret)); | ||
725 | } | ||
726 | |||
727 | template<> template<> | ||
728 | void namevalue_object_t::test<23>() | ||
729 | { | ||
730 | LLNameValue nValue1(" SecondLife STRING RW SIM 22222"); | ||
731 | LLNameValue nValue2(" Virtual STRING RW SIM 33333"); | ||
732 | bool b_ret = (nValue1 >= nValue2) ? 1 : 0; | ||
733 | ensure("operator>= failed",!b_ret); | ||
734 | |||
735 | LLNameValue nValue3(" SecondLife F32 RW SIM 33333"); | ||
736 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
737 | b_ret = (nValue3 >= nValue4) ? 1 : 0; | ||
738 | ensure("2:operator<= failed",b_ret); | ||
739 | |||
740 | } | ||
741 | |||
742 | template<> template<> | ||
743 | void namevalue_object_t::test<24>() | ||
744 | { | ||
745 | LLNameValue nValue1(" SecondLife STRING RW SIM 33333"); | ||
746 | LLNameValue nValue2(" Virtual STRING RW SIM 33333"); | ||
747 | bool b_ret = (nValue1 < nValue2) ? 1 : 0; | ||
748 | ensure("operator< failed",!b_ret); | ||
749 | |||
750 | LLNameValue nValue3(" SecondLife F32 RW SIM 11111"); | ||
751 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
752 | b_ret = (nValue3 < nValue4) ? 1 : 0; | ||
753 | ensure("2:operator< failed",b_ret); | ||
754 | |||
755 | } | ||
756 | |||
757 | template<> template<> | ||
758 | void namevalue_object_t::test<25>() | ||
759 | { | ||
760 | LLNameValue nValue1(" SecondLife STRING RW SIM 33333"); | ||
761 | LLNameValue nValue2(" Virtual STRING RW SIM 33333"); | ||
762 | bool b_ret = (nValue1 > nValue2) ? 1 : 0; | ||
763 | ensure("1:operator> failed",!b_ret); | ||
764 | |||
765 | LLNameValue nValue3(" SecondLife F32 RW SIM 11111"); | ||
766 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
767 | b_ret = (nValue3 > nValue4) ? 1 : 0; | ||
768 | ensure("2:operator> failed",!b_ret); | ||
769 | |||
770 | LLNameValue nValue5(" SecondLife S32 RW SIM 22222"); | ||
771 | LLNameValue nValue6(" Virtual F32 RW SIM 11111"); | ||
772 | b_ret = (nValue5 > nValue6) ? 1 : 0; | ||
773 | ensure("3:operator> failed",b_ret); | ||
774 | } | ||
775 | |||
776 | template<> template<> | ||
777 | void namevalue_object_t::test<26>() | ||
778 | { | ||
779 | LLNameValue nValue1(" SecondLife STRING RW SIM 33333"); | ||
780 | LLNameValue nValue2(" Virtual STRING RW SIM 33333"); | ||
781 | bool b_ret = (nValue1 != nValue2) ? 1 : 0; | ||
782 | ensure("1:operator!= failed",!b_ret); | ||
783 | |||
784 | LLNameValue nValue3(" SecondLife F32 RW SIM 11111"); | ||
785 | LLNameValue nValue4(" Virtual F32 RW SIM 22222"); | ||
786 | b_ret = (nValue3 != nValue4) ? 1 : 0; | ||
787 | ensure("2:operator!= failed",b_ret); | ||
788 | |||
789 | } | ||
790 | |||
791 | |||
792 | template<> template<> | ||
793 | void namevalue_object_t::test<27>() | ||
794 | { | ||
795 | LLNameValue nValue1(" SecondLife F32 RW SIM 33333"); | ||
796 | LLNameValue nValue2("Virtual"); | ||
797 | nValue2 = -nValue1; | ||
798 | ensure_equals("1:operator unary- failed",*nValue2.getF32(), -33333.f); | ||
799 | |||
800 | LLNameValue nValue3(" SecondLife U32 RW SIM 11111"); | ||
801 | LLNameValue nValue4("Virtual S32"); | ||
802 | nValue4 = -nValue3; | ||
803 | ensure_equals("2:operator unary- failed",*nValue4.getS32(), -11111); | ||
804 | |||
805 | LLNameValue nValue5(" SecondLife VEC3 RW SIM <1, 1, 1>"); | ||
806 | LLNameValue nValue6("Virtual VEC3"); | ||
807 | LLVector3 vec(-1, -1, -1); | ||
808 | nValue6 = -nValue5; | ||
809 | ensure_equals("3:operator unary- failed",*nValue6.getVec3(), vec); | ||
810 | } | ||
811 | |||
812 | template<> template<> | ||
813 | void namevalue_object_t::test<28>() | ||
814 | { | ||
815 | LLNameValue nValue("SecondLife", "This is a test", "ASSET", "R", "S", NameValueCallbackFunction, (void**) this); | ||
816 | |||
817 | ensure("getAsset failed", (0 == strcmp(nValue.getAsset(),"This is a test"))); | ||
818 | // this should not have updated as it is read only. | ||
819 | nValue.setAsset("New Value should not be updated"); | ||
820 | ensure("setAsset on ReadOnly failed", (0 == strcmp(nValue.getAsset(),"This is a test"))); | ||
821 | |||
822 | LLNameValue nValue1("SecondLife", "1234", "U32", "R", "S", NameValueCallbackFunction, (void**) this); | ||
823 | // this should not have updated as it is read only. | ||
824 | nValue1.setU32(4567); | ||
825 | ensure("setU32 on ReadOnly failed", *nValue1.getU32() == 1234); | ||
826 | |||
827 | LLNameValue nValue2("SecondLife", "1234", "S32", "R", "S", NameValueCallbackFunction, (void**) this); | ||
828 | // this should not have updated as it is read only. | ||
829 | nValue2.setS32(4567); | ||
830 | ensure("setS32 on ReadOnly failed", *nValue2.getS32() == 1234); | ||
831 | |||
832 | LLNameValue nValue3("SecondLife", "1234", "F32", "R", "S", NameValueCallbackFunction, (void**) this); | ||
833 | // this should not have updated as it is read only. | ||
834 | nValue3.setF32(4567); | ||
835 | ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234); | ||
836 | nValue3 = nValue3 * 2; | ||
837 | ensure("setF32 on ReadOnly failed", *nValue3.getF32() == 1234); | ||
838 | |||
839 | LLNameValue nValue4("SecondLife", "<1,2,3>", "VEC3", "R", "S", NameValueCallbackFunction, (void**) this); | ||
840 | // this should not have updated as it is read only. | ||
841 | LLVector3 vec(4,5,6); | ||
842 | nValue3.setVec3(vec); | ||
843 | LLVector3 vec1(1,2,3); | ||
844 | ensure("setVec3 on ReadOnly failed", *nValue4.getVec3() == vec1); | ||
845 | |||
846 | // cant test for U64 as no set64 exists nor any operators support U64 type | ||
847 | } | ||
848 | } | ||
diff --git a/linden/indra/test/llpermissions_tut.cpp b/linden/indra/test/llpermissions_tut.cpp new file mode 100644 index 0000000..0c9082b --- /dev/null +++ b/linden/indra/test/llpermissions_tut.cpp | |||
@@ -0,0 +1,553 @@ | |||
1 | /** | ||
2 | * @file llpermissions_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date March 2007 | ||
5 | * @brief llpermissions test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "message.h" | ||
34 | #include "llpermissions.h" | ||
35 | |||
36 | |||
37 | namespace tut | ||
38 | { | ||
39 | struct permission | ||
40 | { | ||
41 | }; | ||
42 | typedef test_group<permission> permission_t; | ||
43 | typedef permission_t::object permission_object_t; | ||
44 | tut::permission_t tut_permission("permission"); | ||
45 | |||
46 | template<> template<> | ||
47 | void permission_object_t::test<1>() | ||
48 | { | ||
49 | LLPermissions permissions; | ||
50 | LLUUID uuid = permissions.getCreator(); | ||
51 | LLUUID uuid1 = permissions.getOwner(); | ||
52 | LLUUID uuid2 = permissions.getGroup(); | ||
53 | LLUUID uuid3 = permissions.getLastOwner(); | ||
54 | |||
55 | ensure("LLPermission Get Functions failed", (uuid == LLUUID::null && uuid1 == LLUUID::null && | ||
56 | uuid2 == LLUUID::null && uuid3 == LLUUID::null)); | ||
57 | ensure("LLPermission Get Functions failed", (permissions.getMaskBase() == PERM_ALL && permissions.getMaskOwner() == PERM_ALL && | ||
58 | permissions.getMaskGroup() == PERM_ALL && permissions.getMaskEveryone() == PERM_ALL && permissions.getMaskNextOwner() == PERM_ALL)); | ||
59 | ensure("Ownership functions failed", (permissions.isGroupOwned() == FALSE && permissions.isOwned() == FALSE)); | ||
60 | } | ||
61 | |||
62 | template<> template<> | ||
63 | void permission_object_t::test<2>() | ||
64 | { | ||
65 | LLPermissions permissions; | ||
66 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
67 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
68 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
69 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
70 | permissions.init(creator, owner, lastOwner, group); | ||
71 | |||
72 | ensure_equals("init/getCreator():failed to return the creator ", creator, permissions.getCreator()); | ||
73 | ensure_equals("init/getOwner():failed to return the owner ", owner, permissions.getOwner()); | ||
74 | ensure_equals("init/getLastOwner():failed to return the group ", lastOwner, permissions.getLastOwner()); | ||
75 | ensure_equals("init/getGroup():failed to return the group ", group, permissions.getGroup()); | ||
76 | } | ||
77 | |||
78 | template<> template<> | ||
79 | void permission_object_t::test<3>() | ||
80 | { | ||
81 | LLPermissions permissions; | ||
82 | U32 base = PERM_ALL; | ||
83 | U32 owner = PERM_ITEM_UNRESTRICTED; //PERM_ITEM_UNRESTRICTED = PERM_MODIFY | PERM_COPY | PERM_TRANSFER; | ||
84 | U32 group = PERM_TRANSFER | PERM_MOVE | PERM_COPY|PERM_MODIFY; | ||
85 | U32 everyone = PERM_TRANSFER | PERM_MOVE | PERM_MODIFY; | ||
86 | U32 next = PERM_NONE; | ||
87 | |||
88 | U32 fixedbase = base; | ||
89 | U32 fixedowner = PERM_ITEM_UNRESTRICTED; //owner & fixedbase | ||
90 | U32 fixedgroup = PERM_ITEM_UNRESTRICTED; // no PERM_MOVE as owner does not have that perm either | ||
91 | U32 fixedeveryone = PERM_TRANSFER; // no PERM_MOVE. Everyone can never modify. | ||
92 | U32 fixednext = PERM_NONE; | ||
93 | |||
94 | permissions.initMasks(base, owner, everyone, group, next); // will fix perms if not allowed. | ||
95 | ensure_equals("initMasks/getMaskBase():failed to return the MaskBase ", fixedbase, permissions.getMaskBase()); | ||
96 | ensure_equals("initMasks/getMaskOwner():failed to return the MaskOwner ", fixedowner, permissions.getMaskOwner()); | ||
97 | ensure_equals("initMasks/getMaskEveryone():failed to return the MaskGroup ", fixedgroup, permissions.getMaskGroup()); | ||
98 | ensure_equals("initMasks/getMaskEveryone():failed to return the MaskEveryone ", fixedeveryone, permissions.getMaskEveryone()); | ||
99 | ensure_equals("initMasks/getMaskNextOwner():failed to return the MaskNext ", fixednext, permissions.getMaskNextOwner()); | ||
100 | |||
101 | // explictly set should maintain the values | ||
102 | permissions.setMaskBase(base); //no fixing | ||
103 | ensure_equals("setMaskBase/getMaskBase():failed to return the MaskBase ", base, permissions.getMaskBase()); | ||
104 | |||
105 | permissions.setMaskOwner(owner); | ||
106 | ensure_equals("setMaskOwner/getMaskOwner():failed to return the MaskOwner ", owner, permissions.getMaskOwner()); | ||
107 | |||
108 | permissions.setMaskEveryone(everyone); | ||
109 | ensure_equals("setMaskEveryone/getMaskEveryone():failed to return the MaskEveryone ", everyone, permissions.getMaskEveryone()); | ||
110 | |||
111 | permissions.setMaskGroup(group); | ||
112 | ensure_equals("setMaskGroup/getMaskEveryone():failed to return the MaskGroup ", group, permissions.getMaskGroup()); | ||
113 | |||
114 | permissions.setMaskNext(next); | ||
115 | ensure_equals("setMaskNext/getMaskNextOwner():failed to return the MaskNext ", next, permissions.getMaskNextOwner()); | ||
116 | |||
117 | // further tests can be added to ensure perms for owner/group/everyone etc. get properly fixed. | ||
118 | // code however suggests that there is no explict check if the perms are correct and the user of this | ||
119 | // class is expected to know how to use them correctly. skipping further test cases for now for various | ||
120 | // perm combinations. | ||
121 | } | ||
122 | |||
123 | template<> template<> | ||
124 | void permission_object_t::test<4>() | ||
125 | { | ||
126 | LLPermissions perm,perm1; | ||
127 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
128 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
129 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
130 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
131 | perm1.init(creator,owner,lastOwner,group); | ||
132 | perm.set(perm1); | ||
133 | ensure("set():failed to set ", (creator == perm.getCreator()) && (owner == perm.getOwner())&& | ||
134 | (lastOwner == perm.getLastOwner())&& (group == perm.getGroup())); | ||
135 | } | ||
136 | |||
137 | template<> template<> | ||
138 | void permission_object_t::test<5>() | ||
139 | { | ||
140 | LLPermissions perm,perm1; | ||
141 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
142 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
143 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
144 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
145 | perm1.init(creator,owner,lastOwner,group); | ||
146 | |||
147 | U32 base = PERM_TRANSFER; | ||
148 | U32 ownerp = PERM_TRANSFER; | ||
149 | U32 groupp = PERM_TRANSFER; | ||
150 | U32 everyone = PERM_TRANSFER; | ||
151 | U32 next = PERM_NONE; | ||
152 | |||
153 | perm1.initMasks(base, ownerp, everyone, groupp, next); | ||
154 | |||
155 | base = PERM_ALL; | ||
156 | ownerp = PERM_ITEM_UNRESTRICTED; //PERM_ITEM_UNRESTRICTED = PERM_MODIFY | PERM_COPY | PERM_TRANSFER; | ||
157 | groupp = PERM_TRANSFER | PERM_COPY|PERM_MODIFY; | ||
158 | everyone = PERM_TRANSFER; | ||
159 | next = PERM_NONE; | ||
160 | |||
161 | perm.init(creator,owner,lastOwner,group); | ||
162 | perm.initMasks(base, ownerp, everyone, groupp, next); | ||
163 | |||
164 | // restrict permissions by accumulation | ||
165 | perm.accumulate(perm1); | ||
166 | |||
167 | U32 fixedbase = PERM_TRANSFER | PERM_MOVE; | ||
168 | U32 fixedowner = PERM_TRANSFER; | ||
169 | U32 fixedgroup = PERM_TRANSFER; | ||
170 | U32 fixedeveryone = PERM_TRANSFER; | ||
171 | U32 fixednext = PERM_NONE; | ||
172 | |||
173 | ensure_equals("accumulate failed ", fixedbase, perm.getMaskBase()); | ||
174 | ensure_equals("accumulate failed ", fixedowner, perm.getMaskOwner()); | ||
175 | ensure_equals("accumulate failed ", fixedgroup, perm.getMaskGroup()); | ||
176 | ensure_equals("accumulate failed ", fixedeveryone, perm.getMaskEveryone()); | ||
177 | ensure_equals("accumulate failed ", fixednext, perm.getMaskNextOwner()); | ||
178 | } | ||
179 | |||
180 | template<> template<> | ||
181 | void permission_object_t::test<6>() | ||
182 | { | ||
183 | LLPermissions perm; | ||
184 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
185 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
186 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
187 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
188 | perm.init(creator,owner,lastOwner,group); | ||
189 | ensure_equals("getSafeOwner:failed ", owner,perm.getSafeOwner()); | ||
190 | |||
191 | ///NULL Owner | ||
192 | perm.init(creator,LLUUID::null,lastOwner,group); | ||
193 | ensure_equals("getSafeOwner:failed ", group, perm.getSafeOwner()); | ||
194 | } | ||
195 | |||
196 | template<> template<> | ||
197 | void permission_object_t::test<7>() | ||
198 | { | ||
199 | LLPermissions perm1; | ||
200 | LLUUID uuid; | ||
201 | BOOL is_group_owned = FALSE; | ||
202 | ensure("1:getOwnership:failed ", (FALSE == perm1.getOwnership(uuid,is_group_owned))); | ||
203 | |||
204 | LLPermissions perm; | ||
205 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
206 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
207 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
208 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
209 | perm.init(creator,owner,lastOwner,group); | ||
210 | perm.getOwnership(uuid,is_group_owned); | ||
211 | ensure("2:getOwnership:failed ", ((uuid == owner) && (FALSE == is_group_owned))); | ||
212 | |||
213 | perm.init(creator,LLUUID::null,lastOwner,group); | ||
214 | perm.getOwnership(uuid,is_group_owned); | ||
215 | ensure("3:getOwnership:failed ", ((uuid == group) && (TRUE == is_group_owned))); | ||
216 | } | ||
217 | |||
218 | template<> template<> | ||
219 | void permission_object_t::test<8>() | ||
220 | { | ||
221 | LLPermissions perm,perm1; | ||
222 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
223 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
224 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
225 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
226 | perm.init(creator,owner,lastOwner,group); | ||
227 | perm1.init(creator,owner,lastOwner,group); | ||
228 | ensure_equals("getCRC32:failed ", perm.getCRC32(),perm1.getCRC32()); | ||
229 | } | ||
230 | |||
231 | template<> template<> | ||
232 | void permission_object_t::test<9>() | ||
233 | { | ||
234 | LLPermissions perm; | ||
235 | LLUUID agent("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
236 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
237 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
238 | bool is_atomic = TRUE; | ||
239 | ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(agent,owner,group,is_atomic))); | ||
240 | |||
241 | LLUUID owner2("68edcf47-ccd7-45b8-9f90-1649d7f12807"); | ||
242 | LLUUID group2("9c8eca51-53d5-42a7-bb58-cef070395db9"); | ||
243 | |||
244 | // cant change - agent need to be current owner | ||
245 | ensure("setOwnerAndGroup():failed ", (FALSE == perm.setOwnerAndGroup(agent,owner2,group2,is_atomic))); | ||
246 | |||
247 | // should be able to change - agent and owner same as current owner | ||
248 | ensure("setOwnerAndGroup():failed ", (TRUE == perm.setOwnerAndGroup(owner,owner,group2,is_atomic))); | ||
249 | } | ||
250 | |||
251 | template<> template<> | ||
252 | void permission_object_t::test<10>() | ||
253 | { | ||
254 | LLPermissions perm; | ||
255 | LLUUID agent; | ||
256 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
257 | ensure("deedToGroup():failed ", (TRUE == perm.deedToGroup(agent,group))); | ||
258 | } | ||
259 | template<> template<> | ||
260 | void permission_object_t::test<11>() | ||
261 | { | ||
262 | LLPermissions perm; | ||
263 | LLUUID agent; | ||
264 | BOOL set = 1; | ||
265 | U32 bits = PERM_TRANSFER | PERM_MODIFY; | ||
266 | ensure("setBaseBits():failed ", (TRUE == perm.setBaseBits(agent, set, bits))); | ||
267 | ensure("setOwnerBits():failed ", (TRUE == perm.setOwnerBits(agent, set, bits))); | ||
268 | |||
269 | LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
270 | ensure("setBaseBits():failed ", (FALSE == perm.setBaseBits(agent1, set, bits))); | ||
271 | ensure("setOwnerBits():failed ", (FALSE == perm.setOwnerBits(agent1, set, bits))); | ||
272 | } | ||
273 | |||
274 | template<> template<> | ||
275 | void permission_object_t::test<12>() | ||
276 | { | ||
277 | LLPermissions perm; | ||
278 | LLUUID agent; | ||
279 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
280 | BOOL set = 1; | ||
281 | U32 bits = 10; | ||
282 | ensure("setGroupBits():failed ", (TRUE == perm.setGroupBits(agent,group, set, bits))); | ||
283 | ensure("setEveryoneBits():failed ", (TRUE == perm.setEveryoneBits(agent,group, set, bits))); | ||
284 | ensure("setNextOwnerBits():failed ", (TRUE == perm.setNextOwnerBits(agent,group, set, bits))); | ||
285 | |||
286 | LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
287 | ensure("setGroupBits():failed ", (FALSE == perm.setGroupBits(agent1,group, set, bits))); | ||
288 | ensure("setEveryoneBits():failed ", (FALSE == perm.setEveryoneBits(agent1,group, set, bits))); | ||
289 | ensure("setNextOwnerBits():failed ", (FALSE == perm.setNextOwnerBits(agent1,group, set, bits))); | ||
290 | } | ||
291 | |||
292 | template<> template<> | ||
293 | void permission_object_t::test<13>() | ||
294 | { | ||
295 | LLPermissions perm; | ||
296 | LLUUID agent; | ||
297 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
298 | U32 bits = 10; | ||
299 | ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent,group))); | ||
300 | |||
301 | LLUUID agent1("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
302 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
303 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
304 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
305 | perm.init(creator,owner,lastOwner,group); | ||
306 | ensure("allowOperationBy():failed ", (TRUE == perm.allowOperationBy(bits,agent1,group))); | ||
307 | } | ||
308 | |||
309 | template<> template<> | ||
310 | void permission_object_t::test<14>() | ||
311 | { | ||
312 | LLPermissions perm; | ||
313 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
314 | LLUUID owner; | ||
315 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
316 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
317 | perm.init(creator,owner,lastOwner,group); | ||
318 | LLUUID agent; | ||
319 | ensure("1:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent))); | ||
320 | ensure("2:allowModifyBy():failed ", (TRUE == perm.allowModifyBy(agent,group))); | ||
321 | |||
322 | U32 val1 = 0x7FFFFFFF; | ||
323 | S32 sVal = 1 << 14; | ||
324 | sVal = val1 & sVal; | ||
325 | LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
326 | ensure("3:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1))); | ||
327 | ensure("4:allowModifyBy():failed ", (sVal == perm.allowModifyBy(agent1,group))); | ||
328 | } | ||
329 | |||
330 | template<> template<> | ||
331 | void permission_object_t::test<15>() | ||
332 | { | ||
333 | LLPermissions perm; | ||
334 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
335 | LLUUID owner; | ||
336 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
337 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
338 | perm.init(creator,owner,lastOwner,group); | ||
339 | LLUUID agent; | ||
340 | ensure("1:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent))); | ||
341 | ensure("2:allowCopyBy():failed ", (TRUE == perm.allowModifyBy(agent,group))); | ||
342 | |||
343 | U32 val1 = 0x7FFFFFFF; | ||
344 | S32 sVal = 1 << 15; | ||
345 | sVal = val1 & sVal; | ||
346 | LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
347 | ensure("3:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1))); | ||
348 | ensure("4:allowCopyBy():failed ", (sVal == perm.allowCopyBy(agent1,group))); | ||
349 | } | ||
350 | |||
351 | template<> template<> | ||
352 | void permission_object_t::test<16>() | ||
353 | { | ||
354 | LLPermissions perm; | ||
355 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
356 | LLUUID owner; | ||
357 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
358 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
359 | perm.init(creator,owner,lastOwner,group); | ||
360 | LLUUID agent; | ||
361 | ensure("1:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent))); | ||
362 | ensure("2:allowMoveBy():failed ", (TRUE == perm.allowMoveBy(agent,group))); | ||
363 | |||
364 | U32 val1 = 0x7FFFFFFF; | ||
365 | S32 sVal = 1 << 19; | ||
366 | sVal = val1 & sVal; | ||
367 | LLUUID agent1("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
368 | ensure("3:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1))); | ||
369 | ensure("4:allowMoveBy():failed ", (sVal == perm.allowMoveBy(agent1,group))); | ||
370 | } | ||
371 | |||
372 | template<> template<> | ||
373 | void permission_object_t::test<17>() | ||
374 | { | ||
375 | LLPermissions perm; | ||
376 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
377 | LLUUID owner; | ||
378 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
379 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
380 | LLUUID agent; | ||
381 | ensure("1:allowMoveBy():failed ", (TRUE == perm.allowTransferTo(agent))); | ||
382 | |||
383 | perm.init(creator,owner,lastOwner,group); | ||
384 | U32 val1 = 0x7FFFFFFF; | ||
385 | S32 sVal = 1 << 13; | ||
386 | sVal = val1 & sVal; | ||
387 | ensure("2:allowMoveBy():failed ", (sVal == perm.allowTransferTo(agent))); | ||
388 | } | ||
389 | |||
390 | template<> template<> | ||
391 | void permission_object_t::test<18>() | ||
392 | { | ||
393 | LLPermissions perm,perm1; | ||
394 | ensure("1:Operator==:failed ", perm == perm1); | ||
395 | |||
396 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
397 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
398 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
399 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
400 | perm.init(creator,owner,lastOwner,group); | ||
401 | perm = perm1; | ||
402 | ensure("2:Operator==:failed ", perm == perm1); | ||
403 | } | ||
404 | |||
405 | template<> template<> | ||
406 | void permission_object_t::test<19>() | ||
407 | { | ||
408 | LLPermissions perm,perm1; | ||
409 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
410 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
411 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
412 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
413 | perm.init(creator,owner,lastOwner,group); | ||
414 | ensure("2:Operator==:failed ", perm != perm1); | ||
415 | } | ||
416 | |||
417 | template<> template<> | ||
418 | void permission_object_t::test<20>() | ||
419 | { | ||
420 | FILE* fp = fopen("linden_file.dat","w+"); | ||
421 | if(!fp) | ||
422 | { | ||
423 | llerrs << "file coudnt be opened\n" << llendl; | ||
424 | return; | ||
425 | } | ||
426 | LLPermissions perm,perm1; | ||
427 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
428 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
429 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
430 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
431 | perm.init(creator,owner,lastOwner,group); | ||
432 | |||
433 | U32 base = PERM_TRANSFER | PERM_COPY; | ||
434 | U32 ownerp = PERM_TRANSFER; | ||
435 | U32 groupp = PERM_TRANSFER; | ||
436 | U32 everyone = PERM_TRANSFER; | ||
437 | U32 next = PERM_NONE; | ||
438 | |||
439 | perm.initMasks(base, ownerp, everyone, groupp, next); | ||
440 | |||
441 | perm.exportFile(fp); | ||
442 | fclose(fp); | ||
443 | fp = fopen("linden_file.dat","r+"); | ||
444 | if(!fp) | ||
445 | { | ||
446 | llerrs << "file coudnt be opened\n" << llendl; | ||
447 | return; | ||
448 | } | ||
449 | perm1.importFile(fp); | ||
450 | fclose(fp); | ||
451 | ensure("exportFile()/importFile():failed to export and import the data ", perm1 == perm); | ||
452 | } | ||
453 | |||
454 | template<> template<> | ||
455 | void permission_object_t::test<21>() | ||
456 | { | ||
457 | LLPermissions perm,perm1; | ||
458 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
459 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
460 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
461 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
462 | perm.init(creator,owner,lastOwner,group); | ||
463 | |||
464 | U32 base = PERM_TRANSFER | PERM_COPY; | ||
465 | U32 ownerp = PERM_TRANSFER; | ||
466 | U32 groupp = PERM_TRANSFER; | ||
467 | U32 everyone = PERM_TRANSFER; | ||
468 | U32 next = PERM_NONE; | ||
469 | |||
470 | perm.initMasks(base, ownerp, everyone, groupp, next); | ||
471 | |||
472 | std::ostringstream ostream; | ||
473 | perm.exportLegacyStream(ostream); | ||
474 | std::istringstream istream(ostream.str()); | ||
475 | perm1.importLegacyStream(istream); | ||
476 | |||
477 | ensure("exportLegacyStream()/importLegacyStream():failed to export and import the data ", perm1 == perm); | ||
478 | } | ||
479 | |||
480 | template<> template<> | ||
481 | void permission_object_t::test<22>() | ||
482 | { | ||
483 | LLPermissions perm,perm1; | ||
484 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
485 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
486 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
487 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
488 | perm.init(creator,owner,lastOwner,group); | ||
489 | LLXMLNode* xml_node = perm.exportFileXML(); | ||
490 | perm1.importXML(xml_node); | ||
491 | ensure("exportFileXML()/importXML():failed to export and import the data ", perm1 == perm); | ||
492 | } | ||
493 | |||
494 | template<> template<> | ||
495 | void permission_object_t::test<23>() | ||
496 | { | ||
497 | LLPermissions perm,perm1; | ||
498 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
499 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
500 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
501 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
502 | perm.init(creator,owner,lastOwner,group); | ||
503 | std::ostringstream stream1, stream2; | ||
504 | stream1 << perm; | ||
505 | perm1.init(creator,owner,lastOwner,group); | ||
506 | stream2 << perm1; | ||
507 | ensure("1:operator << failed",(stream1.str() == stream2.str())); | ||
508 | } | ||
509 | |||
510 | template<> template<> | ||
511 | void permission_object_t::test<24>() | ||
512 | { | ||
513 | LLPermissions perm,perm1; | ||
514 | LLUUID creator("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); | ||
515 | LLUUID owner("68edcf47-ccd7-45b8-9f90-1649d7f12806"); | ||
516 | LLUUID lastOwner("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); | ||
517 | LLUUID group("9c8eca51-53d5-42a7-bb58-cef070395db8"); | ||
518 | perm.init(creator,owner,lastOwner,group); | ||
519 | |||
520 | U32 base = PERM_TRANSFER | PERM_COPY; | ||
521 | U32 ownerp = PERM_TRANSFER; | ||
522 | U32 groupp = PERM_TRANSFER; | ||
523 | U32 everyone = PERM_TRANSFER; | ||
524 | U32 next = PERM_NONE; | ||
525 | |||
526 | perm.initMasks(base, ownerp, everyone, groupp, next); | ||
527 | |||
528 | LLSD sd = ll_create_sd_from_permissions(perm); | ||
529 | perm1 = ll_permissions_from_sd(sd); | ||
530 | ensure_equals("ll_permissions_from_sd() and ll_create_sd_from_permissions()functions failed", perm, perm1); | ||
531 | } | ||
532 | |||
533 | template<> template<> | ||
534 | void permission_object_t::test<25>() | ||
535 | { | ||
536 | LLAggregatePermissions AggrPermission; | ||
537 | LLAggregatePermissions AggrPermission1; | ||
538 | ensure("getU8() function failed", (AggrPermission.getU8() == 0)); | ||
539 | ensure("isEmpty() function failed", (AggrPermission.isEmpty() == TRUE)); | ||
540 | AggrPermission.getValue(PERM_TRANSFER); | ||
541 | ensure_equals("getValue() function failed", AggrPermission.getValue(PERM_TRANSFER), 0x00); | ||
542 | |||
543 | AggrPermission.aggregate(PERM_ITEM_UNRESTRICTED); | ||
544 | ensure("aggregate() function failed", (AggrPermission.isEmpty() == FALSE)); | ||
545 | |||
546 | AggrPermission1.aggregate(AggrPermission); | ||
547 | ensure("aggregate() function failed", (AggrPermission1.isEmpty() == FALSE)); | ||
548 | |||
549 | std::ostringstream stream1; | ||
550 | stream1 << AggrPermission; | ||
551 | ensure("operator<< failed", (stream1.str() == "{PI_COPY=All, PI_MODIFY=All, PI_TRANSFER=All}")); | ||
552 | } | ||
553 | } | ||
diff --git a/linden/indra/test/llquaternion_tut.cpp b/linden/indra/test/llquaternion_tut.cpp new file mode 100644 index 0000000..f64e87a --- /dev/null +++ b/linden/indra/test/llquaternion_tut.cpp | |||
@@ -0,0 +1,665 @@ | |||
1 | /** | ||
2 | * @file llquaternion_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief Test cases of llquaternion.h | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "llmath.h" | ||
33 | #include "lltut.h" | ||
34 | #include "linden_common.h" | ||
35 | #include "llquaternion.h" | ||
36 | #include "v4math.h" | ||
37 | #include "v3math.h" | ||
38 | #include "v3dmath.h" | ||
39 | #include "m4math.h" | ||
40 | #include "m3math.h" | ||
41 | #include "math.h" | ||
42 | |||
43 | namespace tut | ||
44 | { | ||
45 | struct llquat_test | ||
46 | { | ||
47 | }; | ||
48 | typedef test_group<llquat_test> llquat_test_t; | ||
49 | typedef llquat_test_t::object llquat_test_object_t; | ||
50 | tut::llquat_test_t tut_llquat_test("llquat"); | ||
51 | |||
52 | //test case for LLQuaternion::LLQuaternion(void) fn. | ||
53 | template<> template<> | ||
54 | void llquat_test_object_t::test<1>() | ||
55 | { | ||
56 | LLQuaternion llquat; | ||
57 | ensure("LLQuaternion::LLQuaternion() failed", 0.f == llquat.mQ[0] && | ||
58 | 0.f == llquat.mQ[1] && | ||
59 | 0.f == llquat.mQ[2] && | ||
60 | 1.f == llquat.mQ[3]); | ||
61 | } | ||
62 | |||
63 | //test case for explicit LLQuaternion(const LLMatrix4 &mat) fn. | ||
64 | template<> template<> | ||
65 | void llquat_test_object_t::test<2>() | ||
66 | { | ||
67 | LLMatrix4 llmat; | ||
68 | LLVector4 vector1(2.0f, 1.0f, 3.0f, 6.0f); | ||
69 | LLVector4 vector2(5.0f, 6.0f, 0.0f, 1.0f); | ||
70 | LLVector4 vector3(2.0f, 1.0f, 2.0f, 9.0f); | ||
71 | LLVector4 vector4(3.0f, 8.0f, 1.0f, 5.0f); | ||
72 | |||
73 | llmat.initRows(vector1, vector2, vector3, vector4); | ||
74 | ensure("explicit LLQuaternion(const LLMatrix4 &mat) failed", 2.0f == llmat.mMatrix[0][0] && | ||
75 | 1.0f == llmat.mMatrix[0][1] && | ||
76 | 3.0f == llmat.mMatrix[0][2] && | ||
77 | 6.0f == llmat.mMatrix[0][3] && | ||
78 | 5.0f == llmat.mMatrix[1][0] && | ||
79 | 6.0f == llmat.mMatrix[1][1] && | ||
80 | 0.0f == llmat.mMatrix[1][2] && | ||
81 | 1.0f == llmat.mMatrix[1][3] && | ||
82 | 2.0f == llmat.mMatrix[2][0] && | ||
83 | 1.0f == llmat.mMatrix[2][1] && | ||
84 | 2.0f == llmat.mMatrix[2][2] && | ||
85 | 9.0f == llmat.mMatrix[2][3] && | ||
86 | 3.0f == llmat.mMatrix[3][0] && | ||
87 | 8.0f == llmat.mMatrix[3][1] && | ||
88 | 1.0f == llmat.mMatrix[3][2] && | ||
89 | 5.0f == llmat.mMatrix[3][3]); | ||
90 | } | ||
91 | |||
92 | template<> template<> | ||
93 | void llquat_test_object_t::test<3>() | ||
94 | { | ||
95 | LLMatrix3 llmat; | ||
96 | |||
97 | LLVector3 vect1(3.4028234660000000f , 234.56f, 4234.442234f); | ||
98 | LLVector3 vect2(741.434f, 23.00034f, 6567.223423f); | ||
99 | LLVector3 vect3(566.003034f, 12.98705f, 234.764423f); | ||
100 | llmat.setRows(vect1, vect2, vect3); | ||
101 | |||
102 | ensure("LLMatrix3::setRows fn failed.", 3.4028234660000000f == llmat.mMatrix[0][0] && | ||
103 | 234.56f == llmat.mMatrix[0][1] && | ||
104 | 4234.442234f == llmat.mMatrix[0][2] && | ||
105 | 741.434f == llmat.mMatrix[1][0] && | ||
106 | 23.00034f == llmat.mMatrix[1][1] && | ||
107 | 6567.223423f == llmat.mMatrix[1][2] && | ||
108 | 566.003034f == llmat.mMatrix[2][0] && | ||
109 | 12.98705f == llmat.mMatrix[2][1] && | ||
110 | 234.764423f == llmat.mMatrix[2][2]); | ||
111 | } | ||
112 | |||
113 | //test case for LLQuaternion(F32 x, F32 y, F32 z, F32 w), setQuatInit() and normQuat() fns. | ||
114 | template<> template<> | ||
115 | void llquat_test_object_t::test<4>() | ||
116 | { | ||
117 | F32 x_val = 3.0f; | ||
118 | F32 y_val = 2.0f; | ||
119 | F32 z_val = 6.0f; | ||
120 | F32 w_val = 1.0f; | ||
121 | |||
122 | LLQuaternion res_quat; | ||
123 | res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
124 | res_quat.normQuat(); | ||
125 | |||
126 | ensure("LLQuaternion::normQuat() fn failed", | ||
127 | is_approx_equal(0.42426407f, res_quat.mQ[0]) && | ||
128 | is_approx_equal(0.28284273f, res_quat.mQ[1]) && | ||
129 | is_approx_equal(0.84852815f, res_quat.mQ[2]) && | ||
130 | is_approx_equal(0.14142136f, res_quat.mQ[3])); | ||
131 | |||
132 | x_val = 0.0f; | ||
133 | y_val = 0.0f; | ||
134 | z_val = 0.0f; | ||
135 | w_val = 0.0f; | ||
136 | |||
137 | res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
138 | res_quat.normQuat(); | ||
139 | |||
140 | ensure("LLQuaternion::normQuat() fn. failed.", | ||
141 | is_approx_equal(0.0f, res_quat.mQ[0]) && | ||
142 | is_approx_equal(0.0f, res_quat.mQ[1]) && | ||
143 | is_approx_equal(0.0f, res_quat.mQ[2]) && | ||
144 | is_approx_equal(1.0f, res_quat.mQ[3])); | ||
145 | |||
146 | |||
147 | ensure("LLQuaternion::normQuat() fn. failed.", | ||
148 | is_approx_equal(0.0f, res_quat.mQ[0]) && | ||
149 | is_approx_equal(0.0f, res_quat.mQ[1]) && | ||
150 | is_approx_equal(0.0f, res_quat.mQ[2]) && | ||
151 | is_approx_equal(1.0f, res_quat.mQ[3])); | ||
152 | } | ||
153 | |||
154 | //test case for conjQuat() and transQuat() fns. | ||
155 | template<> template<> | ||
156 | void llquat_test_object_t::test<5>() | ||
157 | { | ||
158 | F32 x_val = 3.0f; | ||
159 | F32 y_val = 2.0f; | ||
160 | F32 z_val = 6.0f; | ||
161 | F32 w_val = 1.0f; | ||
162 | |||
163 | LLQuaternion res_quat; | ||
164 | LLQuaternion result, result1; | ||
165 | result1 = result = res_quat.setQuatInit(x_val, y_val, z_val, w_val); | ||
166 | |||
167 | result.conjQuat(); | ||
168 | result1.transQuat(); | ||
169 | |||
170 | ensure("LLQuaternion::conjQuat and LLQuaternion::transQuat failed ", | ||
171 | is_approx_equal(result1.mQ[0], result.mQ[0]) && | ||
172 | is_approx_equal(result1.mQ[1], result.mQ[1]) && | ||
173 | is_approx_equal(result1.mQ[2], result.mQ[2])); | ||
174 | |||
175 | } | ||
176 | |||
177 | //test case for dot(const LLQuaternion &a, const LLQuaternion &b) fn. | ||
178 | template<> template<> | ||
179 | void llquat_test_object_t::test<6>() | ||
180 | { | ||
181 | LLQuaternion quat1(3.0f, 2.0f, 6.0f, 0.0f), quat2(1.0f, 1.0f, 1.0f, 1.0f); | ||
182 | ensure("1. The two values are different", llround(12.000000f, 2) == llround(dot(quat1, quat2), 2)); | ||
183 | |||
184 | LLQuaternion quat0(3.0f, 9.334f, 34.5f, 23.0f), quat(34.5f, 23.23f, 2.0f, 45.5f); | ||
185 | ensure("2. The two values are different", llround(1435.828807f, 2) == llround(dot(quat0, quat), 2)); | ||
186 | } | ||
187 | |||
188 | //test case for LLQuaternion &LLQuaternion::constrain(F32 radians) fn. | ||
189 | template<> template<> | ||
190 | void llquat_test_object_t::test<7>() | ||
191 | { | ||
192 | F32 radian = 60.0f; | ||
193 | LLQuaternion quat(3.0f, 2.0f, 6.0f, 0.0f); | ||
194 | LLQuaternion quat1; | ||
195 | quat1 = quat.constrain(radian); | ||
196 | ensure("1. LLQuaternion::constrain(F32 radians) failed", | ||
197 | is_approx_equal_fraction(-0.423442f, quat1.mQ[0], 8) && | ||
198 | is_approx_equal_fraction(-0.282295f, quat1.mQ[1], 8) && | ||
199 | is_approx_equal_fraction(-0.846884f, quat1.mQ[2], 8) && | ||
200 | is_approx_equal_fraction(0.154251f, quat1.mQ[3], 8)); | ||
201 | |||
202 | |||
203 | radian = 30.0f; | ||
204 | LLQuaternion quat0(37.50f, 12.0f, 86.023f, 40.32f); | ||
205 | quat1 = quat0.constrain(radian); | ||
206 | |||
207 | ensure("2. LLQuaternion::constrain(F32 radians) failed", | ||
208 | is_approx_equal_fraction(37.500000f, quat1.mQ[0], 8) && | ||
209 | is_approx_equal_fraction(12.0000f, quat1.mQ[1], 8) && | ||
210 | is_approx_equal_fraction(86.0230f, quat1.mQ[2], 8) && | ||
211 | is_approx_equal_fraction(40.320000f, quat1.mQ[3], 8)); | ||
212 | } | ||
213 | |||
214 | template<> template<> | ||
215 | void llquat_test_object_t::test<8>() | ||
216 | { | ||
217 | F32 value1 = 15.0f; | ||
218 | LLQuaternion quat1(1.0f, 2.0f, 4.0f, 1.0f); | ||
219 | LLQuaternion quat2(4.0f, 3.0f, 6.5f, 9.7f); | ||
220 | LLQuaternion res_lerp, res_slerp, res_nlerp; | ||
221 | |||
222 | //test case for lerp(F32 t, const LLQuaternion &q) fn. | ||
223 | res_lerp = lerp(value1, quat1); | ||
224 | ensure("1. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", | ||
225 | is_approx_equal_fraction(0.181355f, res_lerp.mQ[0], 16) && | ||
226 | is_approx_equal_fraction(0.362711f, res_lerp.mQ[1], 16) && | ||
227 | is_approx_equal_fraction(0.725423f, res_lerp.mQ[2], 16) && | ||
228 | is_approx_equal_fraction(0.556158f, res_lerp.mQ[3], 16)); | ||
229 | |||
230 | //test case for lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) fn. | ||
231 | res_lerp = lerp(value1, quat1, quat2); | ||
232 | ensure("2. LLQuaternion lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) failed", | ||
233 | is_approx_equal_fraction(0.314306f, res_lerp.mQ[0], 16) && | ||
234 | is_approx_equal_fraction(0.116156f, res_lerp.mQ[1], 16) && | ||
235 | is_approx_equal_fraction(0.283559f, res_lerp.mQ[2], 16) && | ||
236 | is_approx_equal_fraction(0.898506f, res_lerp.mQ[3], 16)); | ||
237 | |||
238 | //test case for slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b ) fn. | ||
239 | res_slerp = slerp(value1, quat1, quat2); | ||
240 | ensure("3. LLQuaternion slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b) failed", | ||
241 | is_approx_equal_fraction(46.000f, res_slerp.mQ[0], 16) && | ||
242 | is_approx_equal_fraction(17.00f, res_slerp.mQ[1], 16) && | ||
243 | is_approx_equal_fraction(41.5f, res_slerp.mQ[2], 16) && | ||
244 | is_approx_equal_fraction(131.5f, res_slerp.mQ[3], 16)); | ||
245 | |||
246 | //test case for nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) fn. | ||
247 | res_nlerp = nlerp(value1, quat1, quat2); | ||
248 | ensure("4. LLQuaternion nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) failed", | ||
249 | is_approx_equal_fraction(0.314306f, res_nlerp.mQ[0], 16) && | ||
250 | is_approx_equal_fraction(0.116157f, res_nlerp.mQ[1], 16) && | ||
251 | is_approx_equal_fraction(0.283559f, res_nlerp.mQ[2], 16) && | ||
252 | is_approx_equal_fraction(0.898506f, res_nlerp.mQ[3], 16)); | ||
253 | |||
254 | //test case for nlerp(F32 t, const LLQuaternion &q) fn. | ||
255 | res_slerp = slerp(value1, quat1); | ||
256 | ensure("5. LLQuaternion slerp(F32 t, const LLQuaternion &q) failed", | ||
257 | is_approx_equal_fraction(1.0f, res_slerp.mQ[0], 16) && | ||
258 | is_approx_equal_fraction(2.0f, res_slerp.mQ[1], 16) && | ||
259 | is_approx_equal_fraction(4.0000f, res_slerp.mQ[2], 16) && | ||
260 | is_approx_equal_fraction(1.000f, res_slerp.mQ[3], 16)); | ||
261 | |||
262 | LLQuaternion quat3(2.0f, 1.0f, 5.5f, 10.5f); | ||
263 | LLQuaternion res_nlerp1; | ||
264 | value1 = 100.0f; | ||
265 | res_nlerp1 = nlerp(value1, quat3); | ||
266 | ensure("6. LLQuaternion nlerp(F32 t, const LLQuaternion &q) failed", | ||
267 | is_approx_equal_fraction(0.268245f, res_nlerp1.mQ[0], 16) && is_approx_equal_fraction(0.134122f, res_nlerp1.mQ[1], 2) && | ||
268 | is_approx_equal_fraction(0.737673f, res_nlerp1.mQ[2], 16) && | ||
269 | is_approx_equal_fraction(0.604892f, res_nlerp1.mQ[3], 16)); | ||
270 | |||
271 | //test case for lerp(F32 t, const LLQuaternion &q) fn. | ||
272 | res_lerp = lerp(value1, quat2); | ||
273 | ensure("7. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", | ||
274 | is_approx_equal_fraction(0.404867f, res_lerp.mQ[0], 16) && | ||
275 | is_approx_equal_fraction(0.303650f, res_lerp.mQ[1], 16) && | ||
276 | is_approx_equal_fraction(0.657909f, res_lerp.mQ[2], 16) && | ||
277 | is_approx_equal_fraction(0.557704f, res_lerp.mQ[3], 16)); | ||
278 | |||
279 | } | ||
280 | |||
281 | template<> template<> | ||
282 | void llquat_test_object_t::test<9>() | ||
283 | { | ||
284 | //test case for LLQuaternion operator*(const LLQuaternion &a, const LLQuaternion &b) fn | ||
285 | LLQuaternion quat1(1.0f, 2.5f, 3.5f, 5.5f); | ||
286 | LLQuaternion quat2(4.0f, 3.0f, 5.0f, 1.0f); | ||
287 | LLQuaternion result = quat1 * quat2; | ||
288 | ensure("1. LLQuaternion Operator* failed", (21.0f == result.mQ[0]) && | ||
289 | (10.0f == result.mQ[1]) && | ||
290 | (38.0f == result.mQ[2]) && | ||
291 | (-23.5f == result.mQ[3])); | ||
292 | |||
293 | LLQuaternion quat3(2341.340f, 2352.345f, 233.25f, 7645.5f); | ||
294 | LLQuaternion quat4(674.067f, 893.0897f, 578.0f, 231.0f); | ||
295 | result = quat3 * quat4; | ||
296 | ensure("2. LLQuaternion Operator* failed", (4543086.5f == result.mQ[0]) && | ||
297 | (8567578.0f == result.mQ[1]) && | ||
298 | (3967591.25f == result.mQ[2]) && | ||
299 | (-2047783.25f == result.mQ[3])); | ||
300 | |||
301 | //inline LLQuaternion operator+(const LLQuaternion &a, const LLQuaternion &b)fn. | ||
302 | result = quat1 + quat2; | ||
303 | ensure("3. LLQuaternion operator+ failed", (5.0f == result.mQ[0]) && | ||
304 | (5.5f == result.mQ[1]) && | ||
305 | (8.5f == result.mQ[2]) && | ||
306 | (6.5f == result.mQ[3])); | ||
307 | |||
308 | result = quat3 + quat4; | ||
309 | ensure( | ||
310 | "4. LLQuaternion operator+ failed", | ||
311 | is_approx_equal(3015.407227f, result.mQ[0]) && | ||
312 | is_approx_equal(3245.434570f, result.mQ[1]) && | ||
313 | (811.25f == result.mQ[2]) && | ||
314 | (7876.5f == result.mQ[3])); | ||
315 | |||
316 | //inline LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) fn | ||
317 | result = quat1 - quat2; | ||
318 | ensure( | ||
319 | "5. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed", | ||
320 | (-3.0f == result.mQ[0]) && | ||
321 | (-0.5f == result.mQ[1]) && | ||
322 | (-1.5f == result.mQ[2]) && | ||
323 | (4.5f == result.mQ[3])); | ||
324 | |||
325 | result = quat3 - quat4; | ||
326 | ensure( | ||
327 | "6. LLQuaternion operator-(const LLQuaternion &a, const LLQuaternion &b) failed", | ||
328 | is_approx_equal(1667.273071f, result.mQ[0]) && | ||
329 | is_approx_equal(1459.255249f, result.mQ[1]) && | ||
330 | (-344.75f == result.mQ[2]) && | ||
331 | (7414.50f == result.mQ[3])); | ||
332 | } | ||
333 | |||
334 | //test case for LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) fn. | ||
335 | template<> template<> | ||
336 | void llquat_test_object_t::test<10>() | ||
337 | { | ||
338 | #if (LL_RELEASE && LL_LINUX) | ||
339 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
340 | #endif | ||
341 | LLVector4 vect(12.0f, 5.0f, 60.0f, 75.1f); | ||
342 | LLQuaternion quat(2323.034f, 23.5f, 673.23f, 57667.5f); | ||
343 | LLVector4 result = vect * quat; | ||
344 | ensure( | ||
345 | "1. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed", | ||
346 | (39928406016.0f == result.mV[0]) && | ||
347 | (1457801728.0f == result.mV[1]) && | ||
348 | (200580612096.0f == result.mV[2]) && | ||
349 | (75.099998f == result.mV[3])); | ||
350 | |||
351 | LLVector4 vect1(22.0f, 45.0f, 40.0f, 78.1f); | ||
352 | LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f); | ||
353 | result = vect1 * quat1; | ||
354 | ensure( | ||
355 | "2. LLVector4 operator*(const LLVector4 &a, const LLQuaternion &rot) failed", | ||
356 | is_approx_equal(-58153.5390f, result.mV[0]) && | ||
357 | (183787.8125f == result.mV[1]) && | ||
358 | (116864.164063f == result.mV[2]) && | ||
359 | (78.099998f == result.mV[3])); | ||
360 | } | ||
361 | |||
362 | //test case for LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) fn. | ||
363 | template<> template<> | ||
364 | void llquat_test_object_t::test<11>() | ||
365 | { | ||
366 | LLVector3 vect(12.0f, 5.0f, 60.0f); | ||
367 | LLQuaternion quat(23.5f, 6.5f, 3.23f, 56.5f); | ||
368 | LLVector3 result = vect * quat; | ||
369 | ensure( | ||
370 | "1. LLVEctor3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed", | ||
371 | is_approx_equal(97182.953125f,result.mV[0]) && | ||
372 | is_approx_equal(-135405.640625f, result.mV[1]) && | ||
373 | is_approx_equal(162986.140f, result.mV[2])); | ||
374 | |||
375 | LLVector3 vect1(5.0f, 40.0f, 78.1f); | ||
376 | LLQuaternion quat1(2.034f, 45.5f, 37.23f, 7.5f); | ||
377 | result = vect1 * quat1; | ||
378 | ensure( | ||
379 | "2. LLVector3 operator*(const LLVector3 &a, const LLQuaternion &rot) failed", | ||
380 | is_approx_equal(33217.703f, result.mV[0]) && | ||
381 | is_approx_equal(295383.8125f, result.mV[1]) && | ||
382 | is_approx_equal(84718.140f, result.mV[2])); | ||
383 | } | ||
384 | |||
385 | //test case for LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) fn. | ||
386 | template<> template<> | ||
387 | void llquat_test_object_t::test<12>() | ||
388 | { | ||
389 | LLVector3d vect(-2.0f, 5.0f, -6.0f); | ||
390 | LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f); | ||
391 | LLVector3d result = vect * quat; | ||
392 | ensure( | ||
393 | "1. LLVEctor3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ", | ||
394 | (-633.0f == result.mdV[0]) && | ||
395 | (-300.0f == result.mdV[1]) && | ||
396 | (-36.0f == result.mdV[2])); | ||
397 | |||
398 | LLVector3d vect1(5.0f, -4.5f, 8.21f); | ||
399 | LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f); | ||
400 | result = vect1 * quat1; | ||
401 | ensure( | ||
402 | "2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", | ||
403 | is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) && | ||
404 | is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) && | ||
405 | is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8)); | ||
406 | |||
407 | LLVector3d vect2(2.0f, 3.5f, 1.1f); | ||
408 | LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f); | ||
409 | result = vect2 * quat2; | ||
410 | ensure( | ||
411 | "3. LLvector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", | ||
412 | is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) && | ||
413 | is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) && | ||
414 | is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8)); | ||
415 | } | ||
416 | |||
417 | //test case for inline LLQuaternion operator-(const LLQuaternion &a) fn. | ||
418 | template<> template<> | ||
419 | void llquat_test_object_t::test<13>() | ||
420 | { | ||
421 | LLQuaternion quat(23.5f, 34.5f, 16723.4f, 324.7f); | ||
422 | LLQuaternion result = -quat; | ||
423 | ensure( | ||
424 | "1. LLQuaternion operator-(const LLQuaternion &a) failed", | ||
425 | (-23.5f == result.mQ[0]) && | ||
426 | (-34.5f == result.mQ[1]) && | ||
427 | (-16723.4f == result.mQ[2]) && | ||
428 | (-324.7f == result.mQ[3])); | ||
429 | |||
430 | LLQuaternion quat1(-3.5f, -34.5f, -16.4f, -154.7f); | ||
431 | result = -quat1; | ||
432 | ensure( | ||
433 | "2. LLQuaternion operator-(const LLQuaternion &a) failed.", | ||
434 | (3.5f == result.mQ[0]) && | ||
435 | (34.5f == result.mQ[1]) && | ||
436 | (16.4f == result.mQ[2]) && | ||
437 | (154.7f == result.mQ[3])); | ||
438 | } | ||
439 | |||
440 | //test case for inline LLQuaternion operator*(F32 a, const LLQuaternion &q) and | ||
441 | //inline LLQuaternion operator*(F32 a, const LLQuaternion &q) fns. | ||
442 | template<> template<> | ||
443 | void llquat_test_object_t::test<14>() | ||
444 | { | ||
445 | LLQuaternion quat_value(9.0f, 8.0f, 7.0f, 6.0f); | ||
446 | F32 a =3.5f; | ||
447 | LLQuaternion result = a * quat_value; | ||
448 | LLQuaternion result1 = quat_value * a; | ||
449 | |||
450 | ensure( | ||
451 | "1. LLQuaternion operator* failed", | ||
452 | (result.mQ[0] == result1.mQ[0]) && | ||
453 | (result.mQ[1] == result1.mQ[1]) && | ||
454 | (result.mQ[2] == result1.mQ[2]) && | ||
455 | (result.mQ[3] == result1.mQ[3])); | ||
456 | |||
457 | |||
458 | LLQuaternion quat_val(9454.0f, 43568.3450f, 456343247.0343f, 2346.03434f); | ||
459 | a =-3324.3445f; | ||
460 | result = a * quat_val; | ||
461 | result1 = quat_val * a; | ||
462 | |||
463 | ensure( | ||
464 | "2. LLQuaternion operator* failed", | ||
465 | (result.mQ[0] == result1.mQ[0]) && | ||
466 | (result.mQ[1] == result1.mQ[1]) && | ||
467 | (result.mQ[2] == result1.mQ[2]) && | ||
468 | (result.mQ[3] == result1.mQ[3])); | ||
469 | } | ||
470 | |||
471 | template<> template<> | ||
472 | void llquat_test_object_t::test<15>() | ||
473 | { | ||
474 | // test cases for inline LLQuaternion operator~(const LLQuaternion &a) | ||
475 | LLQuaternion quat_val(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
476 | LLQuaternion result = ~quat_val; | ||
477 | ensure( | ||
478 | "1. LLQuaternion operator~(const LLQuaternion &a) failed ", | ||
479 | (-2323.634f == result.mQ[0]) && | ||
480 | (43535.4f == result.mQ[1]) && | ||
481 | (-3455.88f == result.mQ[2]) && | ||
482 | (-32232.45f == result.mQ[3])); | ||
483 | |||
484 | //test case for inline bool LLQuaternion::operator==(const LLQuaternion &b) const | ||
485 | LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
486 | LLQuaternion quat_val2(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
487 | ensure( | ||
488 | "2. LLQuaternion::operator==(const LLQuaternion &b) failed", | ||
489 | quat_val1 == quat_val2); | ||
490 | } | ||
491 | |||
492 | template<> template<> | ||
493 | void llquat_test_object_t::test<16>() | ||
494 | { | ||
495 | //test case for inline bool LLQuaternion::operator!=(const LLQuaternion &b) const | ||
496 | LLQuaternion quat_val1(2323.634f, -43535.4f, 3455.88f, -32232.45f); | ||
497 | LLQuaternion quat_val2(0, -43535.4f, 3455.88f, -32232.45f); | ||
498 | ensure("LLQuaternion::operator!=(const LLQuaternion &b) failed", quat_val1 != quat_val2); | ||
499 | } | ||
500 | |||
501 | template<> template<> | ||
502 | void llquat_test_object_t::test<17>() | ||
503 | { | ||
504 | //test case for LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) | ||
505 | F32 x = 2.0f; | ||
506 | F32 y = 1.0f; | ||
507 | F32 z = 3.0f; | ||
508 | |||
509 | LLQuaternion result = mayaQ(x, y, z, LLQuaternion::XYZ); | ||
510 | ensure( | ||
511 | "1. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ", | ||
512 | is_approx_equal_fraction(0.0172174f, result.mQ[0], 16) && | ||
513 | is_approx_equal_fraction(0.009179f, result.mQ[1], 16) && | ||
514 | is_approx_equal_fraction(0.026020f, result.mQ[2], 16) && | ||
515 | is_approx_equal_fraction(0.999471f, result.mQ[3], 16)); | ||
516 | |||
517 | LLQuaternion result1 = mayaQ(x, y, z, LLQuaternion::YZX); | ||
518 | ensure( | ||
519 | "2. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ", | ||
520 | is_approx_equal_fraction(0.017217f, result1.mQ[0], 16) && | ||
521 | is_approx_equal_fraction(0.008265f, result1.mQ[1], 16) && | ||
522 | is_approx_equal_fraction(0.026324f, result1.mQ[2], 16) && | ||
523 | is_approx_equal_fraction(0.999471f, result1.mQ[3], 16)); | ||
524 | |||
525 | LLQuaternion result2 = mayaQ(x, y, z, LLQuaternion::ZXY); | ||
526 | ensure( | ||
527 | "3. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZXY", | ||
528 | is_approx_equal_fraction(0.017674f, result2.mQ[0], 16) && | ||
529 | is_approx_equal_fraction(0.008265f, result2.mQ[1], 16) && | ||
530 | is_approx_equal_fraction(0.026020f, result2.mQ[2], 16) && | ||
531 | is_approx_equal_fraction(0.999471f, result2.mQ[3], 16)); | ||
532 | |||
533 | LLQuaternion result3 = mayaQ(x, y, z, LLQuaternion::XZY); | ||
534 | ensure( | ||
535 | "4. TLLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XZY", | ||
536 | is_approx_equal_fraction(0.017674f, result3.mQ[0], 16) && | ||
537 | is_approx_equal_fraction(0.009179f, result3.mQ[1], 16) && | ||
538 | is_approx_equal_fraction(0.026020f, result3.mQ[2], 16) && | ||
539 | is_approx_equal_fraction(0.999463f, result3.mQ[3], 16)); | ||
540 | |||
541 | LLQuaternion result4 = mayaQ(x, y, z, LLQuaternion::YXZ); | ||
542 | ensure( | ||
543 | "5. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for YXZ", | ||
544 | is_approx_equal_fraction(0.017217f, result4.mQ[0], 16) && | ||
545 | is_approx_equal_fraction(0.009179f, result4.mQ[1], 16) && | ||
546 | is_approx_equal_fraction(0.026324f, result4.mQ[2], 16) && | ||
547 | is_approx_equal_fraction(0.999463f, result4.mQ[3], 16)); | ||
548 | |||
549 | LLQuaternion result5 = mayaQ(x, y, z, LLQuaternion::ZYX); | ||
550 | ensure( | ||
551 | "6. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZYX", | ||
552 | is_approx_equal_fraction(0.017674f, result5.mQ[0], 16) && | ||
553 | is_approx_equal_fraction(0.008265f, result5.mQ[1], 16) && | ||
554 | is_approx_equal_fraction(0.026324f, result5.mQ[2], 16) && | ||
555 | is_approx_equal_fraction(0.999463f, result5.mQ[3], 16)); | ||
556 | } | ||
557 | |||
558 | template<> template<> | ||
559 | void llquat_test_object_t::test<18>() | ||
560 | { | ||
561 | // test case for friend std::ostream& operator<<(std::ostream &s, const LLQuaternion &a) fn | ||
562 | LLQuaternion a(1.0f, 1.0f, 1.0f, 1.0f); | ||
563 | std::ostringstream result_value; | ||
564 | result_value << a; | ||
565 | ensure_equals("1. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }"); | ||
566 | |||
567 | LLQuaternion b(-31.034f, 231.2340f, 3451.344320f, -341.0f); | ||
568 | std::ostringstream result_value1; | ||
569 | result_value1 << b; | ||
570 | ensure_equals("2. Operator << failed", result_value1.str(), "{ -31.034, 231.234, 3451.34, -341 }"); | ||
571 | |||
572 | LLQuaternion c(1.0f, 2.2f, 3.3f, 4.4f); | ||
573 | result_value << c; | ||
574 | ensure_equals("3. Operator << failed", result_value.str(), "{ 1, 1, 1, 1 }{ 1, 2.2, 3.3, 4.4 }"); | ||
575 | |||
576 | } | ||
577 | |||
578 | template<> template<> | ||
579 | void llquat_test_object_t::test<19>() | ||
580 | { | ||
581 | //test case for const char *OrderToString( const LLQuaternion::Order order ) fn | ||
582 | const char* result = OrderToString(LLQuaternion::XYZ); | ||
583 | ensure("1. OrderToString failed for XYZ", (0 == strcmp("XYZ", result))); | ||
584 | |||
585 | result = OrderToString(LLQuaternion::YZX); | ||
586 | ensure("2. OrderToString failed for YZX", (0 == strcmp("YZX", result))); | ||
587 | |||
588 | result = OrderToString(LLQuaternion::ZXY); | ||
589 | ensure( | ||
590 | "3. OrderToString failed for ZXY", | ||
591 | (0 == strcmp("ZXY", result)) && | ||
592 | (0 != strcmp("XYZ", result)) && | ||
593 | (0 != strcmp("YXZ", result)) && | ||
594 | (0 != strcmp("ZYX", result)) && | ||
595 | (0 != strcmp("XYZ", result))); | ||
596 | |||
597 | result = OrderToString(LLQuaternion::XZY); | ||
598 | ensure("4. OrderToString failed for XZY", (0 == strcmp("XZY", result))); | ||
599 | |||
600 | result = OrderToString(LLQuaternion::ZYX); | ||
601 | ensure("5. OrderToString failed for ZYX", (0 == strcmp("ZYX", result))); | ||
602 | |||
603 | result = OrderToString(LLQuaternion::YXZ); | ||
604 | ensure("6.OrderToString failed for YXZ", (0 == strcmp("YXZ", result))); | ||
605 | } | ||
606 | |||
607 | template<> template<> | ||
608 | void llquat_test_object_t::test<20>() | ||
609 | { | ||
610 | //test case for LLQuaternion::Order StringToOrder( const char *str ) fn | ||
611 | int result = StringToOrder("XYZ"); | ||
612 | ensure("1. LLQuaternion::Order StringToOrder(const char *str ) failed for XYZ", 0 == result); | ||
613 | |||
614 | result = StringToOrder("YZX"); | ||
615 | ensure("2. LLQuaternion::Order StringToOrder(const char *str) failed for YZX", 1 == result); | ||
616 | |||
617 | result = StringToOrder("ZXY"); | ||
618 | ensure("3. LLQuaternion::Order StringToOrder(const char *str) failed for ZXY", 2 == result); | ||
619 | |||
620 | result = StringToOrder("XZY"); | ||
621 | ensure("4. LLQuaternion::Order StringToOrder(const char *str) failed for XZY", 3 == result); | ||
622 | |||
623 | result = StringToOrder("YXZ"); | ||
624 | ensure("5. LLQuaternion::Order StringToOrder(const char *str) failed for YXZ", 4 == result); | ||
625 | |||
626 | result = StringToOrder("ZYX"); | ||
627 | ensure("6. LLQuaternion::Order StringToOrder(const char *str) failed for ZYX", 5 == result); | ||
628 | |||
629 | } | ||
630 | |||
631 | template<> template<> | ||
632 | void llquat_test_object_t::test<21>() | ||
633 | { | ||
634 | //void LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) const fn | ||
635 | F32 angle_value = 90.0f; | ||
636 | LLVector3 vect(12.0f, 4.0f, 1.0f); | ||
637 | LLQuaternion llquat(angle_value, vect); | ||
638 | llquat.getAngleAxis(&angle_value, vect); | ||
639 | ensure( | ||
640 | "LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) failed", | ||
641 | is_approx_equal_fraction(2.035406f, angle_value, 16) && | ||
642 | is_approx_equal_fraction(0.315244f, vect.mV[1], 16) && | ||
643 | is_approx_equal_fraction(0.078811f, vect.mV[2], 16) && | ||
644 | is_approx_equal_fraction(0.945733f, vect.mV[0], 16)); | ||
645 | } | ||
646 | |||
647 | template<> template<> | ||
648 | void llquat_test_object_t::test<22>() | ||
649 | { | ||
650 | //test case for void LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const fn | ||
651 | F32 roll = -12.0f; | ||
652 | F32 pitch = -22.43f; | ||
653 | F32 yaw = 11.0f; | ||
654 | |||
655 | LLQuaternion llquat; | ||
656 | llquat.getEulerAngles(&roll, &pitch, &yaw); | ||
657 | ensure( | ||
658 | "LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) failed", | ||
659 | is_approx_equal(0.000f, llquat.mQ[0]) && | ||
660 | is_approx_equal(0.000f, llquat.mQ[1]) && | ||
661 | is_approx_equal(0.000f, llquat.mQ[2]) && | ||
662 | is_approx_equal(1.000f, llquat.mQ[3])); | ||
663 | } | ||
664 | |||
665 | } | ||
diff --git a/linden/indra/test/llsaleinfo_tut.cpp b/linden/indra/test/llsaleinfo_tut.cpp new file mode 100644 index 0000000..9dc7f77 --- /dev/null +++ b/linden/indra/test/llsaleinfo_tut.cpp | |||
@@ -0,0 +1,248 @@ | |||
1 | /** | ||
2 | * @file LLSaleInfo_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief Test cases of llsaleinfo.h | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llsaleinfo.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct llsaleinfo_tut | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t; | ||
42 | typedef llsaleinfo_tut_t::object llsaleinfo_test_t; | ||
43 | tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo"); | ||
44 | |||
45 | template<> template<> | ||
46 | void llsaleinfo_test_t::test<1>() | ||
47 | { | ||
48 | //test case for getSaleType(), getSalePrice(), getCRC32() fn. | ||
49 | //test case for setSaleType(), setSalePrice() fn. | ||
50 | |||
51 | S32 sale_price = 10000; | ||
52 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
53 | char* sale= "copy"; | ||
54 | |||
55 | LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
56 | LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
57 | |||
58 | ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType()); | ||
59 | ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
60 | ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice()); | ||
61 | ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32()); | ||
62 | ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale)); | ||
63 | ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
64 | ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
65 | |||
66 | llsaleinfo.setSalePrice(10000000); | ||
67 | llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL); | ||
68 | sale = "cntn"; | ||
69 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
70 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
71 | |||
72 | ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType()); | ||
73 | ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
74 | ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice()); | ||
75 | ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32()); | ||
76 | ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale)); | ||
77 | ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
78 | ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
79 | |||
80 | llsaleinfo.setSalePrice(55000550); | ||
81 | llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS); | ||
82 | sale = "orig"; | ||
83 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
84 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
85 | |||
86 | ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType()); | ||
87 | ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
88 | ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice()); | ||
89 | ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32()); | ||
90 | ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale)); | ||
91 | ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
92 | ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
93 | |||
94 | llsaleinfo.setSalePrice(-6432); | ||
95 | llsaleinfo.setSaleType(LLSaleInfo::FS_NOT); | ||
96 | sale = "not"; | ||
97 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
98 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
99 | |||
100 | ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType()); | ||
101 | ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale()); | ||
102 | ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice()); | ||
103 | ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32()); | ||
104 | ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale)); | ||
105 | ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
106 | ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
107 | } | ||
108 | |||
109 | template<> template<> | ||
110 | void llsaleinfo_test_t::test<2>() | ||
111 | { | ||
112 | |||
113 | FILE* fp = fopen("linden_file.dat","w+"); | ||
114 | if(!fp) | ||
115 | { | ||
116 | llerrs << "file could not be opened\n" << llendl; | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | S32 sale_price = 43500; | ||
121 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
122 | |||
123 | llsaleinfo.exportFile(fp); | ||
124 | fclose(fp); | ||
125 | |||
126 | LLSaleInfo llsaleinfo1; | ||
127 | U32 perm_mask; | ||
128 | BOOL has_perm_mask; | ||
129 | fp = fopen("linden_file.dat","r"); | ||
130 | |||
131 | if(!fp) | ||
132 | { | ||
133 | llerrs << "file coudnt be opened\n" << llendl; | ||
134 | return; | ||
135 | } | ||
136 | |||
137 | llsaleinfo1.importFile(fp, has_perm_mask, perm_mask); | ||
138 | fclose(fp); | ||
139 | |||
140 | ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() && | ||
141 | llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice()); | ||
142 | } | ||
143 | |||
144 | template<> template<> | ||
145 | void llsaleinfo_test_t::test<3>() | ||
146 | { | ||
147 | S32 sale_price = 525452; | ||
148 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
149 | |||
150 | std::ostringstream ostream; | ||
151 | llsaleinfo.exportLegacyStream(ostream); | ||
152 | |||
153 | std::istringstream istream(ostream.str()); | ||
154 | LLSaleInfo llsaleinfo1; | ||
155 | U32 perm_mask = 0; | ||
156 | BOOL has_perm_mask = FALSE; | ||
157 | llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask); | ||
158 | |||
159 | ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() && | ||
160 | llsaleinfo.getSaleType() == llsaleinfo1.getSaleType()); | ||
161 | } | ||
162 | |||
163 | template<> template<> | ||
164 | void llsaleinfo_test_t::test<4>() | ||
165 | { | ||
166 | // LLXMLNode is teh suck. | ||
167 | #if 0 | ||
168 | S32 sale_price = 23445; | ||
169 | LLSaleInfo saleinfo(LLSaleInfo::FS_CONTENTS, sale_price); | ||
170 | |||
171 | LLXMLNode* x_node = saleinfo.exportFileXML(); | ||
172 | |||
173 | LLSaleInfo saleinfo1(LLSaleInfo::FS_NOT, 0); | ||
174 | |||
175 | saleinfo1.importXML(x_node); | ||
176 | ensure_equals("1.importXML() fn failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
177 | ensure_equals("2.importXML() fn failed", saleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
178 | #endif | ||
179 | } | ||
180 | |||
181 | template<> template<> | ||
182 | void llsaleinfo_test_t::test<5>() | ||
183 | { | ||
184 | S32 sale_price = 99000; | ||
185 | LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
186 | |||
187 | LLSD sd_result = saleinfo.asLLSD(); | ||
188 | |||
189 | U32 perm_mask = 0 ; | ||
190 | BOOL has_perm_mask = FALSE; | ||
191 | |||
192 | LLSaleInfo saleinfo1; | ||
193 | saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask); | ||
194 | |||
195 | ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
196 | ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
197 | } | ||
198 | |||
199 | //static EForSale lookup(const char* name) fn test | ||
200 | template<> template<> | ||
201 | void llsaleinfo_test_t::test<6>() | ||
202 | { | ||
203 | S32 sale_price = 233223; | ||
204 | LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig"); | ||
205 | |||
206 | ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL); | ||
207 | |||
208 | LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
209 | const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY); | ||
210 | ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result)); | ||
211 | } | ||
212 | |||
213 | //void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test | ||
214 | template<> template<> | ||
215 | void llsaleinfo_test_t::test<7>() | ||
216 | { | ||
217 | S32 sale_price = 20; | ||
218 | LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
219 | LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price); | ||
220 | saleinfo1.accumulate(saleinfo); | ||
221 | ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40); | ||
222 | |||
223 | } | ||
224 | |||
225 | // test cases of bool operator==(const LLSaleInfo &rhs) fn | ||
226 | // test case of bool operator!=(const LLSaleInfo &rhs) fn | ||
227 | template<> template<> | ||
228 | void llsaleinfo_test_t::test<8>() | ||
229 | { | ||
230 | S32 sale_price = 55000; | ||
231 | LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
232 | LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
233 | LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2); | ||
234 | |||
235 | ensure("operator == fn. failed", true == (saleinfo == saleinfoequal)); | ||
236 | ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal)); | ||
237 | } | ||
238 | |||
239 | template<> template<> | ||
240 | void llsaleinfo_test_t::test<9>() | ||
241 | { | ||
242 | |||
243 | //TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const | ||
244 | //TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block) | ||
245 | //TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num) | ||
246 | } | ||
247 | |||
248 | } | ||
diff --git a/linden/indra/test/llsdmessagebuilder_tut.cpp b/linden/indra/test/llsdmessagebuilder_tut.cpp index d48584a..95a49dd 100755 --- a/linden/indra/test/llsdmessagebuilder_tut.cpp +++ b/linden/indra/test/llsdmessagebuilder_tut.cpp | |||
@@ -134,7 +134,7 @@ namespace tut | |||
134 | void LLSDMessageBuilderTestObject::test<7>() | 134 | void LLSDMessageBuilderTestObject::test<7>() |
135 | // F32 | 135 | // F32 |
136 | { | 136 | { |
137 | F32 outValue, inValue = 121.44; | 137 | F32 outValue, inValue = 121.44f; |
138 | LLSDMessageBuilder builder = defaultBuilder(); | 138 | LLSDMessageBuilder builder = defaultBuilder(); |
139 | builder.addF32("var", inValue); | 139 | builder.addF32("var", inValue); |
140 | LLSDMessageReader reader = setReader(builder); | 140 | LLSDMessageReader reader = setReader(builder); |
diff --git a/linden/indra/test/llsdmessagereader_tut.cpp b/linden/indra/test/llsdmessagereader_tut.cpp index 707cf31..5b644d0 100755 --- a/linden/indra/test/llsdmessagereader_tut.cpp +++ b/linden/indra/test/llsdmessagereader_tut.cpp | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <tut/tut.h> | 30 | #include <tut/tut.h> |
31 | #include "lltut.h" | 31 | #include "lltut.h" |
32 | 32 | ||
33 | #include "message.h" | ||
33 | #include "llsdmessagereader.h" | 34 | #include "llsdmessagereader.h" |
34 | #include "llsdutil.h" | 35 | #include "llsdutil.h" |
35 | 36 | ||
@@ -41,7 +42,7 @@ namespace tut | |||
41 | const std::string& expected_name) | 42 | const std::string& expected_name) |
42 | { | 43 | { |
43 | LLSDMessageReader msg; | 44 | LLSDMessageReader msg; |
44 | msg.setMessage(msg_name, msg_data); | 45 | msg.setMessage(gMessageStringTable.getString(msg_name.c_str()), msg_data); |
45 | ensure_equals("Ensure name", std::string(msg.getMessageName()), | 46 | ensure_equals("Ensure name", std::string(msg.getMessageName()), |
46 | expected_name); | 47 | expected_name); |
47 | } | 48 | } |
@@ -189,7 +190,7 @@ namespace tut | |||
189 | void LLSDMessageReaderTestObject::test<9>() | 190 | void LLSDMessageReaderTestObject::test<9>() |
190 | // F32 | 191 | // F32 |
191 | { | 192 | { |
192 | F32 outValue, inValue = 121.44; | 193 | F32 outValue, inValue = 121.44f; |
193 | LLSDMessageReader msg = testType(inValue); | 194 | LLSDMessageReader msg = testType(inValue); |
194 | msg.getF32("block", "var", outValue); | 195 | msg.getF32("block", "var", outValue); |
195 | ensure_equals("Ensure F32", outValue, inValue); | 196 | ensure_equals("Ensure F32", outValue, inValue); |
@@ -317,4 +318,3 @@ namespace tut | |||
317 | ensure_equals("Ensure Binary", outValue, inValue); | 318 | ensure_equals("Ensure Binary", outValue, inValue); |
318 | } | 319 | } |
319 | } | 320 | } |
320 | |||
diff --git a/linden/indra/test/llsdtraits.h b/linden/indra/test/llsdtraits.h index 2e6a96a..84fc1fe 100644 --- a/linden/indra/test/llsdtraits.h +++ b/linden/indra/test/llsdtraits.h | |||
@@ -1,3 +1,31 @@ | |||
1 | /** | ||
2 | * @file llsdtraits.h | ||
3 | * @brief Unit test helpers | ||
4 | * | ||
5 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * Second Life Viewer Source Code | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
1 | #ifndef LLSDTRAITS_H | 29 | #ifndef LLSDTRAITS_H |
2 | #define LLSDTRAITS_H | 30 | #define LLSDTRAITS_H |
3 | 31 | ||
diff --git a/linden/indra/test/llsdutil_tut.cpp b/linden/indra/test/llsdutil_tut.cpp new file mode 100644 index 0000000..bb5d7fd --- /dev/null +++ b/linden/indra/test/llsdutil_tut.cpp | |||
@@ -0,0 +1,152 @@ | |||
1 | /** | ||
2 | * @file llsdutil_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief LLSD conversion routines test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include "linden_common.h" | ||
32 | #include "lltut.h" | ||
33 | #include "v3color.h" | ||
34 | #include "v4math.h" | ||
35 | #include "m4math.h" | ||
36 | #include "llsdutil.h" | ||
37 | |||
38 | |||
39 | namespace tut | ||
40 | { | ||
41 | struct llsdutil_data | ||
42 | { | ||
43 | }; | ||
44 | typedef test_group<llsdutil_data> llsdutil_test;; | ||
45 | typedef llsdutil_test::object llsdutil_object; | ||
46 | tut::llsdutil_test tutil("llsdutil"); | ||
47 | |||
48 | template<> template<> | ||
49 | void llsdutil_object::test<1>() | ||
50 | { | ||
51 | LLSD sd; | ||
52 | U64 valueIn , valueOut; | ||
53 | valueIn = U64L(0xFEDCBA9876543210); | ||
54 | sd = ll_sd_from_U64(valueIn); | ||
55 | valueOut = ll_U64_from_sd(sd); | ||
56 | ensure_equals("U64 valueIn->sd->valueOut", valueIn, valueOut); | ||
57 | } | ||
58 | |||
59 | template<> template<> | ||
60 | void llsdutil_object::test<2>() | ||
61 | { | ||
62 | LLSD sd; | ||
63 | U32 valueIn, valueOut; | ||
64 | valueIn = 0x87654321; | ||
65 | sd = ll_sd_from_U32(valueIn); | ||
66 | valueOut = ll_U32_from_sd(sd); | ||
67 | ensure_equals("U32 valueIn->sd->valueOut", valueIn, valueOut); | ||
68 | } | ||
69 | |||
70 | template<> template<> | ||
71 | void llsdutil_object::test<3>() | ||
72 | { | ||
73 | U32 valueIn, valueOut; | ||
74 | valueIn = 0x87654321; | ||
75 | LLSD sd; | ||
76 | sd = ll_sd_from_ipaddr(valueIn); | ||
77 | valueOut = ll_ipaddr_from_sd(sd); | ||
78 | ensure_equals("valueIn->sd->valueOut", valueIn, valueOut); | ||
79 | } | ||
80 | |||
81 | template<> template<> | ||
82 | void llsdutil_object::test<4>() | ||
83 | { | ||
84 | LLSD sd; | ||
85 | LLVector3 vec1(-1.0, 2.0, -3.0); | ||
86 | sd = ll_sd_from_vector3(vec1); | ||
87 | LLVector3 vec2 = ll_vector3_from_sd(sd); | ||
88 | ensure_equals("vector3 -> sd -> vector3: 1", vec1, vec2); | ||
89 | |||
90 | LLVector3 vec3(sd); | ||
91 | ensure_equals("vector3 -> sd -> vector3: 2", vec1, vec3); | ||
92 | |||
93 | sd.clear(); | ||
94 | vec1.setVec(0., 0., 0.); | ||
95 | sd = ll_sd_from_vector3(vec1); | ||
96 | vec2 = ll_vector3_from_sd(sd); | ||
97 | ensure_equals("vector3 -> sd -> vector3: 3", vec1, vec2); | ||
98 | sd.clear(); | ||
99 | } | ||
100 | |||
101 | template<> template<> | ||
102 | void llsdutil_object::test<5>() | ||
103 | { | ||
104 | LLSD sd; | ||
105 | LLVector3d vec1((F64)(U64L(0xFEDCBA9876543210) << 2), -1., 0); | ||
106 | sd = ll_sd_from_vector3d(vec1); | ||
107 | LLVector3d vec2 = ll_vector3d_from_sd(sd); | ||
108 | ensure_equals("vector3d -> sd -> vector3d: 1", vec1, vec2); | ||
109 | |||
110 | LLVector3d vec3(sd); | ||
111 | ensure_equals("vector3d -> sd -> vector3d : 2", vec1, vec3); | ||
112 | } | ||
113 | |||
114 | template<> template<> | ||
115 | void llsdutil_object::test<6>() | ||
116 | { | ||
117 | LLSD sd; | ||
118 | LLVector2 vec((F32) -3., (F32) 4.2); | ||
119 | sd = ll_sd_from_vector2(vec); | ||
120 | LLVector2 vec1 = ll_vector2_from_sd(sd); | ||
121 | ensure_equals("vector2 -> sd -> vector2", vec, vec1); | ||
122 | |||
123 | LLSD sd2 = ll_sd_from_vector2(vec1); | ||
124 | ensure_equals("sd -> vector2 -> sd: 2", sd, sd2); | ||
125 | } | ||
126 | |||
127 | template<> template<> | ||
128 | void llsdutil_object::test<7>() | ||
129 | { | ||
130 | LLSD sd; | ||
131 | LLQuaternion quat((F32) 1., (F32) -0.98, (F32) 2.3, (F32) 0xffff); | ||
132 | sd = ll_sd_from_quaternion(quat); | ||
133 | LLQuaternion quat1 = ll_quaternion_from_sd(sd); | ||
134 | ensure_equals("LLQuaternion -> sd -> LLQuaternion", quat, quat1); | ||
135 | |||
136 | LLSD sd2 = ll_sd_from_quaternion(quat1); | ||
137 | ensure_equals("sd -> LLQuaternion -> sd ", sd, sd2); | ||
138 | } | ||
139 | |||
140 | template<> template<> | ||
141 | void llsdutil_object::test<8>() | ||
142 | { | ||
143 | LLSD sd; | ||
144 | LLColor4 c(1.0f, 2.2f, 4.0f, 7.f); | ||
145 | sd = ll_sd_from_color4(c); | ||
146 | LLColor4 c1 =ll_color4_from_sd(sd); | ||
147 | ensure_equals("LLColor4 -> sd -> LLColor4", c, c1); | ||
148 | |||
149 | LLSD sd1 = ll_sd_from_color4(c1); | ||
150 | ensure_equals("sd -> LLColor4 -> sd", sd, sd1); | ||
151 | } | ||
152 | } | ||
diff --git a/linden/indra/test/llstreamtools_tut.cpp b/linden/indra/test/llstreamtools_tut.cpp new file mode 100644 index 0000000..aea2e4f --- /dev/null +++ b/linden/indra/test/llstreamtools_tut.cpp | |||
@@ -0,0 +1,928 @@ | |||
1 | /** | ||
2 | * @file llstreamtools_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date February 2007 | ||
5 | * @brief llstreamtools test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include <fstream> | ||
33 | #include "llstreamtools.h" | ||
34 | #include "lltut.h" | ||
35 | |||
36 | |||
37 | namespace tut | ||
38 | { | ||
39 | struct streamtools_data | ||
40 | { | ||
41 | }; | ||
42 | typedef test_group<streamtools_data> streamtools_test; | ||
43 | typedef streamtools_test::object streamtools_object; | ||
44 | tut::streamtools_test streamtools_testcase("streamtools"); | ||
45 | |||
46 | //test cases for skip_whitespace() | ||
47 | template<> template<> | ||
48 | void streamtools_object::test<1>() | ||
49 | { | ||
50 | char arr[255]; | ||
51 | std::string str; | ||
52 | std::string expected_result; | ||
53 | std::string actual_result; | ||
54 | std::istringstream is; | ||
55 | |||
56 | is.str(str = ""); | ||
57 | ensure("skip_whitespace: empty string", (false == skip_whitespace(is))); | ||
58 | |||
59 | is.clear(); | ||
60 | is.str(str = " SecondLife is a 3D World"); | ||
61 | skip_whitespace(is); | ||
62 | is.get(arr, 255, '\0'); | ||
63 | expected_result = "SecondLife is a 3D World"; | ||
64 | ensure_equals("skip_whitespace: space", arr, expected_result); | ||
65 | |||
66 | is.clear(); | ||
67 | is.str(str = "\t \tSecondLife is a 3D World"); | ||
68 | skip_whitespace(is); | ||
69 | is.get(arr, 255, '\0'); | ||
70 | expected_result = "SecondLife is a 3D World"; | ||
71 | ensure_equals("skip_whitespace: space and tabs", arr, expected_result); | ||
72 | |||
73 | is.clear(); | ||
74 | is.str(str = "\t \tSecondLife is a 3D World "); | ||
75 | skip_whitespace(is); | ||
76 | is.get(arr, 255, '\0'); | ||
77 | expected_result = "SecondLife is a 3D World "; | ||
78 | ensure_equals("skip_whitespace: space at end", arr, expected_result); | ||
79 | |||
80 | is.clear(); | ||
81 | is.str(str = "\t \r\nSecondLife is a 3D World"); | ||
82 | skip_whitespace(is); | ||
83 | is.get(arr, 255, '\0'); | ||
84 | expected_result = "\r\nSecondLife is a 3D World"; | ||
85 | ensure_equals("skip_whitespace: space at end", arr, expected_result); | ||
86 | } | ||
87 | |||
88 | //testcases for skip_emptyspaces() | ||
89 | template<> template<> | ||
90 | void streamtools_object::test<2>() | ||
91 | { | ||
92 | char arr[255]; | ||
93 | std::string str; | ||
94 | std::string expected_result; | ||
95 | std::string actual_result; | ||
96 | std::istringstream is; | ||
97 | bool ret; | ||
98 | |||
99 | is.clear(); | ||
100 | is.str(str = " \tSecondLife is a 3D World.\n"); | ||
101 | skip_emptyspace(is); | ||
102 | is.get(arr, 255, '\0'); | ||
103 | expected_result = "SecondLife is a 3D World.\n"; | ||
104 | ensure_equals("skip_emptyspace: space and tabs", arr, expected_result); | ||
105 | |||
106 | is.clear(); | ||
107 | is.str(str = " \t\r\n \r SecondLife is a 3D World.\n"); | ||
108 | skip_emptyspace(is); | ||
109 | is.get(arr, 255, '\0'); | ||
110 | expected_result = "SecondLife is a 3D World.\n"; | ||
111 | ensure_equals("skip_emptyspace: space, tabs, carriage return, newline", arr, expected_result); | ||
112 | |||
113 | is.clear(); | ||
114 | is.str(str = ""); | ||
115 | ret = skip_emptyspace(is); | ||
116 | is.get(arr, 255, '\0'); | ||
117 | ensure("skip_emptyspace: empty string", ret == false); | ||
118 | |||
119 | is.clear(); | ||
120 | is.str(str = " \r\n \t "); | ||
121 | ret = skip_emptyspace(is); | ||
122 | is.get(arr, 255, '\0'); | ||
123 | ensure("skip_emptyspace: space newline empty", ret == false); | ||
124 | } | ||
125 | |||
126 | //testcases for skip_comments_and_emptyspace() | ||
127 | template<> template<> | ||
128 | void streamtools_object::test<3>() | ||
129 | { | ||
130 | char arr[255]; | ||
131 | std::string str; | ||
132 | std::string expected_result; | ||
133 | std::string actual_result; | ||
134 | std::istringstream is; | ||
135 | bool ret; | ||
136 | |||
137 | is.clear(); | ||
138 | is.str(str = " \t\r\n \r SecondLife is a 3D World.\n"); | ||
139 | skip_comments_and_emptyspace(is); | ||
140 | is.get(arr, 255, '\0'); | ||
141 | expected_result = "SecondLife is a 3D World.\n"; | ||
142 | ensure_equals("skip_comments_and_emptyspace: space, tabs, carriage return, newline", arr, expected_result); | ||
143 | |||
144 | is.clear(); | ||
145 | is.str(str = "# \r\n SecondLife is a 3D World."); | ||
146 | skip_comments_and_emptyspace(is); | ||
147 | is.get(arr, 255, '\0'); | ||
148 | expected_result = "SecondLife is a 3D World."; | ||
149 | ensure_equals("skip_comments_and_emptyspace: skip comment - 1", arr, expected_result); | ||
150 | |||
151 | is.clear(); | ||
152 | is.str(str = "# \r\n # SecondLife is a 3D World. ##"); | ||
153 | skip_comments_and_emptyspace(is); | ||
154 | is.get(arr, 255, '\0'); | ||
155 | expected_result = ""; | ||
156 | ensure_equals("skip_comments_and_emptyspace: skip comment - 2", arr, expected_result); | ||
157 | |||
158 | is.clear(); | ||
159 | is.str(str = " \r\n SecondLife is a 3D World. ##"); | ||
160 | skip_comments_and_emptyspace(is); | ||
161 | is.get(arr, 255, '\0'); | ||
162 | expected_result = "SecondLife is a 3D World. ##"; | ||
163 | ensure_equals("skip_comments_and_emptyspace: skip comment - 3", arr, expected_result); | ||
164 | |||
165 | is.clear(); | ||
166 | is.str(str = ""); | ||
167 | ret = skip_comments_and_emptyspace(is); | ||
168 | is.get(arr, 255, '\0'); | ||
169 | ensure("skip_comments_and_emptyspace: empty string", ret == false); | ||
170 | |||
171 | is.clear(); | ||
172 | is.str(str = " \r\n \t # SecondLife is a 3D World"); | ||
173 | ret = skip_comments_and_emptyspace(is); | ||
174 | is.get(arr, 255, '\0'); | ||
175 | ensure("skip_comments_and_emptyspace: space newline comment empty", ret == false); | ||
176 | } | ||
177 | |||
178 | //testcases for skip_line() | ||
179 | template<> template<> | ||
180 | void streamtools_object::test<4>() | ||
181 | { | ||
182 | char arr[255]; | ||
183 | std::string str; | ||
184 | std::string expected_result; | ||
185 | std::string actual_result; | ||
186 | std::istringstream is; | ||
187 | bool ret; | ||
188 | |||
189 | is.clear(); | ||
190 | is.str(str = "SecondLife is a 3D World.\n\n It provides an opportunity to the site \nuser to perform real life activities in virtual world."); | ||
191 | skip_line(is); | ||
192 | is.get(arr, 255, '\0'); | ||
193 | expected_result = "\n It provides an opportunity to the site \nuser to perform real life activities in virtual world."; | ||
194 | ensure_equals("skip_line: 1 newline", arr, expected_result); | ||
195 | |||
196 | is.clear(); | ||
197 | is.str(expected_result); | ||
198 | skip_line(is); | ||
199 | is.get(arr, 255, '\0'); | ||
200 | expected_result = " It provides an opportunity to the site \nuser to perform real life activities in virtual world."; | ||
201 | ensure_equals("skip_line: 2 newline", arr, expected_result); | ||
202 | |||
203 | is.clear(); | ||
204 | is.str(expected_result); | ||
205 | skip_line(is); | ||
206 | is.get(arr, 255, '\0'); | ||
207 | expected_result = "user to perform real life activities in virtual world."; | ||
208 | ensure_equals("skip_line: 3 newline", arr, expected_result); | ||
209 | |||
210 | is.clear(); | ||
211 | is.str(str = ""); | ||
212 | ret = skip_line(is); | ||
213 | ensure("skip_line: empty string", ret == false); | ||
214 | } | ||
215 | |||
216 | |||
217 | // testcases for skip_to_next_word() | ||
218 | template<> template<> | ||
219 | void streamtools_object::test<5>() | ||
220 | { | ||
221 | char arr[255]; | ||
222 | std::string str; | ||
223 | std::string expected_result; | ||
224 | std::string actual_result; | ||
225 | std::istringstream is; | ||
226 | bool ret; | ||
227 | |||
228 | is.clear(); | ||
229 | is.str(str = "SecondLife is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world."); | ||
230 | skip_to_next_word(is); // get past SecondLife | ||
231 | is.get(arr, 255, '\0'); | ||
232 | expected_result = "is a 3D_World.\n\n It-provides an opportunity to the site \nuser to perform real life activities in virtual world."; | ||
233 | ensure_equals("skip_to_next_word: 1", arr, expected_result); | ||
234 | |||
235 | is.clear(); | ||
236 | is.str(expected_result); | ||
237 | skip_to_next_word(is); // get past is | ||
238 | skip_to_next_word(is); // get past a | ||
239 | skip_to_next_word(is); // get past 3D_World.\n\n | ||
240 | is.get(arr, 255, '\0'); | ||
241 | expected_result = "It-provides an opportunity to the site \nuser to perform real life activities in virtual world."; | ||
242 | ensure_equals("skip_to_next_word: get past .\n\n 2", arr, expected_result); | ||
243 | |||
244 | is.clear(); | ||
245 | is.str(expected_result); | ||
246 | skip_to_next_word(is); // get past It- | ||
247 | expected_result = "provides an opportunity to the site \nuser to perform real life activities in virtual world."; | ||
248 | is.get(arr, 255, '\0'); | ||
249 | ensure_equals("skip_to_next_word: get past -", arr, expected_result); | ||
250 | |||
251 | is.clear(); | ||
252 | is.str(str = ""); | ||
253 | ret = skip_to_next_word(is); | ||
254 | ensure("skip_line: empty string", ret == false); | ||
255 | |||
256 | is.clear(); | ||
257 | is.str(str = " \r\n\r\n"); | ||
258 | ret = skip_to_next_word(is); | ||
259 | ensure("skip_line: space new lines", ret == false); | ||
260 | } | ||
261 | |||
262 | |||
263 | //testcases for skip_to_end_of_next_keyword() | ||
264 | template<> template<> | ||
265 | void streamtools_object::test<6>() | ||
266 | { | ||
267 | char arr[255]; | ||
268 | std::string str; | ||
269 | std::string expected_result; | ||
270 | std::string actual_result; | ||
271 | std::istringstream is; | ||
272 | bool ret; | ||
273 | |||
274 | is.clear(); | ||
275 | is.str(str = "FIRSTKEY followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld."); | ||
276 | ret = skip_to_end_of_next_keyword("FIRSTKEY", is); | ||
277 | is.get(arr, 255, '\0'); | ||
278 | expected_result = " followed by second delimiter\nSECONDKEY\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld."; | ||
279 | ensure_equals("skip_to_end_of_next_keyword: 1", arr, expected_result); | ||
280 | |||
281 | is.clear(); | ||
282 | is.str(expected_result); | ||
283 | ret = skip_to_end_of_next_keyword("SECONDKEY", is); | ||
284 | is.get(arr, 255, '\0'); | ||
285 | expected_result = "\t SecondValue followed by third delimiter \nSECONDKEY\nFOURTHKEY FOURTHVALUEis a 3DWorld."; | ||
286 | ensure_equals("skip_to_end_of_next_keyword: 2", arr, expected_result); | ||
287 | |||
288 | is.clear(); | ||
289 | is.str(expected_result); | ||
290 | ret = skip_to_end_of_next_keyword("SECONDKEY", is); | ||
291 | is.get(arr, 255, '\0'); | ||
292 | expected_result = "\nFOURTHKEY FOURTHVALUEis a 3DWorld."; | ||
293 | ensure_equals("skip_to_end_of_next_keyword: 3", arr, expected_result); | ||
294 | |||
295 | is.clear(); | ||
296 | is.str(expected_result); | ||
297 | ret = skip_to_end_of_next_keyword("FOURTHKEY", is); | ||
298 | is.get(arr, 255, '\0'); | ||
299 | expected_result = " FOURTHVALUEis a 3DWorld."; | ||
300 | ensure_equals("skip_to_end_of_next_keyword: 4", arr, expected_result); | ||
301 | |||
302 | is.clear(); | ||
303 | is.str(str = "{should be skipped as newline/space/tab does not follow but this one should be picked\n { Does it?\n"); | ||
304 | ret = skip_to_end_of_next_keyword("{", is); | ||
305 | is.get(arr, 255, '\0'); | ||
306 | expected_result = " Does it?\n"; | ||
307 | ensure_equals("skip_to_end_of_next_keyword: multiple delim matches on same line", arr, expected_result); | ||
308 | |||
309 | is.clear(); | ||
310 | is.str(str = "Delim { could not be found at start"); | ||
311 | ret = skip_to_end_of_next_keyword("{", is); | ||
312 | ensure("skip_to_end_of_next_keyword: delim should not be present", ret == false); | ||
313 | |||
314 | is.clear(); | ||
315 | is.str(str = "Empty Delim"); | ||
316 | ret = skip_to_end_of_next_keyword("", is); | ||
317 | ensure("skip_to_end_of_next_keyword: empty delim should not be valid", ret == false); | ||
318 | |||
319 | is.clear(); | ||
320 | is.str(str = ""); | ||
321 | ret = skip_to_end_of_next_keyword("}", is); | ||
322 | ensure("skip_to_end_of_next_keyword: empty string", ret == false); | ||
323 | } | ||
324 | |||
325 | //testcases for get_word(std::string& output_string, std::istream& input_stream) | ||
326 | template<> template<> | ||
327 | void streamtools_object::test<7>() | ||
328 | { | ||
329 | std::string str; | ||
330 | std::string expected_result; | ||
331 | std::string actual_result; | ||
332 | std::istringstream is; | ||
333 | bool ret; | ||
334 | |||
335 | is.clear(); | ||
336 | is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n"); | ||
337 | actual_result = ""; | ||
338 | ret = get_word(actual_result, is); | ||
339 | expected_result = "First"; | ||
340 | ensure_equals("get_word: 1", actual_result, expected_result); | ||
341 | |||
342 | actual_result = ""; | ||
343 | ret = get_word(actual_result, is); | ||
344 | expected_result = "Second"; | ||
345 | ensure_equals("get_word: 2", actual_result, expected_result); | ||
346 | |||
347 | actual_result = ""; | ||
348 | ret = get_word(actual_result, is); | ||
349 | expected_result = "Third"; | ||
350 | ensure_equals("get_word: 3", actual_result, expected_result); | ||
351 | |||
352 | // the current implementation of get_word seems inconsistent with | ||
353 | // skip_to_next_word. skip_to_next_word treats any character other | ||
354 | // than alhpa-numeric and '_' as a delimter, while get_word() | ||
355 | // treats only isspace() (i.e. space, form-feed('\f'), newline ('\n'), | ||
356 | // carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') | ||
357 | // as delimiters | ||
358 | actual_result = ""; | ||
359 | ret = get_word(actual_result, is); // will copy Fourth-ShouldThisBePartOfFourth | ||
360 | expected_result = "Fourth-ShouldThisBePartOfFourth"; // as per current impl. | ||
361 | ensure_equals("get_word: 4", actual_result, expected_result); | ||
362 | |||
363 | actual_result = ""; | ||
364 | ret = get_word(actual_result, is); // will copy Fifth | ||
365 | expected_result = "Fifth"; // as per current impl. | ||
366 | ensure_equals("get_word: 5", actual_result, expected_result); | ||
367 | |||
368 | is.clear(); | ||
369 | is.str(str = " \t \r \n "); | ||
370 | actual_result = ""; | ||
371 | ret = get_word(actual_result, is); | ||
372 | ensure("get_word: empty all spaces, newline tabs", ret == false); | ||
373 | |||
374 | is.clear(); | ||
375 | is.str(str = ""); | ||
376 | actual_result = ""; | ||
377 | ret = get_word(actual_result, is); | ||
378 | ensure("get_word: empty string", ret == false); | ||
379 | } | ||
380 | |||
381 | // testcase for get_word and skip_to_next_word compatibility | ||
382 | template<> template<> | ||
383 | void streamtools_object::test<8>() | ||
384 | { | ||
385 | std::string str; | ||
386 | std::string expected_result; | ||
387 | std::string actual_result; | ||
388 | std::istringstream is; | ||
389 | bool ret; | ||
390 | |||
391 | is.clear(); | ||
392 | is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n"); | ||
393 | actual_result = ""; | ||
394 | ret = get_word(actual_result, is); // First | ||
395 | actual_result = ""; | ||
396 | ret = get_word(actual_result, is); // Second | ||
397 | actual_result = ""; | ||
398 | ret = get_word(actual_result, is); // Third | ||
399 | |||
400 | // the current implementation of get_word seems inconsistent with | ||
401 | // skip_to_next_word. skip_to_next_word treats any character other | ||
402 | // than alhpa-numeric and '_' as a delimter, while get_word() | ||
403 | // treats only isspace() (i.e. space, form-feed('\f'), newline ('\n'), | ||
404 | // carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v') | ||
405 | // as delimiters | ||
406 | actual_result = ""; | ||
407 | ret = get_word(actual_result, is); // will copy Fourth-ShouldThisBePartOfFourth | ||
408 | |||
409 | actual_result = ""; | ||
410 | ret = get_word(actual_result, is); // will copy Fifth | ||
411 | |||
412 | is.clear(); | ||
413 | is.str(str = " First Second \t \r \n Third Fourth_ShouldThisBePartOfFourth Fifth\n"); | ||
414 | ret = skip_to_next_word(is); // should now point to First | ||
415 | ret = skip_to_next_word(is); // should now point to Second | ||
416 | ret = skip_to_next_word(is); // should now point to Third | ||
417 | ret = skip_to_next_word(is); // should now point to Fourth | ||
418 | ret = skip_to_next_word(is); // should now point to ShouldThisBePartOfFourth | ||
419 | expected_result = ""; | ||
420 | // will copy ShouldThisBePartOfFourth, the fifth word, | ||
421 | // while using get_word above five times result in getting "Fifth" | ||
422 | ret = get_word(expected_result, is); | ||
423 | ensure_equals("get_word: skip_to_next_word compatibility", actual_result, expected_result); | ||
424 | } | ||
425 | |||
426 | //testcases for get_word(std::string& output_string, std::istream& input_stream, int n) | ||
427 | template<> template<> | ||
428 | void streamtools_object::test<9>() | ||
429 | { | ||
430 | std::string str; | ||
431 | std::string expected_result; | ||
432 | std::string actual_result; | ||
433 | std::istringstream is; | ||
434 | bool ret; | ||
435 | |||
436 | is.clear(); | ||
437 | is.str(str = " First Second \t \r \n Third Fourth-ShouldThisBePartOfFourth Fifth\n"); | ||
438 | actual_result = ""; | ||
439 | ret = get_word(actual_result, is, 255); | ||
440 | expected_result = "First"; | ||
441 | ensure_equals("get_word: 1", actual_result, expected_result); | ||
442 | |||
443 | actual_result = ""; | ||
444 | ret = get_word(actual_result, is, 4); | ||
445 | expected_result = "Seco"; // should be cut short | ||
446 | ensure_equals("get_word: 2", actual_result, expected_result); | ||
447 | |||
448 | actual_result = ""; | ||
449 | ret = get_word(actual_result, is, 255); | ||
450 | expected_result = "nd"; // get remainder of Second | ||
451 | ensure_equals("get_word: 3", actual_result, expected_result); | ||
452 | |||
453 | actual_result = ""; | ||
454 | ret = get_word(actual_result, is, 0); // 0 size string | ||
455 | expected_result = ""; // get remainder of Second | ||
456 | ensure_equals("get_word: 0 sized output", actual_result, expected_result); | ||
457 | |||
458 | actual_result = ""; | ||
459 | ret = get_word(actual_result, is, 255); | ||
460 | expected_result = "Third"; | ||
461 | ensure_equals("get_word: 4", actual_result, expected_result); | ||
462 | |||
463 | is.clear(); | ||
464 | is.str(str = " \t \r \n "); | ||
465 | actual_result = ""; | ||
466 | ret = get_word(actual_result, is, 255); | ||
467 | ensure("get_word: empty all spaces, newline tabs", ret == false); | ||
468 | |||
469 | is.clear(); | ||
470 | is.str(str = ""); | ||
471 | actual_result = ""; | ||
472 | ret = get_word(actual_result, is, 255); | ||
473 | ensure("get_word: empty string", ret == false); | ||
474 | } | ||
475 | |||
476 | //test cases for get_line(std::string& output_string, std::istream& input_stream) | ||
477 | template<> template<> | ||
478 | void streamtools_object::test<10>() | ||
479 | { | ||
480 | std::string str; | ||
481 | std::string expected_result; | ||
482 | std::string actual_result; | ||
483 | std::istringstream is; | ||
484 | bool ret; | ||
485 | |||
486 | is.clear(); | ||
487 | is.str(str = "First Second \t \r\n Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n"); | ||
488 | actual_result = ""; | ||
489 | ret = get_line(actual_result, is); | ||
490 | expected_result = "First Second \t \n"; | ||
491 | ensure_equals("get_line: 1", actual_result, expected_result); | ||
492 | |||
493 | actual_result = ""; | ||
494 | ret = get_line(actual_result, is); | ||
495 | expected_result = " Third Fourth-ShouldThisBePartOfFourth IsThisFifth\n"; | ||
496 | ensure_equals("get_line: 2", actual_result, expected_result); | ||
497 | |||
498 | is.clear(); | ||
499 | is.str(str = "\nFirst Line.\n\nSecond Line.\n"); | ||
500 | actual_result = ""; | ||
501 | ret = get_line(actual_result, is); | ||
502 | expected_result = "\n"; | ||
503 | ensure_equals("get_line: First char as newline", actual_result, expected_result); | ||
504 | |||
505 | actual_result = ""; | ||
506 | ret = get_line(actual_result, is); | ||
507 | expected_result = "First Line.\n"; | ||
508 | ensure_equals("get_line: 3", actual_result, expected_result); | ||
509 | |||
510 | actual_result = ""; | ||
511 | ret = get_line(actual_result, is); | ||
512 | expected_result = "\n"; | ||
513 | ensure_equals("get_line: 4", actual_result, expected_result); | ||
514 | |||
515 | actual_result = ""; | ||
516 | ret = get_line(actual_result, is); | ||
517 | expected_result = "Second Line.\n"; | ||
518 | ensure_equals("get_line: 5", actual_result, expected_result); | ||
519 | } | ||
520 | |||
521 | //test cases for get_line(std::string& output_string, std::istream& input_stream) | ||
522 | template<> template<> | ||
523 | void streamtools_object::test<11>() | ||
524 | { | ||
525 | std::string str; | ||
526 | std::string expected_result; | ||
527 | std::string actual_result; | ||
528 | std::istringstream is; | ||
529 | bool ret; | ||
530 | |||
531 | is.clear(); | ||
532 | is.str(str = "One Line only with no newline"); | ||
533 | actual_result = ""; | ||
534 | ret = get_line(actual_result, is); | ||
535 | expected_result = "One Line only with no newline"; | ||
536 | ensure_equals("get_line: No newline", actual_result, expected_result); | ||
537 | ensure_equals("return value is good state of stream", ret, is.good()); | ||
538 | } | ||
539 | |||
540 | //test cases for get_line(std::string& output_string, std::istream& input_stream) | ||
541 | template<> template<> | ||
542 | void streamtools_object::test<12>() | ||
543 | { | ||
544 | skip_fail("get_line() incorrectly handles lone carriage return."); | ||
545 | std::string str; | ||
546 | std::string expected_result; | ||
547 | std::string actual_result; | ||
548 | std::istringstream is; | ||
549 | bool ret; | ||
550 | |||
551 | // need to be check if this test case is wrong or the implementation is wrong. | ||
552 | is.clear(); | ||
553 | is.str(str = "Should not skip \r unless they are followed with newline .\r\n"); | ||
554 | actual_result = ""; | ||
555 | ret = get_line(actual_result, is); | ||
556 | expected_result = "Should not skip \r unless they are followed with newline .\n"; | ||
557 | ensure_equals("get_line: carriage return skipped even though not followed by newline", actual_result, expected_result); | ||
558 | } | ||
559 | |||
560 | //test cases for get_line(std::string& output_string, std::istream& input_stream) | ||
561 | template<> template<> | ||
562 | void streamtools_object::test<13>() | ||
563 | { | ||
564 | std::string str; | ||
565 | std::string expected_result; | ||
566 | std::string actual_result; | ||
567 | std::istringstream is; | ||
568 | bool ret; | ||
569 | |||
570 | is.clear(); | ||
571 | is.str(str = "\n"); | ||
572 | actual_result = ""; | ||
573 | ret = get_line(actual_result, is); | ||
574 | expected_result = "\n"; | ||
575 | ensure_equals("get_line: Just newline", actual_result, expected_result); | ||
576 | } | ||
577 | |||
578 | |||
579 | //testcases for get_line(std::string& output_string, std::istream& input_stream, int n) | ||
580 | template<> template<> | ||
581 | void streamtools_object::test<14>() | ||
582 | { | ||
583 | std::string str; | ||
584 | std::string expected_result; | ||
585 | std::string actual_result; | ||
586 | std::istringstream is; | ||
587 | bool ret; | ||
588 | |||
589 | is.clear(); | ||
590 | is.str(str = "First Line.\nSecond Line.\n"); | ||
591 | actual_result = ""; | ||
592 | ret = get_line(actual_result, is, 255); | ||
593 | expected_result = "First Line.\n"; | ||
594 | ensure_equals("get_line: Basic Operation", actual_result, expected_result); | ||
595 | |||
596 | actual_result = ""; | ||
597 | ret = get_line(actual_result, is, sizeof("Second")-1); | ||
598 | expected_result = "Second\n"; | ||
599 | ensure_equals("get_line: Insufficient length 1", actual_result, expected_result); | ||
600 | |||
601 | actual_result = ""; | ||
602 | ret = get_line(actual_result, is, 255); | ||
603 | expected_result = " Line.\n"; | ||
604 | ensure_equals("get_line: Remainder after earlier insufficient length", actual_result, expected_result); | ||
605 | |||
606 | is.clear(); | ||
607 | is.str(str = "One Line only with no newline with limited length"); | ||
608 | actual_result = ""; | ||
609 | ret = get_line(actual_result, is, sizeof("One Line only with no newline with limited length")-1); | ||
610 | expected_result = "One Line only with no newline with limited length\n"; | ||
611 | ensure_equals("get_line: No newline with limited length", actual_result, expected_result); | ||
612 | |||
613 | is.clear(); | ||
614 | is.str(str = "One Line only with no newline"); | ||
615 | actual_result = ""; | ||
616 | ret = get_line(actual_result, is, 255); | ||
617 | expected_result = "One Line only with no newline"; | ||
618 | ensure_equals("get_line: No newline", actual_result, expected_result); | ||
619 | } | ||
620 | |||
621 | //testcases for get_line(std::string& output_string, std::istream& input_stream, int n) | ||
622 | template<> template<> | ||
623 | void streamtools_object::test<15>() | ||
624 | { | ||
625 | std::string str; | ||
626 | std::string expected_result; | ||
627 | std::string actual_result; | ||
628 | std::istringstream is; | ||
629 | bool ret; | ||
630 | |||
631 | is.clear(); | ||
632 | is.str(str = "One Line only with no newline"); | ||
633 | actual_result = ""; | ||
634 | ret = get_line(actual_result, is, 255); | ||
635 | expected_result = "One Line only with no newline"; | ||
636 | ensure_equals("get_line: No newline", actual_result, expected_result); | ||
637 | ensure_equals("return value is good state of stream", ret, is.good()); | ||
638 | } | ||
639 | |||
640 | //testcases for remove_last_char() | ||
641 | template<> template<> | ||
642 | void streamtools_object::test<16>() | ||
643 | { | ||
644 | std::string str; | ||
645 | std::string expected_result; | ||
646 | bool ret; | ||
647 | |||
648 | str = "SecondLife is a 3D World"; | ||
649 | |||
650 | ret = remove_last_char('d',str); | ||
651 | expected_result = "SecondLife is a 3D Worl"; | ||
652 | ensure_equals("remove_last_char: should remove last char", str, expected_result); | ||
653 | |||
654 | str = "SecondLife is a 3D World"; | ||
655 | ret = remove_last_char('W',str); | ||
656 | expected_result = "SecondLife is a 3D World"; | ||
657 | ensure_equals("remove_last_char: should not remove as it is not last char", str, expected_result); | ||
658 | ensure("remove_last_char: should return false", ret == false); | ||
659 | |||
660 | str = "SecondLife is a 3D World\n"; | ||
661 | ret = remove_last_char('\n',str); | ||
662 | expected_result = "SecondLife is a 3D World"; | ||
663 | ensure_equals("remove_last_char: should remove last newline", str, expected_result); | ||
664 | ensure("remove_last_char: should remove newline and return true", ret == true); | ||
665 | } | ||
666 | |||
667 | |||
668 | //testcases for unescaped_string() | ||
669 | template<> template<> | ||
670 | void streamtools_object::test<17>() | ||
671 | { | ||
672 | std::string str; | ||
673 | std::string expected_result; | ||
674 | |||
675 | str = "SecondLife is a 3D world \\n"; | ||
676 | unescape_string(str); | ||
677 | expected_result = "SecondLife is a 3D world \n"; | ||
678 | ensure_equals("unescape_string: newline", str, expected_result); | ||
679 | |||
680 | str = "SecondLife is a 3D world \\\\t \\n"; | ||
681 | unescape_string(str); | ||
682 | expected_result = "SecondLife is a 3D world \\t \n"; | ||
683 | ensure_equals("unescape_string: backslash and newline", str, expected_result); | ||
684 | |||
685 | str = "SecondLife is a 3D world \\ "; | ||
686 | unescape_string(str); | ||
687 | expected_result = "SecondLife is a 3D world \\ "; | ||
688 | ensure_equals("unescape_string: insufficient to unescape", str, expected_result); | ||
689 | |||
690 | str = "SecondLife is a 3D world \\n \\n \\n \\\\\\n"; | ||
691 | unescape_string(str); | ||
692 | expected_result = "SecondLife is a 3D world \n \n \n \\\n"; | ||
693 | ensure_equals("unescape_string: multipel newline and backslash", str, expected_result); | ||
694 | |||
695 | str = "SecondLife is a 3D world \\t"; | ||
696 | unescape_string(str); | ||
697 | expected_result = "SecondLife is a 3D world \\t"; | ||
698 | ensure_equals("unescape_string: leaves tab as is", str, expected_result); | ||
699 | |||
700 | str = "\\n"; | ||
701 | unescape_string(str); | ||
702 | expected_result = "\n"; | ||
703 | ensure_equals("unescape_string: only a newline", str, expected_result); | ||
704 | } | ||
705 | |||
706 | //testcases for escape_string() | ||
707 | template<> template<> | ||
708 | void streamtools_object::test<18>() | ||
709 | { | ||
710 | std::string str; | ||
711 | std::string expected_result; | ||
712 | |||
713 | str = "SecondLife is a 3D world \n"; | ||
714 | escape_string(str); | ||
715 | expected_result = "SecondLife is a 3D world \\n"; | ||
716 | ensure_equals("escape_string: newline", str, expected_result); | ||
717 | |||
718 | str = "SecondLife is a 3D world \\t \n"; | ||
719 | escape_string(str); | ||
720 | expected_result = "SecondLife is a 3D world \\\\t \\n"; | ||
721 | ensure_equals("escape_string: backslash and newline", str, expected_result); | ||
722 | |||
723 | str = "SecondLife is a 3D world \n \n \n \\\n"; | ||
724 | escape_string(str); | ||
725 | expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\\\n"; | ||
726 | ensure_equals("escape_string: multipel newline and backslash", str, expected_result); | ||
727 | |||
728 | str = "SecondLife is a 3D world \t"; | ||
729 | escape_string(str); | ||
730 | expected_result = "SecondLife is a 3D world \t"; | ||
731 | ensure_equals("unescape_string: leaves tab as is", str, expected_result); | ||
732 | |||
733 | str = "\n"; | ||
734 | escape_string(str); | ||
735 | expected_result = "\\n"; | ||
736 | ensure_equals("unescape_string: only a newline", str, expected_result); | ||
737 | |||
738 | // serialization/deserialization escape->unescape | ||
739 | str = "SecondLife is a 3D world \n \n \n \\\n"; | ||
740 | escape_string(str); | ||
741 | unescape_string(str); | ||
742 | expected_result = "SecondLife is a 3D world \n \n \n \\\n"; | ||
743 | ensure_equals("escape_string: should preserve with escape/unescape", str, expected_result); | ||
744 | |||
745 | // serialization/deserialization unescape->escape | ||
746 | str = "SecondLife is a 3D world \\n \\n \\n \\\\"; | ||
747 | unescape_string(str); | ||
748 | escape_string(str); | ||
749 | expected_result = "SecondLife is a 3D world \\n \\n \\n \\\\"; | ||
750 | ensure_equals("escape_string: should preserve with unescape/escape", str, expected_result); | ||
751 | } | ||
752 | |||
753 | // testcases for replace_newlines_with_whitespace() | ||
754 | template<> template<> | ||
755 | void streamtools_object::test<19>() | ||
756 | { | ||
757 | std::string str; | ||
758 | std::string expected_result; | ||
759 | |||
760 | str = "SecondLife is a 3D \n\nworld\n"; | ||
761 | replace_newlines_with_whitespace(str); | ||
762 | expected_result = "SecondLife is a 3D world "; | ||
763 | ensure_equals("replace_newlines_with_whitespace: replace all newline", str, expected_result); | ||
764 | |||
765 | str = "\nSecondLife is a 3D world\n"; | ||
766 | replace_newlines_with_whitespace(str); | ||
767 | expected_result = " SecondLife is a 3D world "; | ||
768 | ensure_equals("replace_newlines_with_whitespace: begin and newline", str, expected_result); | ||
769 | |||
770 | str = "SecondLife is a 3D world\r\t"; | ||
771 | replace_newlines_with_whitespace(str); | ||
772 | expected_result = "SecondLife is a 3D world\r\t"; | ||
773 | ensure_equals("replace_newlines_with_whitespace: should only replace newline", str, expected_result); | ||
774 | |||
775 | str = ""; | ||
776 | replace_newlines_with_whitespace(str); | ||
777 | expected_result = ""; | ||
778 | ensure_equals("replace_newlines_with_whitespace: empty string", str, expected_result); | ||
779 | } | ||
780 | |||
781 | //testcases for remove_double_quotes() | ||
782 | template<> template<> | ||
783 | void streamtools_object::test<20>() | ||
784 | { | ||
785 | std::string str; | ||
786 | std::string expected_result; | ||
787 | |||
788 | str = "SecondLife is a \"\"3D world"; | ||
789 | remove_double_quotes(str); | ||
790 | expected_result = "SecondLife is a 3D world"; | ||
791 | ensure_equals("remove_double_quotes: replace empty doube quotes", str, expected_result); | ||
792 | |||
793 | str = "SecondLife is a \"3D world"; | ||
794 | remove_double_quotes(str); | ||
795 | expected_result = "SecondLife is a 3D world"; | ||
796 | ensure_equals("remove_double_quotes: keep as is it matching quote not found", str, expected_result); | ||
797 | } | ||
798 | |||
799 | // testcases for get_brace_count() | ||
800 | template<> template<> | ||
801 | void streamtools_object::test<21>() | ||
802 | { | ||
803 | skip_fail("get_brace_count() has bugs."); | ||
804 | |||
805 | std::string str; | ||
806 | std::string expected_result; | ||
807 | int count; | ||
808 | |||
809 | str = " { "; | ||
810 | count = get_brace_count(str); | ||
811 | ensure("get_brace_count: 1 for {", count == 1); | ||
812 | |||
813 | str = "\t}\t\t \n"; | ||
814 | count = get_brace_count(str); | ||
815 | ensure("get_brace_count: 1 for {", count == -1); | ||
816 | |||
817 | str = "\t\t\t \n"; | ||
818 | count = get_brace_count(str); | ||
819 | ensure("get_brace_count: 0 for no braces", count == 0); | ||
820 | |||
821 | str = "{ Remaining line not empty\n"; | ||
822 | count = get_brace_count(str); | ||
823 | ensure("get_brace_count: 0 for remainign line not empty", count == 0); | ||
824 | |||
825 | /* shouldn't this return 1? */ | ||
826 | str = "{ /*Remaining line in comment*/\n"; | ||
827 | count = get_brace_count(str); | ||
828 | ensure("get_brace_count: 1 for { with remaining line in comment", count == 1); | ||
829 | |||
830 | /* shouldn't this return -1? */ | ||
831 | str = " } //Remaining line in comment \n"; | ||
832 | count = get_brace_count(str); | ||
833 | ensure("get_brace_count: -1 for } with remaining line in comment", count == -1); | ||
834 | } | ||
835 | |||
836 | //testcases for get_keyword_and_value() | ||
837 | template<> template<> | ||
838 | void streamtools_object::test<22>() | ||
839 | { | ||
840 | std::string s = "SecondLife is a 3D World"; | ||
841 | std::string keyword; | ||
842 | std::string value; | ||
843 | get_keyword_and_value(keyword, value, s); | ||
844 | ensure("get_keyword_and_value: Unable to get Keyword and Value", ((keyword == "SecondLife") && (value == "is a 3D World"))); | ||
845 | |||
846 | s = "SecondLife"; | ||
847 | get_keyword_and_value(keyword, value, s); | ||
848 | ensure("get_keyword_and_value: value should be empty", ((keyword == "SecondLife") && (value == ""))); | ||
849 | |||
850 | s = "SecondLife \t is cool! \n"; | ||
851 | get_keyword_and_value(keyword, value, s); | ||
852 | ensure("get_keyword_and_value: remove space before value but not after", ((keyword == "SecondLife") && (value == "is cool! "))); | ||
853 | } | ||
854 | |||
855 | //testcases for get_keyword_and_value() | ||
856 | template<> template<> | ||
857 | void streamtools_object::test<23>() | ||
858 | { | ||
859 | skip_fail("get_keyword_and_value() has bugs."); | ||
860 | |||
861 | std::string s; | ||
862 | std::string keyword = "SOME PRIOR KEYWORD"; | ||
863 | std::string value = "SOME PRIOR VALUE"; | ||
864 | |||
865 | s = "SecondLife\n"; | ||
866 | get_keyword_and_value(keyword, value, s); | ||
867 | ensure("get_keyword_and_value: terminated with newline. value should be empty", ((keyword == "SecondLife") && (value == ""))); | ||
868 | } | ||
869 | |||
870 | //testcases for get_keyword_and_value() | ||
871 | template<> template<> | ||
872 | void streamtools_object::test<24>() | ||
873 | { | ||
874 | skip_fail("get_keyword_and_value() has bugs."); | ||
875 | |||
876 | std::string s; | ||
877 | std::string keyword = "SOME PRIOR KEYWORD"; | ||
878 | std::string value = "SOME PRIOR VALUE"; | ||
879 | |||
880 | s = ""; | ||
881 | get_keyword_and_value(keyword, value, s); | ||
882 | ensure("get_keyword_and_value: empty string. keyword value should empty", ((keyword == "") && (value == ""))); | ||
883 | } | ||
884 | |||
885 | //testcase for fullread() | ||
886 | template<> template<> | ||
887 | void streamtools_object::test<25>() | ||
888 | { | ||
889 | std::string str = "First Line.\nSecond Line\n"; | ||
890 | std::istringstream is(str); | ||
891 | char buf[255] = {0}; | ||
892 | |||
893 | fullread(is, buf, 255); | ||
894 | ensure_memory_matches("fullread: read with newlines", (void*) buf, str.size()-1, (void*) str.c_str(), str.size()-1); | ||
895 | |||
896 | is.clear(); | ||
897 | is.str(str = "First Line.\nSecond Line\n"); | ||
898 | memset(buf, 0, 255); | ||
899 | |||
900 | char expected_string[] = "First Line.\nSecond"; | ||
901 | int len = sizeof(expected_string)-1; | ||
902 | fullread(is, buf, len); | ||
903 | ensure_memory_matches("fullread: read with newlines", (void*) buf, len, (void*) &expected_string, len); | ||
904 | } | ||
905 | |||
906 | |||
907 | // testcases for operator >> | ||
908 | |||
909 | template<> template<> | ||
910 | void streamtools_object::test<26>() | ||
911 | { | ||
912 | char arr[255]; | ||
913 | std::string str; | ||
914 | std::string toCheck = "SecondLife" ; | ||
915 | std::string expected_result; | ||
916 | std::istringstream stream("SecondLife is a 3D World"); | ||
917 | stream >> toCheck.c_str(); | ||
918 | stream.get(arr, 255, '\0'); | ||
919 | expected_result = " is a 3D World"; | ||
920 | ensure_equals("istream << operator", arr, expected_result); | ||
921 | |||
922 | stream.clear(); | ||
923 | stream.str(str = "SecondLife is a 3D World"); | ||
924 | toCheck = "is"; | ||
925 | stream >> toCheck.c_str(); | ||
926 | ensure("istream << operator should have failed", stream.good() == false); | ||
927 | } | ||
928 | } | ||
diff --git a/linden/indra/test/llstring_tut.cpp b/linden/indra/test/llstring_tut.cpp index 040955b..f49fb1c 100644 --- a/linden/indra/test/llstring_tut.cpp +++ b/linden/indra/test/llstring_tut.cpp | |||
@@ -6,6 +6,7 @@ | |||
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
diff --git a/linden/indra/test/lltemplatemessagebuilder_tut.cpp b/linden/indra/test/lltemplatemessagebuilder_tut.cpp new file mode 100644 index 0000000..d25e57e --- /dev/null +++ b/linden/indra/test/lltemplatemessagebuilder_tut.cpp | |||
@@ -0,0 +1,964 @@ | |||
1 | /** | ||
2 | * @file lltemplatemessagebuilder_tut.cpp | ||
3 | * @date 2007-04 | ||
4 | * @brief Tests for building messages. | ||
5 | * | ||
6 | * Copyright (c) 2007-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 | |||
33 | #include "llapr.h" | ||
34 | #include "llmessagetemplate.h" | ||
35 | #include "llquaternion.h" | ||
36 | #include "lltemplatemessagebuilder.h" | ||
37 | #include "lltemplatemessagereader.h" | ||
38 | #include "llversion.h" | ||
39 | #include "message_prehash.h" | ||
40 | #include "u64.h" | ||
41 | #include "v3dmath.h" | ||
42 | #include "v3math.h" | ||
43 | #include "v4math.h" | ||
44 | |||
45 | namespace tut | ||
46 | { | ||
47 | static LLTemplateMessageBuilder::message_template_name_map_t nameMap; | ||
48 | static LLTemplateMessageReader::message_template_number_map_t numberMap; | ||
49 | |||
50 | struct LLTemplateMessageBuilderTestData | ||
51 | { | ||
52 | static LLMessageTemplate defaultTemplate() | ||
53 | { | ||
54 | static bool init = false; | ||
55 | if(! init) | ||
56 | { | ||
57 | ll_init_apr(); | ||
58 | start_messaging_system("notafile", 13035, | ||
59 | LL_VERSION_MAJOR, | ||
60 | LL_VERSION_MINOR, | ||
61 | LL_VERSION_PATCH, | ||
62 | FALSE, | ||
63 | "notasharedsecret"); | ||
64 | init_prehash_data(); | ||
65 | init = true; | ||
66 | } | ||
67 | return LLMessageTemplate(_PREHASH_TestMessage, 1, MFT_HIGH); | ||
68 | } | ||
69 | |||
70 | static LLMessageBlock* defaultBlock(const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) | ||
71 | { | ||
72 | return createBlock(_PREHASH_Test0, type, size, block); | ||
73 | } | ||
74 | |||
75 | static LLMessageBlock* createBlock(char* name, const EMsgVariableType type = MVT_NULL, const S32 size = 0, EMsgBlockType block = MBT_VARIABLE) | ||
76 | { | ||
77 | LLMessageBlock* result = new LLMessageBlock(name, block); | ||
78 | if(type != MVT_NULL) | ||
79 | { | ||
80 | result->addVariable(_PREHASH_Test0, type, size); | ||
81 | } | ||
82 | return result; | ||
83 | } | ||
84 | |||
85 | static LLTemplateMessageBuilder* defaultBuilder(LLMessageTemplate& messageTemplate, char* name = _PREHASH_Test0) | ||
86 | { | ||
87 | nameMap[_PREHASH_TestMessage] = &messageTemplate; | ||
88 | LLTemplateMessageBuilder* builder = new LLTemplateMessageBuilder(nameMap); | ||
89 | builder->newMessage(_PREHASH_TestMessage); | ||
90 | builder->nextBlock(name); | ||
91 | return builder; | ||
92 | } | ||
93 | |||
94 | /** Takes ownership of builder */ | ||
95 | static LLTemplateMessageReader* setReader( | ||
96 | LLMessageTemplate& messageTemplate, | ||
97 | LLTemplateMessageBuilder* builder, | ||
98 | U8 offset = 0) | ||
99 | { | ||
100 | numberMap[1] = &messageTemplate; | ||
101 | const U32 bufferSize = 1024; | ||
102 | U8 buffer[bufferSize]; | ||
103 | // zero out the packet ID field | ||
104 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
105 | U32 builtSize = builder->buildMessage(buffer, bufferSize, offset); | ||
106 | delete builder; | ||
107 | LLTemplateMessageReader* reader = new LLTemplateMessageReader(numberMap); | ||
108 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
109 | reader->readMessage(buffer, LLHost()); | ||
110 | return reader; | ||
111 | } | ||
112 | |||
113 | }; | ||
114 | |||
115 | typedef test_group<LLTemplateMessageBuilderTestData> LLTemplateMessageBuilderTestGroup; | ||
116 | typedef LLTemplateMessageBuilderTestGroup::object LLTemplateMessageBuilderTestObject; | ||
117 | LLTemplateMessageBuilderTestGroup templateMessageBuilderTestGroup("LLTemplateMessageBuilder"); | ||
118 | |||
119 | template<> template<> | ||
120 | void LLTemplateMessageBuilderTestObject::test<1>() | ||
121 | // construction and test of undefined | ||
122 | { | ||
123 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
124 | messageTemplate.addBlock(defaultBlock()); | ||
125 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
126 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
127 | delete reader; | ||
128 | } | ||
129 | |||
130 | template<> template<> | ||
131 | void LLTemplateMessageBuilderTestObject::test<2>() | ||
132 | // BOOL | ||
133 | { | ||
134 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
135 | messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1)); | ||
136 | BOOL outValue, inValue = TRUE; | ||
137 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
138 | builder->addBOOL(_PREHASH_Test0, inValue); | ||
139 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
140 | reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
141 | ensure_equals("Ensure BOOL", inValue, outValue); | ||
142 | delete reader; | ||
143 | } | ||
144 | |||
145 | template<> template<> | ||
146 | void LLTemplateMessageBuilderTestObject::test<3>() | ||
147 | // U8 | ||
148 | { | ||
149 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
150 | messageTemplate.addBlock(defaultBlock(MVT_U8, 1)); | ||
151 | U8 outValue, inValue = 2; | ||
152 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
153 | builder->addU8(_PREHASH_Test0, inValue); | ||
154 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
155 | reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
156 | ensure_equals("Ensure U8", inValue, outValue); | ||
157 | delete reader; | ||
158 | } | ||
159 | |||
160 | template<> template<> | ||
161 | void LLTemplateMessageBuilderTestObject::test<4>() | ||
162 | // S16 | ||
163 | { | ||
164 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
165 | messageTemplate.addBlock(defaultBlock(MVT_S16, 2)); | ||
166 | S16 outValue, inValue = 90; | ||
167 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
168 | builder->addS16(_PREHASH_Test0, inValue); | ||
169 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
170 | reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
171 | ensure_equals("Ensure S16", inValue, outValue); | ||
172 | delete reader; | ||
173 | } | ||
174 | |||
175 | template<> template<> | ||
176 | void LLTemplateMessageBuilderTestObject::test<5>() | ||
177 | // U16 | ||
178 | { | ||
179 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
180 | messageTemplate.addBlock(defaultBlock(MVT_U16, 2)); | ||
181 | U16 outValue, inValue = 3; | ||
182 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
183 | builder->addU16(_PREHASH_Test0, inValue); | ||
184 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
185 | reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
186 | ensure_equals("Ensure U16", inValue, outValue); | ||
187 | delete reader; | ||
188 | } | ||
189 | |||
190 | template<> template<> | ||
191 | void LLTemplateMessageBuilderTestObject::test<6>() | ||
192 | // S32 | ||
193 | { | ||
194 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
195 | messageTemplate.addBlock(defaultBlock(MVT_S32, 4)); | ||
196 | S32 outValue, inValue = 44; | ||
197 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
198 | builder->addS32(_PREHASH_Test0, inValue); | ||
199 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
200 | reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
201 | ensure_equals("Ensure S32", inValue, outValue); | ||
202 | delete reader; | ||
203 | } | ||
204 | |||
205 | template<> template<> | ||
206 | void LLTemplateMessageBuilderTestObject::test<7>() | ||
207 | // F32 | ||
208 | { | ||
209 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
210 | messageTemplate.addBlock(defaultBlock(MVT_F32, 4)); | ||
211 | F32 outValue, inValue = 121.44f; | ||
212 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
213 | builder->addF32(_PREHASH_Test0, inValue); | ||
214 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
215 | reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
216 | ensure_equals("Ensure F32", inValue, outValue); | ||
217 | delete reader; | ||
218 | } | ||
219 | |||
220 | template<> template<> | ||
221 | void LLTemplateMessageBuilderTestObject::test<8>() | ||
222 | // U32 | ||
223 | { | ||
224 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
225 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4)); | ||
226 | U32 outValue, inValue = 88; | ||
227 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
228 | builder->addU32(_PREHASH_Test0, inValue); | ||
229 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
230 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
231 | ensure_equals("Ensure U32", inValue, outValue); | ||
232 | delete reader; | ||
233 | } | ||
234 | |||
235 | template<> template<> | ||
236 | void LLTemplateMessageBuilderTestObject::test<9>() | ||
237 | // U64 | ||
238 | { | ||
239 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
240 | messageTemplate.addBlock(defaultBlock(MVT_U64, 8)); | ||
241 | U64 outValue, inValue = 121; | ||
242 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
243 | builder->addU64(_PREHASH_Test0, inValue); | ||
244 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
245 | reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
246 | ensure_equals("Ensure U64", inValue, outValue); | ||
247 | delete reader; | ||
248 | } | ||
249 | |||
250 | template<> template<> | ||
251 | void LLTemplateMessageBuilderTestObject::test<10>() | ||
252 | // F64 | ||
253 | { | ||
254 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
255 | messageTemplate.addBlock(defaultBlock(MVT_F64, 8)); | ||
256 | F64 outValue, inValue = 3232143.33; | ||
257 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
258 | builder->addF64(_PREHASH_Test0, inValue); | ||
259 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
260 | reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
261 | ensure_equals("Ensure F64", inValue, outValue); | ||
262 | delete reader; | ||
263 | } | ||
264 | |||
265 | template<> template<> | ||
266 | void LLTemplateMessageBuilderTestObject::test<11>() | ||
267 | // Vector3 | ||
268 | { | ||
269 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
270 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12)); | ||
271 | LLVector3 outValue, inValue = LLVector3(1,2,3); | ||
272 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
273 | builder->addVector3(_PREHASH_Test0, inValue); | ||
274 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
275 | reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
276 | ensure_equals("Ensure LLVector3", inValue, outValue); | ||
277 | delete reader; | ||
278 | } | ||
279 | |||
280 | template<> template<> | ||
281 | void LLTemplateMessageBuilderTestObject::test<12>() | ||
282 | // Vector4 | ||
283 | { | ||
284 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
285 | messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16)); | ||
286 | LLVector4 outValue, inValue = LLVector4(1,2,3,4); | ||
287 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
288 | builder->addVector4(_PREHASH_Test0, inValue); | ||
289 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
290 | reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
291 | ensure_equals("Ensure LLVector4", inValue, outValue); | ||
292 | delete reader; | ||
293 | } | ||
294 | |||
295 | template<> template<> | ||
296 | void LLTemplateMessageBuilderTestObject::test<13>() | ||
297 | // Vector3d | ||
298 | { | ||
299 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
300 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24)); | ||
301 | LLVector3d outValue, inValue = LLVector3d(1,2,3); | ||
302 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
303 | builder->addVector3d(_PREHASH_Test0, inValue); | ||
304 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
305 | reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
306 | ensure_equals("Ensure LLVector3d", inValue, outValue); | ||
307 | delete reader; | ||
308 | } | ||
309 | |||
310 | template<> template<> | ||
311 | void LLTemplateMessageBuilderTestObject::test<14>() | ||
312 | // Quaternion | ||
313 | { | ||
314 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
315 | messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); | ||
316 | LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); | ||
317 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
318 | builder->addQuat(_PREHASH_Test0, inValue); | ||
319 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
320 | reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
321 | ensure_equals("Ensure LLQuaternion", inValue, outValue); | ||
322 | delete reader; | ||
323 | } | ||
324 | |||
325 | template<> template<> | ||
326 | void LLTemplateMessageBuilderTestObject::test<15>() | ||
327 | // UUID | ||
328 | { | ||
329 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
330 | messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16)); | ||
331 | LLUUID outValue, inValue; | ||
332 | inValue.generate(); | ||
333 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
334 | builder->addUUID(_PREHASH_Test0, inValue); | ||
335 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
336 | reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
337 | ensure_equals("Ensure UUID", inValue, outValue); | ||
338 | delete reader; | ||
339 | } | ||
340 | |||
341 | template<> template<> | ||
342 | void LLTemplateMessageBuilderTestObject::test<16>() | ||
343 | // IPAddr | ||
344 | { | ||
345 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
346 | messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4)); | ||
347 | U32 outValue, inValue = 12344556; | ||
348 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
349 | builder->addIPAddr(_PREHASH_Test0, inValue); | ||
350 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
351 | reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
352 | ensure_equals("Ensure IPAddr", inValue, outValue); | ||
353 | delete reader; | ||
354 | } | ||
355 | |||
356 | template<> template<> | ||
357 | void LLTemplateMessageBuilderTestObject::test<17>() | ||
358 | // IPPort | ||
359 | { | ||
360 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
361 | messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2)); | ||
362 | U16 outValue, inValue = 80; | ||
363 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
364 | builder->addIPPort(_PREHASH_Test0, inValue); | ||
365 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
366 | reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
367 | ensure_equals("Ensure IPPort", inValue, outValue); | ||
368 | delete reader; | ||
369 | } | ||
370 | |||
371 | template<> template<> | ||
372 | void LLTemplateMessageBuilderTestObject::test<18>() | ||
373 | // String | ||
374 | { | ||
375 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
376 | messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1)); | ||
377 | std::string outValue, inValue = "testing"; | ||
378 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
379 | builder->addString(_PREHASH_Test0, inValue.c_str()); | ||
380 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
381 | char buffer[MAX_STRING]; | ||
382 | reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer); | ||
383 | outValue = buffer; | ||
384 | ensure_equals("Ensure String", inValue, outValue); | ||
385 | delete reader; | ||
386 | } | ||
387 | |||
388 | template<> template<> | ||
389 | void LLTemplateMessageBuilderTestObject::test<19>() | ||
390 | // block name !-> binary order | ||
391 | { | ||
392 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
393 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
394 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
395 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
396 | U32 bufferSize1, bufferSize2; | ||
397 | |||
398 | // build template: Test0 before Test1 | ||
399 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
400 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
401 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
402 | |||
403 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
404 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
405 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
406 | builder->nextBlock(_PREHASH_Test1); | ||
407 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
408 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
409 | delete builder; | ||
410 | |||
411 | // build template: Test1 before Test0 | ||
412 | messageTemplate = defaultTemplate(); | ||
413 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
414 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
415 | |||
416 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
417 | builder = defaultBuilder(messageTemplate, _PREHASH_Test1); | ||
418 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
419 | builder->nextBlock(_PREHASH_Test0); | ||
420 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
421 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
422 | delete builder; | ||
423 | |||
424 | ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2); | ||
425 | ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
426 | } | ||
427 | |||
428 | template<> template<> | ||
429 | void LLTemplateMessageBuilderTestObject::test<20>() | ||
430 | // block build order !-> binary order | ||
431 | { | ||
432 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
433 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
434 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
435 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
436 | U32 bufferSize1, bufferSize2; | ||
437 | |||
438 | // build template: Test0 before Test1 | ||
439 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
440 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
441 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
442 | |||
443 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
444 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
445 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
446 | builder->nextBlock(_PREHASH_Test1); | ||
447 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
448 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
449 | delete builder; | ||
450 | |||
451 | // build message: 1st declared block var == 0xaaaa, 2nd declared block var == 0xbbbb | ||
452 | builder = defaultBuilder(messageTemplate, _PREHASH_Test1); | ||
453 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
454 | builder->nextBlock(_PREHASH_Test0); | ||
455 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
456 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
457 | delete builder; | ||
458 | |||
459 | ensure_equals("Ensure Buffer Sizes Equal", bufferSize1, bufferSize2); | ||
460 | ensure_equals("Ensure Buffer Contents Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
461 | } | ||
462 | |||
463 | template<> template<> | ||
464 | void LLTemplateMessageBuilderTestObject::test<21>() | ||
465 | // block appended in declaration -> data appended in binary | ||
466 | { | ||
467 | U8 buffer1[MAX_BUFFER_SIZE]; | ||
468 | memset(buffer1, 0, MAX_BUFFER_SIZE); | ||
469 | U8 buffer2[MAX_BUFFER_SIZE]; | ||
470 | memset(buffer2, 0, MAX_BUFFER_SIZE); | ||
471 | U32 bufferSize1, bufferSize2; | ||
472 | |||
473 | // Build template: Test0 only | ||
474 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
475 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
476 | |||
477 | // Build message | ||
478 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
479 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
480 | bufferSize1 = builder->buildMessage(buffer1, MAX_BUFFER_SIZE, 0); | ||
481 | delete builder; | ||
482 | |||
483 | // Build template: Test0 before Test1 | ||
484 | messageTemplate = defaultTemplate(); | ||
485 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
486 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
487 | |||
488 | // Build message | ||
489 | builder = defaultBuilder(messageTemplate, _PREHASH_Test0); | ||
490 | builder->addU32(_PREHASH_Test0, 0xaaaa); | ||
491 | builder->nextBlock(_PREHASH_Test1); | ||
492 | builder->addU32(_PREHASH_Test0, 0xbbbb); | ||
493 | bufferSize2 = builder->buildMessage(buffer2, MAX_BUFFER_SIZE, 0); | ||
494 | delete builder; | ||
495 | |||
496 | ensure_not_equals("Ensure Buffer Sizes Not Equal", bufferSize1, bufferSize2); | ||
497 | ensure_equals("Ensure Buffer Prefix Equal", memcmp(buffer1, buffer2, bufferSize1), 0); | ||
498 | ensure_not_equals("Ensure Buffer Contents Not Equal", memcmp(buffer1, buffer2, bufferSize2), 0); | ||
499 | } | ||
500 | |||
501 | template<> template<> | ||
502 | void LLTemplateMessageBuilderTestObject::test<22>() | ||
503 | // repeated penultimate block (crashes when data in LLDynamicArrayIndexed) | ||
504 | { | ||
505 | U32 inTest00 = 0, inTest01 = 1, inTest1 = 2; | ||
506 | U32 outTest00, outTest01, outTest1; | ||
507 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
508 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4)); | ||
509 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
510 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
511 | builder->addU32(_PREHASH_Test0, inTest00); | ||
512 | builder->nextBlock(_PREHASH_Test0); | ||
513 | builder->addU32(_PREHASH_Test0, inTest01); | ||
514 | builder->nextBlock(_PREHASH_Test1); | ||
515 | builder->addU32(_PREHASH_Test0, inTest1); | ||
516 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
517 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest00, 0); | ||
518 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest01, 1); | ||
519 | reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outTest1); | ||
520 | ensure_equals("Ensure Test0[0]", inTest00, outTest00); | ||
521 | ensure_equals("Ensure Test0[1]", inTest01, outTest01); | ||
522 | ensure_equals("Ensure Test1", inTest1, outTest1); | ||
523 | delete reader; | ||
524 | } | ||
525 | |||
526 | template<> template<> | ||
527 | void LLTemplateMessageBuilderTestObject::test<23>() | ||
528 | // variable repeated block name never accessed | ||
529 | { | ||
530 | U32 inTest = 1, outTest; | ||
531 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
532 | messageTemplate.addBlock( | ||
533 | createBlock(_PREHASH_Test0, MVT_U32, 4, MBT_SINGLE)); | ||
534 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
535 | |||
536 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
537 | builder->addU32(_PREHASH_Test0, inTest); | ||
538 | |||
539 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
540 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outTest); | ||
541 | S32 blockCount = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
542 | ensure_equals("Ensure block count", blockCount, 0); | ||
543 | ensure_equals("Ensure Test0", inTest, outTest); | ||
544 | delete reader; | ||
545 | } | ||
546 | |||
547 | template<> template<> | ||
548 | void LLTemplateMessageBuilderTestObject::test<24>() | ||
549 | // forwarding message | ||
550 | { | ||
551 | // build template | ||
552 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
553 | messageTemplate.addBlock(createBlock(_PREHASH_Test0, MVT_U32, 4)); | ||
554 | |||
555 | // build message | ||
556 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
557 | builder->addU32(_PREHASH_Test0, 42); | ||
558 | |||
559 | // read message | ||
560 | LLTemplateMessageReader* reader = setReader(messageTemplate, builder); | ||
561 | |||
562 | // forward message | ||
563 | builder = defaultBuilder(messageTemplate); | ||
564 | builder->newMessage(_PREHASH_TestMessage); | ||
565 | reader->copyToBuilder(*builder); | ||
566 | U8 buffer[MAX_BUFFER_SIZE]; | ||
567 | builder->buildMessage(buffer, MAX_BUFFER_SIZE, 0); | ||
568 | |||
569 | delete builder; | ||
570 | delete reader; | ||
571 | } | ||
572 | |||
573 | template<> template<> | ||
574 | void LLTemplateMessageBuilderTestObject::test<25>() | ||
575 | // non-zero offset with undefined | ||
576 | { | ||
577 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
578 | messageTemplate.addBlock(defaultBlock()); | ||
579 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
580 | LLTemplateMessageReader* reader = setReader( | ||
581 | messageTemplate, builder, 10); | ||
582 | delete reader; | ||
583 | } | ||
584 | |||
585 | template<> template<> | ||
586 | void LLTemplateMessageBuilderTestObject::test<26>() | ||
587 | // non-zero offset with BOOL | ||
588 | { | ||
589 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
590 | messageTemplate.addBlock(defaultBlock(MVT_BOOL, 1)); | ||
591 | BOOL outValue, inValue = TRUE; | ||
592 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
593 | builder->addBOOL(_PREHASH_Test0, inValue); | ||
594 | LLTemplateMessageReader* reader = setReader( | ||
595 | messageTemplate, builder, 1); | ||
596 | reader->getBOOL(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
597 | ensure_equals("Ensure BOOL", inValue, outValue); | ||
598 | delete reader; | ||
599 | } | ||
600 | |||
601 | template<> template<> | ||
602 | void LLTemplateMessageBuilderTestObject::test<27>() | ||
603 | // non-zero offset with U8 | ||
604 | { | ||
605 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
606 | messageTemplate.addBlock(defaultBlock(MVT_U8, 1)); | ||
607 | U8 outValue, inValue = 2; | ||
608 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
609 | builder->addU8(_PREHASH_Test0, inValue); | ||
610 | LLTemplateMessageReader* reader = setReader( | ||
611 | messageTemplate, builder, 255); | ||
612 | reader->getU8(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
613 | ensure_equals("Ensure U8", inValue, outValue); | ||
614 | delete reader; | ||
615 | } | ||
616 | |||
617 | template<> template<> | ||
618 | void LLTemplateMessageBuilderTestObject::test<28>() | ||
619 | // non-zero offset with S16 | ||
620 | { | ||
621 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
622 | messageTemplate.addBlock(defaultBlock(MVT_S16, 2)); | ||
623 | S16 outValue, inValue = 90; | ||
624 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
625 | builder->addS16(_PREHASH_Test0, inValue); | ||
626 | LLTemplateMessageReader* reader = setReader( | ||
627 | messageTemplate, builder, 2); | ||
628 | reader->getS16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
629 | ensure_equals("Ensure S16", inValue, outValue); | ||
630 | delete reader; | ||
631 | } | ||
632 | |||
633 | template<> template<> | ||
634 | void LLTemplateMessageBuilderTestObject::test<29>() | ||
635 | // non-zero offset with U16 | ||
636 | { | ||
637 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
638 | messageTemplate.addBlock(defaultBlock(MVT_U16, 2)); | ||
639 | U16 outValue, inValue = 3; | ||
640 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
641 | builder->addU16(_PREHASH_Test0, inValue); | ||
642 | LLTemplateMessageReader* reader = setReader( | ||
643 | messageTemplate, builder, 4); | ||
644 | reader->getU16(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
645 | ensure_equals("Ensure U16", inValue, outValue); | ||
646 | delete reader; | ||
647 | } | ||
648 | |||
649 | template<> template<> | ||
650 | void LLTemplateMessageBuilderTestObject::test<30>() | ||
651 | // non-zero offset with S32 | ||
652 | { | ||
653 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
654 | messageTemplate.addBlock(defaultBlock(MVT_S32, 4)); | ||
655 | S32 outValue, inValue = 44; | ||
656 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
657 | builder->addS32(_PREHASH_Test0, inValue); | ||
658 | LLTemplateMessageReader* reader = setReader( | ||
659 | messageTemplate, builder, 4); | ||
660 | reader->getS32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
661 | ensure_equals("Ensure S32", inValue, outValue); | ||
662 | delete reader; | ||
663 | } | ||
664 | |||
665 | template<> template<> | ||
666 | void LLTemplateMessageBuilderTestObject::test<31>() | ||
667 | // non-zero offset with F32 | ||
668 | { | ||
669 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
670 | messageTemplate.addBlock(defaultBlock(MVT_F32, 4)); | ||
671 | F32 outValue, inValue = 121.44f; | ||
672 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
673 | builder->addF32(_PREHASH_Test0, inValue); | ||
674 | LLTemplateMessageReader* reader = setReader( | ||
675 | messageTemplate, builder, 16); | ||
676 | reader->getF32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
677 | ensure_equals("Ensure F32", inValue, outValue); | ||
678 | delete reader; | ||
679 | } | ||
680 | |||
681 | template<> template<> | ||
682 | void LLTemplateMessageBuilderTestObject::test<32>() | ||
683 | // non-zero offset with U32 | ||
684 | { | ||
685 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
686 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4)); | ||
687 | U32 outValue, inValue = 88; | ||
688 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
689 | builder->addU32(_PREHASH_Test0, inValue); | ||
690 | LLTemplateMessageReader* reader = setReader( | ||
691 | messageTemplate, builder, 127); | ||
692 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
693 | ensure_equals("Ensure U32", inValue, outValue); | ||
694 | delete reader; | ||
695 | } | ||
696 | |||
697 | template<> template<> | ||
698 | void LLTemplateMessageBuilderTestObject::test<33>() | ||
699 | // non-zero offset with U64 | ||
700 | { | ||
701 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
702 | messageTemplate.addBlock(defaultBlock(MVT_U64, 8)); | ||
703 | U64 outValue, inValue = 121; | ||
704 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
705 | builder->addU64(_PREHASH_Test0, inValue); | ||
706 | LLTemplateMessageReader* reader = setReader( | ||
707 | messageTemplate, builder, 32); | ||
708 | reader->getU64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
709 | ensure_equals("Ensure U64", inValue, outValue); | ||
710 | delete reader; | ||
711 | } | ||
712 | |||
713 | template<> template<> | ||
714 | void LLTemplateMessageBuilderTestObject::test<34>() | ||
715 | // non-zero offset with F64 | ||
716 | { | ||
717 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
718 | messageTemplate.addBlock(defaultBlock(MVT_F64, 8)); | ||
719 | F64 outValue, inValue = 3232143.33; | ||
720 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
721 | builder->addF64(_PREHASH_Test0, inValue); | ||
722 | LLTemplateMessageReader* reader = setReader( | ||
723 | messageTemplate, builder, 128); | ||
724 | reader->getF64(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
725 | ensure_equals("Ensure F64", inValue, outValue); | ||
726 | delete reader; | ||
727 | } | ||
728 | |||
729 | template<> template<> | ||
730 | void LLTemplateMessageBuilderTestObject::test<35>() | ||
731 | // non-zero offset with Vector3 | ||
732 | { | ||
733 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
734 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3, 12)); | ||
735 | LLVector3 outValue, inValue = LLVector3(1,2,3); | ||
736 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
737 | builder->addVector3(_PREHASH_Test0, inValue); | ||
738 | LLTemplateMessageReader* reader = setReader( | ||
739 | messageTemplate, builder, 63); | ||
740 | reader->getVector3(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
741 | ensure_equals("Ensure LLVector3", inValue, outValue); | ||
742 | delete reader; | ||
743 | } | ||
744 | |||
745 | template<> template<> | ||
746 | void LLTemplateMessageBuilderTestObject::test<36>() | ||
747 | // non-zero offset with Vector4 | ||
748 | { | ||
749 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
750 | messageTemplate.addBlock(defaultBlock(MVT_LLVector4, 16)); | ||
751 | LLVector4 outValue, inValue = LLVector4(1,2,3,4); | ||
752 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
753 | builder->addVector4(_PREHASH_Test0, inValue); | ||
754 | LLTemplateMessageReader* reader = setReader( | ||
755 | messageTemplate, builder, 64); | ||
756 | reader->getVector4(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
757 | ensure_equals("Ensure LLVector4", inValue, outValue); | ||
758 | delete reader; | ||
759 | } | ||
760 | |||
761 | template<> template<> | ||
762 | void LLTemplateMessageBuilderTestObject::test<37>() | ||
763 | // non-zero offset with Vector3d | ||
764 | { | ||
765 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
766 | messageTemplate.addBlock(defaultBlock(MVT_LLVector3d, 24)); | ||
767 | LLVector3d outValue, inValue = LLVector3d(1,2,3); | ||
768 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
769 | builder->addVector3d(_PREHASH_Test0, inValue); | ||
770 | LLTemplateMessageReader* reader = setReader( | ||
771 | messageTemplate, builder, 64); | ||
772 | reader->getVector3d(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
773 | ensure_equals("Ensure LLVector3d", inValue, outValue); | ||
774 | delete reader; | ||
775 | } | ||
776 | |||
777 | template<> template<> | ||
778 | void LLTemplateMessageBuilderTestObject::test<38>() | ||
779 | // non-zero offset with Quaternion | ||
780 | { | ||
781 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
782 | messageTemplate.addBlock(defaultBlock(MVT_LLQuaternion, 12)); | ||
783 | LLQuaternion outValue, inValue = LLQuaternion(1,2,3,0); | ||
784 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
785 | builder->addQuat(_PREHASH_Test0, inValue); | ||
786 | LLTemplateMessageReader* reader = setReader( | ||
787 | messageTemplate, builder, 12); | ||
788 | reader->getQuat(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
789 | ensure_equals("Ensure LLQuaternion", inValue, outValue); | ||
790 | delete reader; | ||
791 | } | ||
792 | |||
793 | template<> template<> | ||
794 | void LLTemplateMessageBuilderTestObject::test<39>() | ||
795 | // non-zero offset with UUID | ||
796 | { | ||
797 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
798 | messageTemplate.addBlock(defaultBlock(MVT_LLUUID, 16)); | ||
799 | LLUUID outValue, inValue; | ||
800 | inValue.generate(); | ||
801 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
802 | builder->addUUID(_PREHASH_Test0, inValue); | ||
803 | LLTemplateMessageReader* reader = setReader( | ||
804 | messageTemplate, builder, 31); | ||
805 | reader->getUUID(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
806 | ensure_equals("Ensure UUID", inValue, outValue); | ||
807 | delete reader; | ||
808 | } | ||
809 | |||
810 | template<> template<> | ||
811 | void LLTemplateMessageBuilderTestObject::test<40>() | ||
812 | // non-zero offset with IPAddr | ||
813 | { | ||
814 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
815 | messageTemplate.addBlock(defaultBlock(MVT_IP_ADDR, 4)); | ||
816 | U32 outValue, inValue = 12344556; | ||
817 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
818 | builder->addIPAddr(_PREHASH_Test0, inValue); | ||
819 | LLTemplateMessageReader* reader = setReader( | ||
820 | messageTemplate, builder, 32); | ||
821 | reader->getIPAddr(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
822 | ensure_equals("Ensure IPAddr", inValue, outValue); | ||
823 | delete reader; | ||
824 | } | ||
825 | |||
826 | template<> template<> | ||
827 | void LLTemplateMessageBuilderTestObject::test<41>() | ||
828 | // non-zero offset with IPPort | ||
829 | { | ||
830 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
831 | messageTemplate.addBlock(defaultBlock(MVT_IP_PORT, 2)); | ||
832 | U16 outValue, inValue = 80; | ||
833 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
834 | builder->addIPPort(_PREHASH_Test0, inValue); | ||
835 | LLTemplateMessageReader* reader = setReader( | ||
836 | messageTemplate, builder, 6); | ||
837 | reader->getIPPort(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
838 | ensure_equals("Ensure IPPort", inValue, outValue); | ||
839 | delete reader; | ||
840 | } | ||
841 | |||
842 | template<> template<> | ||
843 | void LLTemplateMessageBuilderTestObject::test<42>() | ||
844 | // non-zero offset with String | ||
845 | { | ||
846 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
847 | messageTemplate.addBlock(defaultBlock(MVT_VARIABLE, 1)); | ||
848 | std::string outValue, inValue = "testing"; | ||
849 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
850 | builder->addString(_PREHASH_Test0, inValue.c_str()); | ||
851 | LLTemplateMessageReader* reader = setReader( | ||
852 | messageTemplate, builder, 255); | ||
853 | char buffer[MAX_STRING]; | ||
854 | reader->getString(_PREHASH_Test0, _PREHASH_Test0, MAX_STRING, buffer); | ||
855 | outValue = buffer; | ||
856 | ensure_equals("Ensure String", inValue, outValue); | ||
857 | delete reader; | ||
858 | } | ||
859 | |||
860 | template<> template<> | ||
861 | void LLTemplateMessageBuilderTestObject::test<43>() | ||
862 | // read past end of message -> default values (forward compatibility) | ||
863 | { | ||
864 | // build message with single block | ||
865 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
866 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
867 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
868 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
869 | builder->addU32(_PREHASH_Test0, inValue); | ||
870 | const U32 bufferSize = 1024; | ||
871 | U8 buffer[bufferSize]; | ||
872 | memset(buffer, 0xaa, bufferSize); | ||
873 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
874 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
875 | delete builder; | ||
876 | |||
877 | // add block to reader template | ||
878 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4, MBT_SINGLE)); | ||
879 | |||
880 | // read message value and default value | ||
881 | numberMap[1] = &messageTemplate; | ||
882 | LLTemplateMessageReader* reader = | ||
883 | new LLTemplateMessageReader(numberMap); | ||
884 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
885 | reader->readMessage(buffer, LLHost()); | ||
886 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
887 | reader->getU32(_PREHASH_Test1, _PREHASH_Test0, outValue2); | ||
888 | ensure_equals("Ensure present value ", outValue, inValue); | ||
889 | ensure_equals("Ensure default value ", outValue2, 0); | ||
890 | delete reader; | ||
891 | } | ||
892 | |||
893 | template<> template<> | ||
894 | void LLTemplateMessageBuilderTestObject::test<44>() | ||
895 | // read variable block past end of message -> 0 repeats | ||
896 | { | ||
897 | // build message with single block | ||
898 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
899 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
900 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
901 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
902 | builder->addU32(_PREHASH_Test0, inValue); | ||
903 | const U32 bufferSize = 1024; | ||
904 | U8 buffer[bufferSize]; | ||
905 | memset(buffer, 0xaa, bufferSize); | ||
906 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
907 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
908 | delete builder; | ||
909 | |||
910 | // add variable block to reader template | ||
911 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_U32, 4)); | ||
912 | |||
913 | // read message value and check block repeat count | ||
914 | numberMap[1] = &messageTemplate; | ||
915 | LLTemplateMessageReader* reader = | ||
916 | new LLTemplateMessageReader(numberMap); | ||
917 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
918 | reader->readMessage(buffer, LLHost()); | ||
919 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
920 | outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
921 | ensure_equals("Ensure present value ", outValue, inValue); | ||
922 | ensure_equals("Ensure 0 repeats ", outValue2, 0); | ||
923 | delete reader; | ||
924 | } | ||
925 | |||
926 | template<> template<> | ||
927 | void LLTemplateMessageBuilderTestObject::test<45>() | ||
928 | // read variable length data past end of message -> 0 length | ||
929 | { | ||
930 | // build message with single block | ||
931 | LLMessageTemplate messageTemplate = defaultTemplate(); | ||
932 | messageTemplate.addBlock(defaultBlock(MVT_U32, 4, MBT_SINGLE)); | ||
933 | U32 outValue, outValue2, inValue = 0xbbbbbbbb; | ||
934 | LLTemplateMessageBuilder* builder = defaultBuilder(messageTemplate); | ||
935 | builder->addU32(_PREHASH_Test0, inValue); | ||
936 | const U32 bufferSize = 1024; | ||
937 | U8 buffer[bufferSize]; | ||
938 | memset(buffer, 0xaa, bufferSize); | ||
939 | memset(buffer, 0, LL_PACKET_ID_SIZE); | ||
940 | U32 builtSize = builder->buildMessage(buffer, bufferSize, 0); | ||
941 | delete builder; | ||
942 | |||
943 | // add variable block to reader template | ||
944 | messageTemplate.addBlock(createBlock(_PREHASH_Test1, MVT_VARIABLE, 4, | ||
945 | MBT_SINGLE)); | ||
946 | |||
947 | // read message value and default string | ||
948 | numberMap[1] = &messageTemplate; | ||
949 | LLTemplateMessageReader* reader = | ||
950 | new LLTemplateMessageReader(numberMap); | ||
951 | reader->validateMessage(buffer, builtSize, LLHost()); | ||
952 | reader->readMessage(buffer, LLHost()); | ||
953 | reader->getU32(_PREHASH_Test0, _PREHASH_Test0, outValue); | ||
954 | char outBuffer[bufferSize]; | ||
955 | memset(buffer, 0xcc, bufferSize); | ||
956 | reader->getString(_PREHASH_Test1, _PREHASH_Test0, bufferSize, | ||
957 | outBuffer); | ||
958 | outValue2 = reader->getNumberOfBlocks(_PREHASH_Test1); | ||
959 | ensure_equals("Ensure present value ", outValue, inValue); | ||
960 | ensure_equals("Ensure unchanged buffer ", strlen(outBuffer), 0); | ||
961 | delete reader; | ||
962 | } | ||
963 | } | ||
964 | |||
diff --git a/linden/indra/test/lltut.h b/linden/indra/test/lltut.h index 626ff60..f40555e 100644 --- a/linden/indra/test/lltut.h +++ b/linden/indra/test/lltut.h | |||
@@ -28,12 +28,6 @@ | |||
28 | * COMPLETENESS OR PERFORMANCE. | 28 | * COMPLETENESS OR PERFORMANCE. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | /** | ||
32 | * | ||
33 | * THOROUGH_DESCRIPTION | ||
34 | * | ||
35 | */ | ||
36 | |||
37 | #ifndef LL_LLTUT_H | 31 | #ifndef LL_LLTUT_H |
38 | #define LL_LLTUT_H | 32 | #define LL_LLTUT_H |
39 | 33 | ||
diff --git a/linden/indra/test/lluuidhashmap_tut.cpp b/linden/indra/test/lluuidhashmap_tut.cpp new file mode 100644 index 0000000..a787326 --- /dev/null +++ b/linden/indra/test/lluuidhashmap_tut.cpp | |||
@@ -0,0 +1,359 @@ | |||
1 | /** | ||
2 | * @file lluuidhashmap_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-02 | ||
5 | * @brief Test cases for LLUUIDHashMap | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "linden_common.h" | ||
33 | #include "lluuidhashmap.h" | ||
34 | #include "llsdserialize.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | class UUIDTableEntry | ||
39 | { | ||
40 | public: | ||
41 | UUIDTableEntry() | ||
42 | { | ||
43 | mID.setNull(); | ||
44 | mValue = 0; | ||
45 | } | ||
46 | |||
47 | UUIDTableEntry(const LLUUID& id, U32 value) | ||
48 | { | ||
49 | mID = id; | ||
50 | mValue = value; | ||
51 | } | ||
52 | |||
53 | ~UUIDTableEntry(){}; | ||
54 | |||
55 | static BOOL uuidEq(const LLUUID &uuid, const UUIDTableEntry &id_pair) | ||
56 | { | ||
57 | if (uuid == id_pair.mID) | ||
58 | { | ||
59 | return TRUE; | ||
60 | } | ||
61 | return FALSE; | ||
62 | } | ||
63 | |||
64 | const LLUUID& getID() { return mID; } | ||
65 | const U32& getValue() { return mValue; } | ||
66 | |||
67 | protected: | ||
68 | LLUUID mID; | ||
69 | U32 mValue; | ||
70 | }; | ||
71 | |||
72 | struct hashmap_test | ||
73 | { | ||
74 | }; | ||
75 | |||
76 | typedef test_group<hashmap_test> hash_index_t; | ||
77 | typedef hash_index_t::object hash_index_object_t; | ||
78 | tut::hash_index_t tut_hash_index("hashmap_test"); | ||
79 | |||
80 | // stress test | ||
81 | template<> template<> | ||
82 | void hash_index_object_t::test<1>() | ||
83 | { | ||
84 | LLUUIDHashMap<UUIDTableEntry, 32> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
85 | const int numElementsToCheck = 32*256*32; | ||
86 | std::vector<LLUUID> idList(numElementsToCheck); | ||
87 | int i; | ||
88 | |||
89 | for (i = 0; i < numElementsToCheck; i++) | ||
90 | { | ||
91 | LLUUID id; | ||
92 | id.generate(); | ||
93 | UUIDTableEntry entry(id, i); | ||
94 | hashTable.set(id, entry); | ||
95 | idList[i] = id; | ||
96 | } | ||
97 | |||
98 | for (i = 0; i < numElementsToCheck; i++) | ||
99 | { | ||
100 | LLUUID idToCheck = idList[i]; | ||
101 | UUIDTableEntry entryToCheck = hashTable.get(idToCheck); | ||
102 | ensure("set/get did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i); | ||
103 | } | ||
104 | |||
105 | for (i = 0; i < numElementsToCheck; i++) | ||
106 | { | ||
107 | LLUUID idToCheck = idList[i]; | ||
108 | if (i % 2 != 0) | ||
109 | { | ||
110 | hashTable.remove(idToCheck); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | for (i = 0; i < numElementsToCheck; i++) | ||
115 | { | ||
116 | LLUUID idToCheck = idList[i]; | ||
117 | ensure("remove or check did not work", (i % 2 == 0 && hashTable.check(idToCheck)) || (i % 2 != 0 && !hashTable.check(idToCheck))); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | // test removing all but one element. | ||
122 | template<> template<> | ||
123 | void hash_index_object_t::test<2>() | ||
124 | { | ||
125 | LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
126 | const int numElementsToCheck = 5; | ||
127 | std::vector<LLUUID> idList(numElementsToCheck*10); | ||
128 | int i; | ||
129 | |||
130 | for (i = 0; i < numElementsToCheck; i++) | ||
131 | { | ||
132 | LLUUID id; | ||
133 | id.generate(); | ||
134 | UUIDTableEntry entry(id, i); | ||
135 | hashTable.set(id, entry); | ||
136 | idList[i] = id; | ||
137 | } | ||
138 | |||
139 | ensure("getLength failed", hashTable.getLength() == numElementsToCheck); | ||
140 | |||
141 | // remove all but the last element | ||
142 | for (i = 0; i < numElementsToCheck-1; i++) | ||
143 | { | ||
144 | LLUUID idToCheck = idList[i]; | ||
145 | hashTable.remove(idToCheck); | ||
146 | } | ||
147 | |||
148 | // there should only be one element left now. | ||
149 | ensure("getLength failed", hashTable.getLength() == 1); | ||
150 | |||
151 | for (i = 0; i < numElementsToCheck; i++) | ||
152 | { | ||
153 | LLUUID idToCheck = idList[i]; | ||
154 | if (i != numElementsToCheck - 1) | ||
155 | { | ||
156 | ensure("remove did not work", hashTable.check(idToCheck) == FALSE); | ||
157 | } | ||
158 | else | ||
159 | { | ||
160 | UUIDTableEntry entryToCheck = hashTable.get(idToCheck); | ||
161 | ensure("remove did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i); | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | |||
166 | // test overriding of value already set. | ||
167 | template<> template<> | ||
168 | void hash_index_object_t::test<3>() | ||
169 | { | ||
170 | LLUUIDHashMap<UUIDTableEntry, 5> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
171 | const int numElementsToCheck = 10; | ||
172 | std::vector<LLUUID> idList(numElementsToCheck); | ||
173 | int i; | ||
174 | |||
175 | for (i = 0; i < numElementsToCheck; i++) | ||
176 | { | ||
177 | LLUUID id; | ||
178 | id.generate(); | ||
179 | UUIDTableEntry entry(id, i); | ||
180 | hashTable.set(id, entry); | ||
181 | idList[i] = id; | ||
182 | } | ||
183 | |||
184 | for (i = 0; i < numElementsToCheck; i++) | ||
185 | { | ||
186 | LLUUID id = idList[i]; | ||
187 | // set new entry with value = i+numElementsToCheck | ||
188 | UUIDTableEntry entry(id, i+numElementsToCheck); | ||
189 | hashTable.set(id, entry); | ||
190 | } | ||
191 | |||
192 | for (i = 0; i < numElementsToCheck; i++) | ||
193 | { | ||
194 | LLUUID idToCheck = idList[i]; | ||
195 | UUIDTableEntry entryToCheck = hashTable.get(idToCheck); | ||
196 | ensure("set/get did not work", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)(i+numElementsToCheck)); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // test removeAll() | ||
201 | template<> template<> | ||
202 | void hash_index_object_t::test<4>() | ||
203 | { | ||
204 | LLUUIDHashMap<UUIDTableEntry, 5> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
205 | const int numElementsToCheck = 10; | ||
206 | std::vector<LLUUID> idList(numElementsToCheck); | ||
207 | int i; | ||
208 | |||
209 | for (i = 0; i < numElementsToCheck; i++) | ||
210 | { | ||
211 | LLUUID id; | ||
212 | id.generate(); | ||
213 | UUIDTableEntry entry(id, i); | ||
214 | hashTable.set(id, entry); | ||
215 | idList[i] = id; | ||
216 | } | ||
217 | |||
218 | hashTable.removeAll(); | ||
219 | ensure("removeAll failed", hashTable.getLength() == 0); | ||
220 | } | ||
221 | |||
222 | |||
223 | // test sparse map - force it by creating 256 entries that fall into 256 different nodes | ||
224 | template<> template<> | ||
225 | void hash_index_object_t::test<5>() | ||
226 | { | ||
227 | LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
228 | const int numElementsToCheck = 256; | ||
229 | std::vector<LLUUID> idList(numElementsToCheck); | ||
230 | int i; | ||
231 | |||
232 | for (i = 0; i < numElementsToCheck; i++) | ||
233 | { | ||
234 | LLUUID id; | ||
235 | id.generate(); | ||
236 | // LLUUIDHashMap uses mData[0] to pick the bucket | ||
237 | // overwrite mData[0] so that it ranges from 0 to 255 | ||
238 | id.mData[0] = i; | ||
239 | UUIDTableEntry entry(id, i); | ||
240 | hashTable.set(id, entry); | ||
241 | idList[i] = id; | ||
242 | } | ||
243 | |||
244 | for (i = 0; i < numElementsToCheck; i++) | ||
245 | { | ||
246 | LLUUID idToCheck = idList[i]; | ||
247 | UUIDTableEntry entryToCheck = hashTable.get(idToCheck); | ||
248 | ensure("set/get did not work for sparse map", entryToCheck.getID() == idToCheck && entryToCheck.getValue() == (size_t)i); | ||
249 | } | ||
250 | |||
251 | for (i = 0; i < numElementsToCheck; i++) | ||
252 | { | ||
253 | LLUUID idToCheck = idList[i]; | ||
254 | if (i % 2 != 0) | ||
255 | { | ||
256 | hashTable.remove(idToCheck); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | for (i = 0; i < numElementsToCheck; i++) | ||
261 | { | ||
262 | LLUUID idToCheck = idList[i]; | ||
263 | ensure("remove or check did not work for sparse map", (i % 2 == 0 && hashTable.check(idToCheck)) || (i % 2 != 0 && !hashTable.check(idToCheck))); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | // iterator | ||
268 | template<> template<> | ||
269 | void hash_index_object_t::test<6>() | ||
270 | { | ||
271 | LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
272 | LLUUIDHashMapIter<UUIDTableEntry, 2> hashIter(&hashTable); | ||
273 | const int numElementsToCheck = 256; | ||
274 | std::vector<LLUUID> idList(numElementsToCheck); | ||
275 | int i; | ||
276 | |||
277 | for (i = 0; i < numElementsToCheck; i++) | ||
278 | { | ||
279 | LLUUID id; | ||
280 | id.generate(); | ||
281 | // LLUUIDHashMap uses mData[0] to pick the bucket | ||
282 | // overwrite mData[0] so that it ranges from 0 to 255 | ||
283 | // to create a sparse map | ||
284 | id.mData[0] = i; | ||
285 | UUIDTableEntry entry(id, i); | ||
286 | hashTable.set(id, entry); | ||
287 | idList[i] = id; | ||
288 | } | ||
289 | |||
290 | hashIter.first(); | ||
291 | int numElementsIterated = 0; | ||
292 | while(!hashIter.done()) | ||
293 | { | ||
294 | numElementsIterated++; | ||
295 | UUIDTableEntry tableEntry = *hashIter; | ||
296 | LLUUID id = tableEntry.getID(); | ||
297 | hashIter.next(); | ||
298 | ensure("Iteration failed for sparse map", tableEntry.getValue() < (size_t)numElementsToCheck && idList[tableEntry.getValue()] == tableEntry.getID()); | ||
299 | } | ||
300 | |||
301 | ensure("iteration count failed", numElementsIterated == numElementsToCheck); | ||
302 | } | ||
303 | |||
304 | // remove after middle of iteration | ||
305 | template<> template<> | ||
306 | void hash_index_object_t::test<7>() | ||
307 | { | ||
308 | LLUUIDHashMap<UUIDTableEntry, 2> hashTable(UUIDTableEntry::uuidEq, UUIDTableEntry()); | ||
309 | LLUUIDHashMapIter<UUIDTableEntry, 2> hashIter(&hashTable); | ||
310 | const int numElementsToCheck = 256; | ||
311 | std::vector<LLUUID> idList(numElementsToCheck); | ||
312 | int i; | ||
313 | |||
314 | LLUUID uuidtoSearch; | ||
315 | for (i = 0; i < numElementsToCheck; i++) | ||
316 | { | ||
317 | LLUUID id; | ||
318 | id.generate(); | ||
319 | // LLUUIDHashMap uses mData[0] to pick the bucket | ||
320 | // overwrite mData[0] so that it ranges from 0 to 255 | ||
321 | // to create a sparse map | ||
322 | id.mData[0] = i; | ||
323 | UUIDTableEntry entry(id, i); | ||
324 | hashTable.set(id, entry); | ||
325 | idList[i] = id; | ||
326 | |||
327 | // pick uuid somewhere in the middle | ||
328 | if (i == 5) | ||
329 | { | ||
330 | uuidtoSearch = id; | ||
331 | } | ||
332 | } | ||
333 | |||
334 | hashIter.first(); | ||
335 | int numElementsIterated = 0; | ||
336 | while(!hashIter.done()) | ||
337 | { | ||
338 | numElementsIterated++; | ||
339 | UUIDTableEntry tableEntry = *hashIter; | ||
340 | LLUUID id = tableEntry.getID(); | ||
341 | if (uuidtoSearch == id) | ||
342 | { | ||
343 | break; | ||
344 | } | ||
345 | hashIter.next(); | ||
346 | } | ||
347 | |||
348 | // current iterator implementation will not allow any remove operations | ||
349 | // until ALL elements have been iterated over. this seems to be | ||
350 | // an unnecessary restriction. Iterator should have a method to | ||
351 | // reset() its state so that further operations (inckuding remove) | ||
352 | // can be performed on the HashMap without having to iterate thru | ||
353 | // all the remaining nodes. | ||
354 | |||
355 | // hashIter.reset(); | ||
356 | // hashTable.remove(uuidtoSearch); | ||
357 | // ensure("remove after iteration reset failed", hashTable.check(uuidtoSearch) == FALSE); | ||
358 | } | ||
359 | } | ||
diff --git a/linden/indra/test/llxorcipher_tut.cpp b/linden/indra/test/llxorcipher_tut.cpp new file mode 100644 index 0000000..07b33b6 --- /dev/null +++ b/linden/indra/test/llxorcipher_tut.cpp | |||
@@ -0,0 +1,133 @@ | |||
1 | /** | ||
2 | * @file llxorcipher_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief llxorcipher, llnullcipher test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "llxorcipher.h" | ||
34 | #include "llnullcipher.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct cipher | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<cipher> cipher_t; | ||
42 | typedef cipher_t::object cipher_object_t; | ||
43 | tut::cipher_t tut_cipher("cipher"); | ||
44 | |||
45 | //encrypt->decrypt | ||
46 | template<> template<> | ||
47 | void cipher_object_t::test<1>() | ||
48 | { | ||
49 | const U32 len = 3; | ||
50 | const U8 pad[] = "abc"; | ||
51 | const char str[] = "SecondLife"; | ||
52 | const S32 str_len = sizeof(str); | ||
53 | U8 encrypted[str_len]; | ||
54 | U8 decrypted[str_len]; | ||
55 | LLXORCipher xorCipher(pad, len); | ||
56 | LLXORCipher xorCipher1(pad, len); | ||
57 | |||
58 | U32 length = xorCipher.requiredEncryptionSpace(50); | ||
59 | ensure("requiredEncryptionSpace() function failed", (length == 50)); | ||
60 | |||
61 | U32 lenEncrypted = xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len); | ||
62 | ensure("Encryption failed", (lenEncrypted == str_len)); | ||
63 | U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len); | ||
64 | ensure("Decryption failed", (lenDecrypted == str_len)); | ||
65 | ensure_memory_matches("LLXORCipher Encrypt/Decrypt failed", str, str_len, decrypted, lenDecrypted); | ||
66 | } | ||
67 | |||
68 | // operator= | ||
69 | template<> template<> | ||
70 | void cipher_object_t::test<2>() | ||
71 | { | ||
72 | const U8 pad[] = "ABCDEFGHIJKLMNOPQ"; // pad len longer than data to be ciphered | ||
73 | const U32 pad_len = sizeof(pad); | ||
74 | const U8 pad1[] = "SecondLife"; | ||
75 | const U32 pad_len1 = sizeof(pad1); | ||
76 | const char str[] = "To Be Ciphered"; | ||
77 | const S32 str_len = sizeof(str); | ||
78 | U8 encrypted[str_len]; | ||
79 | U8 decrypted[str_len]; | ||
80 | |||
81 | LLXORCipher xorCipher(pad, pad_len); | ||
82 | LLXORCipher xorCipher1(pad1, pad_len1); | ||
83 | |||
84 | xorCipher.encrypt((U8 *) str, str_len, encrypted, str_len); | ||
85 | // make xorCipher1 same as xorCipher..so that xorCipher1 can decrypt what was | ||
86 | // encrypted using xorCipher | ||
87 | xorCipher1 = xorCipher; | ||
88 | U32 lenDecrypted = xorCipher1.decrypt(encrypted, str_len, decrypted, str_len); | ||
89 | ensure_memory_matches("LLXORCipher operator= failed", str, str_len, decrypted, lenDecrypted); | ||
90 | } | ||
91 | |||
92 | //in place encrypt->decrypt | ||
93 | template<> template<> | ||
94 | void cipher_object_t::test<3>() | ||
95 | { | ||
96 | U32 padNum = 0x12349087; | ||
97 | const U8* pad = (U8*) &padNum; | ||
98 | const U32 pad_len = sizeof(U32); | ||
99 | char str[] = "To Be Ciphered a long string.........!!!."; | ||
100 | char str1[] = "To Be Ciphered a long string.........!!!."; // same as str | ||
101 | const S32 str_len = sizeof(str); | ||
102 | |||
103 | LLXORCipher xorCipher(pad, pad_len); | ||
104 | LLXORCipher xorCipher1(pad, pad_len); | ||
105 | xorCipher.encrypt((U8 *) str, str_len); | ||
106 | // it should not be the same as original data! | ||
107 | ensure("LLXORCipher: In Place encrypt failed", memcmp(str, str1, str_len) != 0); | ||
108 | xorCipher1.decrypt((U8 *) str, str_len); | ||
109 | // it should not be the same as original data! | ||
110 | ensure_memory_matches("LLXORCipher: In Place decrypt failed", str, str_len, str1, str_len); | ||
111 | } | ||
112 | |||
113 | //LLNullCipher encrypt->decrypt | ||
114 | template<> template<> | ||
115 | void cipher_object_t::test<4>() | ||
116 | { | ||
117 | const char str[] = "SecondLife"; | ||
118 | const S32 str_len = sizeof(str); | ||
119 | U8 encrypted[str_len]; | ||
120 | U8 decrypted[str_len]; | ||
121 | LLNullCipher nullCipher; | ||
122 | LLNullCipher nullCipher1; | ||
123 | |||
124 | U32 length = nullCipher.requiredEncryptionSpace(50); | ||
125 | ensure("LLNullCipher::requiredEncryptionSpace() function failed", (length == 50)); | ||
126 | |||
127 | U32 len1 = nullCipher.encrypt((U8 *) str, str_len, encrypted, str_len); | ||
128 | ensure_memory_matches("LLNullCipher - Source transformed during encryption.", encrypted, len1, str, str_len); | ||
129 | |||
130 | U32 len2 = nullCipher1.decrypt(encrypted, str_len, decrypted, str_len); | ||
131 | ensure_memory_matches("LLNullCipher - Decryption failed", decrypted, len2, str, str_len); | ||
132 | } | ||
133 | } | ||
diff --git a/linden/indra/test/m3math_tut.cpp b/linden/indra/test/m3math_tut.cpp index 62ad365..b693193 100644 --- a/linden/indra/test/m3math_tut.cpp +++ b/linden/indra/test/m3math_tut.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | * @file m3math_tut.cpp | 2 | * @file m3math_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date March 2007 | 4 | * @date 2007-03 |
5 | * @brief Test cases of m3math.h | 5 | * @brief Test cases of m3math.h |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
diff --git a/linden/indra/test/message_tut.cpp b/linden/indra/test/message_tut.cpp new file mode 100644 index 0000000..366c2b4 --- /dev/null +++ b/linden/indra/test/message_tut.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | /** | ||
2 | * @file lldatapacker_tut.cpp | ||
3 | * @date 2007-04 | ||
4 | * @brief LLDataPacker test cases. | ||
5 | * | ||
6 | * Copyright (c) 2007-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 | |||
33 | #include "llapr.h" | ||
34 | #include "llversion.h" | ||
35 | #include "message.h" | ||
36 | #include "message_prehash.h" | ||
37 | |||
38 | namespace | ||
39 | { | ||
40 | struct Response : public LLHTTPNode::Response | ||
41 | { | ||
42 | virtual void result(const LLSD&) {} | ||
43 | virtual void status(S32 code, const std::string& message) | ||
44 | { | ||
45 | mStatus = code; | ||
46 | } | ||
47 | S32 mStatus; | ||
48 | }; | ||
49 | } | ||
50 | |||
51 | namespace tut | ||
52 | { | ||
53 | struct LLMessageSystemTestData | ||
54 | { | ||
55 | LLMessageSystemTestData() | ||
56 | { | ||
57 | static bool init = false; | ||
58 | if(! init) | ||
59 | { | ||
60 | ll_init_apr(); | ||
61 | init_prehash_data(); | ||
62 | init = true; | ||
63 | } | ||
64 | |||
65 | // currently test disconnected message system | ||
66 | start_messaging_system("notafile", 13035, | ||
67 | LL_VERSION_MAJOR, | ||
68 | LL_VERSION_MINOR, | ||
69 | LL_VERSION_PATCH, | ||
70 | FALSE, | ||
71 | "notasharedsecret"); | ||
72 | } | ||
73 | |||
74 | ~LLMessageSystemTestData() | ||
75 | { | ||
76 | // not end_messaging_system() | ||
77 | delete gMessageSystem; | ||
78 | gMessageSystem = NULL; | ||
79 | } | ||
80 | }; | ||
81 | |||
82 | typedef test_group<LLMessageSystemTestData> LLMessageSystemTestGroup; | ||
83 | typedef LLMessageSystemTestGroup::object LLMessageSystemTestObject; | ||
84 | LLMessageSystemTestGroup messageTestGroup("LLMessageSystem"); | ||
85 | |||
86 | template<> template<> | ||
87 | void LLMessageSystemTestObject::test<1>() | ||
88 | // dispatch unknown message | ||
89 | { | ||
90 | const char* name = "notamessasge"; | ||
91 | const LLSD message; | ||
92 | const LLPointer<Response> response = new Response(); | ||
93 | gMessageSystem->dispatch(name, message, response); | ||
94 | ensure_equals(response->mStatus, 404); | ||
95 | } | ||
96 | } | ||
97 | |||
diff --git a/linden/indra/test/test.cpp b/linden/indra/test/test.cpp index 8f6f672..1c03768 100644 --- a/linden/indra/test/test.cpp +++ b/linden/indra/test/test.cpp | |||
@@ -64,7 +64,8 @@ public: | |||
64 | mTotalTests(0), | 64 | mTotalTests(0), |
65 | mPassedTests(0), | 65 | mPassedTests(0), |
66 | mFailedTests(0), | 66 | mFailedTests(0), |
67 | mSkippedTests(0) | 67 | mSkippedTests(0), |
68 | mSkipedFailTests(0) | ||
68 | { | 69 | { |
69 | } | 70 | } |
70 | 71 | ||
@@ -86,7 +87,7 @@ public: | |||
86 | break; | 87 | break; |
87 | case tut::test_result::fail: | 88 | case tut::test_result::fail: |
88 | ++mFailedTests; | 89 | ++mFailedTests; |
89 | out << "fail '" << tr.message << "'"; | 90 | out << "fail"; |
90 | break; | 91 | break; |
91 | case tut::test_result::ex: | 92 | case tut::test_result::ex: |
92 | ++mFailedTests; | 93 | ++mFailedTests; |
@@ -104,12 +105,20 @@ public: | |||
104 | ++mSkippedTests; | 105 | ++mSkippedTests; |
105 | out << "skipped"; | 106 | out << "skipped"; |
106 | break; | 107 | break; |
108 | case tut::test_result::skip_fail: | ||
109 | ++mSkipedFailTests; | ||
110 | out << "skipped known failure"; | ||
111 | break; | ||
107 | default: | 112 | default: |
108 | ++mFailedTests; | 113 | ++mFailedTests; |
109 | out << "unknown"; | 114 | out << "unknown"; |
110 | } | 115 | } |
111 | if(mVerboseMode || (tr.result != tut::test_result::ok)) | 116 | if(mVerboseMode || (tr.result != tut::test_result::ok)) |
112 | { | 117 | { |
118 | if(!tr.message.empty()) | ||
119 | { | ||
120 | out << ": '" << tr.message << "'"; | ||
121 | } | ||
113 | std::cout << out.str() << std::endl; | 122 | std::cout << out.str() << std::endl; |
114 | } | 123 | } |
115 | } | 124 | } |
@@ -118,11 +127,17 @@ public: | |||
118 | { | 127 | { |
119 | std::cout << std::endl; | 128 | std::cout << std::endl; |
120 | std::cout << "Total Tests: " << mTotalTests << std::endl; | 129 | std::cout << "Total Tests: " << mTotalTests << std::endl; |
121 | std::cout << "Passed Tests : " << mPassedTests << std::endl; | 130 | std::cout << "Passed Tests: " << mPassedTests << std::endl; |
122 | 131 | ||
123 | if (mSkippedTests > 0) | 132 | if (mSkippedTests > 0) |
124 | { | 133 | { |
125 | std::cout << "Skipped Tests : " << mSkippedTests << std::endl; | 134 | std::cout << "Skipped Tests: " << mSkippedTests << std::endl; |
135 | } | ||
136 | |||
137 | if (mSkipedFailTests > 0) | ||
138 | { | ||
139 | std::cout << "Skipped known failures: " << mSkipedFailTests | ||
140 | << std::endl; | ||
126 | } | 141 | } |
127 | 142 | ||
128 | if(mFailedTests > 0) | 143 | if(mFailedTests > 0) |
@@ -137,10 +152,11 @@ public: | |||
137 | 152 | ||
138 | protected: | 153 | protected: |
139 | bool mVerboseMode; | 154 | bool mVerboseMode; |
140 | S32 mTotalTests; | 155 | int mTotalTests; |
141 | S32 mPassedTests; | 156 | int mPassedTests; |
142 | S32 mFailedTests; | 157 | int mFailedTests; |
143 | S32 mSkippedTests; | 158 | int mSkippedTests; |
159 | int mSkipedFailTests; | ||
144 | }; | 160 | }; |
145 | 161 | ||
146 | static const apr_getopt_option_t TEST_CL_OPTIONS[] = | 162 | static const apr_getopt_option_t TEST_CL_OPTIONS[] = |
diff --git a/linden/indra/test/test.vcproj b/linden/indra/test/test.vcproj index cb9c7af..1a55b8c 100644 --- a/linden/indra/test/test.vcproj +++ b/linden/indra/test/test.vcproj | |||
@@ -20,7 +20,7 @@ | |||
20 | <Tool | 20 | <Tool |
21 | Name="VCCLCompilerTool" | 21 | Name="VCCLCompilerTool" |
22 | Optimization="0" | 22 | Optimization="0" |
23 | AdditionalIncludeDirectories="..\llcommon;..\llmessage;..\llmath;..\..\libraries\include;..\llinventory;"..\..\libraries\i686-win32\include";..\llxml;..\lldatabase" | 23 | AdditionalIncludeDirectories="..\llcharacter;..\llcommon;..\lldatabase;..\llinventory;..\llmath;..\llmessage;..\llxml;"..\..\libraries\i686-win32\include";..\..\libraries\include" |
24 | PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;LL_WINDOWS;LL_DEBUG" | 24 | PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;LL_WINDOWS;LL_DEBUG" |
25 | MinimalRebuild="FALSE" | 25 | MinimalRebuild="FALSE" |
26 | BasicRuntimeChecks="3" | 26 | BasicRuntimeChecks="3" |
@@ -74,7 +74,7 @@ | |||
74 | <Tool | 74 | <Tool |
75 | Name="VCCLCompilerTool" | 75 | Name="VCCLCompilerTool" |
76 | Optimization="0" | 76 | Optimization="0" |
77 | AdditionalIncludeDirectories="..\llcommon;..\llmessage;..\llmath;..\..\libraries\include;..\llinventory;"..\..\libraries\i686-win32\include";..\llxml;..\lldatabase" | 77 | AdditionalIncludeDirectories="..\llcharacter;..\llcommon;..\lldatabase;..\llinventory;..\llmath;..\llmessage;..\llxml;"..\..\libraries\i686-win32\include";..\..\libraries\include" |
78 | PreprocessorDefinitions="WIN32;__WIN32;NDEBUG;_WINDOWS;LL_WINDOWS;LL_RELEASE;APR_DECLARE_STATIC;LL_HTTPD=1" | 78 | PreprocessorDefinitions="WIN32;__WIN32;NDEBUG;_WINDOWS;LL_WINDOWS;LL_RELEASE;APR_DECLARE_STATIC;LL_HTTPD=1" |
79 | MinimalRebuild="FALSE" | 79 | MinimalRebuild="FALSE" |
80 | BasicRuntimeChecks="3" | 80 | BasicRuntimeChecks="3" |
@@ -130,7 +130,7 @@ | |||
130 | <Tool | 130 | <Tool |
131 | Name="VCCLCompilerTool" | 131 | Name="VCCLCompilerTool" |
132 | Optimization="0" | 132 | Optimization="0" |
133 | AdditionalIncludeDirectories="..\llcommon;..\llmessage;..\llmath;..\..\libraries\include;..\llinventory;"..\..\libraries\i686-win32\include";..\llxml;..\lldatabase" | 133 | AdditionalIncludeDirectories="..\llcharacter;..\llcommon;..\lldatabase;..\llinventory;..\llmath;..\llmessage;..\llxml;"..\..\libraries\i686-win32\include";..\..\libraries\include" |
134 | PreprocessorDefinitions="WIN32;__WIN32;NDEBUG;_WINDOWS;LL_WINDOWS;LL_RELEASE;APR_DECLARE_STATIC;LL_HTTPD=1" | 134 | PreprocessorDefinitions="WIN32;__WIN32;NDEBUG;_WINDOWS;LL_WINDOWS;LL_RELEASE;APR_DECLARE_STATIC;LL_HTTPD=1" |
135 | MinimalRebuild="FALSE" | 135 | MinimalRebuild="FALSE" |
136 | BasicRuntimeChecks="3" | 136 | BasicRuntimeChecks="3" |
@@ -193,23 +193,47 @@ | |||
193 | <File | 193 | <File |
194 | RelativePath=".\io.cpp"> | 194 | RelativePath=".\io.cpp"> |
195 | </File> | 195 | </File> |
196 | <File | ||
197 | RelativePath=".\llbuffer_tut.cpp"> | ||
198 | </File> | ||
196 | 199 | ||
197 | <File | 200 | <File |
201 | RelativePath=".\lldate_tut.cpp"> | ||
202 | </File> | ||
203 | <File | ||
198 | RelativePath=".\llerror_tut.cpp"> | 204 | RelativePath=".\llerror_tut.cpp"> |
199 | </File> | 205 | </File> |
200 | <File | 206 | <File |
207 | RelativePath=".\llhost_tut.cpp"> | ||
208 | </File> | ||
209 | <File | ||
201 | RelativePath=".\llhttpclient_tut.cpp"> | 210 | RelativePath=".\llhttpclient_tut.cpp"> |
202 | </File> | 211 | </File> |
203 | <File | 212 | <File |
213 | RelativePath=".\lljoint_tut.cpp"> | ||
214 | </File> | ||
215 | <File | ||
204 | RelativePath=".\llmime_tut.cpp"> | 216 | RelativePath=".\llmime_tut.cpp"> |
205 | </File> | 217 | </File> |
206 | <File | 218 | <File |
219 | RelativePath=".\llnamevalue_tut.cpp"> | ||
220 | </File> | ||
221 | <File | ||
222 | RelativePath=".\llpermissions_tut.cpp"> | ||
223 | </File> | ||
224 | <File | ||
207 | RelativePath=".\llpipeutil.cpp"> | 225 | RelativePath=".\llpipeutil.cpp"> |
208 | </File> | 226 | </File> |
209 | <File | 227 | <File |
228 | RelativePath=".\llquaternion_tut.cpp"> | ||
229 | </File> | ||
230 | <File | ||
210 | RelativePath=".\llrandom_tut.cpp"> | 231 | RelativePath=".\llrandom_tut.cpp"> |
211 | </File> | 232 | </File> |
212 | <File | 233 | <File |
234 | RelativePath=".\llsaleinfo_tut.cpp"> | ||
235 | </File> | ||
236 | <File | ||
213 | RelativePath=".\llsd_new_tut.cpp"> | 237 | RelativePath=".\llsd_new_tut.cpp"> |
214 | </File> | 238 | </File> |
215 | <File | 239 | <File |
@@ -225,9 +249,18 @@ | |||
225 | RelativePath=".\llsdtraits.h"> | 249 | RelativePath=".\llsdtraits.h"> |
226 | </File> | 250 | </File> |
227 | <File | 251 | <File |
252 | RelativePath=".\llsdutil_tut.cpp"> | ||
253 | </File> | ||
254 | <File | ||
228 | RelativePath=".\llservicebuilder_tut.cpp"> | 255 | RelativePath=".\llservicebuilder_tut.cpp"> |
229 | </File> | 256 | </File> |
230 | <File | 257 | <File |
258 | RelativePath=".\llstreamtools_tut.cpp"> | ||
259 | </File> | ||
260 | <File | ||
261 | RelativePath=".\lltemplatemessagebuilder_tut.cpp"> | ||
262 | </File> | ||
263 | <File | ||
231 | RelativePath=".\lltiming_tut.cpp"> | 264 | RelativePath=".\lltiming_tut.cpp"> |
232 | </File> | 265 | </File> |
233 | <File | 266 | <File |
@@ -240,6 +273,9 @@ | |||
240 | RelativePath=".\lluserrelations_tut.cpp"> | 273 | RelativePath=".\lluserrelations_tut.cpp"> |
241 | </File> | 274 | </File> |
242 | <File | 275 | <File |
276 | RelativePath=".\lluuidhashmap_tut.cpp"> | ||
277 | </File> | ||
278 | <File | ||
243 | RelativePath=".\math.cpp"> | 279 | RelativePath=".\math.cpp"> |
244 | </File> | 280 | </File> |
245 | <File | 281 | <File |
@@ -248,6 +284,30 @@ | |||
248 | <File | 284 | <File |
249 | RelativePath=".\test.cpp"> | 285 | RelativePath=".\test.cpp"> |
250 | </File> | 286 | </File> |
287 | <File | ||
288 | RelativePath=".\v2math_tut.cpp"> | ||
289 | </File> | ||
290 | <File | ||
291 | RelativePath=".\v3color_tut.cpp"> | ||
292 | </File> | ||
293 | <File | ||
294 | RelativePath=".\v3dmath_tut.cpp"> | ||
295 | </File> | ||
296 | <File | ||
297 | RelativePath=".\v3math_tut.cpp"> | ||
298 | </File> | ||
299 | <File | ||
300 | RelativePath=".\v4color_tut.cpp"> | ||
301 | </File> | ||
302 | <File | ||
303 | RelativePath=".\v4coloru_tut.cpp"> | ||
304 | </File> | ||
305 | <File | ||
306 | RelativePath=".\v4math_tut.cpp"> | ||
307 | </File> | ||
308 | <File | ||
309 | RelativePath=".\xform_tut.cpp"> | ||
310 | </File> | ||
251 | </Filter> | 311 | </Filter> |
252 | <Filter | 312 | <Filter |
253 | Name="Header Files" | 313 | Name="Header Files" |
diff --git a/linden/indra/test/v2math_tut.cpp b/linden/indra/test/v2math_tut.cpp index e94a19b..0765989 100644 --- a/linden/indra/test/v2math_tut.cpp +++ b/linden/indra/test/v2math_tut.cpp | |||
@@ -1,11 +1,12 @@ | |||
1 | /** | 1 | /** |
2 | * @file v2math_tut.cpp | 2 | * @file v2math_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date February 2007 | 4 | * @date 2007-02 |
5 | * @brief v2math test cases. | 5 | * @brief v2math test cases. |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -94,7 +95,9 @@ namespace tut | |||
94 | { | 95 | { |
95 | F32 x =-2.0f, y = -3.0f ; | 96 | F32 x =-2.0f, y = -3.0f ; |
96 | LLVector2 vec2(x,y); | 97 | LLVector2 vec2(x,y); |
97 | ensure("abs():Fail ", TRUE == vec2.abs() && is_approx_equal(x, 2.f) && is_approx_equal(y, 3.f)); | 98 | ensure_equals("abs():Fail", vec2.abs(), TRUE); |
99 | ensure("abs() x", is_approx_equal(vec2.mV[VX], 2.f)); | ||
100 | ensure("abs() y", is_approx_equal(vec2.mV[VY], 3.f)); | ||
98 | 101 | ||
99 | ensure("isNull():Fail ", FALSE == vec2.isNull()); //Returns TRUE if vector has a _very_small_ length | 102 | ensure("isNull():Fail ", FALSE == vec2.isNull()); //Returns TRUE if vector has a _very_small_ length |
100 | 103 | ||
@@ -258,6 +261,9 @@ namespace tut | |||
258 | template<> template<> | 261 | template<> template<> |
259 | void v2math_object::test<13>() | 262 | void v2math_object::test<13>() |
260 | { | 263 | { |
264 | #if (LL_RELEASE && LL_LINUX) | ||
265 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
266 | #endif | ||
261 | F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f; | 267 | F32 x1 = 1.f, y1 = 2.f,x2 = 2.332f, y2 = -1.23f; |
262 | F32 val1, val2; | 268 | F32 val1, val2; |
263 | LLVector2 vec2(x1, y1), vec3(x2, y2); | 269 | LLVector2 vec2(x1, y1), vec3(x2, y2); |
@@ -425,6 +431,10 @@ namespace tut | |||
425 | template<> template<> | 431 | template<> template<> |
426 | void v2math_object::test<23>() | 432 | void v2math_object::test<23>() |
427 | { | 433 | { |
434 | #if (LL_RELEASE && LL_LINUX) | ||
435 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
436 | #endif | ||
437 | |||
428 | F32 x1 =1.f, y1 = 2.f; | 438 | F32 x1 =1.f, y1 = 2.f; |
429 | F32 val1, val2; | 439 | F32 val1, val2; |
430 | LLVector2 vec2(x1, y1); | 440 | LLVector2 vec2(x1, y1); |
diff --git a/linden/indra/test/v3color_tut.cpp b/linden/indra/test/v3color_tut.cpp new file mode 100644 index 0000000..411d196 --- /dev/null +++ b/linden/indra/test/v3color_tut.cpp | |||
@@ -0,0 +1,314 @@ | |||
1 | /** | ||
2 | * @file v3color_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief v3color test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "v3color.h" | ||
35 | |||
36 | |||
37 | namespace tut | ||
38 | { | ||
39 | struct v3color_data | ||
40 | { | ||
41 | }; | ||
42 | typedef test_group<v3color_data> v3color_test; | ||
43 | typedef v3color_test::object v3color_object; | ||
44 | tut::v3color_test v3color_testcase("v3color"); | ||
45 | |||
46 | template<> template<> | ||
47 | void v3color_object::test<1>() | ||
48 | { | ||
49 | LLColor3 llcolor3; | ||
50 | ensure("1:LLColor3:Fail to initialize ", (0.0f == llcolor3.mV[0]) && (0.0f == llcolor3.mV[1]) && (0.0f == llcolor3.mV[2])); | ||
51 | F32 r = 2.0f, g = 3.2f, b = 1.f; | ||
52 | F32 v1,v2,v3; | ||
53 | LLColor3 llcolor3a(r,g,b); | ||
54 | ensure("2:LLColor3:Fail to initialize " ,(2.0f == llcolor3a.mV[0]) && (3.2f == llcolor3a.mV[1]) && (1.f == llcolor3a.mV[2])); | ||
55 | |||
56 | const F32 vec[3] = {2.0f, 3.2f,1.f}; | ||
57 | LLColor3 llcolor3b(vec); | ||
58 | ensure("3:LLColor3:Fail to initialize " ,(2.0f == llcolor3b.mV[0]) && (3.2f == llcolor3b.mV[1]) && (1.f == llcolor3b.mV[2])); | ||
59 | char* str = "561122"; | ||
60 | LLColor3 llcolor3c(str); | ||
61 | v1 = (F32)86.0f/255.0f; // 0x56 = 86 | ||
62 | v2 = (F32)17.0f/255.0f; // 0x11 = 17 | ||
63 | v3 = (F32)34.0f/255.f; // 0x22 = 34 | ||
64 | ensure("4:LLColor3:Fail to initialize " ,(v1 == llcolor3c.mV[0]) && (v2 == llcolor3c.mV[1]) && (v3 == llcolor3c.mV[2])); | ||
65 | } | ||
66 | |||
67 | template<> template<> | ||
68 | void v3color_object::test<2>() | ||
69 | { | ||
70 | LLColor3 llcolor3; | ||
71 | llcolor3.setToBlack(); | ||
72 | ensure("setToBlack:Fail to set black ", ((llcolor3.mV[0] == 0.f) && (llcolor3.mV[1] == 0.f) && (llcolor3.mV[2] == 0.f))); | ||
73 | llcolor3.setToWhite(); | ||
74 | ensure("setToWhite:Fail to set white ", ((llcolor3.mV[0] == 1.f) && (llcolor3.mV[1] == 1.f) && (llcolor3.mV[2] == 1.f))); | ||
75 | } | ||
76 | |||
77 | template<> template<> | ||
78 | void v3color_object::test<3>() | ||
79 | { | ||
80 | F32 r = 2.3436212f, g = 1231.f, b = 4.7849321232f; | ||
81 | LLColor3 llcolor3, llcolor3a; | ||
82 | llcolor3.setVec(r,g,b); | ||
83 | ensure("1:setVec(r,g,b) Fail ",((r == llcolor3.mV[0]) && (g == llcolor3.mV[1]) && (b == llcolor3.mV[2]))); | ||
84 | llcolor3a.setVec(llcolor3); | ||
85 | ensure_equals("2:setVec(LLColor3) Fail ", llcolor3,llcolor3a); | ||
86 | F32 vec[3] = {1.2324f, 2.45634f, .234563f}; | ||
87 | llcolor3.setToBlack(); | ||
88 | llcolor3.setVec(vec); | ||
89 | ensure("3:setVec(F32*) Fail ",((vec[0] == llcolor3.mV[0]) && (vec[1] == llcolor3.mV[1]) && (vec[2] == llcolor3.mV[2]))); | ||
90 | } | ||
91 | |||
92 | template<> template<> | ||
93 | void v3color_object::test<4>() | ||
94 | { | ||
95 | F32 r = 2.3436212f, g = 1231.f, b = 4.7849321232f; | ||
96 | LLColor3 llcolor3(r,g,b); | ||
97 | ensure("magVecSquared:Fail ", is_approx_equal(llcolor3.magVecSquared(), (r*r + g*g + b*b))); | ||
98 | ensure("magVec:Fail ", is_approx_equal(llcolor3.magVec(), fsqrtf(r*r + g*g + b*b))); | ||
99 | } | ||
100 | |||
101 | template<> template<> | ||
102 | void v3color_object::test<5>() | ||
103 | { | ||
104 | #if (LL_RELEASE && LL_LINUX) | ||
105 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
106 | #endif | ||
107 | F32 r = 2.3436212f, g = 1231.f, b = 4.7849321232f; | ||
108 | F32 val1, val2,val3; | ||
109 | LLColor3 llcolor3(r,g,b); | ||
110 | F32 vecMag = llcolor3.normVec(); | ||
111 | F32 mag = fsqrtf(r*r + g*g + b*b); | ||
112 | F32 oomag = 1.f / mag; | ||
113 | val1 = r * oomag; | ||
114 | val2 = g * oomag; | ||
115 | val3 = b * oomag; | ||
116 | ensure("1:normVec failed ", (val1 == llcolor3.mV[0] && val2 == llcolor3.mV[1] && val3 == llcolor3.mV[2] && vecMag == mag)); | ||
117 | r = .000000000f, g = 0.f, b = 0.0f; | ||
118 | llcolor3.setVec(r,g,b); | ||
119 | vecMag = llcolor3.normVec(); | ||
120 | ensure("2:normVec failed should be 0. ", (0. == llcolor3.mV[0] && 0. == llcolor3.mV[1] && 0. == llcolor3.mV[2] && vecMag == 0.)); | ||
121 | } | ||
122 | |||
123 | template<> template<> | ||
124 | void v3color_object::test<6>() | ||
125 | { | ||
126 | F32 r = 2.3436212f, g = -1231.f, b = .7849321232f; | ||
127 | std::ostringstream stream1, stream2; | ||
128 | LLColor3 llcolor3(r,g,b),llcolor3a; | ||
129 | stream1 << llcolor3; | ||
130 | llcolor3a.setVec(r,g,b); | ||
131 | stream2 << llcolor3a; | ||
132 | ensure("operator << failed ", (stream1.str() == stream2.str())); | ||
133 | } | ||
134 | |||
135 | template<> template<> | ||
136 | void v3color_object::test<7>() | ||
137 | { | ||
138 | F32 r = 2.3436212f, g = -1231.f, b = .7849321232f; | ||
139 | LLColor3 llcolor3(r,g,b),llcolor3a; | ||
140 | llcolor3a = llcolor3; | ||
141 | ensure("operator == failed ", (llcolor3a == llcolor3)); | ||
142 | } | ||
143 | |||
144 | template<> template<> | ||
145 | void v3color_object::test<8>() | ||
146 | { | ||
147 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
148 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2),llcolor3b; | ||
149 | llcolor3b = llcolor3 + llcolor3a ; | ||
150 | ensure("1:operator+ failed",is_approx_equal(r1+r2 ,llcolor3b.mV[0]) && is_approx_equal(g1+g2,llcolor3b.mV[1])&& is_approx_equal(b1+b2,llcolor3b.mV[2])); | ||
151 | r1 = -.235f, g1 = -24.32f, b1 = 2.13f, r2 = -2.3f, g2 = 1.f, b2 = 34.21f; | ||
152 | llcolor3.setVec(r1,g1,b1); | ||
153 | llcolor3a.setVec(r2,g2,b2); | ||
154 | llcolor3b = llcolor3 + llcolor3a; | ||
155 | ensure("2:operator+ failed",is_approx_equal(r1+r2 ,llcolor3b.mV[0]) && is_approx_equal(g1+g2,llcolor3b.mV[1])&& is_approx_equal(b1+b2,llcolor3b.mV[2])); | ||
156 | } | ||
157 | |||
158 | template<> template<> | ||
159 | void v3color_object::test<9>() | ||
160 | { | ||
161 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
162 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2),llcolor3b; | ||
163 | llcolor3b = llcolor3 - llcolor3a ; | ||
164 | ensure("1:operator- failed",is_approx_equal(r1-r2 ,llcolor3b.mV[0]) && is_approx_equal(g1-g2,llcolor3b.mV[1])&& is_approx_equal(b1-b2,llcolor3b.mV[2])); | ||
165 | r1 = -.235f, g1 = -24.32f, b1 = 2.13f, r2 = -2.3f, g2 = 1.f, b2 = 34.21f; | ||
166 | llcolor3.setVec(r1,g1,b1); | ||
167 | llcolor3a.setVec(r2,g2,b2); | ||
168 | llcolor3b = llcolor3 - llcolor3a; | ||
169 | ensure("2:operator- failed",is_approx_equal(r1-r2 ,llcolor3b.mV[0]) && is_approx_equal(g1-g2,llcolor3b.mV[1])&& is_approx_equal(b1-b2,llcolor3b.mV[2])); | ||
170 | } | ||
171 | |||
172 | template<> template<> | ||
173 | void v3color_object::test<10>() | ||
174 | { | ||
175 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
176 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2),llcolor3b; | ||
177 | llcolor3b = llcolor3 * llcolor3a; | ||
178 | ensure("1:operator* failed",is_approx_equal(r1*r2 ,llcolor3b.mV[0]) && is_approx_equal(g1*g2,llcolor3b.mV[1])&& is_approx_equal(b1*b2,llcolor3b.mV[2])); | ||
179 | llcolor3a.setToBlack(); | ||
180 | F32 mulVal = 4.332f; | ||
181 | llcolor3a = llcolor3 * mulVal; | ||
182 | ensure("2:operator* failed",is_approx_equal(r1*mulVal ,llcolor3a.mV[0]) && is_approx_equal(g1*mulVal,llcolor3a.mV[1])&& is_approx_equal(b1*mulVal,llcolor3a.mV[2])); | ||
183 | llcolor3a.setToBlack(); | ||
184 | llcolor3a = mulVal * llcolor3; | ||
185 | ensure("3:operator* failed",is_approx_equal(r1*mulVal ,llcolor3a.mV[0]) && is_approx_equal(g1*mulVal,llcolor3a.mV[1])&& is_approx_equal(b1*mulVal,llcolor3a.mV[2])); | ||
186 | } | ||
187 | |||
188 | template<> template<> | ||
189 | void v3color_object::test<11>() | ||
190 | { | ||
191 | F32 r = 2.3436212f, g = 1231.f, b = 4.7849321232f; | ||
192 | LLColor3 llcolor3(r,g,b),llcolor3a; | ||
193 | llcolor3a = -llcolor3; | ||
194 | ensure("operator- failed ", (-llcolor3a == llcolor3)); | ||
195 | } | ||
196 | |||
197 | template<> template<> | ||
198 | void v3color_object::test<12>() | ||
199 | { | ||
200 | F32 r = 2.3436212f, g = 1231.f, b = 4.7849321232f; | ||
201 | LLColor3 llcolor3(r,g,b),llcolor3a(r,g,b); | ||
202 | ensure_equals("1:operator== failed",llcolor3a,llcolor3); | ||
203 | r = 13.3436212f, g = -11.f, b = .7849321232f; | ||
204 | llcolor3.setVec(r,g,b); | ||
205 | llcolor3a.setVec(r,g,b); | ||
206 | ensure_equals("2:operator== failed",llcolor3a,llcolor3); | ||
207 | } | ||
208 | |||
209 | template<> template<> | ||
210 | void v3color_object::test<13>() | ||
211 | { | ||
212 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
213 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
214 | ensure("1:operator!= failed",(llcolor3 != llcolor3a)); | ||
215 | llcolor3.setToBlack(); | ||
216 | llcolor3a.setVec(llcolor3); | ||
217 | ensure("2:operator!= failed", ( FALSE == (llcolor3a != llcolor3))); | ||
218 | } | ||
219 | |||
220 | template<> template<> | ||
221 | void v3color_object::test<14>() | ||
222 | { | ||
223 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
224 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
225 | llcolor3a += llcolor3; | ||
226 | ensure("1:operator+= failed",is_approx_equal(r1+r2 ,llcolor3a.mV[0]) && is_approx_equal(g1+g2,llcolor3a.mV[1])&& is_approx_equal(b1+b2,llcolor3a.mV[2])); | ||
227 | llcolor3.setVec(r1,g1,b1); | ||
228 | llcolor3a.setVec(r2,g2,b2); | ||
229 | llcolor3a += llcolor3; | ||
230 | ensure("2:operator+= failed",is_approx_equal(r1+r2 ,llcolor3a.mV[0]) && is_approx_equal(g1+g2,llcolor3a.mV[1])&& is_approx_equal(b1+b2,llcolor3a.mV[2])); | ||
231 | } | ||
232 | |||
233 | template<> template<> | ||
234 | void v3color_object::test<15>() | ||
235 | { | ||
236 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
237 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
238 | llcolor3a -= llcolor3; | ||
239 | ensure("1:operator-= failed", is_approx_equal(r2-r1, llcolor3a.mV[0])); | ||
240 | ensure("2:operator-= failed", is_approx_equal(g2-g1, llcolor3a.mV[1])); | ||
241 | ensure("3:operator-= failed", is_approx_equal(b2-b1, llcolor3a.mV[2])); | ||
242 | llcolor3.setVec(r1,g1,b1); | ||
243 | llcolor3a.setVec(r2,g2,b2); | ||
244 | llcolor3a -= llcolor3; | ||
245 | ensure("4:operator-= failed", is_approx_equal(r2-r1, llcolor3a.mV[0])); | ||
246 | ensure("5:operator-= failed", is_approx_equal(g2-g1, llcolor3a.mV[1])); | ||
247 | ensure("6:operator-= failed", is_approx_equal(b2-b1, llcolor3a.mV[2])); | ||
248 | } | ||
249 | |||
250 | template<> template<> | ||
251 | void v3color_object::test<16>() | ||
252 | { | ||
253 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
254 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
255 | llcolor3a *= llcolor3; | ||
256 | ensure("1:operator*= failed",is_approx_equal(r1*r2 ,llcolor3a.mV[0]) && is_approx_equal(g1*g2,llcolor3a.mV[1])&& is_approx_equal(b1*b2,llcolor3a.mV[2])); | ||
257 | F32 mulVal = 4.332f; | ||
258 | llcolor3 *=mulVal; | ||
259 | ensure("2:operator*= failed",is_approx_equal(r1*mulVal ,llcolor3.mV[0]) && is_approx_equal(g1*mulVal,llcolor3.mV[1])&& is_approx_equal(b1*mulVal,llcolor3.mV[2])); | ||
260 | } | ||
261 | |||
262 | template<> template<> | ||
263 | void v3color_object::test<17>() | ||
264 | { | ||
265 | F32 r = 2.3436212f, g = -1231.f, b = .7849321232f; | ||
266 | LLColor3 llcolor3(r,g,b); | ||
267 | llcolor3.clamp(); | ||
268 | ensure("1:clamp:Fail to clamp " ,(1.0f == llcolor3.mV[0]) && (0.f == llcolor3.mV[1]) && (b == llcolor3.mV[2])); | ||
269 | r = -2.3436212f, g = -1231.f, b = 67.7849321232f; | ||
270 | llcolor3.setVec(r,g,b); | ||
271 | llcolor3.clamp(); | ||
272 | ensure("2:clamp:Fail to clamp " ,(0.f == llcolor3.mV[0]) && (0.f == llcolor3.mV[1]) && (1.f == llcolor3.mV[2])); | ||
273 | } | ||
274 | |||
275 | template<> template<> | ||
276 | void v3color_object::test<18>() | ||
277 | { | ||
278 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
279 | F32 val = 2.3f,val1,val2,val3; | ||
280 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
281 | val1 = r1 + (r2 - r1)* val; | ||
282 | val2 = g1 + (g2 - g1)* val; | ||
283 | val3 = b1 + (b2 - b1)* val; | ||
284 | LLColor3 llcolor3b = lerp(llcolor3,llcolor3a,val); | ||
285 | ensure("lerp failed ", ((val1 ==llcolor3b.mV[0])&& (val2 ==llcolor3b.mV[1]) && (val3 ==llcolor3b.mV[2]))); | ||
286 | } | ||
287 | |||
288 | template<> template<> | ||
289 | void v3color_object::test<19>() | ||
290 | { | ||
291 | F32 r1 =1.f, g1 = 2.f,b1 = 1.2f, r2 = -2.3f, g2 = 1.11f, b2 = 1234.234f; | ||
292 | LLColor3 llcolor3(r1,g1,b1),llcolor3a(r2,g2,b2); | ||
293 | F32 val = distVec(llcolor3,llcolor3a); | ||
294 | ensure("distVec failed ", is_approx_equal(fsqrtf((r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2)) ,val)); | ||
295 | |||
296 | F32 val1 = distVec_squared(llcolor3,llcolor3a); | ||
297 | ensure("distVec_squared failed ", is_approx_equal(((r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2)) ,val1)); | ||
298 | } | ||
299 | |||
300 | template<> template<> | ||
301 | void v3color_object::test<20>() | ||
302 | { | ||
303 | F32 r1 = 1.02223f, g1 = 22222.212f, b1 = 122222.00002f; | ||
304 | LLColor3 llcolor31(r1,g1,b1); | ||
305 | |||
306 | LLSD sd = llcolor31.getValue(); | ||
307 | LLColor3 llcolor32; | ||
308 | llcolor32.setValue(sd); | ||
309 | ensure_equals("LLColor3::setValue/getValue failed", llcolor31, llcolor32); | ||
310 | |||
311 | LLColor3 llcolor33(sd); | ||
312 | ensure_equals("LLColor3(LLSD) failed", llcolor31, llcolor33); | ||
313 | } | ||
314 | } | ||
diff --git a/linden/indra/test/v3dmath_tut.cpp b/linden/indra/test/v3dmath_tut.cpp index 88ade71..2f5ea8e 100644 --- a/linden/indra/test/v3dmath_tut.cpp +++ b/linden/indra/test/v3dmath_tut.cpp | |||
@@ -1,7 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | * @file v3dmath_tut.cpp | 2 | * @file v3dmath_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date March 2007 | 4 | * @date 2007-03 |
5 | * @brief v3dmath test cases. | 5 | * @brief v3dmath test cases. |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
@@ -212,21 +212,70 @@ namespace tut | |||
212 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | 212 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; |
213 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2); | 213 | LLVector3d vec3D(x1,y1,z1),vec3Da(x2,y2,z2); |
214 | F64 res = vec3D * vec3Da; | 214 | F64 res = vec3D * vec3Da; |
215 | ensure("1:operator* failed",(res == (x1*x2 + y1*y2 + z1*z2))); | 215 | ensure_approximately_equals( |
216 | "1:operator* failed", | ||
217 | res, | ||
218 | (x1*x2 + y1*y2 + z1*z2), | ||
219 | 8); | ||
216 | vec3Da.clearVec(); | 220 | vec3Da.clearVec(); |
217 | F64 mulVal = 4.2; | 221 | F64 mulVal = 4.2; |
218 | vec3Da = vec3D * mulVal; | 222 | vec3Da = vec3D * mulVal; |
219 | ensure("2:operator* failed",(x1*mulVal == vec3Da.mdV[VX]) && (y1*mulVal == vec3Da.mdV[VY])&& (z1*mulVal == vec3Da.mdV[VZ])); | 223 | ensure_approximately_equals( |
224 | "2a:operator* failed", | ||
225 | vec3Da.mdV[VX], | ||
226 | x1*mulVal, | ||
227 | 8); | ||
228 | ensure_approximately_equals( | ||
229 | "2b:operator* failed", | ||
230 | vec3Da.mdV[VY], | ||
231 | y1*mulVal, | ||
232 | 8); | ||
233 | ensure_approximately_equals( | ||
234 | "2c:operator* failed", | ||
235 | vec3Da.mdV[VZ], | ||
236 | z1*mulVal, | ||
237 | 8); | ||
220 | vec3Da.clearVec(); | 238 | vec3Da.clearVec(); |
221 | vec3Da = mulVal * vec3D; | 239 | vec3Da = mulVal * vec3D; |
222 | ensure("3:operator* failed",(x1*mulVal == vec3Da.mdV[VX]) && (y1*mulVal == vec3Da.mdV[VY])&& (z1*mulVal == vec3Da.mdV[VZ])); | 240 | ensure_approximately_equals( |
241 | "3a:operator* failed", | ||
242 | vec3Da.mdV[VX], | ||
243 | x1*mulVal, | ||
244 | 8); | ||
245 | ensure_approximately_equals( | ||
246 | "3b:operator* failed", | ||
247 | vec3Da.mdV[VY], | ||
248 | y1*mulVal, | ||
249 | 8); | ||
250 | ensure_approximately_equals( | ||
251 | "3c:operator* failed", | ||
252 | vec3Da.mdV[VZ], | ||
253 | z1*mulVal, | ||
254 | 8); | ||
223 | vec3D *= mulVal; | 255 | vec3D *= mulVal; |
224 | ensure("4:operator*= failed",(x1*mulVal == vec3D.mdV[VX]) && (y1*mulVal == vec3D.mdV[VY])&& (z1*mulVal == vec3D.mdV[VZ])); | 256 | ensure_approximately_equals( |
257 | "4a:operator*= failed", | ||
258 | vec3D.mdV[VX], | ||
259 | x1*mulVal, | ||
260 | 8); | ||
261 | ensure_approximately_equals( | ||
262 | "4b:operator*= failed", | ||
263 | vec3D.mdV[VY], | ||
264 | y1*mulVal, | ||
265 | 8); | ||
266 | ensure_approximately_equals( | ||
267 | "4c:operator*= failed", | ||
268 | vec3D.mdV[VZ], | ||
269 | z1*mulVal, | ||
270 | 8); | ||
225 | } | 271 | } |
226 | 272 | ||
227 | template<> template<> | 273 | template<> template<> |
228 | void v3dmath_object::test<12>() | 274 | void v3dmath_object::test<12>() |
229 | { | 275 | { |
276 | #if (LL_RELEASE && LL_LINUX) | ||
277 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
278 | #endif | ||
230 | F64 x1 = 1., y1 = 2., z1 = -1.1; | 279 | F64 x1 = 1., y1 = 2., z1 = -1.1; |
231 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; | 280 | F64 x2 = 1.2, y2 = 2.5, z2 = 1.; |
232 | F64 val1, val2, val3; | 281 | F64 val1, val2, val3; |
@@ -247,15 +296,57 @@ namespace tut | |||
247 | F64 t = 1.f / div; | 296 | F64 t = 1.f / div; |
248 | LLVector3d vec3D(x1,y1,z1), vec3Da; | 297 | LLVector3d vec3D(x1,y1,z1), vec3Da; |
249 | vec3Da = vec3D/div; | 298 | vec3Da = vec3D/div; |
250 | ensure("1:operator/ failed",(x1*t == vec3Da.mdV[VX]) && (y1*t == vec3Da.mdV[VY])&& (z1*t == vec3Da.mdV[VZ])); | 299 | ensure_approximately_equals( |
251 | x1 = 1.23, y1 = 4., z1 = -2.32; | 300 | "1a:operator/ failed", |
252 | vec3D.clearVec(); | 301 | vec3Da.mdV[VX], |
253 | vec3Da.clearVec(); | 302 | x1*t, |
254 | vec3D.setVec(x1,y1,z1); | 303 | 8); |
255 | vec3Da = vec3D/div; | 304 | ensure_approximately_equals( |
256 | ensure("2:operator/ failed",(x1*t == vec3Da.mdV[VX]) && (y1*t == vec3Da.mdV[VY])&& (z1*t == vec3Da.mdV[VZ])); | 305 | "1b:operator/ failed", |
257 | vec3D /= div; | 306 | vec3Da.mdV[VY], |
258 | ensure("3:operator/= failed",(x1*t == vec3D.mdV[VX]) && (y1*t == vec3D.mdV[VY])&& (z1*t == vec3D.mdV[VZ])); | 307 | y1*t, |
308 | 8); | ||
309 | ensure_approximately_equals( | ||
310 | "1c:operator/ failed", | ||
311 | vec3Da.mdV[VZ], | ||
312 | z1*t, | ||
313 | 8); | ||
314 | x1 = 1.23, y1 = 4., z1 = -2.32; | ||
315 | vec3D.clearVec(); | ||
316 | vec3Da.clearVec(); | ||
317 | vec3D.setVec(x1,y1,z1); | ||
318 | vec3Da = vec3D/div; | ||
319 | ensure_approximately_equals( | ||
320 | "2a:operator/ failed", | ||
321 | vec3Da.mdV[VX], | ||
322 | x1*t, | ||
323 | 8); | ||
324 | ensure_approximately_equals( | ||
325 | "2b:operator/ failed", | ||
326 | vec3Da.mdV[VY], | ||
327 | y1*t, | ||
328 | 8); | ||
329 | ensure_approximately_equals( | ||
330 | "2c:operator/ failed", | ||
331 | vec3Da.mdV[VZ], | ||
332 | z1*t, | ||
333 | 8); | ||
334 | vec3D /= div; | ||
335 | ensure_approximately_equals( | ||
336 | "3a:operator/= failed", | ||
337 | vec3D.mdV[VX], | ||
338 | x1*t, | ||
339 | 8); | ||
340 | ensure_approximately_equals( | ||
341 | "3b:operator/= failed", | ||
342 | vec3D.mdV[VY], | ||
343 | y1*t, | ||
344 | 8); | ||
345 | ensure_approximately_equals( | ||
346 | "3c:operator/= failed", | ||
347 | vec3D.mdV[VZ], | ||
348 | z1*t, | ||
349 | 8); | ||
259 | } | 350 | } |
260 | 351 | ||
261 | template<> template<> | 352 | template<> template<> |
@@ -324,18 +415,48 @@ namespace tut | |||
324 | LLVector3d vec3D(x,y,z); | 415 | LLVector3d vec3D(x,y,z); |
325 | F64 mag = vec3D.normVec(); | 416 | F64 mag = vec3D.normVec(); |
326 | mag = 1.f/ mag; | 417 | mag = 1.f/ mag; |
327 | ensure("1:normVec: Fail ", (x* mag == vec3D.mdV[VX]) && (y* mag == vec3D.mdV[VY])&& (z* mag == vec3D.mdV[VZ])); | 418 | ensure_approximately_equals( |
419 | "1a:normVec: Fail ", | ||
420 | vec3D.mdV[VX], | ||
421 | x * mag, | ||
422 | 8); | ||
423 | ensure_approximately_equals( | ||
424 | "1b:normVec: Fail ", | ||
425 | vec3D.mdV[VY], | ||
426 | y * mag, | ||
427 | 8); | ||
428 | ensure_approximately_equals( | ||
429 | "1c:normVec: Fail ", | ||
430 | vec3D.mdV[VZ], | ||
431 | z * mag, | ||
432 | 8); | ||
328 | x = 0.000000001, y = 0.000000001, z = 0.000000001; | 433 | x = 0.000000001, y = 0.000000001, z = 0.000000001; |
329 | vec3D.clearVec(); | 434 | vec3D.clearVec(); |
330 | vec3D.setVec(x,y,z); | 435 | vec3D.setVec(x,y,z); |
331 | mag = vec3D.normVec(); | 436 | mag = vec3D.normVec(); |
332 | ensure("2:normVec: Fail ", (x* mag == vec3D.mdV[VX]) && (y* mag == vec3D.mdV[VY])&& (z* mag == vec3D.mdV[VZ])); | 437 | ensure_approximately_equals( |
438 | "2a:normVec: Fail ", | ||
439 | vec3D.mdV[VX], | ||
440 | x * mag, | ||
441 | 8); | ||
442 | ensure_approximately_equals( | ||
443 | "2b:normVec: Fail ", | ||
444 | vec3D.mdV[VY], | ||
445 | y * mag, | ||
446 | 8); | ||
447 | ensure_approximately_equals( | ||
448 | "2c:normVec: Fail ", | ||
449 | vec3D.mdV[VZ], | ||
450 | z * mag, | ||
451 | 8); | ||
333 | } | 452 | } |
334 | 453 | ||
335 | template<> template<> | 454 | template<> template<> |
336 | void v3dmath_object::test<20>() | 455 | void v3dmath_object::test<20>() |
337 | { | 456 | { |
338 | F64 x1 = 1111.232222, y1 = 2222222222.22, z1 = 422222222222; | 457 | F64 x1 = 1111.232222; |
458 | F64 y1 = 2222222222.22; | ||
459 | F64 z1 = 422222222222.0; | ||
339 | char buf[] = "1111.232222 2222222222.22 422222222222"; | 460 | char buf[] = "1111.232222 2222222222.22 422222222222"; |
340 | LLVector3d vec3Da, vec3Db(x1,y1,z1); | 461 | LLVector3d vec3Da, vec3Db(x1,y1,z1); |
341 | LLVector3d::parseVector3d(buf, &vec3Da); | 462 | LLVector3d::parseVector3d(buf, &vec3Da); |
@@ -399,4 +520,4 @@ namespace tut | |||
399 | angle = acos(angle); | 520 | angle = acos(angle); |
400 | ensure("2:angle_between: Fail ", (angle == angle2)); | 521 | ensure("2:angle_between: Fail ", (angle == angle2)); |
401 | } | 522 | } |
402 | } \ No newline at end of file | 523 | } |
diff --git a/linden/indra/test/v3math_tut.cpp b/linden/indra/test/v3math_tut.cpp index 36eaca9..4f4e7e0 100644 --- a/linden/indra/test/v3math_tut.cpp +++ b/linden/indra/test/v3math_tut.cpp | |||
@@ -1,11 +1,12 @@ | |||
1 | /** | 1 | /** |
2 | * @file v3math_tut.cpp | 2 | * @file v3math_tut.cpp |
3 | * @author Adroit | 3 | * @author Adroit |
4 | * @date February 2007 | 4 | * @date 2007-02 |
5 | * @brief v3math test cases. | 5 | * @brief v3math test cases. |
6 | * | 6 | * |
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | 7 | * Copyright (c) 2007-2007, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -389,6 +390,9 @@ namespace tut | |||
389 | template<> template<> | 390 | template<> template<> |
390 | void v3math_object::test<22>() | 391 | void v3math_object::test<22>() |
391 | { | 392 | { |
393 | #if (LL_RELEASE && LL_LINUX) | ||
394 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
395 | #endif | ||
392 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; | 396 | F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f; |
393 | F32 val1,val2,val3; | 397 | F32 val1,val2,val3; |
394 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); | 398 | LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2); |
@@ -523,6 +527,9 @@ namespace tut | |||
523 | template<> template<> | 527 | template<> template<> |
524 | void v3math_object::test<32>() | 528 | void v3math_object::test<32>() |
525 | { | 529 | { |
530 | #if (LL_RELEASE && LL_LINUX) | ||
531 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
532 | #endif | ||
526 | F32 x =12.3524f, y = -342.f,z = 4.126341f; | 533 | F32 x =12.3524f, y = -342.f,z = 4.126341f; |
527 | LLVector3 vec3(x,y,z); | 534 | LLVector3 vec3(x,y,z); |
528 | F32 mag = vec3.normVec(); | 535 | F32 mag = vec3.normVec(); |
@@ -549,6 +556,9 @@ namespace tut | |||
549 | template<> template<> | 556 | template<> template<> |
550 | void v3math_object::test<34>() | 557 | void v3math_object::test<34>() |
551 | { | 558 | { |
559 | #if (LL_RELEASE && LL_LINUX) | ||
560 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
561 | #endif | ||
552 | F32 x = 10.f, y = 20.f, z = -15.f; | 562 | F32 x = 10.f, y = 20.f, z = -15.f; |
553 | F32 x1, y1, z1; | 563 | F32 x1, y1, z1; |
554 | F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f; | 564 | F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f; |
@@ -565,4 +575,4 @@ namespace tut | |||
565 | z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz); | 575 | z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz); |
566 | ensure("2:quantize8: Fail ", (x1 == vec3a.mV[VX]) && (y1 == vec3a.mV[VY])&& (z1 == vec3a.mV[VZ])); | 576 | ensure("2:quantize8: Fail ", (x1 == vec3a.mV[VX]) && (y1 == vec3a.mV[VY])&& (z1 == vec3a.mV[VZ])); |
567 | } | 577 | } |
568 | } \ No newline at end of file | 578 | } |
diff --git a/linden/indra/test/v4color_tut.cpp b/linden/indra/test/v4color_tut.cpp new file mode 100644 index 0000000..2d1cd7e --- /dev/null +++ b/linden/indra/test/v4color_tut.cpp | |||
@@ -0,0 +1,364 @@ | |||
1 | /** | ||
2 | * @file v4color_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief v4color test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | |||
32 | #include <tut/tut.h> | ||
33 | #include "lltut.h" | ||
34 | #include "linden_common.h" | ||
35 | #include "v4coloru.h" | ||
36 | #include "llsd.h" | ||
37 | #include "v3color.h" | ||
38 | #include "v4color.h" | ||
39 | |||
40 | |||
41 | namespace tut | ||
42 | { | ||
43 | struct v4color_data | ||
44 | { | ||
45 | }; | ||
46 | typedef test_group<v4color_data> v4color_test; | ||
47 | typedef v4color_test::object v4color_object; | ||
48 | tut::v4color_test v4color_testcase("v4color"); | ||
49 | |||
50 | template<> template<> | ||
51 | void v4color_object::test<1>() | ||
52 | { | ||
53 | LLColor4 llcolor4; | ||
54 | ensure("1:LLColor4:Fail to initialize ", ((0 == llcolor4.mV[VX]) && (0 == llcolor4.mV[VY]) && (0 == llcolor4.mV[VZ])&& (1.0f == llcolor4.mV[VW]))); | ||
55 | |||
56 | F32 r = 0x20, g = 0xFFFF, b = 0xFF, a = 0xAF; | ||
57 | LLColor4 llcolor4a(r,g,b); | ||
58 | ensure("2:LLColor4:Fail to initialize ", ((r == llcolor4a.mV[VX]) && (g == llcolor4a.mV[VY]) && (b == llcolor4a.mV[VZ])&& (1.0f == llcolor4a.mV[VW]))); | ||
59 | |||
60 | LLColor4 llcolor4b(r,g,b,a); | ||
61 | ensure("3:LLColor4:Fail to initialize ", ((r == llcolor4b.mV[VX]) && (g == llcolor4b.mV[VY]) && (b == llcolor4b.mV[VZ])&& (a == llcolor4b.mV[VW]))); | ||
62 | |||
63 | const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f}; | ||
64 | LLColor4 llcolor4c(vec); | ||
65 | ensure("4:LLColor4:Fail to initialize ", ((vec[0] == llcolor4c.mV[VX]) && (vec[1] == llcolor4c.mV[VY]) && (vec[2] == llcolor4c.mV[VZ])&& (vec[3] == llcolor4c.mV[VW]))); | ||
66 | |||
67 | LLColor3 llcolor3(-2.23f,1.01f,42.3f); | ||
68 | F32 val = -.1f; | ||
69 | LLColor4 llcolor4d(llcolor3,val); | ||
70 | ensure("5:LLColor4:Fail to initialize ", ((llcolor3.mV[VX] == llcolor4d.mV[VX]) && (llcolor3.mV[VY] == llcolor4d.mV[VY]) && (llcolor3.mV[VZ] == llcolor4d.mV[VZ])&& (val == llcolor4d.mV[VW]))); | ||
71 | |||
72 | LLSD sd = llcolor4d.getValue(); | ||
73 | LLColor4 llcolor4e(sd); | ||
74 | ensure_equals("6:LLColor4:(LLSD) failed ", llcolor4d, llcolor4e); | ||
75 | |||
76 | U8 r1 = 0xF2, g1 = 0xFA, b1 = 0xBF; | ||
77 | LLColor4U color4u(r1,g1,b1); | ||
78 | LLColor4 llcolor4g(color4u); | ||
79 | const F32 SCALE = 1.f/255.f; | ||
80 | F32 r2 = r1*SCALE, g2 = g1* SCALE, b2 = b1* SCALE; | ||
81 | ensure("7:LLColor4:Fail to initialize ", ((r2 == llcolor4g.mV[VX]) && (g2 == llcolor4g.mV[VY]) && (b2 == llcolor4g.mV[VZ]))); | ||
82 | } | ||
83 | |||
84 | template<> template<> | ||
85 | void v4color_object::test<2>() | ||
86 | { | ||
87 | LLColor4 llcolor(1.0, 2.0, 3.0, 4.0); | ||
88 | LLSD llsd = llcolor.getValue(); | ||
89 | LLColor4 llcolor4(llsd), llcolor4a; | ||
90 | llcolor4a.setValue(llsd); | ||
91 | ensure("setValue: failed", (llcolor4 == llcolor4a)); | ||
92 | LLSD sd = llcolor4a.getValue(); | ||
93 | LLColor4 llcolor4b(sd); | ||
94 | ensure("getValue: Failed ", (llcolor4b == llcolor4a)); | ||
95 | } | ||
96 | |||
97 | template<> template<> | ||
98 | void v4color_object::test<3>() | ||
99 | { | ||
100 | F32 r = 0x20, g = 0xFFFF, b = 0xFF,a = 0xAF; | ||
101 | LLColor4 llcolor4(r,g,b,a); | ||
102 | llcolor4.setToBlack(); | ||
103 | ensure("setToBlack:Fail to set the black ", ((0 == llcolor4.mV[VX]) && (0 == llcolor4.mV[VY]) && (0 == llcolor4.mV[VZ])&& (1.0f == llcolor4.mV[VW]))); | ||
104 | |||
105 | llcolor4.setToWhite(); | ||
106 | ensure("setToWhite:Fail to set the white ", ((1.f == llcolor4.mV[VX]) && (1.f == llcolor4.mV[VY]) && (1.f == llcolor4.mV[VZ])&& (1.0f == llcolor4.mV[VW]))); | ||
107 | } | ||
108 | |||
109 | template<> template<> | ||
110 | void v4color_object::test<4>() | ||
111 | { | ||
112 | F32 r = 0x20, g = 0xFFFF, b = 0xFF, a = 0xAF; | ||
113 | LLColor4 llcolor4; | ||
114 | llcolor4.setVec(r,g,b); | ||
115 | ensure("1:setVec:Fail to set the values ", ((r == llcolor4.mV[VX]) && (g == llcolor4.mV[VY]) && (b == llcolor4.mV[VZ])&& (1.f == llcolor4.mV[VW]))); | ||
116 | |||
117 | llcolor4.setVec(r,g,b,a); | ||
118 | ensure("2:setVec:Fail to set the values ", ((r == llcolor4.mV[VX]) && (g == llcolor4.mV[VY]) && (b == llcolor4.mV[VZ])&& (a == llcolor4.mV[VW]))); | ||
119 | |||
120 | LLColor4 llcolor4a; | ||
121 | llcolor4a.setVec(llcolor4); | ||
122 | ensure_equals("3:setVec:Fail to set the values ", llcolor4a,llcolor4); | ||
123 | |||
124 | LLColor3 llcolor3(-2.23f,1.01f,42.3f); | ||
125 | llcolor4a.setVec(llcolor3); | ||
126 | ensure("4:setVec:Fail to set the values ", ((llcolor3.mV[VX] == llcolor4a.mV[VX]) && (llcolor3.mV[VY] == llcolor4a.mV[VY]) && (llcolor3.mV[VZ] == llcolor4a.mV[VZ]))); | ||
127 | |||
128 | F32 val = -.33f; | ||
129 | llcolor4a.setVec(llcolor3,val); | ||
130 | ensure("4:setVec:Fail to set the values ", ((llcolor3.mV[VX] == llcolor4a.mV[VX]) && (llcolor3.mV[VY] == llcolor4a.mV[VY]) && (llcolor3.mV[VZ] == llcolor4a.mV[VZ]) && (val == llcolor4a.mV[VW]))); | ||
131 | |||
132 | const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f}; | ||
133 | LLColor4 llcolor4c; | ||
134 | llcolor4c.setVec(vec); | ||
135 | ensure("5:setVec:Fail to initialize ", ((vec[0] == llcolor4c.mV[VX]) && (vec[1] == llcolor4c.mV[VY]) && (vec[2] == llcolor4c.mV[VZ])&& (vec[3] == llcolor4c.mV[VW]))); | ||
136 | |||
137 | U8 r1 = 0xF2, g1 = 0xFA, b1= 0xBF; | ||
138 | LLColor4U color4u(r1,g1,b1); | ||
139 | llcolor4.setVec(color4u); | ||
140 | const F32 SCALE = 1.f/255.f; | ||
141 | F32 r2 = r1*SCALE, g2 = g1* SCALE, b2 = b1* SCALE; | ||
142 | ensure("6:setVec:Fail to initialize ", ((r2 == llcolor4.mV[VX]) && (g2 == llcolor4.mV[VY]) && (b2 == llcolor4.mV[VZ]))); | ||
143 | } | ||
144 | |||
145 | template<> template<> | ||
146 | void v4color_object::test<5>() | ||
147 | { | ||
148 | F32 alpha = 0xAF; | ||
149 | LLColor4 llcolor4; | ||
150 | llcolor4.setAlpha(alpha); | ||
151 | ensure("setAlpha:Fail to initialize ", (alpha == llcolor4.mV[VW])); | ||
152 | } | ||
153 | |||
154 | template<> template<> | ||
155 | void v4color_object::test<6>() | ||
156 | { | ||
157 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
158 | LLColor4 llcolor4(r,g,b); | ||
159 | ensure("magVecSquared:Fail ", is_approx_equal(llcolor4.magVecSquared(), (r*r + g*g + b*b))); | ||
160 | ensure("magVec:Fail ", is_approx_equal(llcolor4.magVec(), fsqrtf(r*r + g*g + b*b))); | ||
161 | } | ||
162 | |||
163 | template<> template<> | ||
164 | void v4color_object::test<7>() | ||
165 | { | ||
166 | #if (LL_RELEASE && LL_LINUX) | ||
167 | skip_fail("Doesn't work under Linux -- FIX ME!"); | ||
168 | #endif | ||
169 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
170 | LLColor4 llcolor4(r,g,b); | ||
171 | F32 vecMag = llcolor4.normVec(); | ||
172 | F32 mag = fsqrtf(r*r + g*g + b*b); | ||
173 | F32 oomag = 1.f / mag; | ||
174 | F32 val1 = r * oomag, val2 = g * oomag, val3 = b * oomag; | ||
175 | ensure("1:normVec failed ", (val1 == llcolor4.mV[0] && val2 == llcolor4.mV[1] && val3 == llcolor4.mV[2] && vecMag == mag)); | ||
176 | } | ||
177 | |||
178 | template<> template<> | ||
179 | void v4color_object::test<8>() | ||
180 | { | ||
181 | LLColor4 llcolor4; | ||
182 | ensure("1:isOpaque failed ",(1 == llcolor4.isOpaque())); | ||
183 | F32 r = 0x20, g = 0xFFFF, b = 0xFF,a = 1.f; | ||
184 | llcolor4.setVec(r,g,b,a); | ||
185 | ensure("2:isOpaque failed ",(1 == llcolor4.isOpaque())); | ||
186 | a = 2.f; | ||
187 | llcolor4.setVec(r,g,b,a); | ||
188 | ensure("3:isOpaque failed ",(0 == llcolor4.isOpaque())); | ||
189 | } | ||
190 | |||
191 | template<> template<> | ||
192 | void v4color_object::test<9>() | ||
193 | { | ||
194 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
195 | LLColor4 llcolor4(r,g,b); | ||
196 | ensure("1:operator [] failed",( r == llcolor4[0])); | ||
197 | ensure("2:operator [] failed",( g == llcolor4[1])); | ||
198 | ensure("3:operator [] failed",( b == llcolor4[2])); | ||
199 | |||
200 | r = 0xA20, g = 0xFBFF, b = 0xFFF; | ||
201 | llcolor4.setVec(r,g,b); | ||
202 | F32 &ref1 = llcolor4[0]; | ||
203 | ensure("4:operator [] failed",( ref1 == llcolor4[0])); | ||
204 | F32 &ref2 = llcolor4[1]; | ||
205 | ensure("5:operator [] failed",( ref2 == llcolor4[1])); | ||
206 | F32 &ref3 = llcolor4[2]; | ||
207 | ensure("6:operator [] failed",( ref3 == llcolor4[2])); | ||
208 | } | ||
209 | |||
210 | template<> template<> | ||
211 | void v4color_object::test<10>() | ||
212 | { | ||
213 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
214 | LLColor3 llcolor3(r,g,b); | ||
215 | LLColor4 llcolor4a,llcolor4b; | ||
216 | llcolor4a = llcolor3; | ||
217 | ensure("Operator=:Fail to initialize ", ((llcolor3.mV[0] == llcolor4a.mV[VX]) && (llcolor3.mV[1] == llcolor4a.mV[VY]) && (llcolor3.mV[2] == llcolor4a.mV[VZ]))); | ||
218 | LLSD sd = llcolor4a.getValue(); | ||
219 | llcolor4b = sd; | ||
220 | ensure_equals("Operator= LLSD:Fail ", llcolor4a, llcolor4b); | ||
221 | } | ||
222 | |||
223 | template<> template<> | ||
224 | void v4color_object::test<11>() | ||
225 | { | ||
226 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
227 | std::ostringstream stream1, stream2; | ||
228 | LLColor4 llcolor4a(r,g,b),llcolor4b; | ||
229 | stream1 << llcolor4a; | ||
230 | llcolor4b.setVec(r,g,b); | ||
231 | stream2 << llcolor4b; | ||
232 | ensure("operator << failed ", (stream1.str() == stream2.str())); | ||
233 | } | ||
234 | |||
235 | template<> template<> | ||
236 | void v4color_object::test<12>() | ||
237 | { | ||
238 | F32 r1 = 0x20, g1 = 0xFFFF, b1 = 0xFF; | ||
239 | F32 r2 = 0xABF, g2 = 0xFB, b2 = 0xFFF; | ||
240 | LLColor4 llcolor4a(r1,g1,b1),llcolor4b(r2,g2,b2),llcolor4c; | ||
241 | llcolor4c = llcolor4b + llcolor4a; | ||
242 | ensure("operator+:Fail to Add the values ", (is_approx_equal(r1+r2,llcolor4c.mV[VX]) && is_approx_equal(g1+g2,llcolor4c.mV[VY]) && is_approx_equal(b1+b2,llcolor4c.mV[VZ]))); | ||
243 | |||
244 | llcolor4b += llcolor4a; | ||
245 | ensure("operator+=:Fail to Add the values ", (is_approx_equal(r1+r2,llcolor4b.mV[VX]) && is_approx_equal(g1+g2,llcolor4b.mV[VY]) && is_approx_equal(b1+b2,llcolor4b.mV[VZ]))); | ||
246 | } | ||
247 | |||
248 | template<> template<> | ||
249 | void v4color_object::test<13>() | ||
250 | { | ||
251 | F32 r1 = 0x20, g1 = 0xFFFF, b1 = 0xFF; | ||
252 | F32 r2 = 0xABF, g2 = 0xFB, b2 = 0xFFF; | ||
253 | LLColor4 llcolor4a(r1,g1,b1),llcolor4b(r2,g2,b2),llcolor4c; | ||
254 | llcolor4c = llcolor4a - llcolor4b; | ||
255 | ensure("operator-:Fail to subtract the values ", (is_approx_equal(r1-r2,llcolor4c.mV[VX]) && is_approx_equal(g1-g2,llcolor4c.mV[VY]) && is_approx_equal(b1-b2,llcolor4c.mV[VZ]))); | ||
256 | |||
257 | llcolor4a -= llcolor4b; | ||
258 | ensure("operator-=:Fail to subtract the values ", (is_approx_equal(r1-r2,llcolor4a.mV[VX]) && is_approx_equal(g1-g2,llcolor4a.mV[VY]) && is_approx_equal(b1-b2,llcolor4a.mV[VZ]))); | ||
259 | } | ||
260 | |||
261 | template<> template<> | ||
262 | void v4color_object::test<14>() | ||
263 | { | ||
264 | F32 r1 = 0x20, g1 = 0xFFFF, b1 = 0xFF; | ||
265 | F32 r2 = 0xABF, g2 = 0xFB, b2 = 0xFFF; | ||
266 | LLColor4 llcolor4a(r1,g1,b1),llcolor4b(r2,g2,b2),llcolor4c; | ||
267 | llcolor4c = llcolor4a * llcolor4b; | ||
268 | ensure("1:operator*:Fail to multiply the values", (is_approx_equal(r1*r2,llcolor4c.mV[VX]) && is_approx_equal(g1*g2,llcolor4c.mV[VY]) && is_approx_equal(b1*b2,llcolor4c.mV[VZ]))); | ||
269 | |||
270 | F32 mulVal = 3.33f; | ||
271 | llcolor4c = llcolor4a * mulVal; | ||
272 | ensure("2:operator*:Fail ", (is_approx_equal(r1*mulVal,llcolor4c.mV[VX]) && is_approx_equal(g1*mulVal,llcolor4c.mV[VY]) && is_approx_equal(b1*mulVal,llcolor4c.mV[VZ]))); | ||
273 | llcolor4c = mulVal * llcolor4a; | ||
274 | ensure("3:operator*:Fail to multiply the values", (is_approx_equal(r1*mulVal,llcolor4c.mV[VX]) && is_approx_equal(g1*mulVal,llcolor4c.mV[VY]) && is_approx_equal(b1*mulVal,llcolor4c.mV[VZ]))); | ||
275 | |||
276 | llcolor4a *= mulVal; | ||
277 | ensure("4:operator*=:Fail to multiply the values ", (is_approx_equal(r1*mulVal,llcolor4a.mV[VX]) && is_approx_equal(g1*mulVal,llcolor4a.mV[VY]) && is_approx_equal(b1*mulVal,llcolor4a.mV[VZ]))); | ||
278 | |||
279 | LLColor4 llcolor4d(r1,g1,b1),llcolor4e(r2,g2,b2); | ||
280 | llcolor4e *= llcolor4d; | ||
281 | ensure("5:operator*=:Fail to multiply the values ", (is_approx_equal(r1*r2,llcolor4e.mV[VX]) && is_approx_equal(g1*g2,llcolor4e.mV[VY]) && is_approx_equal(b1*b2,llcolor4e.mV[VZ]))); | ||
282 | } | ||
283 | |||
284 | template<> template<> | ||
285 | void v4color_object::test<15>() | ||
286 | { | ||
287 | F32 r = 0x20, g = 0xFFFF, b = 0xFF,a = 0x30; | ||
288 | F32 div = 12.345f; | ||
289 | LLColor4 llcolor4a(r,g,b,a),llcolor4b; | ||
290 | llcolor4b = llcolor4a % div;//chnage only alpha value nor r,g,b; | ||
291 | ensure("1operator%:Fail ", (is_approx_equal(r,llcolor4b.mV[VX]) && is_approx_equal(g,llcolor4b.mV[VY]) && is_approx_equal(b,llcolor4b.mV[VZ])&& is_approx_equal(div*a,llcolor4b.mV[VW]))); | ||
292 | |||
293 | llcolor4b = div % llcolor4a; | ||
294 | ensure("2operator%:Fail ", (is_approx_equal(r,llcolor4b.mV[VX]) && is_approx_equal(g,llcolor4b.mV[VY]) && is_approx_equal(b,llcolor4b.mV[VZ])&& is_approx_equal(div*a,llcolor4b.mV[VW]))); | ||
295 | |||
296 | llcolor4a %= div; | ||
297 | ensure("operator%=:Fail ", (is_approx_equal(a*div,llcolor4a.mV[VW]))); | ||
298 | } | ||
299 | |||
300 | template<> template<> | ||
301 | void v4color_object::test<16>() | ||
302 | { | ||
303 | F32 r = 0x20, g = 0xFFFF, b = 0xFF,a = 0x30; | ||
304 | LLColor4 llcolor4a(r,g,b,a),llcolor4b; | ||
305 | llcolor4b = llcolor4a; | ||
306 | ensure("1:operator== failed to ensure the equality ", (llcolor4b == llcolor4a)); | ||
307 | F32 r1 = 0x2, g1 = 0xFF, b1 = 0xFA; | ||
308 | LLColor3 llcolor3(r1,g1,b1); | ||
309 | llcolor4b = llcolor3; | ||
310 | ensure("2:operator== failed to ensure the equality ", (llcolor4b == llcolor3)); | ||
311 | ensure("2:operator!= failed to ensure the equality ", (llcolor4a != llcolor3)); | ||
312 | } | ||
313 | |||
314 | template<> template<> | ||
315 | void v4color_object::test<17>() | ||
316 | { | ||
317 | F32 r = 0x20, g = 0xFFFF, b = 0xFF; | ||
318 | LLColor4 llcolor4a(r,g,b),llcolor4b; | ||
319 | LLColor3 llcolor3 = vec4to3(llcolor4a); | ||
320 | ensure("vec4to3:Fail to convert vec4 to vec3 ", (is_approx_equal(llcolor3.mV[VX],llcolor4a.mV[VX]) && is_approx_equal(llcolor3.mV[VY],llcolor4a.mV[VY]) && is_approx_equal(llcolor3.mV[VZ],llcolor4a.mV[VZ]))); | ||
321 | llcolor4b = vec3to4(llcolor3); | ||
322 | ensure_equals("vec3to4:Fail to convert vec3 to vec4 ", llcolor4b, llcolor4a); | ||
323 | } | ||
324 | |||
325 | template<> template<> | ||
326 | void v4color_object::test<18>() | ||
327 | { | ||
328 | F32 r1 = 0x20, g1 = 0xFFFF, b1 = 0xFF, val = 0x20; | ||
329 | F32 r2 = 0xABF, g2 = 0xFB, b2 = 0xFFF; | ||
330 | LLColor4 llcolor4a(r1,g1,b1),llcolor4b(r2,g2,b2),llcolor4c; | ||
331 | llcolor4c = lerp(llcolor4a,llcolor4b,val); | ||
332 | ensure("lerp:Fail ", (is_approx_equal(r1 + (r2 - r1)* val,llcolor4c.mV[VX]) && is_approx_equal(g1 + (g2 - g1)* val,llcolor4c.mV[VY]) && is_approx_equal(b1 + (b2 - b1)* val,llcolor4c.mV[VZ]))); | ||
333 | } | ||
334 | |||
335 | template<> template<> | ||
336 | void v4color_object::test<19>() | ||
337 | { | ||
338 | F32 r = 12.0f, g = -2.3f, b = 1.32f, a = 5.0f; | ||
339 | LLColor4 llcolor4a(r,g,b,a),llcolor4b; | ||
340 | const char *color = "red"; | ||
341 | LLColor4::parseColor(color, &llcolor4b); | ||
342 | ensure_equals("1:parseColor() failed to parse the color value ", llcolor4b, LLColor4::red); | ||
343 | |||
344 | color = "12.0, -2.3, 1.32, 5.0"; | ||
345 | LLColor4::parseColor(color, &llcolor4b); | ||
346 | llcolor4a = llcolor4a * (1.f / 255.f); | ||
347 | ensure_equals("2:parseColor() failed to parse the color value ", llcolor4a,llcolor4b); | ||
348 | |||
349 | color = "yellow5"; | ||
350 | llcolor4a.setVec(r,g,b); | ||
351 | LLColor4::parseColor(color, &llcolor4a); | ||
352 | ensure_equals("3:parseColor() failed to parse the color value ", llcolor4a, LLColor4::yellow5); | ||
353 | } | ||
354 | |||
355 | template<> template<> | ||
356 | void v4color_object::test<20>() | ||
357 | { | ||
358 | F32 r = 12.0f, g = -2.3f, b = 1.32f, a = 5.0f; | ||
359 | LLColor4 llcolor4a(r,g,b,a),llcolor4b; | ||
360 | const char *color = "12.0, -2.3, 1.32, 5.0"; | ||
361 | LLColor4::parseColor4(color, &llcolor4b); | ||
362 | ensure_equals("parseColor4() failed to parse the color value ", llcolor4a, llcolor4b); | ||
363 | } | ||
364 | } | ||
diff --git a/linden/indra/test/v4coloru_tut.cpp b/linden/indra/test/v4coloru_tut.cpp new file mode 100644 index 0000000..f671cf1 --- /dev/null +++ b/linden/indra/test/v4coloru_tut.cpp | |||
@@ -0,0 +1,337 @@ | |||
1 | /** | ||
2 | * @file v4coloru_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief v4coloru test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | |||
32 | #include <tut/tut.h> | ||
33 | #include "lltut.h" | ||
34 | #include "linden_common.h" | ||
35 | #include "llsd.h" | ||
36 | #include "v4coloru.h" | ||
37 | |||
38 | |||
39 | namespace tut | ||
40 | { | ||
41 | struct v4coloru_data | ||
42 | { | ||
43 | }; | ||
44 | typedef test_group<v4coloru_data> v4coloru_test; | ||
45 | typedef v4coloru_test::object v4coloru_object; | ||
46 | tut::v4coloru_test v4coloru_testcase("v4coloru"); | ||
47 | |||
48 | template<> template<> | ||
49 | void v4coloru_object::test<1>() | ||
50 | { | ||
51 | LLColor4U llcolor4u; | ||
52 | ensure("1:LLColor4u:Fail to initialize ", ((0 == llcolor4u.mV[VX]) && (0 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); | ||
53 | |||
54 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23; | ||
55 | LLColor4U llcolor4u1(r,g,b); | ||
56 | ensure("2:LLColor4u:Fail to initialize ", ((r == llcolor4u1.mV[VX]) && (g == llcolor4u1.mV[VY]) && (b == llcolor4u1.mV[VZ])&& (255 == llcolor4u1.mV[VW]))); | ||
57 | |||
58 | LLColor4U llcolor4u2(r,g,b,a); | ||
59 | ensure("3:LLColor4u:Fail to initialize ", ((r == llcolor4u2.mV[VX]) && (g == llcolor4u2.mV[VY]) && (b == llcolor4u2.mV[VZ])&& (a == llcolor4u2.mV[VW]))); | ||
60 | |||
61 | const U8 vec[4] = {0x12,0xFF,0xAF,0x23}; | ||
62 | LLColor4U llcolor4u3(vec); | ||
63 | ensure("4:LLColor4u:Fail to initialize ", ((vec[0] == llcolor4u3.mV[VX]) && (vec[1] == llcolor4u3.mV[VY]) && (vec[2] == llcolor4u3.mV[VZ])&& (vec[3] == llcolor4u3.mV[VW]))); | ||
64 | |||
65 | LLSD sd = llcolor4u3.getValue(); | ||
66 | LLColor4U llcolor4u4(sd); | ||
67 | ensure_equals("5:LLColor4u (LLSD) Failed ", llcolor4u4, llcolor4u3); | ||
68 | } | ||
69 | |||
70 | template<> template<> | ||
71 | void v4coloru_object::test<2>() | ||
72 | { | ||
73 | LLColor4U llcolor4ua(1, 2, 3, 4); | ||
74 | LLSD sd = llcolor4ua.getValue(); | ||
75 | LLColor4U llcolor4u; | ||
76 | llcolor4u.setValue(sd); | ||
77 | ensure_equals("setValue(LLSD)/getValue Failed ", llcolor4u, llcolor4ua); | ||
78 | } | ||
79 | |||
80 | template<> template<> | ||
81 | void v4coloru_object::test<3>() | ||
82 | { | ||
83 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23; | ||
84 | LLColor4U llcolor4u(r,g,b,a); | ||
85 | llcolor4u.setToBlack(); | ||
86 | ensure("setToBlack:Fail to set black ", ((0 == llcolor4u.mV[VX]) && (0 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); | ||
87 | |||
88 | llcolor4u.setToWhite(); | ||
89 | ensure("setToWhite:Fail to white ", ((255 == llcolor4u.mV[VX]) && (255 == llcolor4u.mV[VY]) && (255 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); | ||
90 | } | ||
91 | |||
92 | template<> template<> | ||
93 | void v4coloru_object::test<4>() | ||
94 | { | ||
95 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23; | ||
96 | LLColor4U llcolor4ua(r,g,b,a); | ||
97 | LLSD sd = llcolor4ua.getValue(); | ||
98 | LLColor4U llcolor4u = sd; | ||
99 | ensure_equals("Operator=(LLSD) Failed ", llcolor4u, llcolor4ua); | ||
100 | } | ||
101 | |||
102 | template<> template<> | ||
103 | void v4coloru_object::test<5>() | ||
104 | { | ||
105 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 0x23; | ||
106 | LLColor4U llcolor4u; | ||
107 | llcolor4u.setVec(r,g,b,a); | ||
108 | ensure("1:setVec:Fail to set the values ", ((r == llcolor4u.mV[VX]) && (g == llcolor4u.mV[VY]) && (b == llcolor4u.mV[VZ])&& (a == llcolor4u.mV[VW]))); | ||
109 | |||
110 | llcolor4u.setToBlack(); | ||
111 | llcolor4u.setVec(r,g,b); | ||
112 | ensure("2:setVec:Fail to set the values ", ((r == llcolor4u.mV[VX]) && (g == llcolor4u.mV[VY]) && (b == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); | ||
113 | |||
114 | LLColor4U llcolor4u1; | ||
115 | llcolor4u1.setVec(llcolor4u); | ||
116 | ensure_equals("3:setVec:Fail to set the values ", llcolor4u1,llcolor4u); | ||
117 | |||
118 | const U8 vec[4] = {0x12,0xFF,0xAF,0x23}; | ||
119 | LLColor4U llcolor4u2; | ||
120 | llcolor4u2.setVec(vec); | ||
121 | ensure("4:setVec:Fail to set the values ", ((vec[0] == llcolor4u2.mV[VX]) && (vec[1] == llcolor4u2.mV[VY]) && (vec[2] == llcolor4u2.mV[VZ])&& (vec[3] == llcolor4u2.mV[VW]))); | ||
122 | } | ||
123 | |||
124 | template<> template<> | ||
125 | void v4coloru_object::test<6>() | ||
126 | { | ||
127 | U8 alpha = 0x12; | ||
128 | LLColor4U llcolor4u; | ||
129 | llcolor4u.setAlpha(alpha); | ||
130 | ensure("setAlpha:Fail to set alpha value ", (alpha == llcolor4u.mV[VW])); | ||
131 | } | ||
132 | |||
133 | template<> template<> | ||
134 | void v4coloru_object::test<7>() | ||
135 | { | ||
136 | U8 r = 0x12, g = 0xFF, b = 0xAF; | ||
137 | LLColor4U llcolor4u(r,g,b); | ||
138 | ensure("magVecSquared:Fail ", is_approx_equal(llcolor4u.magVecSquared(), (F32)(r*r + g*g + b*b))); | ||
139 | ensure("magVec:Fail ", is_approx_equal(llcolor4u.magVec(), fsqrtf(r*r + g*g + b*b))); | ||
140 | } | ||
141 | |||
142 | template<> template<> | ||
143 | void v4coloru_object::test<8>() | ||
144 | { | ||
145 | U8 r = 0x12, g = 0xFF, b = 0xAF; | ||
146 | std::ostringstream stream1, stream2; | ||
147 | LLColor4U llcolor4u1(r,g,b),llcolor4u2; | ||
148 | stream1 << llcolor4u1; | ||
149 | llcolor4u2.setVec(r,g,b); | ||
150 | stream2 << llcolor4u2; | ||
151 | ensure("operator << failed ", (stream1.str() == stream2.str())); | ||
152 | } | ||
153 | |||
154 | template<> template<> | ||
155 | void v4coloru_object::test<9>() | ||
156 | { | ||
157 | U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF; | ||
158 | U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B; | ||
159 | LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3; | ||
160 | llcolor4u3 = llcolor4u1 + llcolor4u2; | ||
161 | ensure_equals( | ||
162 | "1a.operator+:Fail to Add the values ", | ||
163 | llcolor4u3.mV[VX], | ||
164 | (U8)(r1+r2)); | ||
165 | ensure_equals( | ||
166 | "1b.operator+:Fail to Add the values ", | ||
167 | llcolor4u3.mV[VY], | ||
168 | (U8)(g1+g2)); | ||
169 | ensure_equals( | ||
170 | "1c.operator+:Fail to Add the values ", | ||
171 | llcolor4u3.mV[VZ], | ||
172 | (U8)(b1+b2)); | ||
173 | |||
174 | llcolor4u2 += llcolor4u1; | ||
175 | ensure_equals( | ||
176 | "2a.operator+=:Fail to Add the values ", | ||
177 | llcolor4u2.mV[VX], | ||
178 | (U8)(r1+r2)); | ||
179 | ensure_equals( | ||
180 | "2b.operator+=:Fail to Add the values ", | ||
181 | llcolor4u2.mV[VY], | ||
182 | (U8)(g1+g2)); | ||
183 | ensure_equals( | ||
184 | "2c.operator+=:Fail to Add the values ", | ||
185 | llcolor4u2.mV[VZ], | ||
186 | (U8)(b1+b2)); | ||
187 | } | ||
188 | |||
189 | template<> template<> | ||
190 | void v4coloru_object::test<10>() | ||
191 | { | ||
192 | U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF; | ||
193 | U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B; | ||
194 | LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3; | ||
195 | llcolor4u3 = llcolor4u1 - llcolor4u2; | ||
196 | ensure_equals( | ||
197 | "1a. operator-:Fail to Add the values ", | ||
198 | llcolor4u3.mV[VX], | ||
199 | (U8)(r1-r2)); | ||
200 | ensure_equals( | ||
201 | "1b. operator-:Fail to Add the values ", | ||
202 | llcolor4u3.mV[VY], | ||
203 | (U8)(g1-g2)); | ||
204 | ensure_equals( | ||
205 | "1c. operator-:Fail to Add the values ", | ||
206 | llcolor4u3.mV[VZ], | ||
207 | (U8)(b1-b2)); | ||
208 | |||
209 | llcolor4u1 -= llcolor4u2; | ||
210 | ensure_equals( | ||
211 | "2a. operator-=:Fail to Add the values ", | ||
212 | llcolor4u1.mV[VX], | ||
213 | (U8)(r1-r2)); | ||
214 | ensure_equals( | ||
215 | "2b. operator-=:Fail to Add the values ", | ||
216 | llcolor4u1.mV[VY], | ||
217 | (U8)(g1-g2)); | ||
218 | ensure_equals( | ||
219 | "2c. operator-=:Fail to Add the values ", | ||
220 | llcolor4u1.mV[VZ], | ||
221 | (U8)(b1-b2)); | ||
222 | } | ||
223 | |||
224 | template<> template<> | ||
225 | void v4coloru_object::test<11>() | ||
226 | { | ||
227 | U8 r1 = 0x12, g1 = 0xFF, b1 = 0xAF; | ||
228 | U8 r2 = 0x1C, g2 = 0x9A, b2 = 0x1B; | ||
229 | LLColor4U llcolor4u1(r1,g1,b1), llcolor4u2(r2,g2,b2),llcolor4u3; | ||
230 | llcolor4u3 = llcolor4u1 * llcolor4u2; | ||
231 | ensure_equals( | ||
232 | "1a. operator*:Fail to multiply the values", | ||
233 | llcolor4u3.mV[VX], | ||
234 | (U8)(r1*r2)); | ||
235 | ensure_equals( | ||
236 | "1b. operator*:Fail to multiply the values", | ||
237 | llcolor4u3.mV[VY], | ||
238 | (U8)(g1*g2)); | ||
239 | ensure_equals( | ||
240 | "1c. operator*:Fail to multiply the values", | ||
241 | llcolor4u3.mV[VZ], | ||
242 | (U8)(b1*b2)); | ||
243 | |||
244 | U8 mulVal = 123; | ||
245 | llcolor4u1 *= mulVal; | ||
246 | ensure_equals( | ||
247 | "2a. operator*=:Fail to multiply the values", | ||
248 | llcolor4u1.mV[VX], | ||
249 | (U8)(r1*mulVal)); | ||
250 | ensure_equals( | ||
251 | "2b. operator*=:Fail to multiply the values", | ||
252 | llcolor4u1.mV[VY], | ||
253 | (U8)(g1*mulVal)); | ||
254 | ensure_equals( | ||
255 | "2c. operator*=:Fail to multiply the values", | ||
256 | llcolor4u1.mV[VZ], | ||
257 | (U8)(b1*mulVal)); | ||
258 | } | ||
259 | |||
260 | template<> template<> | ||
261 | void v4coloru_object::test<12>() | ||
262 | { | ||
263 | U8 r = 0x12, g = 0xFF, b = 0xAF; | ||
264 | LLColor4U llcolor4u(r,g,b),llcolor4u1; | ||
265 | llcolor4u1 = llcolor4u; | ||
266 | ensure("operator== failed to ensure the equality ", (llcolor4u1 == llcolor4u)); | ||
267 | llcolor4u1.setToBlack(); | ||
268 | ensure("operator!= failed to ensure the equality ", (llcolor4u1 != llcolor4u)); | ||
269 | } | ||
270 | |||
271 | template<> template<> | ||
272 | void v4coloru_object::test<13>() | ||
273 | { | ||
274 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 12; | ||
275 | LLColor4U llcolor4u(r,g,b,a); | ||
276 | U8 modVal = 45; | ||
277 | llcolor4u %= modVal; | ||
278 | ensure_equals("operator%=:Fail ", llcolor4u.mV[VW], (U8)(a * modVal)); | ||
279 | } | ||
280 | |||
281 | template<> template<> | ||
282 | void v4coloru_object::test<14>() | ||
283 | { | ||
284 | U8 r = 0x12, g = 0xFF, b = 0xAF, a = 12; | ||
285 | LLColor4U llcolor4u1(r,g,b,a); | ||
286 | const char *color = "12, 23, 132, 50"; | ||
287 | LLColor4U::parseColor4U(color, &llcolor4u1); | ||
288 | ensure("parseColor4U() failed to parse the color value ", ((12 == llcolor4u1.mV[VX]) && (23 == llcolor4u1.mV[VY]) && (132 == llcolor4u1.mV[VZ])&& (50 == llcolor4u1.mV[VW]))); | ||
289 | |||
290 | color = "12, 23, 132"; | ||
291 | ensure("2:parseColor4U() failed to parse the color value ", (FALSE == LLColor4U::parseColor4U(color, &llcolor4u1))); | ||
292 | |||
293 | color = "12"; | ||
294 | ensure("2:parseColor4U() failed to parse the color value ", (FALSE == LLColor4U::parseColor4U(color, &llcolor4u1))); | ||
295 | } | ||
296 | |||
297 | template<> template<> | ||
298 | void v4coloru_object::test<15>() | ||
299 | { | ||
300 | U8 r = 12, g = 123, b = 3, a = 2; | ||
301 | LLColor4U llcolor4u(r,g,b,a),llcolor4u1; | ||
302 | const F32 fVal = 3.f; | ||
303 | llcolor4u1 = llcolor4u.multAll(fVal); | ||
304 | ensure("multAll:Fail to multiply ", (((U8)llround(r * fVal) == llcolor4u1.mV[VX]) && (U8)llround(g * fVal) == llcolor4u1.mV[VY] | ||
305 | && ((U8)llround(b * fVal) == llcolor4u1.mV[VZ])&& ((U8)llround(a * fVal) == llcolor4u1.mV[VW]))); | ||
306 | } | ||
307 | |||
308 | template<> template<> | ||
309 | void v4coloru_object::test<16>() | ||
310 | { | ||
311 | U8 r1 = 12, g1 = 123, b1 = 3, a1 = 2; | ||
312 | U8 r2 = 23, g2 = 230, b2 = 124, a2 = 255; | ||
313 | LLColor4U llcolor4u(r1,g1,b1,a1),llcolor4u1(r2,g2,b2,a2); | ||
314 | llcolor4u1 = llcolor4u1.addClampMax(llcolor4u); | ||
315 | ensure("1:addClampMax():Fail to add the value ", ((r1+r2 == llcolor4u1.mV[VX]) && (255 == llcolor4u1.mV[VY]) && (b1+b2 == llcolor4u1.mV[VZ])&& (255 == llcolor4u1.mV[VW]))); | ||
316 | |||
317 | r1 = 132, g1 = 3, b1 = 3, a1 = 2; | ||
318 | r2 = 123, g2 = 230, b2 = 154, a2 = 25; | ||
319 | LLColor4U llcolor4u2(r1,g1,b1,a1),llcolor4u3(r2,g2,b2,a2); | ||
320 | llcolor4u3 = llcolor4u3.addClampMax(llcolor4u2); | ||
321 | ensure("2:addClampMax():Fail to add the value ", ((255 == llcolor4u3.mV[VX]) && (g1+g2 == llcolor4u3.mV[VY]) && (b1+b2 == llcolor4u3.mV[VZ])&& (a1+a2 == llcolor4u3.mV[VW]))); | ||
322 | } | ||
323 | |||
324 | template<> template<> | ||
325 | void v4coloru_object::test<17>() | ||
326 | { | ||
327 | F32 r = 23.f, g = 12.32f, b = -12.3f; | ||
328 | LLColor3 color3(r,g,b); | ||
329 | LLColor4U llcolor4u; | ||
330 | llcolor4u.setVecScaleClamp(color3); | ||
331 | const S32 MAX_COLOR = 255; | ||
332 | F32 color_scale_factor = MAX_COLOR/r; | ||
333 | S32 r2 = llround(r * color_scale_factor); | ||
334 | S32 g2 = llround(g * color_scale_factor); | ||
335 | ensure("setVecScaleClamp():Fail to add the value ", ((r2 == llcolor4u.mV[VX]) && (g2 == llcolor4u.mV[VY]) && (0 == llcolor4u.mV[VZ])&& (255 == llcolor4u.mV[VW]))); | ||
336 | } | ||
337 | } | ||
diff --git a/linden/indra/test/v4math_tut.cpp b/linden/indra/test/v4math_tut.cpp new file mode 100644 index 0000000..055e825 --- /dev/null +++ b/linden/indra/test/v4math_tut.cpp | |||
@@ -0,0 +1,379 @@ | |||
1 | /** | ||
2 | * @file v4math_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief v4math test cases. | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llquaternion.h" | ||
35 | #include "llsd.h" | ||
36 | #include "m4math.h" | ||
37 | #include "v4math.h" | ||
38 | |||
39 | namespace tut | ||
40 | { | ||
41 | struct v4math_data | ||
42 | { | ||
43 | }; | ||
44 | typedef test_group<v4math_data> v4math_test; | ||
45 | typedef v4math_test::object v4math_object; | ||
46 | tut::v4math_test v4math_testcase("v4math"); | ||
47 | |||
48 | template<> template<> | ||
49 | void v4math_object::test<1>() | ||
50 | { | ||
51 | LLVector4 vec4; | ||
52 | ensure("1:LLVector4:Fail to initialize " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (1.0f == vec4.mV[VW]))); | ||
53 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
54 | LLVector4 vec4a(x,y,z); | ||
55 | ensure("2:LLVector4:Fail to initialize " ,((x == vec4a.mV[VX]) && (y == vec4a.mV[VY]) && (z == vec4a.mV[VZ])&& (1.0f == vec4a.mV[VW]))); | ||
56 | LLVector4 vec4b(x,y,z,w); | ||
57 | ensure("3:LLVector4:Fail to initialize " ,((x == vec4b.mV[VX]) && (y == vec4b.mV[VY]) && (z == vec4b.mV[VZ])&& (w == vec4b.mV[VW]))); | ||
58 | const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f}; | ||
59 | LLVector4 vec4c(vec); | ||
60 | ensure("4:LLVector4:Fail to initialize " ,((vec[0] == vec4c.mV[VX]) && (vec[1] == vec4c.mV[VY]) && (vec[2] == vec4c.mV[VZ])&& (vec[3] == vec4c.mV[VW]))); | ||
61 | LLVector3 vec3(-2.23f,1.01f,42.3f); | ||
62 | LLVector4 vec4d(vec3); | ||
63 | ensure("5:LLVector4:Fail to initialize " ,((vec3.mV[VX] == vec4d.mV[VX]) && (vec3.mV[VY] == vec4d.mV[VY]) && (vec3.mV[VZ] == vec4d.mV[VZ])&& (1.f == vec4d.mV[VW]))); | ||
64 | F32 w1 = -.234f; | ||
65 | LLVector4 vec4e(vec3,w1); | ||
66 | ensure("6:LLVector4:Fail to initialize " ,((vec3.mV[VX] == vec4e.mV[VX]) && (vec3.mV[VY] == vec4e.mV[VY]) && (vec3.mV[VZ] == vec4e.mV[VZ])&& (w1 == vec4e.mV[VW]))); | ||
67 | } | ||
68 | |||
69 | template<> template<> | ||
70 | void v4math_object::test<2>() | ||
71 | { | ||
72 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
73 | LLVector4 vec4; | ||
74 | vec4.setVec(x,y,z); | ||
75 | ensure("1:setVec:Fail to initialize " ,((x == vec4.mV[VX]) && (y == vec4.mV[VY]) && (z == vec4.mV[VZ])&& (1.0f == vec4.mV[VW]))); | ||
76 | vec4.clearVec(); | ||
77 | ensure("2:clearVec:Fail " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (1.0f == vec4.mV[VW]))); | ||
78 | vec4.setVec(x,y,z,w); | ||
79 | ensure("3:setVec:Fail to initialize " ,((x == vec4.mV[VX]) && (y == vec4.mV[VY]) && (z == vec4.mV[VZ])&& (w == vec4.mV[VW]))); | ||
80 | vec4.zeroVec(); | ||
81 | ensure("4:zeroVec:Fail " ,((0 == vec4.mV[VX]) && (0 == vec4.mV[VY]) && (0 == vec4.mV[VZ])&& (0 == vec4.mV[VW]))); | ||
82 | LLVector3 vec3(-2.23f,1.01f,42.3f); | ||
83 | vec4.clearVec(); | ||
84 | vec4.setVec(vec3); | ||
85 | ensure("5:setVec:Fail to initialize " ,((vec3.mV[VX] == vec4.mV[VX]) && (vec3.mV[VY] == vec4.mV[VY]) && (vec3.mV[VZ] == vec4.mV[VZ])&& (1.f == vec4.mV[VW]))); | ||
86 | F32 w1 = -.234f; | ||
87 | vec4.zeroVec(); | ||
88 | vec4.setVec(vec3,w1); | ||
89 | ensure("6:setVec:Fail to initialize " ,((vec3.mV[VX] == vec4.mV[VX]) && (vec3.mV[VY] == vec4.mV[VY]) && (vec3.mV[VZ] == vec4.mV[VZ])&& (w1 == vec4.mV[VW]))); | ||
90 | const F32 vec[4] = {.112f ,23.2f, -4.2f, -.0001f}; | ||
91 | LLVector4 vec4a; | ||
92 | vec4a.setVec(vec); | ||
93 | ensure("7:setVec:Fail to initialize " ,((vec[0] == vec4a.mV[VX]) && (vec[1] == vec4a.mV[VY]) && (vec[2] == vec4a.mV[VZ])&& (vec[3] == vec4a.mV[VW]))); | ||
94 | } | ||
95 | |||
96 | template<> template<> | ||
97 | void v4math_object::test<3>() | ||
98 | { | ||
99 | F32 x = 10.f, y = -2.3f, z = -.023f; | ||
100 | LLVector4 vec4(x,y,z); | ||
101 | ensure("magVec:Fail ", is_approx_equal(vec4.magVec(), fsqrtf(x*x + y*y + z*z))); | ||
102 | ensure("magVecSquared:Fail ", is_approx_equal(vec4.magVecSquared(), (x*x + y*y + z*z))); | ||
103 | } | ||
104 | |||
105 | template<> template<> | ||
106 | void v4math_object::test<4>() | ||
107 | { | ||
108 | F32 x = 10.f, y = -2.3f, z = -.023f; | ||
109 | LLVector4 vec4(x,y,z); | ||
110 | F32 mag = vec4.normVec(); | ||
111 | mag = 1.f/ mag; | ||
112 | ensure("1:normVec: Fail " ,is_approx_equal(mag*x,vec4.mV[VX]) && is_approx_equal(mag*y, vec4.mV[VY])&& is_approx_equal(mag*z, vec4.mV[VZ])); | ||
113 | x = 0.000000001f, y = 0.000000001f, z = 0.000000001f; | ||
114 | vec4.clearVec(); | ||
115 | vec4.setVec(x,y,z); | ||
116 | mag = vec4.normVec(); | ||
117 | ensure("2:normVec: Fail " ,is_approx_equal(mag*x,vec4.mV[VX]) && is_approx_equal(mag*y, vec4.mV[VY])&& is_approx_equal(mag*z, vec4.mV[VZ])); | ||
118 | } | ||
119 | |||
120 | template<> template<> | ||
121 | void v4math_object::test<5>() | ||
122 | { | ||
123 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
124 | LLVector4 vec4(x,y,z,w); | ||
125 | vec4.abs(); | ||
126 | ensure("abs:Fail " ,((x == vec4.mV[VX]) && (-y == vec4.mV[VY]) && (-z == vec4.mV[VZ])&& (-w == vec4.mV[VW]))); | ||
127 | vec4.clearVec(); | ||
128 | ensure("isExactlyClear:Fail " ,(TRUE == vec4.isExactlyClear())); | ||
129 | vec4.zeroVec(); | ||
130 | ensure("isExactlyZero:Fail " ,(TRUE == vec4.isExactlyZero())); | ||
131 | } | ||
132 | |||
133 | template<> template<> | ||
134 | void v4math_object::test<6>() | ||
135 | { | ||
136 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
137 | LLVector4 vec4(x,y,z,w),vec4a; | ||
138 | vec4a = vec4.scaleVec(vec4); | ||
139 | ensure("scaleVec:Fail " ,(is_approx_equal(x*x, vec4a.mV[VX]) && is_approx_equal(y*y, vec4a.mV[VY]) && is_approx_equal(z*z, vec4a.mV[VZ])&& is_approx_equal(w*w, vec4a.mV[VW]))); | ||
140 | } | ||
141 | |||
142 | template<> template<> | ||
143 | void v4math_object::test<7>() | ||
144 | { | ||
145 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
146 | LLVector4 vec4(x,y,z,w); | ||
147 | ensure("1:operator [] failed " ,( x == vec4[0])); | ||
148 | ensure("2:operator [] failed " ,( y == vec4[1])); | ||
149 | ensure("3:operator [] failed " ,( z == vec4[2])); | ||
150 | ensure("4:operator [] failed " ,( w == vec4[3])); | ||
151 | x = 23.f, y = -.2361f, z = 3.25; | ||
152 | vec4.setVec(x,y,z); | ||
153 | F32 &ref1 = vec4[0]; | ||
154 | ensure("5:operator [] failed " ,( ref1 == vec4[0])); | ||
155 | F32 &ref2 = vec4[1]; | ||
156 | ensure("6:operator [] failed " ,( ref2 == vec4[1])); | ||
157 | F32 &ref3 = vec4[2]; | ||
158 | ensure("7:operator [] failed " ,( ref3 == vec4[2])); | ||
159 | F32 &ref4 = vec4[3]; | ||
160 | ensure("8:operator [] failed " ,( ref4 == vec4[3])); | ||
161 | } | ||
162 | |||
163 | template<> template<> | ||
164 | void v4math_object::test<8>() | ||
165 | { | ||
166 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
167 | const F32 val[10] = {1.f,2.f,3.f,.34f,.1f,-.5f,2.f,1.23f,1.234f,.89f}; | ||
168 | LLMatrix4 mat(val); | ||
169 | LLVector4 vec4(x,y,z,w),vec4a; | ||
170 | vec4.rotVec(mat); | ||
171 | vec4a.setVec(x,y,z,w); | ||
172 | vec4a.rotVec(mat); | ||
173 | ensure_equals("1:rotVec: Fail " ,vec4a, vec4); | ||
174 | F32 a = 2.32f, b = -23.2f, c = -34.1112f, d = 1.010112f; | ||
175 | LLQuaternion q(a,b,c,d); | ||
176 | LLVector4 vec4b(a,b,c,d),vec4c; | ||
177 | vec4b.rotVec(q); | ||
178 | vec4c.setVec(a, b, c, d); | ||
179 | vec4c.rotVec(q); | ||
180 | ensure_equals("2:rotVec: Fail " ,vec4b, vec4c); | ||
181 | } | ||
182 | |||
183 | template<> template<> | ||
184 | void v4math_object::test<9>() | ||
185 | { | ||
186 | F32 x = 10.f, y = -2.3f, z = -.023f, w = -2.0f; | ||
187 | LLVector4 vec4(x,y,z,w),vec4a;; | ||
188 | std::ostringstream stream1, stream2; | ||
189 | stream1 << vec4; | ||
190 | vec4a.setVec(x,y,z,w); | ||
191 | stream2 << vec4a; | ||
192 | ensure("operator << failed",(stream1.str() == stream2.str())); | ||
193 | } | ||
194 | |||
195 | template<> template<> | ||
196 | void v4math_object::test<10>() | ||
197 | { | ||
198 | F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f, w1 = .23f; | ||
199 | F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f, w2 = 1.3f; | ||
200 | LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2),vec4b; | ||
201 | vec4b = vec4a + vec4; | ||
202 | ensure("1:operator+:Fail to initialize " ,(is_approx_equal(x1+x2,vec4b.mV[VX]) && is_approx_equal(y1+y2,vec4b.mV[VY]) && is_approx_equal(z1+z2,vec4b.mV[VZ]))); | ||
203 | x1 = -2.45f, y1 = 2.1f, z1 = 3.0f; | ||
204 | vec4.clearVec(); | ||
205 | vec4a.clearVec(); | ||
206 | vec4.setVec(x1,y1,z1); | ||
207 | vec4a +=vec4; | ||
208 | ensure_equals("2:operator+=: Fail to initialize", vec4a,vec4); | ||
209 | vec4a += vec4; | ||
210 | ensure("3:operator+=:Fail to initialize " ,(is_approx_equal(2*x1,vec4a.mV[VX]) && is_approx_equal(2*y1,vec4a.mV[VY]) && is_approx_equal(2*z1,vec4a.mV[VZ]))); | ||
211 | } | ||
212 | template<> template<> | ||
213 | void v4math_object::test<11>() | ||
214 | { | ||
215 | F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f, w1 = .23f; | ||
216 | F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f, w2 = 1.3f; | ||
217 | LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2),vec4b; | ||
218 | vec4b = vec4a - vec4; | ||
219 | ensure("1:operator-:Fail to initialize " ,(is_approx_equal(x2-x1,vec4b.mV[VX]) && is_approx_equal(y2-y1,vec4b.mV[VY]) && is_approx_equal(z2-z1,vec4b.mV[VZ]))); | ||
220 | x1 = -2.45f, y1 = 2.1f, z1 = 3.0f; | ||
221 | vec4.clearVec(); | ||
222 | vec4a.clearVec(); | ||
223 | vec4.setVec(x1,y1,z1); | ||
224 | vec4a -=vec4; | ||
225 | ensure_equals("2:operator-=: Fail to initialize" , vec4a,-vec4); | ||
226 | vec4a -=vec4; | ||
227 | ensure("3:operator-=:Fail to initialize " ,(is_approx_equal(-2*x1,vec4a.mV[VX]) && is_approx_equal(-2*y1,vec4a.mV[VY]) && is_approx_equal(-2*z1,vec4a.mV[VZ]))); | ||
228 | } | ||
229 | |||
230 | template<> template<> | ||
231 | void v4math_object::test<12>() | ||
232 | { | ||
233 | F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f; | ||
234 | F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f; | ||
235 | LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2); | ||
236 | F32 res = vec4 * vec4a; | ||
237 | ensure("1:operator* failed " ,is_approx_equal(res, x1*x2 + y1*y2 + z1*z2)); | ||
238 | vec4a.clearVec(); | ||
239 | F32 mulVal = 4.2f; | ||
240 | vec4a = vec4 * mulVal; | ||
241 | ensure("2:operator* failed " ,is_approx_equal(x1*mulVal,vec4a.mV[VX]) && is_approx_equal(y1*mulVal, vec4a.mV[VY])&& is_approx_equal(z1*mulVal, vec4a.mV[VZ])); | ||
242 | vec4a.clearVec(); | ||
243 | vec4a = mulVal * vec4 ; | ||
244 | ensure("3:operator* failed " ,is_approx_equal(x1*mulVal, vec4a.mV[VX]) && is_approx_equal(y1*mulVal, vec4a.mV[VY])&& is_approx_equal(z1*mulVal, vec4a.mV[VZ])); | ||
245 | vec4 *= mulVal; | ||
246 | ensure("4:operator*= failed " ,is_approx_equal(x1*mulVal, vec4.mV[VX]) && is_approx_equal(y1*mulVal, vec4.mV[VY])&& is_approx_equal(z1*mulVal, vec4.mV[VZ])); | ||
247 | } | ||
248 | |||
249 | template<> template<> | ||
250 | void v4math_object::test<13>() | ||
251 | { | ||
252 | F32 x1 = 1.f, y1 = 2.f, z1 = -1.1f; | ||
253 | F32 x2 = 1.2f, y2 = 2.5f, z2 = 1.f; | ||
254 | LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2),vec4b; | ||
255 | vec4b = vec4 % vec4a; | ||
256 | ensure("1:operator% failed " ,is_approx_equal(y1*z2 - y2*z1, vec4b.mV[VX]) && is_approx_equal(z1*x2 -z2*x1, vec4b.mV[VY]) && is_approx_equal(x1*y2-x2*y1, vec4b.mV[VZ])); | ||
257 | vec4 %= vec4a; | ||
258 | ensure_equals("operator%= failed " ,vec4,vec4b); | ||
259 | } | ||
260 | |||
261 | template<> template<> | ||
262 | void v4math_object::test<14>() | ||
263 | { | ||
264 | F32 x = 1.f, y = 2.f, z = -1.1f,div = 4.2f; | ||
265 | F32 t = 1.f / div; | ||
266 | LLVector4 vec4(x,y,z), vec4a; | ||
267 | vec4a = vec4/div; | ||
268 | ensure("1:operator/ failed " ,is_approx_equal(x*t, vec4a.mV[VX]) && is_approx_equal(y*t, vec4a.mV[VY])&& is_approx_equal(z*t, vec4a.mV[VZ])); | ||
269 | x = 1.23f, y = 4.f, z = -2.32f; | ||
270 | vec4.clearVec(); | ||
271 | vec4a.clearVec(); | ||
272 | vec4.setVec(x,y,z); | ||
273 | vec4a = vec4/div; | ||
274 | ensure("2:operator/ failed " ,is_approx_equal(x*t, vec4a.mV[VX]) && is_approx_equal(y*t, vec4a.mV[VY])&& is_approx_equal(z*t, vec4a.mV[VZ])); | ||
275 | vec4 /= div; | ||
276 | ensure("3:operator/ failed " ,is_approx_equal(x*t, vec4.mV[VX]) && is_approx_equal(y*t, vec4.mV[VY])&& is_approx_equal(z*t, vec4.mV[VZ])); | ||
277 | } | ||
278 | |||
279 | template<> template<> | ||
280 | void v4math_object::test<15>() | ||
281 | { | ||
282 | F32 x = 1.f, y = 2.f, z = -1.1f; | ||
283 | LLVector4 vec4(x,y,z), vec4a; | ||
284 | ensure("operator!= failed " ,(vec4 != vec4a)); | ||
285 | vec4a = vec4; | ||
286 | ensure("operator== failed " ,(vec4 ==vec4a)); | ||
287 | } | ||
288 | |||
289 | template<> template<> | ||
290 | void v4math_object::test<16>() | ||
291 | { | ||
292 | F32 x = 1.f, y = 2.f, z = -1.1f; | ||
293 | LLVector4 vec4(x,y,z), vec4a; | ||
294 | vec4a = - vec4; | ||
295 | ensure("operator- failed " , (vec4 == - vec4a)); | ||
296 | } | ||
297 | |||
298 | template<> template<> | ||
299 | void v4math_object::test<17>() | ||
300 | { | ||
301 | F32 x = 1.f, y = 2.f, z = -1.1f,epsilon = .23425f; | ||
302 | LLVector4 vec4(x,y,z), vec4a(x,y,z); | ||
303 | ensure("1:are_parallel: Fail " ,(TRUE == are_parallel(vec4a,vec4,epsilon))); | ||
304 | x = 21.f, y = 12.f, z = -123.1f; | ||
305 | vec4a.clearVec(); | ||
306 | vec4a.setVec(x,y,z); | ||
307 | ensure("2:are_parallel: Fail " ,(FALSE == are_parallel(vec4a,vec4,epsilon))); | ||
308 | } | ||
309 | |||
310 | template<> template<> | ||
311 | void v4math_object::test<18>() | ||
312 | { | ||
313 | F32 x = 1.f, y = 2.f, z = -1.1f; | ||
314 | F32 angle1, angle2; | ||
315 | LLVector4 vec4(x,y,z), vec4a(x,y,z); | ||
316 | angle1 = angle_between(vec4, vec4a); | ||
317 | vec4.normVec(); | ||
318 | vec4a.normVec(); | ||
319 | angle2 = acos(vec4 * vec4a); | ||
320 | ensure_approximately_equals("1:angle_between: Fail " ,angle1,angle2,8); | ||
321 | F32 x1 = 21.f, y1 = 2.23f, z1 = -1.1f; | ||
322 | LLVector4 vec4b(x,y,z), vec4c(x1,y1,z1); | ||
323 | angle1 = angle_between(vec4b, vec4c); | ||
324 | vec4b.normVec(); | ||
325 | vec4c.normVec(); | ||
326 | angle2 = acos(vec4b * vec4c); | ||
327 | ensure_approximately_equals("2:angle_between: Fail " ,angle1,angle2,8); | ||
328 | } | ||
329 | |||
330 | template<> template<> | ||
331 | void v4math_object::test<19>() | ||
332 | { | ||
333 | F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f; | ||
334 | F32 val1,val2; | ||
335 | LLVector4 vec4(x1,y1,z1),vec4a(x2,y2,z2); | ||
336 | val1 = dist_vec(vec4,vec4a); | ||
337 | val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2)); | ||
338 | ensure_equals("dist_vec: Fail ",val2, val1); | ||
339 | val1 = dist_vec_squared(vec4,vec4a); | ||
340 | val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2)); | ||
341 | ensure_equals("dist_vec_squared: Fail ",val2, val1); | ||
342 | } | ||
343 | |||
344 | template<> template<> | ||
345 | void v4math_object::test<20>() | ||
346 | { | ||
347 | F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, w1 = -.23f, x2 = 1.3f, y2 = 1.f, z2 = 1.f,w2 = .12f; | ||
348 | F32 val = 2.3f,val1,val2,val3,val4; | ||
349 | LLVector4 vec4(x1,y1,z1,w1),vec4a(x2,y2,z2,w2); | ||
350 | val1 = x1 + (x2 - x1)* val; | ||
351 | val2 = y1 + (y2 - y1)* val; | ||
352 | val3 = z1 + (z2 - z1)* val; | ||
353 | val4 = w1 + (w2 - w1)* val; | ||
354 | LLVector4 vec4b = lerp(vec4,vec4a,val); | ||
355 | ensure("lerp failed", ((val1 ==vec4b.mV[VX])&& (val2 ==vec4b.mV[VY]) && (val3 ==vec4b.mV[VZ])&& (val4 ==vec4b.mV[VW]))); | ||
356 | } | ||
357 | |||
358 | template<> template<> | ||
359 | void v4math_object::test<21>() | ||
360 | { | ||
361 | F32 x = 1.f, y = 2.f, z = -1.1f; | ||
362 | LLVector4 vec4(x,y,z); | ||
363 | LLVector3 vec3 = vec4to3(vec4); | ||
364 | ensure("vec4to3 failed", ((x == vec3.mV[VX])&& (y == vec3.mV[VY]) && (z == vec3.mV[VZ]))); | ||
365 | LLVector4 vec4a = vec3to4(vec3); | ||
366 | ensure_equals("vec3to4 failed",vec4a,vec4); | ||
367 | } | ||
368 | |||
369 | template<> template<> | ||
370 | void v4math_object::test<22>() | ||
371 | { | ||
372 | F32 x = 1.f, y = 2.f, z = -1.1f; | ||
373 | LLVector4 vec4(x,y,z); | ||
374 | LLSD llsd = vec4.getValue(); | ||
375 | LLVector3 vec3(llsd); | ||
376 | LLVector4 vec4a = vec3to4(vec3); | ||
377 | ensure_equals("getValue failed",vec4a,vec4); | ||
378 | } | ||
379 | } | ||