forked from EQEmu/Server
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathhextoi_32_64_test.h
213 lines (180 loc) · 6.96 KB
/
hextoi_32_64_test.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2013 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __EQEMU_TESTS_HEXTOI_32_64_H
#define __EQEMU_TESTS_HEXTOI_32_64_H
#include "cppunit/cpptest.h"
#include "../common/strings.h"
class hextoi_32_64_Test : public Test::Suite {
typedef void(hextoi_32_64_Test::*TestFunction)(void);
public:
hextoi_32_64_Test() {
TEST_ADD(hextoi_32_64_Test::nullptr32Test);
TEST_ADD(hextoi_32_64_Test::ShortString32Test);
TEST_ADD(hextoi_32_64_Test::SingleDigitUpper32Test);
TEST_ADD(hextoi_32_64_Test::SingleDigitLower32Test);
TEST_ADD(hextoi_32_64_Test::DoubleDigitUpper32Test);
TEST_ADD(hextoi_32_64_Test::DoubleDigitLower32Test);
TEST_ADD(hextoi_32_64_Test::nullptr64Test);
TEST_ADD(hextoi_32_64_Test::ShortString64Test);
TEST_ADD(hextoi_32_64_Test::SingleDigitUpper64Test);
TEST_ADD(hextoi_32_64_Test::SingleDigitLower64Test);
TEST_ADD(hextoi_32_64_Test::DoubleDigitUpper64Test);
TEST_ADD(hextoi_32_64_Test::DoubleDigitLower64Test);
}
~hextoi_32_64_Test() {
}
private:
void nullptr32Test() {
TEST_ASSERT(hextoi(nullptr) == 0);
}
void ShortString32Test() {
// if the string is too short then it should
// spit out a zero.
// strings should be formatted: 0x** or 0X**
TEST_ASSERT(hextoi("") == 0);
TEST_ASSERT(hextoi("0") == 0);
TEST_ASSERT(hextoi("01") == 0);
}
void SingleDigitUpper32Test() {
TEST_ASSERT(hextoi("0x0") == 0);
TEST_ASSERT(hextoi("0x1") == 1);
TEST_ASSERT(hextoi("0x2") == 2);
TEST_ASSERT(hextoi("0x3") == 3);
TEST_ASSERT(hextoi("0x4") == 4);
TEST_ASSERT(hextoi("0x5") == 5);
TEST_ASSERT(hextoi("0x6") == 6);
TEST_ASSERT(hextoi("0x7") == 7);
TEST_ASSERT(hextoi("0x8") == 8);
TEST_ASSERT(hextoi("0x9") == 9);
TEST_ASSERT(hextoi("0xA") == 10);
TEST_ASSERT(hextoi("0xB") == 11);
TEST_ASSERT(hextoi("0xC") == 12);
TEST_ASSERT(hextoi("0xD") == 13);
TEST_ASSERT(hextoi("0xE") == 14);
TEST_ASSERT(hextoi("0xF") == 15);
}
void SingleDigitLower32Test() {
TEST_ASSERT(hextoi("0x0") == 0);
TEST_ASSERT(hextoi("0x1") == 1);
TEST_ASSERT(hextoi("0x2") == 2);
TEST_ASSERT(hextoi("0x3") == 3);
TEST_ASSERT(hextoi("0x4") == 4);
TEST_ASSERT(hextoi("0x5") == 5);
TEST_ASSERT(hextoi("0x6") == 6);
TEST_ASSERT(hextoi("0x7") == 7);
TEST_ASSERT(hextoi("0x8") == 8);
TEST_ASSERT(hextoi("0x9") == 9);
TEST_ASSERT(hextoi("0xa") == 10);
TEST_ASSERT(hextoi("0xb") == 11);
TEST_ASSERT(hextoi("0xc") == 12);
TEST_ASSERT(hextoi("0xd") == 13);
TEST_ASSERT(hextoi("0xe") == 14);
TEST_ASSERT(hextoi("0xf") == 15);
}
// A bit excessive to do an exhaustive test like this
// but it usefully tests multi digit hex.
void DoubleDigitUpper32Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789ABCDEF";
uint32 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
for (std::string::iterator secondDigitIter = hexElements.begin(); secondDigitIter != hexElements.end(); ++secondDigitIter) {
std::string hexToTest = prepend + *firstDigitIter + *secondDigitIter;
TEST_ASSERT(hextoi(hexToTest.c_str()) == value);
value++;
}
}
}
// A bit excessive to do an exhaustive test like this
// but it usefully tests multi digit hex.
void DoubleDigitLower32Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789abcdef";
uint32 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
for (std::string::iterator secondDigitIter = hexElements.begin(); secondDigitIter != hexElements.end(); ++secondDigitIter) {
std::string hexToTest = prepend + *firstDigitIter + *secondDigitIter;
TEST_ASSERT(hextoi(hexToTest.c_str()) == value);
value++;
}
}
}
void nullptr64Test() {
TEST_ASSERT(hextoi64(nullptr) == 0);
}
void ShortString64Test() {
// if the string is too short then it should
// spit out a zero.
// strings should be formatted: 0x** or 0X**
TEST_ASSERT(hextoi64("") == 0);
TEST_ASSERT(hextoi64("0") == 0);
TEST_ASSERT(hextoi64("01") == 0);
}
void SingleDigitUpper64Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789ABCDEF";
uint64 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
std::string hexToTest = prepend + *firstDigitIter;
TEST_ASSERT(hextoi64(hexToTest.c_str()) == value);
value++;
}
}
void SingleDigitLower64Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789abcdef";
uint64 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
std::string hexToTest = prepend + *firstDigitIter;
TEST_ASSERT(hextoi64(hexToTest.c_str()) == value);
value++;
}
}
// A bit excessive to do an exhaustive test like this
// but it usefully tests multi digit hex.
void DoubleDigitUpper64Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789ABCDEF";
uint64 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
for (std::string::iterator secondDigitIter = hexElements.begin(); secondDigitIter != hexElements.end(); ++secondDigitIter) {
std::string hexToTest = prepend + *firstDigitIter + *secondDigitIter;
TEST_ASSERT(hextoi64(hexToTest.c_str()) == value);
value++;
}
}
}
// A bit excessive to do an exhaustive test like this
// but it usefully tests multi digit hex.
void DoubleDigitLower64Test() {
std::string prepend = "0x";
std::string hexToTest;
std::string hexElements = "0123456789abcdef";
uint64 value = 0;
for (std::string::iterator firstDigitIter = hexElements.begin(); firstDigitIter != hexElements.end(); ++firstDigitIter) {
for (std::string::iterator secondDigitIter = hexElements.begin(); secondDigitIter != hexElements.end(); ++secondDigitIter) {
std::string hexToTest = prepend + *firstDigitIter + *secondDigitIter;
TEST_ASSERT(hextoi64(hexToTest.c_str()) == value);
value++;
}
}
}
};
#endif