Use UnitTest-Cpp library for testing
This commit is contained in:
parent
ecaa2bbdfb
commit
00d8fa0886
53 changed files with 1046 additions and 1383 deletions
|
|
@ -1,83 +1,80 @@
|
|||
#include "Archiver.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Tests.hpp"
|
||||
#include "List.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
TEST_DEF_STATIC(SimpleReference) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
SUITE(DoubleLinkedList) {
|
||||
|
||||
list.pushBack(TestClass(5));
|
||||
list.pushFront(TestClass(0));
|
||||
TEST(SimpleReference) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
|
||||
ualni i = -1;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
TEST_EQUAL(iter->getVal(), i);
|
||||
list.pushBack(TestClass(5));
|
||||
list.pushFront(TestClass(0));
|
||||
|
||||
ualni i = -1;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
CHECK_EQUAL(iter->getVal(), i);
|
||||
}
|
||||
|
||||
CHECK(i == 5);
|
||||
|
||||
list.removeAll();
|
||||
}
|
||||
|
||||
TEST(i == 5);
|
||||
TEST(SimplePointer) {
|
||||
tp::List<TestClass*, tp::HeapAlloc> list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) };
|
||||
|
||||
list.removeAll();
|
||||
}
|
||||
list.pushBack(new TestClass(5));
|
||||
list.pushFront(new TestClass(0));
|
||||
|
||||
TEST_DEF_STATIC(SimplePointer) {
|
||||
tp::List<TestClass*, tp::HeapAlloc> list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) };
|
||||
ualni i = -1;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
CHECK_EQUAL(iter->getVal(), i);
|
||||
}
|
||||
|
||||
list.pushBack(new TestClass(5));
|
||||
list.pushFront(new TestClass(0));
|
||||
CHECK(i == 5);
|
||||
|
||||
ualni i = -1;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
TEST_EQUAL(iter->getVal(), i);
|
||||
for (auto iter : list) {
|
||||
delete iter.data();
|
||||
}
|
||||
|
||||
list.removeAll();
|
||||
}
|
||||
|
||||
TEST(i == 5);
|
||||
TEST(Copy) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
tp::List<TestClass, tp::HeapAlloc> list2 = list;
|
||||
|
||||
for (auto iter : list) {
|
||||
delete iter.data();
|
||||
CHECK(list == list2);
|
||||
|
||||
list.removeAll();
|
||||
list2.removeAll();
|
||||
}
|
||||
|
||||
list.removeAll();
|
||||
}
|
||||
TEST(Serialization) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
|
||||
TEST_DEF_STATIC(Copy) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
tp::List<TestClass, tp::HeapAlloc> list2 = list;
|
||||
ArchiverExample<1024, false> write;
|
||||
ArchiverExample<1024, true> read;
|
||||
|
||||
TEST_EQUAL(list, list2);
|
||||
write % list;
|
||||
|
||||
list.removeAll();
|
||||
list2.removeAll();
|
||||
}
|
||||
list.removeAll();
|
||||
|
||||
TEST_DEF_STATIC(Serialization) {
|
||||
tp::List<TestClass, tp::HeapAlloc> list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) };
|
||||
memCopy(read.mBuff, write.mBuff, sizeof(write.mBuff));
|
||||
|
||||
ArchiverExample<1024, false> write;
|
||||
ArchiverExample<1024, true> read;
|
||||
read % list;
|
||||
|
||||
write % list;
|
||||
ualni i = 0;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
CHECK(iter->getVal() == i);
|
||||
}
|
||||
CHECK(i == 4);
|
||||
|
||||
list.removeAll();
|
||||
|
||||
memCopy(read.mBuff, write.mBuff, sizeof(write.mBuff));
|
||||
|
||||
read % list;
|
||||
|
||||
ualni i = 0;
|
||||
for (auto iter : list) {
|
||||
i++;
|
||||
TEST_EQUAL(iter->getVal(), i);
|
||||
list.removeAll();
|
||||
}
|
||||
TEST(i == 4);
|
||||
|
||||
list.removeAll();
|
||||
}
|
||||
|
||||
TEST_DEF(List) {
|
||||
testSimplePointer();
|
||||
testSimpleReference();
|
||||
testSerialization();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue