diff --git a/apps/openmw_test_suite/esm3/testesmwriter.cpp b/apps/openmw_test_suite/esm3/testesmwriter.cpp index 23922d7461..6f14dbe112 100644 --- a/apps/openmw_test_suite/esm3/testesmwriter.cpp +++ b/apps/openmw_test_suite/esm3/testesmwriter.cpp @@ -50,5 +50,38 @@ namespace ESM writer.save(stream); EXPECT_THROW(writer.writeMaybeFixedSizeString(generateRandomString(33), 32), std::runtime_error); } + + struct Esm3EsmWriterRefIdSizeTest : TestWithParam> + { + }; + + // 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) + { + const auto [refId, size] = GetParam(); + + std::ostringstream stream; + + { + ESMWriter writer; + writer.setFormatVersion(CurrentSaveGameFormatVersion); + writer.save(stream); + writer.writeHRefId(refId); + } + + EXPECT_EQ(stream.view().size(), size); + } + + const std::vector> refIdSizes = { + { RefId(), 57 }, + { RefId::stringRefId(std::string(32, 'a')), 89 }, + { RefId::formIdRefId(0x1f), 61 }, + { RefId::generated(0x1f), 65 }, + { RefId::index(REC_INGR, 0x1f), 65 }, + { RefId::esm3ExteriorCell(-42, 42), 65 }, + }; + + INSTANTIATE_TEST_SUITE_P(RefIds, Esm3EsmWriterRefIdSizeTest, ValuesIn(refIdSizes)); } }