Horizon Official Technical Documentation
ReferenceTypeListTest.cpp File Reference
#include "Core/Structures/LinkedList/ReferenceList/Reference.hpp"
#include "Core/Structures/LinkedList/ReferenceList/RefManager.hpp"
#include "Core/Structures/TypeList.hpp"
#include <boost/test/unit_test.hpp>
#include <cstring>
#include <iostream>
#include <cassert>
+ Include dependency graph for ReferenceTypeListTest.cpp:

Classes

class  TestRefManager< OBJECT >
 
class  TestReference< OBJECT >
 
class  ReferenceObject< T >
 
class  GenericTestObject
 
class  A
 
class  B
 
class  C
 
struct  ContainerMapList< OBJECT >
 
struct  ContainerMapList< TypeNull >
 
struct  ContainerMapList< TypeList< HEAD, TAIL > >
 
class  TypeRefContainer< OBJECT_TYPES >
 
class  TypeContainerVisitor< VISITOR, TYPE_CONTAINER >
 
class  CompareGenericTestObjectID
 
struct  GenericTestObjectSearcher< PREDICATE >
 

Namespaces

namespace  TypeListIterator
 

Macros

#define BOOST_TEST_MODULE   "ReferenceTypeListTest"
 
#define MAX_A_TYPES   3
 
#define MAX_B_TYPES   6
 
#define MAX_C_TYPES   9
 
#define ID_CHECK   42
 

Functions

template<class SPECIFIC_TYPE >
SPECIFIC_TYPE * TypeListIterator::Insert (ContainerMapList< SPECIFIC_TYPE > &elements, SPECIFIC_TYPE *obj)
 
template<class SPECIFIC_TYPE >
SPECIFIC_TYPE * TypeListIterator::Insert (ContainerMapList< TypeNull > &, SPECIFIC_TYPE *)
 
template<class SPECIFIC_TYPE , class T >
SPECIFIC_TYPE * TypeListIterator::Insert (ContainerMapList< T > &, SPECIFIC_TYPE *)
 
template<class SPECIFIC_TYPE , class HEAD , class TAIL >
SPECIFIC_TYPE * TypeListIterator::Insert (ContainerMapList< TypeList< HEAD, TAIL > > &elements, SPECIFIC_TYPE *obj)
 
template<class SPECIFIC_TYPE >
size_t TypeListIterator::count (ContainerMapList< SPECIFIC_TYPE > const &elements, SPECIFIC_TYPE *)
 
template<class SPECIFIC_TYPE >
size_t TypeListIterator::count (ContainerMapList< TypeNull > const &, SPECIFIC_TYPE *)
 
template<class SPECIFIC_TYPE , class T >
size_t TypeListIterator::count (ContainerMapList< T > const &, SPECIFIC_TYPE *)
 
template<class SPECIFIC_TYPE , class T >
size_t TypeListIterator::count (ContainerMapList< TypeList< SPECIFIC_TYPE, T > > const &elements, SPECIFIC_TYPE *fake)
 
template<class SPECIFIC_TYPE , class H , class T >
size_t TypeListIterator::count (ContainerMapList< TypeList< H, T > > const &elements, SPECIFIC_TYPE *fake)
 
template<class TypeNull >
size_t TypeListIterator::count_all (ContainerMapList< TypeNull > const &elements)
 
template<class H , class T >
size_t TypeListIterator::count_all (ContainerMapList< TypeList< H, T > > const &elements)
 
template<class VISITOR >
void VisitorHelper (VISITOR &, ContainerMapList< TypeNull > &)
 
template<class VISITOR , class T >
void VisitorHelper (VISITOR &v, ContainerMapList< T > &c)
 
template<class VISITOR , class H , class T >
void VisitorHelper (VISITOR &v, ContainerMapList< TypeList< H, T > > &c)
 
template<class VISITOR , class OBJECT_TYPES >
void VisitorHelper (VISITOR &v, TypeRefContainer< OBJECT_TYPES > &c)
 
