refactor: replace EXPECT_VECTORS_UNOREDERED_EQUAL with gtest matchers
This commit is contained in:
parent
a6c7a18cb8
commit
b1ee327092
|
|
@ -9,9 +9,7 @@ add_executable(tests
|
||||||
test_qbsp.hh
|
test_qbsp.hh
|
||||||
test_qbsp_q2.cc
|
test_qbsp_q2.cc
|
||||||
test_vis.cc
|
test_vis.cc
|
||||||
testutils.hh
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../testmaps.hh
|
${CMAKE_CURRENT_BINARY_DIR}/../testmaps.hh
|
||||||
testutils.hh
|
|
||||||
benchmark.cc
|
benchmark.cc
|
||||||
test_bsputil.cc
|
test_bsputil.cc
|
||||||
test_main.hh)
|
test_main.hh)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include "testutils.hh"
|
|
||||||
#include "test_main.hh"
|
#include "test_main.hh"
|
||||||
|
|
||||||
// FIXME: Clear global data (planes, etc) between each test
|
// FIXME: Clear global data (planes, etc) between each test
|
||||||
|
|
@ -573,7 +572,7 @@ TEST(testmapsQ1, simpleSealed)
|
||||||
|
|
||||||
EXPECT_EQ(bsp.dleafs[1].nummarksurfaces, 6);
|
EXPECT_EQ(bsp.dleafs[1].nummarksurfaces, 6);
|
||||||
EXPECT_EQ(bsp.dleafs[1].firstmarksurface, 0);
|
EXPECT_EQ(bsp.dleafs[1].firstmarksurface, 0);
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(bsp.dleaffaces, std::vector<uint32_t>{0, 1, 2, 3, 4, 5});
|
EXPECT_THAT(bsp.dleaffaces, testing::UnorderedElementsAre(0, 1, 2, 3, 4, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -610,8 +609,8 @@ TEST(testmapsQ1, simpleSealed2)
|
||||||
auto *other_plus_y =
|
auto *other_plus_y =
|
||||||
BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], qvec3d(-64, -368, 128), qvec3d(0, 1, 0)); // back wall +Y normal
|
BSP_FindFaceAtPoint(&bsp, &bsp.dmodels[0], qvec3d(-64, -368, 128), qvec3d(0, 1, 0)); // back wall +Y normal
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(other_markfaces,
|
EXPECT_THAT(other_markfaces,
|
||||||
std::vector<const mface_t *>{other_floor, other_ceil, other_minus_x, other_plus_x, other_plus_y});
|
testing::UnorderedElementsAre(other_floor, other_ceil, other_minus_x, other_plus_x, other_plus_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(testmapsQ1, q1FuncIllusionaryVisblocker)
|
TEST(testmapsQ1, q1FuncIllusionaryVisblocker)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include <qbsp/map.hh>
|
#include <qbsp/map.hh>
|
||||||
#include <common/bsputils.hh>
|
#include <common/bsputils.hh>
|
||||||
|
|
@ -11,7 +12,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "test_qbsp.hh"
|
#include "test_qbsp.hh"
|
||||||
#include "testutils.hh"
|
|
||||||
|
|
||||||
TEST(testmapsQ2, detail)
|
TEST(testmapsQ2, detail)
|
||||||
{
|
{
|
||||||
|
|
@ -189,8 +189,9 @@ TEST(testmapsQ2, areaportal)
|
||||||
//
|
//
|
||||||
// the conceptual area portal has portalnum 1, and consists of two dareaportals entries with connections to area 1
|
// the conceptual area portal has portalnum 1, and consists of two dareaportals entries with connections to area 1
|
||||||
// and 2
|
// and 2
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(bsp.dareaportals, std::vector<dareaportal_t>{{0, 0}, {1, 1}, {1, 2}});
|
EXPECT_THAT(
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(bsp.dareas, std::vector<darea_t>{{0, 0}, {1, 1}, {1, 2}});
|
bsp.dareaportals, testing::UnorderedElementsAreArray(std::vector<dareaportal_t>{{0, 0}, {1, 1}, {1, 2}}));
|
||||||
|
EXPECT_THAT(bsp.dareas, testing::UnorderedElementsAreArray(std::vector<darea_t>{{0, 0}, {1, 1}, {1, 2}}));
|
||||||
|
|
||||||
// look up the leafs
|
// look up the leafs
|
||||||
const qvec3d player_start{-88, -112, 120};
|
const qvec3d player_start{-88, -112, 120};
|
||||||
|
|
@ -221,8 +222,8 @@ TEST(testmapsQ2, areaportal)
|
||||||
EXPECT_EQ(Q2_CONTENTS_SOLID, Leaf_Brushes(&bsp, void_leaf).at(0)->contents);
|
EXPECT_EQ(Q2_CONTENTS_SOLID, Leaf_Brushes(&bsp, void_leaf).at(0)->contents);
|
||||||
|
|
||||||
// check leaf areas
|
// check leaf areas
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(
|
||||||
(std::vector<int32_t>{1, 2}), std::vector<int32_t>{player_start_leaf->area, other_room_leaf->area});
|
(std::vector<int32_t>{player_start_leaf->area, other_room_leaf->area}), testing::UnorderedElementsAre(1, 2));
|
||||||
// the areaportal leaf itself actually gets assigned to one of the two sides' areas
|
// the areaportal leaf itself actually gets assigned to one of the two sides' areas
|
||||||
EXPECT_TRUE(areaportal_leaf->area == 1 || areaportal_leaf->area == 2);
|
EXPECT_TRUE(areaportal_leaf->area == 1 || areaportal_leaf->area == 2);
|
||||||
EXPECT_EQ(0, void_leaf->area); // a solid leaf gets the invalid area
|
EXPECT_EQ(0, void_leaf->area); // a solid leaf gets the invalid area
|
||||||
|
|
@ -250,8 +251,9 @@ TEST(testmapsQ2, areaportalWithDetail)
|
||||||
//
|
//
|
||||||
// the conceptual area portal has portalnum 1, and consists of two dareaportals entries with connections to area 1
|
// the conceptual area portal has portalnum 1, and consists of two dareaportals entries with connections to area 1
|
||||||
// and 2
|
// and 2
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(bsp.dareaportals, std::vector<dareaportal_t>{{0, 0}, {1, 1}, {1, 2}});
|
EXPECT_THAT(
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(bsp.dareas, std::vector<darea_t>{{0, 0}, {1, 1}, {1, 2}});
|
bsp.dareaportals, testing::UnorderedElementsAreArray(std::vector<dareaportal_t>{{0, 0}, {1, 1}, {1, 2}}));
|
||||||
|
EXPECT_THAT(bsp.dareas, testing::UnorderedElementsAreArray(std::vector<darea_t>{{0, 0}, {1, 1}, {1, 2}}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(testmapsQ2, nodrawLight)
|
TEST(testmapsQ2, nodrawLight)
|
||||||
|
|
@ -451,37 +453,37 @@ TEST(testmapsQ2, liquids)
|
||||||
const qvec3d wateropaque_trans33 = watertrans33_trans66 - qvec3d(0, 0, 48);
|
const qvec3d wateropaque_trans33 = watertrans33_trans66 - qvec3d(0, 0, 48);
|
||||||
const qvec3d floor_wateropaque = wateropaque_trans33 - qvec3d(0, 0, 48);
|
const qvec3d floor_wateropaque = wateropaque_trans33 - qvec3d(0, 0, 48);
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_air)),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_air)),
|
||||||
std::vector<std::string>({"e1u1/bluwter", "e1u1/bluwter"}));
|
testing::UnorderedElementsAre("e1u1/bluwter", "e1u1/bluwter"));
|
||||||
EXPECT_EQ(0, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans33_trans66).size());
|
EXPECT_EQ(0, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans33_trans66).size());
|
||||||
EXPECT_EQ(0, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], wateropaque_trans33).size());
|
EXPECT_EQ(0, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], wateropaque_trans33).size());
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], floor_wateropaque)),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], floor_wateropaque)),
|
||||||
std::vector<std::string>({"e1u1/c_met11_2"}));
|
testing::UnorderedElementsAre("e1u1/c_met11_2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const qvec3d watertrans66_slimetrans66{-116, -144, 116};
|
const qvec3d watertrans66_slimetrans66{-116, -144, 116};
|
||||||
|
|
||||||
// water trans66 / slime trans66
|
// water trans66 / slime trans66
|
||||||
{
|
{
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(
|
||||||
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_slimetrans66, qvec3d(0, -1, 0))),
|
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_slimetrans66, qvec3d(0, -1, 0))),
|
||||||
std::vector<std::string>({"e1u1/sewer1"}));
|
testing::UnorderedElementsAre("e1u1/sewer1"));
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(
|
||||||
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_slimetrans66, qvec3d(0, 1, 0))),
|
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], watertrans66_slimetrans66, qvec3d(0, 1, 0))),
|
||||||
std::vector<std::string>({"e1u1/sewer1"}));
|
testing::UnorderedElementsAre("e1u1/sewer1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// slime trans66 / lava trans66
|
// slime trans66 / lava trans66
|
||||||
const qvec3d slimetrans66_lavatrans66 = watertrans66_slimetrans66 + qvec3d(0, 48, 0);
|
const qvec3d slimetrans66_lavatrans66 = watertrans66_slimetrans66 + qvec3d(0, 48, 0);
|
||||||
{
|
{
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(
|
||||||
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], slimetrans66_lavatrans66, qvec3d(0, -1, 0))),
|
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], slimetrans66_lavatrans66, qvec3d(0, -1, 0))),
|
||||||
std::vector<std::string>({"e1u1/brlava"}));
|
testing::UnorderedElementsAre("e1u1/brlava"));
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(
|
||||||
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], slimetrans66_lavatrans66, qvec3d(0, 1, 0))),
|
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], slimetrans66_lavatrans66, qvec3d(0, 1, 0))),
|
||||||
std::vector<std::string>({"e1u1/brlava"}));
|
testing::UnorderedElementsAre("e1u1/brlava"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -589,36 +591,35 @@ TEST(testmapsQ2, mirrorinside)
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("window is not two sided by default");
|
SCOPED_TRACE("window is not two sided by default");
|
||||||
const qvec3d window_pos{192, 96, 156};
|
const qvec3d window_pos{192, 96, 156};
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], window_pos)),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], window_pos)),
|
||||||
std::vector<std::string>({"e2u2/wndow1_1"}));
|
testing::UnorderedElementsAre("e2u2/wndow1_1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("aux is not two sided by default");
|
SCOPED_TRACE("aux is not two sided by default");
|
||||||
const qvec3d aux_pos{32, 96, 156};
|
const qvec3d aux_pos{32, 96, 156};
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], aux_pos)),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], aux_pos)),
|
||||||
std::vector<std::string>({"e1u1/brwater"}));
|
testing::UnorderedElementsAre("e1u1/brwater"));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("mist is two sided by default");
|
SCOPED_TRACE("mist is two sided by default");
|
||||||
const qvec3d mist_pos{32, -28, 156};
|
const qvec3d mist_pos{32, -28, 156};
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], mist_pos)),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], mist_pos)),
|
||||||
std::vector<std::string>({"e1u1/brwater", "e1u1/brwater"}));
|
testing::UnorderedElementsAre("e1u1/brwater", "e1u1/brwater"));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("_mirrorinside 0 disables the inside faces on mist");
|
SCOPED_TRACE("_mirrorinside 0 disables the inside faces on mist");
|
||||||
const qvec3d mist_mirrorinside0_pos{32, -224, 156};
|
const qvec3d mist_mirrorinside0_pos{32, -224, 156};
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], mist_mirrorinside0_pos)),
|
||||||
TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], mist_mirrorinside0_pos)),
|
testing::UnorderedElementsAre("e1u1/brwater"));
|
||||||
std::vector<std::string>({"e1u1/brwater"}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SCOPED_TRACE("_mirrorinside 1 works on func_detail_fence");
|
SCOPED_TRACE("_mirrorinside 1 works on func_detail_fence");
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {32, -348, 156})),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {32, -348, 156})),
|
||||||
std::vector<std::string>({"e1u1/alphamask", "e1u1/alphamask"}));
|
testing::UnorderedElementsAre("e1u1/alphamask", "e1u1/alphamask"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1119,14 +1120,14 @@ TEST(testmapsQ2, chopOrder0)
|
||||||
{
|
{
|
||||||
const auto [bsp, bspx, prt] = LoadTestmapQ2("q2_chop_order_0.map");
|
const auto [bsp, bspx, prt] = LoadTestmapQ2("q2_chop_order_0.map");
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0})),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0})),
|
||||||
std::vector<std::string>({"e1u1/ggrat4_2"}));
|
testing::UnorderedElementsAre("e1u1/ggrat4_2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(testmapsQ2, chopOrder1)
|
TEST(testmapsQ2, chopOrder1)
|
||||||
{
|
{
|
||||||
const auto [bsp, bspx, prt] = LoadTestmapQ2("q2_chop_order_1.map");
|
const auto [bsp, bspx, prt] = LoadTestmapQ2("q2_chop_order_1.map");
|
||||||
|
|
||||||
EXPECT_VECTORS_UNOREDERED_EQUAL(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0})),
|
EXPECT_THAT(TexNames(bsp, BSP_FindFacesAtPoint(&bsp, &bsp.dmodels[0], {0, 0, 0})),
|
||||||
std::vector<std::string>({"e1u1/+0btshoot2"}));
|
testing::UnorderedElementsAre("e1u1/+0btshoot2"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <vis/vis.hh>
|
#include <vis/vis.hh>
|
||||||
|
|
||||||
#include "test_qbsp.hh"
|
#include "test_qbsp.hh"
|
||||||
#include "testutils.hh"
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
static bool q2_leaf_sees(
|
static bool q2_leaf_sees(
|
||||||
const mbsp_t &bsp, const std::unordered_map<int, std::vector<uint8_t>> &vis, const mleaf_t *a, const mleaf_t *b)
|
const mbsp_t &bsp, const std::unordered_map<int, std::vector<uint8_t>> &vis, const mleaf_t *a, const mleaf_t *b)
|
||||||
|
|
@ -154,7 +154,8 @@ TEST(vis, q1FuncIllusionaryVisblockerInteractions)
|
||||||
const auto in_visblocker_covered_by_illusionary = qvec3d(48, 248, 56);
|
const auto in_visblocker_covered_by_illusionary = qvec3d(48, 248, 56);
|
||||||
|
|
||||||
auto *player_start_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], player_start);
|
auto *player_start_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], player_start);
|
||||||
auto *in_visblocker_covered_by_illusionary_leaf = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], in_visblocker_covered_by_illusionary);
|
auto *in_visblocker_covered_by_illusionary_leaf =
|
||||||
|
BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], in_visblocker_covered_by_illusionary);
|
||||||
|
|
||||||
EXPECT_FALSE(q1_leaf_sees(bsp, vis, in_visblocker_covered_by_illusionary_leaf, player_start_leaf));
|
EXPECT_FALSE(q1_leaf_sees(bsp, vis, in_visblocker_covered_by_illusionary_leaf, player_start_leaf));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
template<class A>
|
|
||||||
void EXPECT_VECTORS_UNOREDERED_EQUAL(const A &a, const A &b)
|
|
||||||
{
|
|
||||||
if (a.size() != b.size()) {
|
|
||||||
ADD_FAILURE() << "Expected vectors to be equal (ignoring order)";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &a_elem : a) {
|
|
||||||
if (std::find(b.begin(), b.end(), a_elem) == b.end()) {
|
|
||||||
ADD_FAILURE() << "Expected vectors to be equal (ignoring order)";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue