1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include "tjlist.h"
#include "tjlist_code.h"
#include "tjtest.h"
#include "tjlog_code.h"
const char* ListComponent::get_compName() {return "List";}
LOGGROUNDWORK(ListComponent)
#ifndef NO_UNIT_TEST
class ListTest : public UnitTest {
public:
ListTest() : UnitTest(ListComponent::get_compName()) {}
private:
class StrItem : public ListItem<StrItem>, public STD_string {};
typedef List<StrItem,StrItem*,StrItem&> StrList;
bool check() const {
Log<UnitTest> odinlog(this,"check");
StrItem* item0=new StrItem;
item0->STD_string::operator = ("item0");
StrItem* item1=new StrItem;
item1->STD_string::operator = ("item1");
StrItem* item2=new StrItem;
item2->STD_string::operator = ("item2");
StrList* slist=new StrList;
slist->append(*item0);
slist->append(*item1);
slist->append(*item2);
if(slist->size()!=3) {
ODINLOG(odinlog,errorLog) << "size()!=3" << STD_endl;
return false;
}
int index=0;
for(StrList::constiter it=slist->get_const_begin(); it!=slist->get_const_end(); ++it) {
STD_string expected="item"+itos(index);
if((**it)!=expected) {
ODINLOG(odinlog,errorLog) << "expected=" << expected << STD_endl;
return false;
}
index++;
}
delete item0;
if(slist->size()!=2) {
ODINLOG(odinlog,errorLog) << "size()!=2" << STD_endl;
return false;
}
delete item1;
if(slist->size()!=1) {
ODINLOG(odinlog,errorLog) << "size()!=1" << STD_endl;
return false;
}
if(item2->numof_references()!=1) {
ODINLOG(odinlog,errorLog) << "references(pre)=" << item2->numof_references() << STD_endl;
return false;
}
delete slist;
if(item2->numof_references()!=0) {
ODINLOG(odinlog,errorLog) << "references(post)=" << item2->numof_references() << STD_endl;
return false;
}
delete item2;
return true;
}
};
void alloc_ListTest() {new ListTest();} // create test instance
#endif
|