PuzzleSDK
TemplateMapTest类 参考

#include <UnitTest.h>

+ 类 TemplateMapTest 继承关系图:
+ TemplateMapTest 的协作图:

Public 成员函数

 CREATE_FUNC (TemplateMapTest)
 
virtual void onEnter () override
 
virtual std::string subtitle () const override
 
void constFunc (const cocos2d::Map< std::string, cocos2d::Node * > &map) const
 
- Public 成员函数 继承自 UnitTestDemo
virtual std::string title () const override
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 UnitTest.h49 行定义.

成员函数说明

◆ constFunc()

void TemplateMapTest::constFunc ( const cocos2d::Map< std::string, cocos2d::Node * > &  map) const

在文件 UnitTest.cpp562 行定义.

563{
564 log("[%s]=(tag)%d", "0", map.at("0")->getTag());
565 log("[%s]=(tag)%d", "1", map.find("1")->second->getTag());
566}

被这些函数引用 onEnter().

+ 这是这个函数的调用关系图:

◆ CREATE_FUNC()

TemplateMapTest::CREATE_FUNC ( TemplateMapTest  )

◆ onEnter()

void TemplateMapTest::onEnter ( )
overridevirtual

重载 TestCase .

在文件 UnitTest.cpp371 行定义.

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}
void constFunc(const cocos2d::Map< std::string, cocos2d::Node * > &map) const
Definition: UnitTest.cpp:562
virtual void onEnter() override
Definition: BaseTest.cpp:430

引用了 constFunc() , 以及 TestCase::onEnter().

+ 函数调用图:

◆ subtitle()

std::string TemplateMapTest::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 UnitTest.cpp568 行定义.

569{
570 return "Map<K, V>, should not crash";
571}

该类的文档由以下文件生成: