light: add some tests for the EntDict_Check* functions

This commit is contained in:
Eric Wasylishen 2016-09-19 19:16:45 -06:00
parent 26dcb4f10f
commit f7091c27f8
6 changed files with 78 additions and 4 deletions

View File

@ -176,7 +176,7 @@ bool Light_PointInSolid(const bsp2_t *bsp, const vec3_t point );
void EstimateVisibleBoundsAtPoint(const vec3_t point, vec3_t mins, vec3_t maxs);
bool EntDict_CheckEmptyValues(const entdict_t &entdict);
bool EntDict_CheckNoEmptyValues(const entdict_t &entdict);
bool EntDict_CheckTargetKeysMatched(const entdict_t &entity, const std::vector<entdict_t> &all_edicts);

View File

@ -100,7 +100,10 @@ include_directories(${CMAKE_SOURCE_DIR}/3rdparty/googletest)
set(LIGHT_TEST_SOURCE
${LIGHT_SOURCES}
${GOOGLETEST_SOURCES}
test.cc)
test.cc
test_entities.cc
test_ltface.cc
test_light.cc)
add_executable(testlight EXCLUDE_FROM_ALL ${LIGHT_TEST_SOURCE})
add_test(testlight testlight)

View File

@ -166,7 +166,7 @@ EntDict_PrettyDescription(const entdict_t &entity)
}
bool
EntDict_CheckEmptyValues(const entdict_t &entdict)
EntDict_CheckNoEmptyValues(const entdict_t &entdict)
{
bool ok = true;
// empty values warning
@ -971,7 +971,7 @@ LoadEntities(const globalconfig_t &cfg, const bsp2_t *bsp)
// Make warnings
for (auto &entdict : entdicts) {
EntDict_CheckEmptyValues(entdict);
EntDict_CheckNoEmptyValues(entdict);
EntDict_CheckTargetKeysMatched(entdict, entdicts);
EntDict_CheckTargetnameKeyMatched(entdict, entdicts);
}

65
light/test_entities.cc Normal file
View File

@ -0,0 +1,65 @@
#include "gtest/gtest.h"
#include <light/entities.hh>
#include <vector>
TEST(entities, CheckEmptyValues) {
entdict_t good1 {};
entdict_t good2 {{"foo", "bar"}};
entdict_t bad1 {{"foo", ""}};
entdict_t bad2 {{"", "bar"}};
entdict_t bad3 {{"", ""}};
EXPECT_TRUE(EntDict_CheckNoEmptyValues(good1));
EXPECT_TRUE(EntDict_CheckNoEmptyValues(good2));
EXPECT_FALSE(EntDict_CheckNoEmptyValues(bad1));
EXPECT_FALSE(EntDict_CheckNoEmptyValues(bad2));
EXPECT_FALSE(EntDict_CheckNoEmptyValues(bad3));
}
TEST(entities, CheckTargetKeysMatched) {
std::vector<entdict_t> edicts {
// good
{
{"target", "matched" }
},
{
{"target2", "matched" }
},
{
{"targetname", "matched" }
},
// bad
{
{ "target", "unmatched" }
},
{
{"target", "targets_self" },
{"targetname", "targets_self" }
}
};
EXPECT_TRUE(EntDict_CheckTargetKeysMatched(edicts.at(0), edicts));
EXPECT_TRUE(EntDict_CheckTargetKeysMatched(edicts.at(1), edicts));
EXPECT_TRUE(EntDict_CheckTargetKeysMatched(edicts.at(2), edicts));
EXPECT_FALSE(EntDict_CheckTargetKeysMatched(edicts.at(3), edicts));
EXPECT_FALSE(EntDict_CheckTargetKeysMatched(edicts.at(4), edicts));
}
TEST(entities, CheckTargetnameKeyMatched) {
std::vector<entdict_t> edicts {
// good
{
{"some_mod_specific_target_key", "matched" }
},
{
{"targetname", "matched" }
},
// bad
{
{ "targetname", "unmatched" }
}
};
EXPECT_TRUE(EntDict_CheckTargetnameKeyMatched(edicts.at(0), edicts));
EXPECT_TRUE(EntDict_CheckTargetnameKeyMatched(edicts.at(1), edicts));
EXPECT_FALSE(EntDict_CheckTargetnameKeyMatched(edicts.at(2), edicts));
}

3
light/test_light.cc Normal file
View File

@ -0,0 +1,3 @@
#include "gtest/gtest.h"
#include <light/light.hh>

3
light/test_ltface.cc Normal file
View File

@ -0,0 +1,3 @@
#include "gtest/gtest.h"
#include <light/ltface.hh>