Add a test and address feedback

pull/3236/head
Evil Eye 3 months ago
parent c9ef03fdd1
commit ffe164b28d

@ -78,6 +78,7 @@ file(GLOB UNITTEST_SRC_FILES
esm3/testsaveload.cpp
esm3/testesmwriter.cpp
esm3/testinfoorder.cpp
esm3/testcstringids.cpp
nifosg/testnifloader.cpp

@ -0,0 +1,57 @@
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
#include <components/esm3/loaddial.hpp>
#include <gtest/gtest.h>
namespace ESM
{
namespace
{
TEST(Esm3CStringIdTest, dialNameShouldBeNullTerminated)
{
std::unique_ptr<std::istream> stream;
{
auto ostream = std::make_unique<std::stringstream>();
ESMWriter writer;
writer.setFormatVersion(DefaultFormatVersion);
writer.save(*ostream);
Dialogue record;
record.blank();
record.mStringId = "topic name";
record.mId = RefId::stringRefId(record.mStringId);
record.mType = Dialogue::Topic;
writer.startRecord(Dialogue::sRecordId);
record.save(writer);
writer.endRecord(Dialogue::sRecordId);
stream = std::move(ostream);
}
ESMReader reader;
reader.open(std::move(stream), "stream");
ASSERT_TRUE(reader.hasMoreRecs());
ASSERT_EQ(reader.getRecName(), Dialogue::sRecordId);
reader.getRecHeader();
while (reader.hasMoreSubs())
{
reader.getSubName();
if (reader.retSubName().toInt() == SREC_NAME)
{
reader.getSubHeader();
auto size = reader.getSubSize();
std::string buffer(size, '1');
reader.getExact(buffer.data(), size);
ASSERT_EQ(buffer[size - 1], '\0');
return;
}
else
reader.skipHSub();
}
ASSERT_FALSE(true);
}
}
}

@ -57,7 +57,7 @@ namespace ESM
// If this test failed probably there is a change in RefId format and CurrentSaveGameFormatVersion should be
// incremented, current version should be handled.
TEST_P(Esm3EsmWriterRefIdSizeTest, writeHRefIdShouldProduceCertainNubmerOfBytes)
TEST_P(Esm3EsmWriterRefIdSizeTest, writeHRefIdShouldProduceCertainNumberOfBytes)
{
const auto [refId, size] = GetParam();

@ -85,7 +85,7 @@ namespace ESM
esm.writeHNCString("NAME", mStringId);
}
else if (esm.getFormatVersion() <= MaxNameIsRefIdOnlyFormatVersion)
esm.writeHNRefId("NAME", mId);
esm.writeHNCRefId("NAME", mId);
else
esm.writeHNRefId("ID__", mId);

Loading…
Cancel
Save