| 140 | } |
| 141 | |
| 142 | static 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 | |
| 188 | TEST(S6ImportExportBasic, all) |
| 189 | { |
no test coverage detected