diff --git a/include/light/entities.hh b/include/light/entities.hh index 195db869..b491c973 100644 --- a/include/light/entities.hh +++ b/include/light/entities.hh @@ -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 &all_edicts); diff --git a/light/CMakeLists.txt b/light/CMakeLists.txt index b21d1eba..32e4d54d 100644 --- a/light/CMakeLists.txt +++ b/light/CMakeLists.txt @@ -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) diff --git a/light/entities.cc b/light/entities.cc index cc0adc2a..1df9b4c3 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -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); } diff --git a/light/test_entities.cc b/light/test_entities.cc new file mode 100644 index 00000000..a2aa76e4 --- /dev/null +++ b/light/test_entities.cc @@ -0,0 +1,65 @@ +#include "gtest/gtest.h" + +#include +#include + +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 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 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)); +} diff --git a/light/test_light.cc b/light/test_light.cc new file mode 100644 index 00000000..aa019e82 --- /dev/null +++ b/light/test_light.cc @@ -0,0 +1,3 @@ +#include "gtest/gtest.h" + +#include diff --git a/light/test_ltface.cc b/light/test_ltface.cc new file mode 100644 index 00000000..8b8b9bea --- /dev/null +++ b/light/test_ltface.cc @@ -0,0 +1,3 @@ +#include "gtest/gtest.h" + +#include