typedef TYPELIST_3 (A, B, C) MyTypes
 
void print_count (TypeRefContainer< MyTypes > &refContainer)
 
 BOOST_AUTO_TEST_CASE (ReferenceTypeListTest)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   "ReferenceTypeListTest"

◆ ID_CHECK

#define ID_CHECK   42

◆ MAX_A_TYPES

#define MAX_A_TYPES   3

◆ MAX_B_TYPES

#define MAX_B_TYPES   6

◆ MAX_C_TYPES

#define MAX_C_TYPES   9

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( ReferenceTypeListTest  )

Searcher & Checker tests.

421{
422 TypeRefContainer<MyTypes> refContainer;
423
424 A *a[MAX_A_TYPES];
425 B *b[MAX_B_TYPES];
426 C *c[MAX_C_TYPES];
427
428 print_count(refContainer);
429
430 int aids[] = { 11, 21, 36 };
431 for (int i = 0; i < MAX_A_TYPES; i++) {
432 a[i] = new A(aids[i]);
433 refContainer.template insert<A>(a[i]);
434 assert(a[i]->is_valid());
435 }
436
437 BOOST_CHECK_EQUAL(refContainer.count<A>(), MAX_A_TYPES);
438 BOOST_CHECK_EQUAL(refContainer.count<B>(), 0);
439 BOOST_CHECK_EQUAL(refContainer.count<C>(), 0);
440
441 int bids[6] = { 12, 22, 37, 42, 51, 62 };
442 for (int i = 0; i < MAX_B_TYPES; i++) {
443 b[i] = new B(bids[i]);
444 refContainer.template insert<B>(b[i]);
445 assert(b[i]->is_valid());
446 }
447 BOOST_CHECK_EQUAL(refContainer.count<A>(), MAX_A_TYPES);
448 BOOST_CHECK_EQUAL(refContainer.count<B>(), MAX_B_TYPES);
449 BOOST_CHECK_EQUAL(refContainer.count<C>(), 0);
450
451 int cids[9] = { 13, 23, 38, 43, 52, 63, 71, 87, 99 };
452 for (int i = 0; i < MAX_C_TYPES; i++) {
453 c[i] = new C(cids[i]);
454 refContainer.template insert<C>(c[i]);
455 assert(c[i]->is_valid());
456 }
457
458 BOOST_CHECK_EQUAL(refContainer.count<A>(), MAX_A_TYPES);
459 BOOST_CHECK_EQUAL(refContainer.count<B>(), MAX_B_TYPES);
460 BOOST_CHECK_EQUAL(refContainer.count<C>(), MAX_C_TYPES);
461
462 print_count(refContainer);
463
467#define ID_CHECK 42
468 GenericTestObject *res = nullptr;
472 id_searcher.Visit(refContainer);
473
474 BOOST_CHECK_EQUAL(res->get_id(), ID_CHECK);
475
476 //printf("Found res of type %c id %d\n", res->get_type(), res->get_id());
477
478 for (int i = 0; i < MAX_A_TYPES; i++) {
479 a[i]->remove_reference();
480 delete a[i];
481 }
482 for (int i = 0; i < MAX_B_TYPES; i++) {
483 b[i]->remove_reference();
484 delete b[i];
485 }
486 for (int i = 0; i < MAX_C_TYPES; i++) {
487 c[i]->remove_reference();
488 delete c[i];
489 }
490#undef ID_CHECK
491
492 BOOST_CHECK_EQUAL(refContainer.count<A>(), 0);
493 BOOST_CHECK_EQUAL(refContainer.count<B>(), 0);
494 BOOST_CHECK_EQUAL(refContainer.count<C>(), 0);
495
496 print_count(refContainer);
497}
#define MAX_A_TYPES
Definition: ReferenceTypeListTest.cpp:350
void print_count(TypeRefContainer< MyTypes > &refContainer)
Definition: ReferenceTypeListTest.cpp:354
#define MAX_C_TYPES
Definition: ReferenceTypeListTest.cpp:352
#define ID_CHECK
#define MAX_B_TYPES
Definition: ReferenceTypeListTest.cpp:351
Definition: ObservableStatusTest.cpp:52
Definition: ObservableStatusTest.cpp:69
Definition: ObservableStatusTest.cpp:58
Definition: ReferenceTypeListTest.cpp:367
Definition: ReferenceTypeListTest.cpp:114
virtual int get_id()
Definition: ReferenceTypeListTest.cpp:118
void remove_reference()
Definition: ReferenceTypeListTest.cpp:105
Definition: ReferenceTypeListTest.cpp:327
Definition: ReferenceTypeListTest.cpp:262
size_t count() const
Definition: ReferenceTypeListTest.cpp:266
Definition: ReferenceTypeListTest.cpp:389

