-
Notifications
You must be signed in to change notification settings - Fork 16
/
TestBinary.cpp
156 lines (122 loc) · 3.41 KB
/
TestBinary.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include "UTFail.h"
#include "TestBinary.h"
using namespace std;
TestBinary::TestBinary() {}
void TestBinary::Test1() {
cout << __PRETTY_FUNCTION__ << endl;
Binary b1;
UTASSERT(b1.BufferLength() == 0);
UTASSERT(b1.BufferSize() == 0);
UTASSERT(b1.Buffer() == NULL);
unsigned char *buffer = (unsigned char *)malloc(10);
for (unsigned int i = 0; i < 10; i++) {
buffer[i] = i + 1;
}
Binary b2;
b2.SubsumeBuffer(buffer, 10, 10);
UTASSERT(b2.BufferLength() == 10);
UTASSERT(b2.BufferSize() == 10);
UTASSERT(b2.Buffer() == buffer);
b1.AssignDataToBuffer(buffer, 10);
UTASSERT(b1.BufferLength() == 10);
UTASSERT(b1.BufferSize() == 10);
UTASSERT(b1.Buffer() != buffer);
}
void TestBinary::Test2() {
cout << __PRETTY_FUNCTION__ << endl;
unsigned char *buffer = (unsigned char *)malloc(10);
for (unsigned int i = 0; i < 10; i++) {
buffer[i] = i + 1;
}
Binary b1(buffer, 10, 10);
Binary b2(b1);
UTASSERT(b2.BufferLength() == 10);
UTASSERT(b2.BufferSize() == 10);
UTASSERT(b2.Buffer() == buffer);
UTASSERT(b1.BufferLength() == 0);
UTASSERT(b1.BufferSize() == 0);
UTASSERT(b1.Buffer() == NULL);
}
void TestBinary::Test3() {
cout << __PRETTY_FUNCTION__ << endl;
unsigned char *buffer = (unsigned char *)malloc(10);
for (unsigned int i = 0; i < 10; i++) {
buffer[i] = i + 1;
}
Binary b1(buffer, 10, 10);
Binary b2;
b2.AssignDataToBuffer(buffer, 10);
UTASSERT(b1.Buffer() != b2.Buffer());
UTASSERT(b1.BufferLength() == 10);
UTASSERT(b2.BufferLength() == 10);
b2.ResizeBuffer(100);
UTASSERT(b2.BufferLength() == 10);
UTASSERT(b2.BufferSize() == 100);
for (int i = 0; i < 10; i++) {
UTASSERT(b1.Buffer()[i] == b2.Buffer()[i]);
}
UTASSERT(b1 == b2);
}
void TestBinary::Test4() {
cout << __PRETTY_FUNCTION__ << endl;
Binary b1(128);
UTASSERT(b1.Buffer() != NULL);
UTASSERT(b1.BufferLength() == 0);
UTASSERT(b1.BufferSize() == 128);
unsigned char *buffer = (unsigned char *)malloc(10);
for (unsigned int i = 0; i < 10; i++) {
buffer[i] = i + 1;
}
Binary b2(buffer, 10, 10);
b1.AssignDataToBuffer(buffer, 10);
UTASSERT(b1.BufferLength() == 10);
UTASSERT(b1.BufferSize() == 128);
//Sizing too small should have no effect
b1.ResizeBuffer(5);
UTASSERT(b1.BufferLength() == 10);
UTASSERT(b1.BufferSize() == 128);
UTASSERT(b1 == b2);
b1.ResizeBuffer(256);
UTASSERT(b1.BufferSize() == 256)
UTASSERT(b1 == b2);
}
void TestBinary::Test5() {
cout << __PRETTY_FUNCTION__ << endl;
unsigned char *buffer = (unsigned char *)malloc(10);
for (unsigned int i = 0; i < 10; i++) {
buffer[i] = i + 1;
}
Binary b1(buffer, 10, 10);
b1.ClearBuffer();
UTASSERT(b1.Buffer() == NULL);
UTASSERT(b1.BufferLength() == 0);
UTASSERT(b1.BufferSize() == 0);
}
void TestBinary::Test6() {
cout << __PRETTY_FUNCTION__ << endl;
}
void TestBinary::Test7() {
cout << __PRETTY_FUNCTION__ << endl;
}
int TestBinary::RunSpecificTest(BinaryMemberPointer test) {
int failures = 0;
try {
(this->*test)();
} catch (UTFail &fail) {
failures++;
cout << fail << endl;
}
return failures;
}
int TestBinary::RunTests() {
int failures = 0;
failures += RunSpecificTest(&TestBinary::Test1);
failures += RunSpecificTest(&TestBinary::Test2);
failures += RunSpecificTest(&TestBinary::Test3);
failures += RunSpecificTest(&TestBinary::Test4);
failures += RunSpecificTest(&TestBinary::Test5);
failures += RunSpecificTest(&TestBinary::Test6);
failures += RunSpecificTest(&TestBinary::Test7);
return failures;
}