light: add some tests for the EntDict_Check* functions
This commit is contained in:
parent
26dcb4f10f
commit
f7091c27f8
|
|
@ -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);
|
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);
|
bool EntDict_CheckTargetKeysMatched(const entdict_t &entity, const std::vector<entdict_t> &all_edicts);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,10 @@ include_directories(${CMAKE_SOURCE_DIR}/3rdparty/googletest)
|
||||||
set(LIGHT_TEST_SOURCE
|
set(LIGHT_TEST_SOURCE
|
||||||
${LIGHT_SOURCES}
|
${LIGHT_SOURCES}
|
||||||
${GOOGLETEST_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_executable(testlight EXCLUDE_FROM_ALL ${LIGHT_TEST_SOURCE})
|
||||||
add_test(testlight testlight)
|
add_test(testlight testlight)
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ EntDict_PrettyDescription(const entdict_t &entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
EntDict_CheckEmptyValues(const entdict_t &entdict)
|
EntDict_CheckNoEmptyValues(const entdict_t &entdict)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
// empty values warning
|
// empty values warning
|
||||||
|
|
@ -971,7 +971,7 @@ LoadEntities(const globalconfig_t &cfg, const bsp2_t *bsp)
|
||||||
|
|
||||||
// Make warnings
|
// Make warnings
|
||||||
for (auto &entdict : entdicts) {
|
for (auto &entdict : entdicts) {
|
||||||
EntDict_CheckEmptyValues(entdict);
|
EntDict_CheckNoEmptyValues(entdict);
|
||||||
EntDict_CheckTargetKeysMatched(entdict, entdicts);
|
EntDict_CheckTargetKeysMatched(entdict, entdicts);
|
||||||
EntDict_CheckTargetnameKeyMatched(entdict, entdicts);
|
EntDict_CheckTargetnameKeyMatched(entdict, entdicts);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include <light/light.hh>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include <light/ltface.hh>
|
||||||
Loading…
Reference in New Issue