mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
chore: cleanup LU(W)string writing (#1188)
* chore: cleanup LU(W)string writing and add methods for reading remove redunent "packet" from packet reading helpers move write header to bitstreamutils since it's not packet related add tests for reading/writing LU(W)Strings * remove un-needed function defintions in header * make reading and writing more efficient * p p * quotes * remove unneeded default --------- Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,8 @@ set(DCOMMONTEST_SOURCES
|
||||
"TestLDFFormat.cpp"
|
||||
"TestNiPoint3.cpp"
|
||||
"TestEncoding.cpp"
|
||||
"TestLUString.cpp"
|
||||
"TestLUWString.cpp"
|
||||
"dCommonDependencies.cpp"
|
||||
)
|
||||
|
||||
|
121
tests/dCommonTests/TestLUString.cpp
Normal file
121
tests/dCommonTests/TestLUString.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
|
||||
TEST(LUString33Test, SerializeWriteTestOld) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 33; i++) testString += "a";
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
std::string result;
|
||||
char c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeWriteTestOldPartial) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 15; i++) testString += "a";
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
for (int i = 0; i < 18; i++) bitStream.Write<char>(0);
|
||||
std::string result;
|
||||
char c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeWriteTestNew) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 33; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
std::string result;
|
||||
char c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeWriteTestNewPartial) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 15; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
std::string result;
|
||||
char c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeReadTestOld) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 33; i++) testString += "a";
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
std::string result;
|
||||
char c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeReadTestOldPartial) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 15; i++) testString += "a";
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
for (int i = 0; i < 18; i++) bitStream.Write<char>(0);
|
||||
std::string result;
|
||||
char c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeReadTestNew) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 33; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
LUString result(33);
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result.string, testString);
|
||||
}
|
||||
|
||||
TEST(LUString33Test, SerializeReadTestNewPartial) {
|
||||
CBITSTREAM;
|
||||
std::string testString;
|
||||
for (int i = 0; i < 15; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
LUString result(33);
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result.string, testString);
|
||||
}
|
121
tests/dCommonTests/TestLUWString.cpp
Normal file
121
tests/dCommonTests/TestLUWString.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "dCommonVars.h"
|
||||
|
||||
TEST(LUWString33Test, SerializeWriteTestOld) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 33; i++) testString += u'ü';
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeWriteTestOldPartial) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 15; i++) testString += u'ü';
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
for (int i = 0; i < 18; i++) bitStream.Write<char16_t>(0);
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeWriteTestNew) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 33; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeWriteTestNewPartial) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 15; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeReadTestOld) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 33; i++) testString += u'ü';
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
while (bitStream.Read(c)) result += c;
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeReadTestOldPartial) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 15; i++) testString += u'ü';
|
||||
for (const auto& c : testString) bitStream.Write(c);
|
||||
for (int i = 0; i < 18; i++) bitStream.Write<char16_t>(0);
|
||||
std::u16string result;
|
||||
char16_t c;
|
||||
int nulls = 18;
|
||||
while (bitStream.Read(c)){
|
||||
if (c == 0) {
|
||||
nulls--;
|
||||
continue;
|
||||
}
|
||||
result += c;
|
||||
}
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(nulls, 0);
|
||||
ASSERT_EQ(result, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeReadTestNew) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 33; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
LUWString result(33);
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result.string, testString);
|
||||
}
|
||||
|
||||
TEST(LUWString33Test, SerializeReadTestNewPartial) {
|
||||
CBITSTREAM;
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 15; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
LUWString result(33);
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
ASSERT_EQ(result.string, testString);
|
||||
}
|
Reference in New Issue
Block a user