summaryrefslogtreecommitdiff
path: root/src/testsuite.cpp
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-14 18:35:41 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-14 18:35:41 +0200
commit895554aebccbeeb45e2c469d0bafa1e0d85dd8fb (patch)
tree543357ea7b5af9a17ec56ba1e5db2d33f81cc2bf /src/testsuite.cpp
parent0a9f710e25f22fa67276aa8d15a008a5341b0f2a (diff)
Use std::string internally in UIDGenerator, move UUID_LENGTH into the class as a constant
Diffstat (limited to 'src/testsuite.cpp')
-rw-r--r--src/testsuite.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/testsuite.cpp b/src/testsuite.cpp
index c107217b7..539827cf8 100644
--- a/src/testsuite.cpp
+++ b/src/testsuite.cpp
@@ -331,23 +331,25 @@ bool TestSuite::DoThreadTests()
bool TestSuite::DoGenerateUIDTests()
{
+ const unsigned int UUID_LENGTH = UIDGenerator::UUID_LENGTH;
UIDGenerator uidgen;
uidgen.init(ServerInstance->Config->GetSID());
std::string first_uid = uidgen.GetUID();
- if (first_uid.length() != UUID_LENGTH-1)
+
+ if (first_uid.length() != UUID_LENGTH)
{
std::cout << "GENERATEUID: Generated UID is " << first_uid.length() << " characters long instead of " << UUID_LENGTH-1 << std::endl;
return false;
}
- if (uidgen.current_uid[UUID_LENGTH-1] != '\0')
+ if (uidgen.current_uid.c_str()[UUID_LENGTH] != '\0')
{
std::cout << "GENERATEUID: The null terminator is missing from the end of current_uid" << std::endl;
return false;
}
// The correct UID when generating one for the first time is ...AAAAAA
- std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 4, 'A');
+ std::string correct_uid = ServerInstance->Config->sid + std::string(UUID_LENGTH - 3, 'A');
if (first_uid != correct_uid)
{
std::cout << "GENERATEUID: Generated an invalid first UID: " << first_uid << " instead of " << correct_uid << std::endl;
@@ -356,7 +358,7 @@ bool TestSuite::DoGenerateUIDTests()
// Set current_uid to be ...Z99999
uidgen.current_uid[3] = 'Z';
- for (unsigned int i = 4; i < UUID_LENGTH-1; i++)
+ for (unsigned int i = 4; i < UUID_LENGTH; i++)
uidgen.current_uid[i] = '9';
// Store the UID we'll be incrementing so we can display what's wrong later if necessary
@@ -364,7 +366,7 @@ bool TestSuite::DoGenerateUIDTests()
std::string generated_uid = uidgen.GetUID();
// Correct UID after incrementing ...Z99999 is ...0AAAAA
- correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 5, 'A');
+ correct_uid = ServerInstance->Config->sid + "0" + std::string(UUID_LENGTH - 4, 'A');
if (generated_uid != correct_uid)
{
@@ -373,7 +375,7 @@ bool TestSuite::DoGenerateUIDTests()
}
// Set current_uid to be ...999999 to see if it rolls over correctly
- for (unsigned int i = 3; i < UUID_LENGTH-1; i++)
+ for (unsigned int i = 3; i < UUID_LENGTH; i++)
uidgen.current_uid[i] = '9';
before_increment.assign(uidgen.current_uid);