diff --git a/apps/components_tests/esm3/testsaveload.cpp b/apps/components_tests/esm3/testsaveload.cpp index cffd852c95..afbe410014 100644 --- a/apps/components_tests/esm3/testsaveload.cpp +++ b/apps/components_tests/esm3/testsaveload.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -216,6 +217,19 @@ namespace ESM for (auto& v : dst) v = std::uniform_real_distribution{ -1.0f, 1.0f }(mRandom); } + + void generateBytes(auto iterator, std::size_t count) + { + std::uniform_int_distribution distribution{ 0, + std::numeric_limits::max() }; + std::generate_n(iterator, count, [&] { return static_cast(distribution(mRandom)); }); + } + + void generateStrings(auto iterator, std::size_t count) + { + std::uniform_int_distribution distribution{ 1, 13 }; + std::generate_n(iterator, count, [&] { return generateRandomString(distribution(mRandom)); }); + } }; TEST_F(Esm3SaveLoadRecordTest, headerShouldNotChange) @@ -403,11 +417,29 @@ namespace ESM Script record; record.blank(); record.mId = generateRandomRefId(32); - record.mData.mNumShorts = 42; + record.mData.mNumShorts = 3; + record.mData.mNumFloats = 4; + record.mData.mNumLongs = 5; + record.mData.mScriptDataSize = 13; + generateStrings(std::back_inserter(record.mVarNames), + record.mData.mNumShorts + record.mData.mNumFloats + record.mData.mNumLongs); + record.mData.mStringTableSize = std::accumulate(record.mVarNames.begin(), record.mVarNames.end(), 0, + [](std::size_t r, const std::string& v) { return r + v.size() + 1; }); + generateBytes(std::back_inserter(record.mScriptData), record.mData.mScriptDataSize); + record.mScriptText = generateRandomString(17); + Script result; saveAndLoadRecord(record, GetParam(), result); + EXPECT_EQ(result.mId, record.mId); EXPECT_EQ(result.mData.mNumShorts, record.mData.mNumShorts); + EXPECT_EQ(result.mData.mNumFloats, record.mData.mNumFloats); + EXPECT_EQ(result.mData.mNumShorts, record.mData.mNumShorts); + EXPECT_EQ(result.mData.mScriptDataSize, record.mData.mScriptDataSize); + EXPECT_EQ(result.mData.mStringTableSize, record.mData.mStringTableSize); + EXPECT_EQ(result.mVarNames, record.mVarNames); + EXPECT_EQ(result.mScriptData, record.mScriptData); + EXPECT_EQ(result.mScriptText, record.mScriptText); } TEST_P(Esm3SaveLoadRecordTest, quickKeysShouldNotChange)