References TypeRefContainer< OBJECT_TYPES >::count(), GenericTestObject::get_id(), ID_CHECK, MAX_A_TYPES, MAX_B_TYPES, MAX_C_TYPES, print_count(), ReferenceObject< T >::remove_reference(), and TypeContainerVisitor< VISITOR, TYPE_CONTAINER >::Visit().

+ Here is the call graph for this function:

◆ print_count()

void print_count ( TypeRefContainer< MyTypes > &  refContainer)
355{
356 std::cout << "A: " << refContainer.count<A>()
357 << " | B: " << refContainer.count<B>()
358 << " | C: " << refContainer.count<C>() << std::endl;
359
360 std::cout << "Total of " << refContainer.count_all() << " elements created." << std::endl;
361}
size_t count_all() const
Definition: ReferenceTypeListTest.cpp:271

References TypeRefContainer< OBJECT_TYPES >::count(), and TypeRefContainer< OBJECT_TYPES >::count_all().

Referenced by BOOST_AUTO_TEST_CASE().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ TYPELIST_3()

typedef TYPELIST_3 ( A  ,
B  ,
C   
)

◆ VisitorHelper() [1/4]

template<class VISITOR >
void VisitorHelper ( VISITOR &  ,
ContainerMapList< TypeNull > &   
)
297{
298 // terminate condition container map list
299}

Referenced by TypeContainerVisitor< VISITOR, TYPE_CONTAINER >::Visit(), and VisitorHelper().

+ Here is the caller graph for this function:

◆ VisitorHelper() [2/4]

template<class VISITOR , class T >
void VisitorHelper ( VISITOR &  v,
ContainerMapList< T > &  c 
)
303{
304 v.Visit(c._element);
305}
TestRefManager< OBJECT > _element
Definition: ReferenceTypeListTest.cpp:155

References ContainerMapList< OBJECT >::_element.

◆ VisitorHelper() [3/4]

template<class VISITOR , class H , class T >
void VisitorHelper ( VISITOR &  v,
ContainerMapList< TypeList< H, T > > &  c 
)
310{
311 VisitorHelper(v, c._elements); // template<class OBJECT> struct ContainerMapList
312 VisitorHelper(v, c._tail_elements); // template<class HEAD, class TAIL> struct ContainerMapList<TypeList<HEAD, TAIL>>
313}
void VisitorHelper(VISITOR &, ContainerMapList< TypeNull > &)
Definition: ReferenceTypeListTest.cpp:296

References VisitorHelper().

+ Here is the call graph for this function:

◆ VisitorHelper() [4/4]

template<class VISITOR , class OBJECT_TYPES >
void VisitorHelper ( VISITOR &  v,
TypeRefContainer< OBJECT_TYPES > &  c 
)
318{
320}
ContainerMapList< OBJECT_TYPES > & get_elements(void)
Definition: ReferenceTypeListTest.cpp:285

References TypeRefContainer< OBJECT_TYPES >::get_elements(), and VisitorHelper().

+ Here is the call graph for this function: