MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / CompareStates

Function CompareStates

test/tests/S6ImportExportTests.cpp:142–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142static void CompareStates(MemoryStream& importBuffer, MemoryStream& exportBuffer, MemoryStream& snapshotStream)
143{
144 if (importBuffer.GetLength() != exportBuffer.GetLength())
145 {
146 LOG_WARNING(
147 "Inconsistent export size! Import Size: %llu bytes, Export Size: %llu bytes",
148 static_cast<unsigned long long>(importBuffer.GetLength()),
149 static_cast<unsigned long long>(exportBuffer.GetLength()));
150 }
151
152 std::unique_ptr<IContext> context = CreateContext();
153 EXPECT_NE(context, nullptr);
154 bool initialised = context->Initialise();
155 ASSERT_TRUE(initialised);
156
157 DataSerialiser ds(false, snapshotStream);
158 IGameStateSnapshots* snapshots = GetContext()->GetGameStateSnapshots();
159
160 GameStateSnapshot_t& importSnapshot = snapshots->CreateSnapshot();
161 snapshots->SerialiseSnapshot(importSnapshot, ds);
162
163 GameStateSnapshot_t& exportSnapshot = snapshots->CreateSnapshot();
164 snapshots->SerialiseSnapshot(exportSnapshot, ds);
165
166 try
167 {
168 GameStateCompareData cmpData = snapshots->Compare(importSnapshot, exportSnapshot);
169
170 // Find out if there are any differences between the two states
171 auto res = std::find_if(
172 cmpData.spriteChanges.begin(), cmpData.spriteChanges.end(),
173 [](const GameStateSpriteChange& diff) { return diff.changeType != GameStateSpriteChange::EQUAL; });
174
175 if (res != cmpData.spriteChanges.end())
176 {
177 LOG_WARNING("Snapshot data differences. %s", snapshots->GetCompareDataText(cmpData).c_str());
178 FAIL();
179 }
180 }
181 catch (const std::runtime_error& err)
182 {
183 LOG_WARNING("Snapshot data failed to be read. Snapshot not compared. %s", err.what());
184 FAIL();
185 }
186}
187
188TEST(S6ImportExportBasic, all)
189{

Callers 1

TESTFunction · 0.85

Calls 11

CreateContextFunction · 0.85
GetContextFunction · 0.85
GetGameStateSnapshotsMethod · 0.80
SerialiseSnapshotMethod · 0.80
CompareMethod · 0.80
GetCompareDataTextMethod · 0.80
endMethod · 0.65
GetLengthMethod · 0.45
InitialiseMethod · 0.45
beginMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected