Skip to content

Commit

Permalink
CopySpawnargs test checks EntityKeyValue pointer identities
Browse files Browse the repository at this point in the history
Copied SpawnArgs object should have same key value strings but different
EntityKeyValue object pointers.
  • Loading branch information
Matthew Mott committed Jan 30, 2021
1 parent ff596ac commit fd57c69
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions test/Entity.cpp
Expand Up @@ -211,16 +211,37 @@ TEST_F(EntityTest, CopySpawnargs)

// Clone the entity node
auto lightCopy = light->clone();
const Entity* clonedEnt = Node_getEntity(lightCopy);
Entity* clonedEnt = Node_getEntity(lightCopy);
ASSERT_TRUE(clonedEnt);

// Clone should have all the same spawnargs
// Clone should have all the same spawnarg strings
std::size_t count = 0;
clonedEnt->forEachKeyValue([&](const std::string& k, const std::string& v) {
EXPECT_EQ(spawnArgs.getKeyValue(k), v);
++count;
});
EXPECT_EQ(count, EXTRA_SPAWNARGS.size() + 2 /* name and classname */);

// Clone should NOT have the same actual KeyValue object pointers, although
// the count should be the same
std::set<EntityKeyValue*> origPointers;
std::set<EntityKeyValue*> copiedPointers;
spawnArgs.forEachEntityKeyValue(
[&](const std::string& k, EntityKeyValue& v) {
origPointers.insert(&v);
});
clonedEnt->forEachEntityKeyValue(
[&](const std::string& k, EntityKeyValue& v) {
copiedPointers.insert(&v);
});
EXPECT_EQ(origPointers.size(), count);
EXPECT_EQ(copiedPointers.size(), count);

std::vector<EntityKeyValue*> overlap;
std::set_intersection(origPointers.begin(), origPointers.end(),
copiedPointers.begin(), copiedPointers.end(),
std::back_inserter(overlap));
EXPECT_EQ(overlap.size(), 0);
}

TEST_F(EntityTest, CreateAttachedLightEntity)
Expand Down

0 comments on commit fd57c69

Please sign in to comment.