mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-02 16:32:26 +00:00
- License was intended to be GPLv3 per earlier commit of GPLv3 LICENSE FILE - This is confirmed by the inclusion of libraries that are incompatible with GPLv2 - This is also confirmed by KLS and the agreement of KLS's predecessors - Added GPLv3 license headers to the compilable source files - Removed Folly licensing in strings.h since the string functions do not match the Folly functions and are standard functions - this must have been left over from previous implementations - Removed individual contributor license headers since the project has been under the "developer" mantle for many years - Removed comments on files that were previously automatically generated since they've been manually modified multiple times and there are no automatic scripts referencing them (removed in 2023)
210 lines
6.7 KiB
C++
210 lines
6.7 KiB
C++
/* EQEmu: EQEmulator
|
|
|
|
Copyright (C) 2001-2026 EQEmu Development Team
|
|
|
|
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; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; 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, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#pragma once
|
|
|
|
#include "common/strings.h"
|
|
#include "cppunit/cpptest.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++;
|
|
}
|
|
}
|
|
}
|
|
|
|
};
|