PuzzleSDK
UnitTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25#include "UnitTest.h"
26#include "ui/UIHelper.h"
27#include "network/Uri.h"
28#include "base/ccUtils.h"
29
31using namespace cocos2d::network;
32
33#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
34#if defined (__arm64__)
35#define USE_NEON64
36#define INCLUDE_NEON64
37#elif defined (__ARM_NEON__)
38#define USE_NEON32
39#define INCLUDE_NEON32
40#else
41#endif
42#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
43#if defined (__arm64__) || defined (__aarch64__)
44#define USE_NEON64
45#define INCLUDE_NEON64
46#elif defined (__ARM_NEON__)
47#define INCLUDE_NEON32
48#else
49#endif
50#else
51
52#endif
53
54#if defined (__SSE__)
55#define USE_SSE
56#define INCLUDE_SSE
57#endif
58
59#if (defined INCLUDE_NEON64) || (defined INCLUDE_NEON32) // FIXME: || (defined INCLUDE_SSE)
60#define UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL
61#endif
62
63#define EXPECT_EQ(a, b) assert((a) == (b))
64#define EXPECT_NE(a, b) assert((a) != (b))
65#define EXPECT_TRUE(a) assert(a)
66#define EXPECT_FALSE(a) assert(!(a))
67
68// For ' < o > ' multiply test scene.
69
70UnitTests::UnitTests()
71{
80#ifdef UNIT_TEST_FOR_OPTIMIZED_MATH_UTIL
82#endif
83};
84
85std::string UnitTestDemo::title() const
86{
87 return "UnitTest";
88}
89
90//---------------------------------------------------------------
91
93{
95
96 Vector<Node*> vec;
97 CCASSERT(vec.empty(), "vec should be empty.");
98 CCASSERT(vec.capacity() == 0, "vec.capacity should be 0.");
99 CCASSERT(vec.size() == 0, "vec.size should be 0.");
100 CCASSERT(vec.max_size() > 0, "vec.max_size should > 0.");
101
102 auto node1 = Node::create();
103 node1->setTag(1);
104 vec.pushBack(node1);
105 CCASSERT(node1->getReferenceCount() == 2, "node1->getReferenceCount should be 2.");
106
107 auto node2 = Node::create();
108 node2->setTag(2);
109 vec.pushBack(node2);
110 CCASSERT(vec.getIndex(node1) == 0, "node1 should at index 0 in vec.");
111 CCASSERT(vec.getIndex(node2) == 1, "node2 should at index 1 in vec.");
112
113 auto node3 = Node::create();
114 node3->setTag(3);
115 vec.insert(1, node3);
116 CCASSERT(vec.at(0)->getTag() == 1, "The element at 0, tag should be 1.");
117 CCASSERT(vec.at(1)->getTag() == 3, "The element at 1, tag should be 3.");
118 CCASSERT(vec.at(2)->getTag() == 2, "The element at 2, tag should be 2.");
119
120 // Test copy constructor
121 Vector<Node*> vec2(vec);
122 CCASSERT(vec2.size() == vec.size(), "vec2 and vec should have equal size.");
123 ssize_t size = vec.size();
124 for (ssize_t i = 0; i < size; ++i)
125 {
126 CCASSERT(vec2.at(i) == vec.at(i), "The element at the same index in vec2 and vec2 should be equal.");
127 CCASSERT(vec.at(i)->getReferenceCount() == 3, "The reference count of element in vec is 3. ");
128 CCASSERT(vec2.at(i)->getReferenceCount() == 3, "The reference count of element in vec2 is 3. ");
129 }
130
131 // Test copy assignment operator
132 Vector<Node*> vec3;
133 vec3 = vec2;
134 CCASSERT(vec3.size() == vec2.size(), "vec3 and vec2 should have equal size.");
135 size = vec3.size();
136 for (ssize_t i = 0; i < size; ++i)
137 {
138 CCASSERT(vec3.at(i) == vec2.at(i), "The element at the same index in vec3 and vec2 should be equal.");
139 CCASSERT(vec3.at(i)->getReferenceCount() == 4, "The reference count of element in vec3 is 4. ");
140 CCASSERT(vec2.at(i)->getReferenceCount() == 4, "The reference count of element in vec2 is 4. ");
141 CCASSERT(vec.at(i)->getReferenceCount() == 4, "The reference count of element in vec is 4. ");
142 }
143
144 // Test move constructor
145
146 auto createVector = [](){
147 Vector<Node*> ret;
148
149 for (int i = 0; i < 20; i++)
150 {
151 ret.pushBack(Node::create());
152 }
153
154 int j = 1000;
155 for (auto& child : ret)
156 {
157 child->setTag(j++);
158 }
159
160 return ret;
161 };
162
163 Vector<Node*> vec4(createVector());
164 for (const auto& child : vec4)
165 {
166 CC_UNUSED_PARAM(child);
167 CCASSERT(child->getReferenceCount() == 2, "child's reference count should be 2.");
168 }
169
170 // Test init Vector<T> with capacity
171 Vector<Node*> vec5(10);
172 CCASSERT(vec5.capacity() == 10, "vec5's capacity should be 10.");
173 vec5.reserve(20);
174 CCASSERT(vec5.capacity() == 20, "vec5's capacity should be 20.");
175
176 CCASSERT(vec5.size() == 0, "vec5's size should be 0.");
177 CCASSERT(vec5.empty(), "vec5 is empty now.");
178
179 auto toRemovedNode = Node::create();
180 vec5.pushBack(toRemovedNode);
181 CCASSERT(toRemovedNode->getReferenceCount() == 2, "toRemovedNode's reference count is 2.");
182
183 // Test move assignment operator
184 vec5 = createVector();
185 CCASSERT(toRemovedNode->getReferenceCount() == 1, "toRemovedNode's reference count is 1.");
186 CCASSERT(vec5.size() == 20, "size should be 20");
187
188 for (const auto& child : vec5)
189 {
190 CC_UNUSED_PARAM(child);
191 CCASSERT(child->getReferenceCount() == 2, "child's reference count is 2.");
192 }
193
194 // Test Vector<T>::find
195 CCASSERT(vec.find(node3) == (vec.begin() + 1), "node3 is the 2nd element in vec.");
196 CCASSERT(std::find(std::begin(vec), std::end(vec), node2) == (vec.begin() + 2), "node2 is the 3rd element in vec.");
197
198 CCASSERT(vec.front()->getTag() == 1, "vec's front element's tag is 1.");
199 CCASSERT(vec.back()->getTag() == 2, "vec's back element's tag is 2.");
200
201 CCASSERT(vec.getRandomObject(), "vec getRandomObject should return true.");
202 CCASSERT(!vec.contains(Node::create()), "vec doesn't contain a empty Node instance.");
203 CCASSERT(vec.contains(node1), "vec contains node1.");
204 CCASSERT(vec.contains(node2), "vec contains node2.");
205 CCASSERT(vec.contains(node3), "vec contains node3.");
206 CCASSERT(vec.equals(vec2), "vec is equal to vec2.");
207 CCASSERT(vec.equals(vec3), "vec is equal to vec3.");
208
209 // Insert
210 vec5.insert(2, node1);
211 CCASSERT(vec5.at(2)->getTag() == 1, "vec5's 3rd element's tag is 1.");
212 CCASSERT(vec5.size() == 21, "vec5's size is 21.");
213 vec5.back()->setTag(100);
214 vec5.popBack();
215 CCASSERT(vec5.size() == 20, "vec5's size is 20.");
216 CCASSERT(vec5.back()->getTag() != 100, "the back element of vec5's tag is 100.");
217
218 // Erase and clear
219 Vector<Node*> vec6 = createVector();
220 Vector<Node*> vec7 = vec6; // Copy for check
221
222 CCASSERT(vec6.size() == 20, "vec6's size is 20.");
223 vec6.erase(vec6.begin() + 1); //
224 CCASSERT(vec6.size() == 19, "vec6's size is 19.");
225 CCASSERT((*(vec6.begin() + 1))->getTag() == 1002, "The 2rd element in vec6's tag is 1002.");
226 vec6.erase(vec6.begin() + 2, vec6.begin() + 10);
227 CCASSERT(vec6.size() == 11, "vec6's size is 11.");
228 CCASSERT(vec6.at(0)->getTag() == 1000, "vec6's first element's tag is 1000.");
229 CCASSERT(vec6.at(1)->getTag() == 1002, "vec6's second element's tag is 1002.");
230 CCASSERT(vec6.at(2)->getTag() == 1011, "vec6's third element's tag is 1011.");
231 CCASSERT(vec6.at(3)->getTag() == 1012, "vec6's fouth element's tag is 1012.");
232 vec6.erase(3);
233 CCASSERT(vec6.at(3)->getTag() == 1013, "vec6's 4th element's tag is 1013.");
234 vec6.eraseObject(vec6.at(2));
235 CCASSERT(vec6.at(2)->getTag() == 1013, "vec6's 3rd element's tag is 1013.");
236 vec6.clear();
237
238 auto objA = Node::create(); // retain count is 1
239 auto objB = Node::create();
240 auto objC = Node::create();
241 {
242 Vector<Node*> array1;
243 Vector<Node*> array2;
244
245 // push back objA 3 times
246 array1.pushBack(objA); // retain count is 2
247 array1.pushBack(objA); // retain count is 3
248 array1.pushBack(objA); // retain count is 4
249
250 array2.pushBack(objA); // retain count is 5
251 array2.pushBack(objB);
252 array2.pushBack(objC);
253
254 for (auto obj : array1) {
255 array2.eraseObject(obj);
256 }
257 CCASSERT(objA->getReferenceCount() == 4, "objA's reference count is 4.");
258 }
259 CCASSERT(objA->getReferenceCount() == 1, "objA's reference count is 1.");
260
261 {
262 Vector<Node*> array1;
263 // push back objA 3 times
264 array1.pushBack(objA); // retain count is 2
265 array1.pushBack(objA); // retain count is 3
266 array1.pushBack(objA); // retain count is 4
267 CCASSERT(objA->getReferenceCount() == 4, "objA's reference count is 4.");
268 array1.eraseObject(objA, true); // Remove all occurrences in the Vector.
269 CCASSERT(objA->getReferenceCount() == 1, "objA's reference count is 1.");
270
271 array1.pushBack(objA); // retain count is 2
272 array1.pushBack(objA); // retain count is 3
273 array1.pushBack(objA); // retain count is 4
274
275 array1.eraseObject(objA, false);
276 CCASSERT(objA->getReferenceCount() == 3, "objA's reference count is 3."); // Only remove the first occurrence in the Vector.
277 }
278
279 // Check the retain count in vec7
280 CCASSERT(vec7.size() == 20, "vec7's size is 20.");
281 for (const auto& child : vec7)
282 {
283 CC_UNUSED_PARAM(child);
284 CCASSERT(child->getReferenceCount() == 2, "child's reference count is 2.");
285 }
286
287 // Sort
288 Vector<Node*> vecForSort = createVector();
289 std::sort(vecForSort.begin(), vecForSort.end(), [](Node* a, Node* b){
290 return a->getTag() >= b->getTag();
291 });
292
293 for (int i = 0; i < 20; ++i)
294 {
295 CCASSERT(vecForSort.at(i)->getTag() - 1000 == (19 - i), "vecForSort's element's tag is invalid.");
296 }
297
298 // Reverse
299 vecForSort.reverse();
300 for (int i = 0; i < 20; ++i)
301 {
302 CCASSERT(vecForSort.at(i)->getTag() - 1000 == i, "vecForSort's element's tag is invalid.");
303 }
304
305 // Swap
306 Vector<Node*> vecForSwap = createVector();
307 vecForSwap.swap(2, 4);
308 CCASSERT(vecForSwap.at(2)->getTag() == 1004, "vecForSwap's 3nd element's tag is 1004.");
309 CCASSERT(vecForSwap.at(4)->getTag() == 1002, "vecForSwap's 5rd element's tag is 1002.");
310 vecForSwap.swap(vecForSwap.at(2), vecForSwap.at(4));
311 CCASSERT(vecForSwap.at(2)->getTag() == 1002, "vecForSwap's 3rd element's tag is 1002.");
312 CCASSERT(vecForSwap.at(4)->getTag() == 1004, "vecForSwap's 5rd element's tag is 1004.");
313
314 // shrinkToFit
315 Vector<Node*> vecForShrink = createVector();
316 vecForShrink.reserve(100);
317 CCASSERT(vecForShrink.capacity() == 100, "vecForShrink's capacity is 100.");
318 vecForShrink.pushBack(Node::create());
319 vecForShrink.shrinkToFit();
320 CCASSERT(vecForShrink.capacity() == 21, "vecForShrink's capacity is 21.");
321
322 // get random object
323 // Set the seed by time
324 std::srand((unsigned)time(nullptr));
325 Vector<Node*> vecForRandom = createVector();
326 log("<--- begin ---->");
327 for (int i = 0; i < vecForRandom.size(); ++i)
328 {
329 log("Vector: random object tag = %d", vecForRandom.getRandomObject()->getTag());
330 }
331 log("<---- end ---->");
332
333 // Self assignment
334 Vector<Node*> vecSelfAssign = createVector();
335 vecSelfAssign = vecSelfAssign;
336 CCASSERT(vecSelfAssign.size() == 20, "vecSelfAssign's size is 20.");
337
338 for (const auto& child : vecSelfAssign)
339 {
340 CC_UNUSED_PARAM(child);
341 CCASSERT(child->getReferenceCount() == 2, "child's reference count is 2.");
342 }
343
344 vecSelfAssign = std::move(vecSelfAssign);
345 CCASSERT(vecSelfAssign.size() == 20, "vecSelfAssign's size is 20.");
346
347 for (const auto& child : vecSelfAssign)
348 {
349 CC_UNUSED_PARAM(child);
350 CCASSERT(child->getReferenceCount() == 2, "child's reference count is 2.");
351 }
352
353 // const at
354 Vector<Node*> vecConstAt = createVector();
355 constFunc(vecConstAt);
356}
357
358void TemplateVectorTest::constFunc(const Vector<Node*>& vec) const
359{
360 log("vec[8] = %d", vec.at(8)->getTag());
361}
362
364{
365 return "Vector<T>, should not crash";
366}
367
368
369//---------------------------------------------------------------
370
372{
374
375 auto createMap = [](){
376 Map<std::string, Node*> ret;
377 for (int i = 0; i < 20; ++i)
378 {
379 auto node = Node::create();
380 node->setTag(1000 + i);
381 ret.insert(StringUtils::toString(i), node);
382 }
383
384 return ret;
385 };
386
387 // Default constructor
388 Map<std::string, Node*> map1;
389 CCASSERT(map1.empty(), "map1 is empty.");
390 CCASSERT(map1.size() == 0, "map1's size is 0.");
391 CCASSERT(map1.keys().empty(), "map1's keys are empty.");
392 CCASSERT(map1.keys(Node::create()).empty(), "map1's keys don't contain a empty Node.");
393
394 // Move constructor
395 Map<std::string, Node*> map2 = createMap();
396 for (const auto& e : map2)
397 {
398 CC_UNUSED_PARAM(e);
399 CCASSERT(e.second->getReferenceCount() == 2, "e.second element's reference count is 2.");
400 }
401
402 // Copy constructor
403 Map<std::string, Node*> map3(map2);
404 for (const auto& e : map3)
405 {
406 CC_UNUSED_PARAM(e);
407 CCASSERT(e.second->getReferenceCount() == 3, "e.second's reference count is 3.");
408 }
409
410 // Move assignment operator
411 Map<std::string, Node*> map4;
412 auto unusedNode = Node::create();
413 map4.insert("unused",unusedNode);
414 map4 = createMap();
415 CCASSERT(unusedNode->getReferenceCount() == 1, "unusedNode's reference count is 1.");
416 for (const auto& e : map4)
417 {
418 CC_UNUSED_PARAM(e);
419 CCASSERT(e.second->getReferenceCount() == 2, "e.second's reference count is 2.");
420 }
421
422 // Copy assignment operator
423 Map<std::string, Node*> map5;
424 map5 = map4;
425 for (const auto& e : map5)
426 {
427 CC_UNUSED_PARAM(e);
428 CCASSERT(e.second->getReferenceCount() == 3, "e.second's reference count is 3.");
429 }
430
431 // Check size
432 CCASSERT(map4.size() == map5.size(), "map4's size is equal to map5.size.");
433
434 for (const auto& e : map4)
435 {
436 CC_UNUSED_PARAM(e);
437 CCASSERT(e.second == map5.find(e.first)->second, "e.second can't be found in map5.");
438 }
439
440 // bucket_count, bucket_size(n), bucket
441 log("--------------");
442 log("bucket_count = %d", static_cast<int>(map4.bucketCount()));
443 log("size = %d", static_cast<int>(map4.size()));
444 for (int i = 0; i < map4.bucketCount(); ++i)
445 {
446 log("bucket_size(%d) = %d", i, static_cast<int>(map4.bucketSize(i)));
447 }
448 for (const auto& e : map4)
449 {
450 log("bucket(\"%s\"), bucket index = %d", e.first.c_str(), static_cast<int>(map4.bucket(e.first)));
451 }
452
453 log("----- all keys---------");
454
455 // keys and at
456 auto keys = map4.keys();
457 for (const auto& key : keys)
458 {
459 log("key = %s", key.c_str());
460 }
461
462 auto node10Key = map4.at("10");
463 map4.insert("100", node10Key);
464 map4.insert("101", node10Key);
465 map4.insert("102", node10Key);
466
467 log("------ keys for object --------");
468 auto keysForObject = map4.keys(node10Key);
469 for (const auto& key : keysForObject)
470 {
471 log("key = %s", key.c_str());
472 }
473 log("--------------");
474
475 // at in const function
476 constFunc(map4);
477
478 // find
479 auto nodeToFind = map4.find("10");
480 CC_UNUSED_PARAM(nodeToFind);
481 CCASSERT(nodeToFind->second->getTag() == 1010, "nodeToFind's tag value is 1010.");
482
483 // insert
484 Map<std::string, Node*> map6;
485 auto node1 = Node::create();
486 node1->setTag(101);
487 auto node2 = Node::create();
488 node2->setTag(102);
489 auto node3 = Node::create();
490 node3->setTag(103);
491 map6.insert("insert01", node1);
492 map6.insert("insert02", node2);
493 map6.insert("insert03", node3);
494
495 CCASSERT(node1->getReferenceCount() == 2, "node1's reference count is 2.");
496 CCASSERT(node2->getReferenceCount() == 2, "node2's reference count is 2.");
497 CCASSERT(node3->getReferenceCount() == 2, "node3's reference count is 2.");
498 CCASSERT(map6.at("insert01") == node1, "The element at insert01 is equal to node1.");
499 CCASSERT(map6.at("insert02") == node2, "The element at insert02 is equal to node2.");
500 CCASSERT(map6.at("insert03") == node3, "The element at insert03 is equal to node3.");
501
502 // erase
503 Map<std::string, Node*> mapForErase = createMap();
504 mapForErase.erase(mapForErase.find("9"));
505 CCASSERT(mapForErase.find("9") == mapForErase.end(), "9 is already removed.");
506 CCASSERT(mapForErase.size() == 19, "mapForErase's size is 19.");
507
508 mapForErase.erase("7");
509 CCASSERT(mapForErase.find("7") == mapForErase.end(), "7 is already removed.");
510 CCASSERT(mapForErase.size() == 18, "mapForErase's size is 18.");
511
512 std::vector<std::string> itemsToRemove;
513 itemsToRemove.push_back("2");
514 itemsToRemove.push_back("3");
515 itemsToRemove.push_back("4");
516 mapForErase.erase(itemsToRemove);
517 CCASSERT(mapForErase.size() == 15, "mapForErase's size is 15.");
518
519 // clear
520 Map<std::string, Node*> mapForClear = createMap();
521 auto mapForClearCopy = mapForClear;
522 mapForClear.clear();
523
524 for (const auto& e : mapForClearCopy)
525 {
526 CC_UNUSED_PARAM(e);
527 CCASSERT(e.second->getReferenceCount() == 2, "e.second's reference count is 2.");
528 }
529
530 // get random object
531 // Set the seed by time
532 std::srand((unsigned)time(nullptr));
533 Map<std::string, Node*> mapForRandom = createMap();
534 log("<--- begin ---->");
535 for (int i = 0; i < mapForRandom.size(); ++i)
536 {
537 log("Map: random object tag = %d", mapForRandom.getRandomObject()->getTag());
538 }
539 log("<---- end ---->");
540
541 // Self assignment
542 Map<std::string, Node*> mapForSelfAssign = createMap();
543 mapForSelfAssign = mapForSelfAssign;
544 CCASSERT(mapForSelfAssign.size() == 20, "mapForSelfAssign's size is 20.");
545
546 for (const auto& e : mapForSelfAssign)
547 {
548 CC_UNUSED_PARAM(e);
549 CCASSERT(e.second->getReferenceCount() == 2, "e.second's reference count is 2.");
550 }
551
552 mapForSelfAssign = std::move(mapForSelfAssign);
553 CCASSERT(mapForSelfAssign.size() == 20, "mapForSelfAssign's size is 20.");
554
555 for (const auto& e : mapForSelfAssign)
556 {
557 CC_UNUSED_PARAM(e);
558 CCASSERT(e.second->getReferenceCount() == 2, "e.second's reference's count is 2.");
559 }
560}
561
562void TemplateMapTest::constFunc(const Map<std::string, Node*>& map) const
563{
564 log("[%s]=(tag)%d", "0", map.at("0")->getTag());
565 log("[%s]=(tag)%d", "1", map.find("1")->second->getTag());
566}
567
568std::string TemplateMapTest::subtitle() const
569{
570 return "Map<K, V>, should not crash";
571}
572
573//----------------------------------
574
576{
578
579 Value v1;
580 CCASSERT(v1.getType() == Value::Type::NONE, "v1's value type should be VALUE::Type::NONE.");
581 CCASSERT(v1.isNull(), "v1 is null.");
582
583 Value v2(100);
584 CCASSERT(v2.getType() == Value::Type::INTEGER, "v2's value type should be VALUE::Type::INTEGER.");
585 CCASSERT(!v2.isNull(), "v2 is not null.");
586
587 Value v3(101.4f);
588 CCASSERT(v3.getType() == Value::Type::FLOAT, "v3's value type should be VALUE::Type::FLOAT.");
589 CCASSERT(!v3.isNull(), "v3 is not null.");
590
591 Value v4(106.1);
592 CCASSERT(v4.getType() == Value::Type::DOUBLE, "v4's value type should be VALUE::Type::DOUBLE.");
593 CCASSERT(!v4.isNull(), "v4 is not null.");
594
595 unsigned char byte = 50;
596 Value v5(byte);
597 CCASSERT(v5.getType() == Value::Type::BYTE, "v5's value type should be Value::Type::BTYE.");
598 CCASSERT(!v5.isNull(), "v5 is not null.");
599
600 Value v6(true);
601 CCASSERT(v6.getType() == Value::Type::BOOLEAN, "v6's value type is Value::Type::BOOLEAN.");
602 CCASSERT(!v6.isNull(), "v6 is not null.");
603
604 Value v7("string");
605 CCASSERT(v7.getType() == Value::Type::STRING, "v7's value type is Value::type::STRING.");
606 CCASSERT(!v7.isNull(), "v7 is not null.");
607
608 Value v8(std::string("string2"));
609 CCASSERT(v8.getType() == Value::Type::STRING, "v8's value type is Value::Type::STRING.");
610 CCASSERT(!v8.isNull(), "v8 is not null.");
611
612 auto createValueVector = [&](){
613 ValueVector ret;
614 ret.push_back(v1);
615 ret.push_back(v2);
616 ret.push_back(v3);
617 return ret;
618 };
619
620
621 Value v9(createValueVector());
622 CCASSERT(v9.getType() == Value::Type::VECTOR, "v9's value type is Value::Type::VECTOR.");
623 CCASSERT(!v9.isNull(), "v9 is not null.");
624
625 auto createValueMap = [&](){
626 ValueMap ret;
627 ret["aaa"] = v1;
628 ret["bbb"] = v2;
629 ret["ccc"] = v3;
630 return ret;
631 };
632
633 Value v10(createValueMap());
634 CCASSERT(v10.getType() == Value::Type::MAP, "v10's value type is Value::Type::MAP.");
635 CCASSERT(!v10.isNull(), "v10 is not null.");
636
637 auto createValueMapIntKey = [&](){
638 ValueMapIntKey ret;
639 ret[111] = v1;
640 ret[222] = v2;
641 ret[333] = v3;
642 return ret;
643 };
644
645 Value v11(createValueMapIntKey());
646 CCASSERT(v11.getType() == Value::Type::INT_KEY_MAP, "v11's value type is Value::Type::INT_KEY_MAP.");
647 CCASSERT(!v11.isNull(), "v11 is not null.");
648}
649
650std::string ValueTest::subtitle() const
651{
652 return "Value Test, should not crash";
653}
654
655void ValueTest::constFunc(const Value& /*value*/) const
656{
657}
658
659// UTFConversionTest
660
661// FIXME: made as define to prevent compile warnings in release mode. Better is to be a `const static int`
662#define TEST_CODE_NUM 11
663
664static const char16_t __utf16Code[] =
665{
666 0x3042,
667 0x3044,
668 0x3046,
669 0x3048,
670 0x304A,
671 0x3042,
672 0x3044,
673 0x3046,
674 0x3048,
675 0x304A,
676 0x0041,
677 0x0000,
678};
679
680// to avoid Xcode error, char => unsigned char
681// If you use this table, please cast manually as (const char *).
682static const unsigned char __utf8Code[] =
683{
684 0xE3,0x81,0x82,
685 0xE3,0x81,0x84,
686 0xE3,0x81,0x86,
687 0xE3,0x81,0x88,
688 0xE3,0x81,0x8A,
689 0xE3,0x81,0x82,
690 0xE3,0x81,0x84,
691 0xE3,0x81,0x86,
692 0xE3,0x81,0x88,
693 0xE3,0x81,0x8A,
694 0x41,
695 0x00,
696};
697
698
699static const char16_t WHITE_SPACE_CODE[] =
700{
701 0x0009,
702 0x000A,
703 0x000B,
704 0x000C,
705 0x000D,
706 0x0020,
707 0x0085,
708 0x00A0,
709 0x1680,
710 0x2000,
711 0x2001,
712 0x2002,
713 0x2003,
714 0x2004,
715 0x2005,
716 0x2006,
717 0x2007,
718 0x2008,
719 0x2009,
720 0x200A,
721 0x2028,
722 0x2029,
723 0x202F,
724 0x205F,
725 0x3000
726};
727
728static void doUTFConversion()
729{
730 bool isSuccess = false;
731
732 std::string originalUTF8 = (const char*)__utf8Code;
733 std::u16string originalUTF16 = __utf16Code;
734
735 //---------------------------
736 std::string utf8Str;
737 isSuccess = StringUtils::UTF16ToUTF8(originalUTF16, utf8Str);
738
739 if (isSuccess)
740 {
741 isSuccess = memcmp(utf8Str.data(), originalUTF8.data(), originalUTF8.length()+1)==0;
742 }
743
744 CCASSERT(isSuccess, "StringUtils::UTF16ToUTF8 failed");
745
746 //---------------------------
747 std::u16string utf16Str;
748 isSuccess = StringUtils::UTF8ToUTF16(originalUTF8, utf16Str);
749
750 if (isSuccess)
751 {
752 isSuccess = memcmp(utf16Str.data(), originalUTF16.data(), originalUTF16.length()+1)==0;
753 }
754
755 CCASSERT(isSuccess && (utf16Str.length() == TEST_CODE_NUM), "StringUtils::UTF8ToUTF16 failed");
756
757 //---------------------------
758 auto vec1 = StringUtils::getChar16VectorFromUTF16String(originalUTF16);
759
760 CCASSERT(vec1.size() == originalUTF16.length(), "StringUtils::getChar16VectorFromUTF16String failed");
761
762 //---------------------------
763 std::vector<char16_t> vec2( vec1 );
764 vec2.push_back(0x2009);
765 vec2.push_back(0x2009);
766 vec2.push_back(0x2009);
767 vec2.push_back(0x2009);
768
769 std::vector<char16_t> vec3( vec2 );
770 StringUtils::trimUTF16Vector(vec2);
771
772 CCASSERT(vec1.size() == vec2.size(), "StringUtils::trimUTF16Vector failed");
773
774 for (size_t i = 0; i < vec2.size(); i++ )
775 {
776 CCASSERT(vec1.at(i) == vec2.at(i), "StringUtils::trimUTF16Vector failed");
777 }
778
779 //---------------------------
780 CCASSERT(StringUtils::getCharacterCountInUTF8String(originalUTF8) == TEST_CODE_NUM, "StringUtils::getCharacterCountInUTF8String failed");
781
782 //---------------------------
783 CCASSERT(StringUtils::getIndexOfLastNotChar16(vec3, 0x2009) == (vec1.size()-1), "StringUtils::getIndexOfLastNotChar16 failed");
784
785 //---------------------------
786 CCASSERT(originalUTF16.length() == TEST_CODE_NUM, "The length of the original utf16 string isn't equal to TEST_CODE_NUM");
787
788 //---------------------------
789 size_t whiteCodeNum = sizeof(WHITE_SPACE_CODE) / sizeof(WHITE_SPACE_CODE[0]);
790 for( size_t i = 0; i < whiteCodeNum; i++ )
791 {
792 CCASSERT(StringUtils::isUnicodeSpace(WHITE_SPACE_CODE[i]), "StringUtils::isUnicodeSpace failed");
793 }
794
795 CCASSERT(!StringUtils::isUnicodeSpace(0xFFFF), "StringUtils::isUnicodeSpace failed");
796
797 CCASSERT(!StringUtils::isCJKUnicode(0xFFFF) && StringUtils::isCJKUnicode(0x3100), "StringUtils::isCJKUnicode failed");
798}
799
801{
803
804 for (int i = 0; i < 10000; ++i)
805 {
807 }
808}
809
811{
812 return "UTF8 <-> UTF16 Conversion Test, no crash";
813}
814
815// UIHelperSubStringTest
816
818{
820
821 using cocos2d::ui::Helper;
822 {
823 // Trivial case
824 std::string source = "abcdefghij";
825 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 2) == "ab");
826 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 2, 2) == "cd");
827 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 4, 2) == "ef");
828 }
829 {
830 // Empty string
831 std::string source = "";
832
833 // OK
834 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
835 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 1) == "");
836
837 // Error: These cases cause "out of range" error
838 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
839 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 1) == "");
840 }
841 {
842 // Ascii
843 std::string source = "abc";
844
845 // OK
846 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
847 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
848 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 2, 0) == "");
849 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 3, 0) == "");
850 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 3) == "abc");
851 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 4) == "abc");
852 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 2) == "bc");
853 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 3) == "bc");
854 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 2, 1) == "c");
855 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 2, 2) == "c");
856 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 3, 1) == "");
857 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 3, 2) == "");
858
859 // Error: These cases cause "out of range" error
860 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 4, 0) == "");
861 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 4, 1) == "");
862 }
863 {
864 // CJK characters
865 std::string source = "这里是中文测试例";
866
867 // OK
868 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
869 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
870 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 7, 0) == "");
871 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 8, 0) == "");
872 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 8, 1) == "");
873 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 1) == "\xe8\xbf\x99");
874 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 4) == "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad");
875 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 8) == "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b");
876 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 100) == "\xe8\xbf\x99\xe9\x87\x8c\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95\xe4\xbe\x8b");
877 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 2, 5) == "\xe6\x98\xaf\xe4\xb8\xad\xe6\x96\x87\xe6\xb5\x8b\xe8\xaf\x95");
878 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 6, 2) == "\xe8\xaf\x95\xe4\xbe\x8b");
879 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 6, 100) == "\xe8\xaf\x95\xe4\xbe\x8b");
880
881 // Error: These cases cause "out of range" error
882 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 9, 0) == "");
883 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 9, 1) == "");
884 }
885 {
886 // Redundant UTF-8 sequence for Directory traversal attack (1)
887 std::string source = "\xC0\xAF";
888
889 // Error: Can't convert string to correct encoding such as UTF-32
890 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
891 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 1) == "");
892 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
893 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 1) == "");
894 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 2) == "");
895 }
896 {
897 // Redundant UTF-8 sequence for Directory traversal attack (2)
898 std::string source = "\xE0\x80\xAF";
899
900 // Error: Can't convert string to correct encoding such as UTF-32
901 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
902 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 1) == "");
903 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
904 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 1) == "");
905 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 3) == "");
906 }
907 {
908 // Redundant UTF-8 sequence for Directory traversal attack (3)
909 std::string source = "\xF0\x80\x80\xAF";
910
911 // Error: Can't convert string to correct encoding such as UTF-32
912 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 0) == "");
913 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 1) == "");
914 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 0) == "");
915 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 1, 1) == "");
916 CC_ASSERT(Helper::getSubStringOfUTF8String(source, 0, 4) == "");
917 }
918}
919
921{
922 return "ui::Helper::getSubStringOfUTF8String Test";
923}
924
925// ParseIntegerListTest
928
929 {
930 using cocos2d::utils::parseIntegerList;
931
932 std::vector<int> res1{};
933 EXPECT_EQ(res1, parseIntegerList(""));
934
935 std::vector<int> res2{1};
936 EXPECT_EQ(res2, parseIntegerList("1"));
937
938 std::vector<int> res3{1, 2};
939 EXPECT_EQ(res3, parseIntegerList("1 2"));
940
941 std::vector<int> res4{2, 4, 3, 1, 4, 2, 0, 4, 1, 0, 4, 5};
942 EXPECT_EQ(res4, parseIntegerList("2 4 3 1 4 2 0 4 1 0 4 5"));
943
944 std::vector<int> res5{73, 48, 57, 117, 27, 117, 29, 77, 14, 62, 26, 7, 55, 2};
945 EXPECT_EQ(res5, parseIntegerList("73 48 57 117 27 117 29 77 14 62 26 7 55 2"));
946 }
947}
948
950{
951 return "utils::parseIntegerList Test";
952}
953
954// ParseUriTest
956{
958
959 {
960 std::string s("http://www.facebook.com/hello/world?query#fragment");
961 Uri u = Uri::parse(s);
962 EXPECT_EQ("http", u.getScheme());
963 EXPECT_EQ("", u.getUserName());
964 EXPECT_EQ("", u.getPassword());
965 EXPECT_EQ("www.facebook.com", u.getHost());
966 EXPECT_EQ(0, u.getPort());
967 EXPECT_EQ("www.facebook.com", u.getAuthority());
968 EXPECT_EQ("/hello/world", u.getPath());
969 EXPECT_EQ("query", u.getQuery());
970 EXPECT_EQ("fragment", u.getFragment());
971 EXPECT_EQ(s, u.toString()); // canonical
972 }
973
974 {
975 std::string s("http://www.facebook.com:8080/hello/world?query#fragment");
976 Uri u = Uri::parse(s);
977 EXPECT_EQ("http", u.getScheme());
978 EXPECT_EQ("", u.getUserName());
979 EXPECT_EQ("", u.getPassword());
980 EXPECT_EQ("www.facebook.com", u.getHost());
981 EXPECT_EQ(8080, u.getPort());
982 EXPECT_EQ("www.facebook.com:8080", u.getAuthority());
983 EXPECT_EQ("/hello/world", u.getPath());
984 EXPECT_EQ("query", u.getQuery());
985 EXPECT_EQ("fragment", u.getFragment());
986 EXPECT_EQ(s, u.toString()); // canonical
987 }
988
989 {
990 std::string s("http://127.0.0.1:8080/hello/world?query#fragment");
991 Uri u = Uri::parse(s);
992 EXPECT_EQ("http", u.getScheme());
993 EXPECT_EQ("", u.getUserName());
994 EXPECT_EQ("", u.getPassword());
995 EXPECT_EQ("127.0.0.1", u.getHost());
996 EXPECT_EQ(8080, u.getPort());
997 EXPECT_EQ("127.0.0.1:8080", u.getAuthority());
998 EXPECT_EQ("/hello/world", u.getPath());
999 EXPECT_EQ("query", u.getQuery());
1000 EXPECT_EQ("fragment", u.getFragment());
1001 EXPECT_EQ(s, u.toString()); // canonical
1002 }
1003
1004 {
1005 std::string s("http://[::1]:8080/hello/world?query#fragment");
1006 Uri u = Uri::parse(s);
1007 EXPECT_EQ("http", u.getScheme());
1008 EXPECT_EQ("", u.getUserName());
1009 EXPECT_EQ("", u.getPassword());
1010 EXPECT_EQ("[::1]", u.getHost());
1011 EXPECT_EQ("::1", u.getHostName());
1012 EXPECT_EQ(8080, u.getPort());
1013 EXPECT_EQ("[::1]:8080", u.getAuthority());
1014 EXPECT_EQ("/hello/world", u.getPath());
1015 EXPECT_EQ("query", u.getQuery());
1016 EXPECT_EQ("fragment", u.getFragment());
1017 EXPECT_EQ(s, u.toString()); // canonical
1018 }
1019
1020 {
1021 std::string s("http://[2401:db00:20:7004:face:0:29:0]:8080/hello/world?query");
1022 Uri u = Uri::parse(s);
1023 EXPECT_EQ("http", u.getScheme());
1024 EXPECT_EQ("", u.getUserName());
1025 EXPECT_EQ("", u.getPassword());
1026 EXPECT_EQ("[2401:db00:20:7004:face:0:29:0]", u.getHost());
1027 EXPECT_EQ("2401:db00:20:7004:face:0:29:0", u.getHostName());
1028 EXPECT_EQ(8080, u.getPort());
1029 EXPECT_EQ("[2401:db00:20:7004:face:0:29:0]:8080", u.getAuthority());
1030 EXPECT_EQ("/hello/world", u.getPath());
1031 EXPECT_EQ("query", u.getQuery());
1032 EXPECT_EQ("", u.getFragment());
1033 EXPECT_EQ(s, u.toString()); // canonical
1034 }
1035
1036 {
1037 std::string s("http://[2401:db00:20:7004:face:0:29:0]/hello/world?query");
1038 Uri u = Uri::parse(s);
1039 EXPECT_EQ("http", u.getScheme());
1040 EXPECT_EQ("", u.getUserName());
1041 EXPECT_EQ("", u.getPassword());
1042 EXPECT_EQ("[2401:db00:20:7004:face:0:29:0]", u.getHost());
1043 EXPECT_EQ("2401:db00:20:7004:face:0:29:0", u.getHostName());
1044 EXPECT_EQ(0, u.getPort());
1045 EXPECT_EQ("[2401:db00:20:7004:face:0:29:0]", u.getAuthority());
1046 EXPECT_EQ("/hello/world", u.getPath());
1047 EXPECT_EQ("query", u.getQuery());
1048 EXPECT_EQ("", u.getFragment());
1049 EXPECT_EQ(s, u.toString()); // canonical
1050 }
1051
1052 {
1053 std::string s("http://user:pass@host.com/");
1054 Uri u = Uri::parse(s);
1055 EXPECT_EQ("http", u.getScheme());
1056 EXPECT_EQ("user", u.getUserName());
1057 EXPECT_EQ("pass", u.getPassword());
1058 EXPECT_EQ("host.com", u.getHost());
1059 EXPECT_EQ(0, u.getPort());
1060 EXPECT_EQ("user:pass@host.com", u.getAuthority());
1061 EXPECT_EQ("/", u.getPath());
1062 EXPECT_EQ("", u.getQuery());
1063 EXPECT_EQ("", u.getFragment());
1064 EXPECT_EQ(s, u.toString());
1065 }
1066
1067 {
1068 std::string s("http://user@host.com/");
1069 Uri u = Uri::parse(s);
1070 EXPECT_EQ("http", u.getScheme());
1071 EXPECT_EQ("user", u.getUserName());
1072 EXPECT_EQ("", u.getPassword());
1073 EXPECT_EQ("host.com", u.getHost());
1074 EXPECT_EQ(0, u.getPort());
1075 EXPECT_EQ("user@host.com", u.getAuthority());
1076 EXPECT_EQ("/", u.getPath());
1077 EXPECT_EQ("", u.getQuery());
1078 EXPECT_EQ("", u.getFragment());
1079 EXPECT_EQ(s, u.toString());
1080 }
1081
1082 {
1083 std::string s("http://user:@host.com/");
1084 Uri u = Uri::parse(s);
1085 EXPECT_EQ("http", u.getScheme());
1086 EXPECT_EQ("user", u.getUserName());
1087 EXPECT_EQ("", u.getPassword());
1088 EXPECT_EQ("host.com", u.getHost());
1089 EXPECT_EQ(0, u.getPort());
1090 EXPECT_EQ("user@host.com", u.getAuthority());
1091 EXPECT_EQ("/", u.getPath());
1092 EXPECT_EQ("", u.getQuery());
1093 EXPECT_EQ("", u.getFragment());
1094 EXPECT_EQ("http://user@host.com/", u.toString());
1095 }
1096
1097 {
1098 std::string s("http://:pass@host.com/");
1099 Uri u = Uri::parse(s);
1100 EXPECT_EQ("http", u.getScheme());
1101 EXPECT_EQ("", u.getUserName());
1102 EXPECT_EQ("pass", u.getPassword());
1103 EXPECT_EQ("host.com", u.getHost());
1104 EXPECT_EQ(0, u.getPort());
1105 EXPECT_EQ(":pass@host.com", u.getAuthority());
1106 EXPECT_EQ("/", u.getPath());
1107 EXPECT_EQ("", u.getQuery());
1108 EXPECT_EQ("", u.getFragment());
1109 EXPECT_EQ(s, u.toString());
1110 }
1111
1112 {
1113 std::string s("http://@host.com/");
1114 Uri u = Uri::parse(s);
1115 EXPECT_EQ("http", u.getScheme());
1116 EXPECT_EQ("", u.getUserName());
1117 EXPECT_EQ("", u.getPassword());
1118 EXPECT_EQ("host.com", u.getHost());
1119 EXPECT_EQ(0, u.getPort());
1120 EXPECT_EQ("host.com", u.getAuthority());
1121 EXPECT_EQ("/", u.getPath());
1122 EXPECT_EQ("", u.getQuery());
1123 EXPECT_EQ("", u.getFragment());
1124 EXPECT_EQ("http://host.com/", u.toString());
1125 }
1126
1127 {
1128 std::string s("http://:@host.com/");
1129 Uri u = Uri::parse(s);
1130 EXPECT_EQ("http", u.getScheme());
1131 EXPECT_EQ("", u.getUserName());
1132 EXPECT_EQ("", u.getPassword());
1133 EXPECT_EQ("host.com", u.getHost());
1134 EXPECT_EQ(0, u.getPort());
1135 EXPECT_EQ("host.com", u.getAuthority());
1136 EXPECT_EQ("/", u.getPath());
1137 EXPECT_EQ("", u.getQuery());
1138 EXPECT_EQ("", u.getFragment());
1139 EXPECT_EQ("http://host.com/", u.toString());
1140 }
1141
1142 {
1143 std::string s("file:///etc/motd");
1144 Uri u = Uri::parse(s);
1145 EXPECT_EQ("file", u.getScheme());
1146 EXPECT_EQ("", u.getUserName());
1147 EXPECT_EQ("", u.getPassword());
1148 EXPECT_EQ("", u.getHost());
1149 EXPECT_EQ(0, u.getPort());
1150 EXPECT_EQ("", u.getAuthority());
1151 EXPECT_EQ("/etc/motd", u.getPath());
1152 EXPECT_EQ("", u.getQuery());
1153 EXPECT_EQ("", u.getFragment());
1154 EXPECT_EQ(s, u.toString());
1155 }
1156
1157 {
1158 std::string s("file://etc/motd");
1159 Uri u = Uri::parse(s);
1160 EXPECT_EQ("file", u.getScheme());
1161 EXPECT_EQ("", u.getUserName());
1162 EXPECT_EQ("", u.getPassword());
1163 EXPECT_EQ("etc", u.getHost());
1164 EXPECT_EQ(0, u.getPort());
1165 EXPECT_EQ("etc", u.getAuthority());
1166 EXPECT_EQ("/motd", u.getPath());
1167 EXPECT_EQ("", u.getQuery());
1168 EXPECT_EQ("", u.getFragment());
1169 EXPECT_EQ(s, u.toString());
1170 }
1171
1172 {
1173 // test query parameters
1174 std::string s("http://localhost?&key1=foo&key2=&key3&=bar&=bar=&");
1175 Uri u = Uri::parse(s);
1176 auto paramsList = u.getQueryParams();
1177 std::map<std::string, std::string> params;
1178 for (auto& param : paramsList) {
1179 params[param.first] = param.second;
1180 }
1181 EXPECT_EQ(3, params.size());
1182 EXPECT_EQ("foo", params["key1"]);
1183 EXPECT_NE(params.end(), params.find("key2"));
1184 EXPECT_EQ("", params["key2"]);
1185 EXPECT_NE(params.end(), params.find("key3"));
1186 EXPECT_EQ("", params["key3"]);
1187 }
1188
1189 {
1190 // test query parameters
1191 std::string s("http://localhost?&&&&&&&&&&&&&&&");
1192 Uri u = Uri::parse(s);
1193 auto params = u.getQueryParams();
1194 EXPECT_TRUE(params.empty());
1195 }
1196
1197 {
1198 // test query parameters
1199 std::string s("http://localhost?&=invalid_key&key2&key3=foo");
1200 Uri u = Uri::parse(s);
1201 auto paramsList = u.getQueryParams();
1202 std::map<std::string, std::string> params;
1203 for (auto& param : paramsList) {
1204 params[param.first] = param.second;
1205 }
1206 EXPECT_EQ(2, params.size());
1207 EXPECT_NE(params.end(), params.find("key2"));
1208 EXPECT_EQ("", params["key2"]);
1209 EXPECT_EQ("foo", params["key3"]);
1210 }
1211
1212 {
1213 // test query parameters
1214 std::string s("http://localhost?&key1=====&&=key2&key3=");
1215 Uri u = Uri::parse(s);
1216 auto paramsList = u.getQueryParams();
1217 std::map<std::string, std::string> params;
1218 for (auto& param : paramsList) {
1219 params[param.first] = param.second;
1220 }
1221 EXPECT_EQ(1, params.size());
1222 EXPECT_NE(params.end(), params.find("key3"));
1223 EXPECT_EQ("", params["key3"]);
1224 }
1225
1226 {
1227 // test query parameters
1228 std::string s("ws://localhost:90?key1=foo=bar&key2=foobar&");
1229 Uri u = Uri::parse(s);
1230 auto paramsList = u.getQueryParams();
1231 std::map<std::string, std::string> params;
1232 for (auto& param : paramsList) {
1233 params[param.first] = param.second;
1234 }
1235 EXPECT_EQ(1, params.size());
1236 EXPECT_EQ("foobar", params["key2"]);
1237
1238 // copy constructor
1239 {
1240 Uri v(u);
1241 u = v = u;
1242 EXPECT_TRUE(v.isValid());
1243 EXPECT_EQ("ws", v.getScheme());
1244 EXPECT_EQ("localhost", v.getHost());
1245 EXPECT_EQ("localhost", v.getHostName());
1246 EXPECT_EQ("", v.getPath());
1247 EXPECT_EQ(90, v.getPort());
1248 EXPECT_EQ("", v.getFragment());
1249 EXPECT_EQ("key1=foo=bar&key2=foobar&", v.getQuery());
1250 EXPECT_EQ(u, v);
1251 }
1252
1253 // copy assign operator
1254 {
1255 Uri v;
1256 v = u;
1257 EXPECT_TRUE(v.isValid());
1258 EXPECT_EQ("ws", v.getScheme());
1259 EXPECT_EQ("localhost", v.getHost());
1260 EXPECT_EQ("localhost", v.getHostName());
1261 EXPECT_EQ("", v.getPath());
1262 EXPECT_EQ(90, v.getPort());
1263 EXPECT_EQ("", v.getFragment());
1264 EXPECT_EQ("key1=foo=bar&key2=foobar&", v.getQuery());
1265 EXPECT_EQ(u, v);
1266 }
1267
1268 // Self move assignment
1269 {
1270 u = u;
1271 EXPECT_TRUE(u.isValid());
1272 }
1273
1274 // Self move assignment
1275 {
1276 u = std::move(u);
1277 EXPECT_TRUE(u.isValid());
1278 }
1279
1280 // move constructor
1281 {
1282 Uri v = std::move(u);
1283 EXPECT_FALSE(u.isValid());
1284 EXPECT_TRUE(v.isValid());
1285 EXPECT_EQ("ws", v.getScheme());
1286 EXPECT_EQ("localhost", v.getHost());
1287 EXPECT_EQ("localhost", v.getHostName());
1288 EXPECT_EQ("", v.getPath());
1289 EXPECT_EQ(90, v.getPort());
1290 EXPECT_EQ("", v.getFragment());
1291 EXPECT_EQ("key1=foo=bar&key2=foobar&", v.getQuery());
1292 u = std::move(v);
1293 }
1294
1295 // copy assign operator
1296 {
1297 Uri v;
1298 v = std::move(u);
1299 EXPECT_FALSE(u.isValid());
1300 EXPECT_TRUE(v.isValid());
1301 EXPECT_EQ("ws", v.getScheme());
1302 EXPECT_EQ("localhost", v.getHost());
1303 EXPECT_EQ("localhost", v.getHostName());
1304 EXPECT_EQ("", v.getPath());
1305 EXPECT_EQ(90, v.getPort());
1306 EXPECT_EQ("", v.getFragment());
1307 EXPECT_EQ("key1=foo=bar&key2=foobar&", v.getQuery());
1308 u = v;
1309 }
1310 }
1311
1312 {
1313 std::string s("2http://www.facebook.com");
1314
1315 Uri u = Uri::parse(s);
1316 EXPECT_FALSE(u.isValid());
1317 }
1318
1319 {
1320 std::string s("www[facebook]com");
1321
1322 Uri u = Uri::parse("http://" + s);
1323 EXPECT_FALSE(u.isValid());
1324 }
1325
1326 {
1327 std::string s("http://[::1:8080/hello/world?query#fragment");
1328 Uri u = Uri::parse(s);
1329 EXPECT_FALSE(u.isValid());
1330 }
1331
1332 {
1333 std::string s("http://::1]:8080/hello/world?query#fragment");
1334
1335 Uri u = Uri::parse(s);
1336 EXPECT_FALSE(u.isValid());
1337 }
1338
1339 {
1340 std::string s("http://::1:8080/hello/world?query#fragment");
1341 Uri u = Uri::parse(s);
1342 EXPECT_FALSE(u.isValid());
1343 }
1344
1345 {
1346 std::string s("http://2401:db00:20:7004:face:0:29:0/hello/world?query");
1347 Uri u = Uri::parse(s);
1348 EXPECT_FALSE(u.isValid());
1349 }
1350
1351 {
1352 Uri http = Uri::parse("http://google.com");
1353 Uri https = Uri::parse("https://www.google.com:90");
1354 Uri query = Uri::parse("http://google.com:8080/foo/bar?foo=bar");
1355 Uri localhost = Uri::parse("http://localhost:8080");
1356 Uri ipv6 = Uri::parse("https://[2001:0db8:85a3:0042:1000:8a2e:0370:7334]");
1357 Uri ipv6short = Uri::parse("http://[2001:db8:85a3:42:1000:8a2e:370:7334]");
1358 Uri ipv6port = Uri::parse("http://[2001:db8:85a3:42:1000:8a2e:370:7334]:90");
1359 Uri ipv6abbrev = Uri::parse("http://[2001::7334:a:90]");
1360 Uri ipv6http = Uri::parse("http://[2001::7334:a]:90");
1361 Uri ipv6query = Uri::parse("http://[2001::7334:a]:90/foo/bar?foo=bar");
1362
1363 EXPECT_EQ(http.getScheme(), "http");
1364 EXPECT_EQ(http.getPort(), 0);
1365 EXPECT_EQ(http.getHost(), "google.com");
1366 EXPECT_EQ(https.getScheme(), "https");
1367 EXPECT_EQ(https.getPort(), 90);
1368 EXPECT_EQ(https.getHost(), "www.google.com");
1369 EXPECT_EQ(query.getPort(), 8080);
1370 EXPECT_EQ(query.getPathEtc(), "/foo/bar?foo=bar");
1371 EXPECT_EQ(localhost.getScheme(), "http");
1372 EXPECT_EQ(localhost.getHost(), "localhost");
1373 EXPECT_EQ(localhost.getPort(), 8080);
1374 EXPECT_EQ(ipv6.getScheme(), "https");
1375 EXPECT_EQ(ipv6.getHostName(), "2001:0db8:85a3:0042:1000:8a2e:0370:7334");
1376 EXPECT_EQ(ipv6.getPort(), 0);
1377 EXPECT_EQ(ipv6short.getScheme(), "http");
1378 EXPECT_EQ(ipv6short.getHostName(), "2001:db8:85a3:42:1000:8a2e:370:7334");
1379 EXPECT_EQ(ipv6short.getPort(), 0);
1380 EXPECT_EQ(ipv6port.getScheme(), "http");
1381 EXPECT_EQ(ipv6port.getHostName(), "2001:db8:85a3:42:1000:8a2e:370:7334");
1382 EXPECT_EQ(ipv6port.getPort(), 90);
1383 EXPECT_EQ(ipv6abbrev.getScheme(), "http");
1384 EXPECT_EQ(ipv6abbrev.getHostName(), "2001::7334:a:90");
1385 EXPECT_EQ(ipv6abbrev.getPort(), 0);
1386 EXPECT_EQ(ipv6http.getScheme(), "http");
1387 EXPECT_EQ(ipv6http.getPort(), 90);
1388 EXPECT_EQ(ipv6http.getHostName(), "2001::7334:a");
1389 EXPECT_EQ(ipv6query.getScheme(), "http");
1390 EXPECT_EQ(ipv6query.getPort(), 90);
1391 EXPECT_EQ(ipv6query.getHostName(), "2001::7334:a");
1392 EXPECT_EQ(ipv6query.getPathEtc(), "/foo/bar?foo=bar");
1393 }
1394
1395 {
1396 Uri u0 = Uri::parse("http://localhost:84/foo.html?&q=123");
1397 Uri u1 = Uri::parse("https://localhost:82/foo.html?&q=1");
1398 Uri u2 = Uri::parse("ws://localhost/foo");
1399 Uri u3 = Uri::parse("localhost/foo");
1400 Uri u4 = Uri::parse("localhost:8080");
1401 Uri u5 = Uri::parse("bb://localhost?&foo=12:4&ccc=13");
1402 Uri u6 = Uri::parse("cc://localhost:91?&foo=321&bbb=1");
1403
1404 EXPECT_EQ(u0.getScheme(), "http");
1405 EXPECT_EQ(u0.getHost(), "localhost");
1406 EXPECT_EQ(u0.getPort(), 84);
1407 EXPECT_EQ(u0.getPath(), "/foo.html");
1408 EXPECT_EQ(u0.getPathEtc(), "/foo.html?&q=123");
1409
1410 EXPECT_EQ(u1.getScheme(), "https");
1411 EXPECT_EQ(u1.getHost(), "localhost");
1412 EXPECT_EQ(u1.getPort(), 82);
1413 EXPECT_EQ(u1.getPathEtc(), "/foo.html?&q=1");
1414
1415 EXPECT_EQ(u2.getScheme(), "ws");
1416 EXPECT_EQ(u2.getHost(), "localhost");
1417 EXPECT_EQ(u2.getPort(), 0);
1418 EXPECT_EQ(u2.getPath(), "/foo");
1419
1420 EXPECT_EQ(u3.getScheme(), "");
1421 EXPECT_EQ(u3.getHost(), "localhost");
1422 EXPECT_EQ(u3.getPort(), 0);
1423 EXPECT_EQ(u3.getPath(), "/foo");
1424
1425 EXPECT_EQ(u4.getScheme(), "");
1426 EXPECT_EQ(u4.getHost(), "localhost");
1427 EXPECT_EQ(u4.getPort(), 8080);
1428 EXPECT_EQ(u4.getPath(), "");
1429 EXPECT_EQ(u4.getPathEtc(), "");
1430
1431 EXPECT_EQ(u5.getScheme(), "bb");
1432 EXPECT_EQ(u5.getHost(), "localhost");
1433 EXPECT_EQ(u5.getPort(), 0);
1434 EXPECT_EQ(u5.getPath(), "");
1435 EXPECT_EQ(u5.getPathEtc(), "?&foo=12:4&ccc=13");
1436 EXPECT_EQ(u5.getQuery(), "&foo=12:4&ccc=13");
1437
1438 EXPECT_EQ(u6.getScheme(), "cc");
1439 EXPECT_EQ(u6.getHost(), "localhost");
1440 EXPECT_EQ(u6.getPort(), 91);
1441 EXPECT_EQ(u6.getPath(), "");
1442 EXPECT_EQ(u6.getPathEtc(), "?&foo=321&bbb=1");
1443 EXPECT_EQ(u6.getQuery(), "&foo=321&bbb=1");
1444 }
1445
1446}
1447
1448std::string ParseUriTest::subtitle() const
1449{
1450 return "Uri::parse Test";
1451}
1452
1453// MathUtilTest
1454
1455namespace UnitTest {
1456
1457#ifdef INCLUDE_NEON32
1458#include "math/MathUtilNeon.inl"
1459#endif
1460
1461#ifdef INCLUDE_NEON64
1462#include "math/MathUtilNeon64.inl"
1463#endif
1464
1465#ifdef INCLUDE_SSE
1466//FIXME: #include "math/MathUtilSSE.inl"
1467#endif
1468
1469#include "math/MathUtil.inl"
1470
1471} // namespace UnitTest {
1472
1473// I know the next line looks ugly, but it's a way to test MathUtil. :)
1474using namespace UnitTest::cocos2d;
1475
1476static void __checkMathUtilResult(const char* description, const float* a1, const float* a2, int size)
1477{
1478 log("-------------checking %s ----------------------------", description);
1479 // Check whether the result of the optimized instruction is the same as which is implemented in C
1480 for (int i = 0; i < size; ++i)
1481 {
1482 bool r = fabs(a1[i] - a2[i]) < 0.00001f;//FLT_EPSILON;
1483 if (r)
1484 {
1485 log("Correct: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]);
1486 }
1487 else
1488 {
1489 log("Wrong: a1[%d]=%f, a2[%d]=%f", i, a1[i], i, a2[i]);
1490 }
1491 CCASSERT(r, "The optimized instruction is implemented in a wrong way, please check it!");
1492 }
1493}
1494
1496{
1498
1499 const int MAT4_SIZE = 16;
1500 const int VEC4_SIZE = 4;
1501
1502 const float inMat41[MAT4_SIZE] = {
1503 0.234023f, 2.472349f, 1.984244f, 2.23348f,
1504 0.634124f, 0.234975f, 6.384572f, 0.82368f,
1505 0.738028f, 1.845237f, 1.934721f, 1.62343f,
1506 0.339023f, 3.472452f, 1.324714f, 4.23852f,
1507 };
1508
1509 const float inMat42[MAT4_SIZE] = {
1510 1.640232f, 4.472349f, 0.983244f, 1.23343f,
1511 2.834124f, 8.234975f, 0.082572f, 3.82464f,
1512 3.238028f, 2.845237f, 0.331721f, 4.62544f,
1513 4.539023f, 9.472452f, 3.520714f, 2.23252f,
1514 };
1515
1516 const float scalar = 1.323298f;
1517 const float x = 0.432234f;
1518 const float y = 1.333229f;
1519 const float z = 2.535292f;
1520 const float w = 4.632234f;
1521
1522 const float inVec4[VEC4_SIZE] = {2.323478f, 0.238482f, 4.223783f, 7.238238f};
1523 const float inVec42[VEC4_SIZE] = {0.322374f, 8.258883f, 3.293683f, 2.838337f};
1524
1525 float outMat4Opt[MAT4_SIZE] = {0};
1526 float outMat4C[MAT4_SIZE] = {0};
1527 float outVec4Opt[VEC4_SIZE] = {0};
1528 float outVec4C[VEC4_SIZE] = {0};
1529
1530 // inline static void addMatrix(const float* m, float scalar, float* dst);
1531 MathUtilC::addMatrix(inMat41, scalar, outMat4C);
1532
1533#ifdef INCLUDE_NEON32
1534 MathUtilNeon::addMatrix(inMat41, scalar, outMat4Opt);
1535#endif
1536
1537#ifdef INCLUDE_NEON64
1538 MathUtilNeon64::addMatrix(inMat41, scalar, outMat4Opt);
1539#endif
1540
1541#ifdef INCLUDE_SSE
1542// FIXME:
1543#endif
1544
1545 __checkMathUtilResult("inline static void addMatrix(const float* m, float scalar, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1546 // Clean
1547 memset(outMat4C, 0, sizeof(outMat4C));
1548 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1549
1550 // inline static void addMatrix(const float* m1, const float* m2, float* dst);
1551 MathUtilC::addMatrix(inMat41, inMat42, outMat4C);
1552
1553#ifdef INCLUDE_NEON32
1554 MathUtilNeon::addMatrix(inMat41, inMat42, outMat4Opt);
1555#endif
1556
1557#ifdef INCLUDE_NEON64
1558 MathUtilNeon64::addMatrix(inMat41, inMat42, outMat4Opt);
1559#endif
1560
1561#ifdef INCLUDE_SSE
1562 // FIXME:
1563#endif
1564
1565 __checkMathUtilResult("inline static void addMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1566 // Clean
1567 memset(outMat4C, 0, sizeof(outMat4C));
1568 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1569
1570 // inline static void subtractMatrix(const float* m1, const float* m2, float* dst);
1571 MathUtilC::subtractMatrix(inMat41, inMat42, outMat4C);
1572
1573#ifdef INCLUDE_NEON32
1574 MathUtilNeon::subtractMatrix(inMat41, inMat42, outMat4Opt);
1575#endif
1576
1577#ifdef INCLUDE_NEON64
1578 MathUtilNeon64::subtractMatrix(inMat41, inMat42, outMat4Opt);
1579#endif
1580
1581#ifdef INCLUDE_SSE
1582 // FIXME:
1583#endif
1584
1585 __checkMathUtilResult("inline static void subtractMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1586 // Clean
1587 memset(outMat4C, 0, sizeof(outMat4C));
1588 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1589
1590 // inline static void multiplyMatrix(const float* m, float scalar, float* dst);
1591 MathUtilC::multiplyMatrix(inMat41, scalar, outMat4C);
1592
1593#ifdef INCLUDE_NEON32
1594 MathUtilNeon::multiplyMatrix(inMat41, scalar, outMat4Opt);
1595#endif
1596
1597#ifdef INCLUDE_NEON64
1598 MathUtilNeon64::multiplyMatrix(inMat41, scalar, outMat4Opt);
1599#endif
1600
1601#ifdef INCLUDE_SSE
1602 // FIXME:
1603#endif
1604
1605 __checkMathUtilResult("inline static void multiplyMatrix(const float* m, float scalar, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1606 // Clean
1607 memset(outMat4C, 0, sizeof(outMat4C));
1608 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1609
1610 // inline static void multiplyMatrix(const float* m1, const float* m2, float* dst);
1611 MathUtilC::multiplyMatrix(inMat41, inMat42, outMat4C);
1612
1613#ifdef INCLUDE_NEON32
1614 MathUtilNeon::multiplyMatrix(inMat41, inMat42, outMat4Opt);
1615#endif
1616
1617#ifdef INCLUDE_NEON64
1618 MathUtilNeon64::multiplyMatrix(inMat41, inMat42, outMat4Opt);
1619#endif
1620
1621#ifdef INCLUDE_SSE
1622 // FIXME:
1623#endif
1624
1625 __checkMathUtilResult("inline static void multiplyMatrix(const float* m1, const float* m2, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1626 // Clean
1627 memset(outMat4C, 0, sizeof(outMat4C));
1628 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1629
1630 // inline static void negateMatrix(const float* m, float* dst);
1631 MathUtilC::negateMatrix(inMat41, outMat4C);
1632
1633#ifdef INCLUDE_NEON32
1634 MathUtilNeon::negateMatrix(inMat41, outMat4Opt);
1635#endif
1636
1637#ifdef INCLUDE_NEON64
1638 MathUtilNeon64::negateMatrix(inMat41, outMat4Opt);
1639#endif
1640
1641#ifdef INCLUDE_SSE
1642 // FIXME:
1643#endif
1644
1645 __checkMathUtilResult("inline static void negateMatrix(const float* m, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1646 // Clean
1647 memset(outMat4C, 0, sizeof(outMat4C));
1648 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1649
1650 // inline static void transposeMatrix(const float* m, float* dst);
1651 MathUtilC::transposeMatrix(inMat41, outMat4C);
1652
1653#ifdef INCLUDE_NEON32
1654 MathUtilNeon::transposeMatrix(inMat41, outMat4Opt);
1655#endif
1656
1657#ifdef INCLUDE_NEON64
1658 MathUtilNeon64::transposeMatrix(inMat41, outMat4Opt);
1659#endif
1660
1661#ifdef INCLUDE_SSE
1662 // FIXME:
1663#endif
1664
1665 __checkMathUtilResult("inline static void transposeMatrix(const float* m, float* dst);", outMat4C, outMat4Opt, MAT4_SIZE);
1666 // Clean
1667 memset(outMat4C, 0, sizeof(outMat4C));
1668 memset(outMat4Opt, 0, sizeof(outMat4Opt));
1669
1670 // inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst);
1671 MathUtilC::transformVec4(inMat41, x, y, z, w, outVec4C);
1672
1673#ifdef INCLUDE_NEON32
1674 MathUtilNeon::transformVec4(inMat41, x, y, z, w, outVec4Opt);
1675#endif
1676
1677#ifdef INCLUDE_NEON64
1678 MathUtilNeon64::transformVec4(inMat41, x, y, z, w, outVec4Opt);
1679#endif
1680
1681#ifdef INCLUDE_SSE
1682 // FIXME:
1683#endif
1684
1685 __checkMathUtilResult("inline static void transformVec4(const float* m, float x, float y, float z, float w, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE);
1686 // Clean
1687 memset(outVec4C, 0, sizeof(outVec4C));
1688 memset(outVec4Opt, 0, sizeof(outVec4Opt));
1689
1690 // inline static void transformVec4(const float* m, const float* v, float* dst);
1691 MathUtilC::transformVec4(inMat41, inVec4, outVec4C);
1692
1693#ifdef INCLUDE_NEON32
1694 MathUtilNeon::transformVec4(inMat41, inVec4, outVec4Opt);
1695#endif
1696
1697#ifdef INCLUDE_NEON64
1698 MathUtilNeon64::transformVec4(inMat41, inVec4, outVec4Opt);
1699#endif
1700
1701#ifdef INCLUDE_SSE
1702 // FIXME:
1703#endif
1704
1705 __checkMathUtilResult("inline static void transformVec4(const float* m, const float* v, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE);
1706 // Clean
1707 memset(outVec4C, 0, sizeof(outVec4C));
1708 memset(outVec4Opt, 0, sizeof(outVec4Opt));
1709
1710 // inline static void crossVec3(const float* v1, const float* v2, float* dst);
1711 MathUtilC::crossVec3(inVec4, inVec42, outVec4C);
1712
1713#ifdef INCLUDE_NEON32
1714 MathUtilNeon::crossVec3(inVec4, inVec42, outVec4Opt);
1715#endif
1716
1717#ifdef INCLUDE_NEON64
1718 MathUtilNeon64::crossVec3(inVec4, inVec42, outVec4Opt);
1719#endif
1720
1721#ifdef INCLUDE_SSE
1722 // FIXME:
1723#endif
1724
1725 __checkMathUtilResult("inline static void crossVec3(const float* v1, const float* v2, float* dst);", outVec4C, outVec4Opt, VEC4_SIZE);
1726 // Clean
1727 memset(outVec4C, 0, sizeof(outVec4C));
1728 memset(outVec4Opt, 0, sizeof(outVec4Opt));
1729}
1730
1731std::string MathUtilTest::subtitle() const
1732{
1733 return "MathUtilTest";
1734}
1735
1736// ResizableBufferAdapterTest
1737
1739{
1741
1742 Data data;
1743 ResizableBufferAdapter<Data> buffer(&data);
1744
1745 FileUtils::getInstance()->getContents("effect1.wav", &buffer);
1746 EXPECT_EQ(data.getSize(), 10026);
1747
1748 FileUtils::getInstance()->getContents("effect2.ogg", &buffer);
1749 EXPECT_EQ(data.getSize(), 4278);
1750
1751 FileUtils::getInstance()->getContents("effect1.wav", &buffer);
1752 EXPECT_EQ(data.getSize(), 10026);
1753}
1754
1756{
1757 return "ResiziableBufferAdapter<Data> Test";
1758}
1759
1760
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
#define EXPECT_NE(a, b)
Definition: UnitTest.cpp:64
#define EXPECT_TRUE(a)
Definition: UnitTest.cpp:65
static void __checkMathUtilResult(const char *description, const float *a1, const float *a2, int size)
Definition: UnitTest.cpp:1476
#define EXPECT_FALSE(a)
Definition: UnitTest.cpp:66
static void doUTFConversion()
Definition: UnitTest.cpp:728
#define EXPECT_EQ(a, b)
Definition: UnitTest.cpp:63
USING_NS_CC
Definition: UnitTest.cpp:30
static const unsigned char __utf8Code[]
Definition: UnitTest.cpp:682
static const char16_t WHITE_SPACE_CODE[]
Definition: UnitTest.cpp:699
#define TEST_CODE_NUM
Definition: UnitTest.cpp:662
static const char16_t __utf16Code[]
Definition: UnitTest.cpp:664
virtual std::string subtitle() const override
Definition: UnitTest.cpp:1731
virtual void onEnter() override
Definition: UnitTest.cpp:1495
virtual void onEnter() override
Definition: UnitTest.cpp:926
virtual std::string subtitle() const override
Definition: UnitTest.cpp:949
virtual std::string subtitle() const override
Definition: UnitTest.cpp:1448
virtual void onEnter() override
Definition: UnitTest.cpp:955
virtual std::string subtitle() const override
Definition: UnitTest.cpp:1755
virtual void onEnter() override
Definition: UnitTest.cpp:1738
virtual void onEnter() override
Definition: UnitTest.cpp:371
virtual std::string subtitle() const override
Definition: UnitTest.cpp:568
void constFunc(const cocos2d::Map< std::string, cocos2d::Node * > &map) const
Definition: UnitTest.cpp:562
void constFunc(const cocos2d::Vector< Node * > &vec) const
Definition: UnitTest.cpp:358
virtual void onEnter() override
Definition: UnitTest.cpp:92
virtual std::string subtitle() const override
Definition: UnitTest.cpp:363
virtual void onEnter() override
Definition: BaseTest.cpp:430
virtual std::string subtitle() const override
Definition: UnitTest.cpp:920
virtual void onEnter() override
Definition: UnitTest.cpp:817
virtual std::string subtitle() const override
Definition: UnitTest.cpp:810
virtual void onEnter() override
Definition: UnitTest.cpp:800
virtual std::string title() const override
Definition: UnitTest.cpp:85
virtual std::string subtitle() const override
Definition: UnitTest.cpp:650
virtual void onEnter() override
Definition: UnitTest.cpp:575
void constFunc(const cocos2d::Value &value) const
Definition: UnitTest.cpp:655