Skip to content

Commit

Permalink
TESTS: Add a unit test for writing LocStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Nostritius authored and DrMcCoy committed Jun 26, 2018
1 parent 3e1e60e commit 7507b45
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/aurora/locstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "src/common/error.h"
#include "src/common/ustring.h"
#include "src/common/memreadstream.h"
#include "src/common/memwritestream.h"

#include "src/aurora/locstring.h"
#include "src/aurora/language.h"
Expand Down Expand Up @@ -251,3 +252,26 @@ GTEST_TEST_F(LocString, wrongEncodingNonUTF8) {

EXPECT_STREQ(locString.getString().c_str(), "[!?!]");
}

GTEST_TEST_F(LocString, write) {
Aurora::LocString locString;
locString.setString(Aurora::kLanguageEnglish, Aurora::kLanguageGenderMale, "String to test");
locString.setString(Aurora::kLanguageFrench, Aurora::kLanguageGenderMale, "String pour tester");

Common::MemoryWriteStreamDynamic *writeStream = new Common::MemoryWriteStreamDynamic(true);
locString.writeLocString(*writeStream);

Aurora::LocString locString2;
Common::MemoryReadStream readStream(writeStream->getData(), writeStream->size());
EXPECT_EQ(readStream.readUint32LE(), 0);
EXPECT_EQ(readStream.readUint32LE(), 14);
Common::UString englishString = Common::readStringFixed(readStream, Common::kEncodingASCII, 14);
EXPECT_STREQ(englishString.c_str(), "String to test");

EXPECT_EQ(readStream.readUint32LE(), 2);
EXPECT_EQ(readStream.readUint32LE(), 18);
Common::UString frenchString = Common::readStringFixed(readStream, Common::kEncodingASCII, 18);
EXPECT_STREQ(frenchString.c_str(), "String pour tester");

delete writeStream;
}

0 comments on commit 7507b45

Please sign in to comment.