-
Notifications
You must be signed in to change notification settings - Fork 0
/
idbase.cpp
85 lines (64 loc) · 1.48 KB
/
idbase.cpp
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
#include "idbase.h"
#include "macros.h"
#if defined(IDBASE_TEST_MAIN)
static int allocCount = 0;
struct TestEntity : IDBase{
char name[64];
float pos[3];
TestEntity(){
allocCount++;
}
TestEntity(const TestEntity& ent){
BNS_UNUSED(ent);
allocCount++;
}
~TestEntity(){
allocCount--;
}
};
CREATE_TEST_CASE("IDbase + IDTracker basic") {
ASSERT(allocCount == 0);
{
IDTracker<TestEntity> ents(20);
for(int i = 0; i < 20; i++){
TestEntity* add = ents.CreateAndAdd();
ASSERT(add != nullptr);
}
for(int i = 0; i < 20; i++){
for(int j = i+1; j < 20; j++){
ASSERT(ents.vals[i].id != ents.vals[j].id);
}
}
for(int i = 0; i < 10; i++){
ASSERT(ents.GetByIdNum(i) != nullptr);
ASSERT(ents.GetById(IDHandle<TestEntity>(i)) != nullptr);
ents.RemoveByIdNum(i);
ASSERT(ents.GetByIdNum(i) == nullptr);
ASSERT(ents.GetById(IDHandle<TestEntity>(i)) == nullptr);
}
for(int i = 0; i < 10; i++){
TestEntity* add = ents.CreateAndAdd();
ASSERT(add != nullptr);
}
ASSERT(ents.currentCount == 20);
for(int i = 0; i < 20; i++){
for(int j = i+1; j < 20; j++){
ASSERT(ents.vals[i].id != ents.vals[j].id);
}
}
for(int i = 10; i < 20; i++){
ASSERT(ents.GetByIdNum(i) != nullptr);
ents.RemoveById(IDHandle<TestEntity>(i));
ASSERT(ents.GetByIdNum(i) == nullptr);
}
}
{
IDTracker<TestEntity> ents(20);
for(int i = 1; i < 50; i++){
ents.SetSize(30 * i);
}
}
ASSERT(allocCount == 0);
return 0;
}
#endif