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

Function TEST_F

test/tests/EntityImportTests.cpp:48–61  ·  view source on GitHub ↗

This here tests that CreateEntityAt returns nullptr when trying to create an entity at an index that's already occupied. This behavior is what caused crashes before, corrupted saves had duplicate EntityIndex values that caused CreateEntityAt to return nullptr, which was then dereferenced.

Source from the content-addressed store, hash-verified

46// This behavior is what caused crashes before, corrupted saves had duplicate EntityIndex values that caused CreateEntityAt to
47// return nullptr, which was then dereferenced.
48TEST_F(EntityImportTests, CreateEntityAtDuplicateIndexReturnsNull)
49{
50 auto& gameState = getGameState();
51 gameState.entities.ResetAllEntities();
52
53 // Create an entity at index 100
54 auto* entity1 = gameState.entities.CreateEntityAt<Guest>(EntityId::FromUnderlying(100));
55 ASSERT_NE(entity1, nullptr);
56 EXPECT_EQ(entity1->id.ToUnderlying(), 100u);
57
58 // Try to create another entity at the same index, which should return nullptr
59 auto* entity2 = gameState.entities.CreateEntityAt<Guest>(EntityId::FromUnderlying(100));
60 EXPECT_EQ(entity2, nullptr);
61}
62
63// This test verifies that corrupted S6 files with duplicate EntityIndex values can be loaded without crashing.
64TEST_F(EntityImportTests, S6ImportCorruptedDuplicateEntityIndicesDoesNotCrash)

Callers

nothing calls this directly

Calls 7

GetParkPathFunction · 0.85
FileStreamClass · 0.85
ResetAllEntitiesMethod · 0.80
ToUnderlyingMethod · 0.80
LoadObjectsMethod · 0.80
LoadFromStreamMethod · 0.45
ImportMethod · 0.45

Tested by

no test coverage detected