From fe5ce3765ab3cdef30dec9ed50deb965dcc0cd3c Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 21 Dec 2022 20:56:18 -0700 Subject: [PATCH] test: add a few more area-related assertions --- common/bspfile_generic.cc | 23 +++++++++++++++++++++++ include/common/bspfile_generic.hh | 3 +++ tests/test_qbsp_q2.cc | 7 +++++++ 3 files changed, 33 insertions(+) diff --git a/common/bspfile_generic.cc b/common/bspfile_generic.cc index ebd58854..79862cda 100644 --- a/common/bspfile_generic.cc +++ b/common/bspfile_generic.cc @@ -261,6 +261,29 @@ void bsp2_dclipnode_t::stream_read(std::istream &s) s >= std::tie(planenum, children); } +// mleaf_t + +static auto tuple(const mleaf_t &l) +{ + return std::tie( + l.contents, + l.visofs, + l.mins, + l.maxs, + l.firstmarksurface, + l.nummarksurfaces, + l.ambient_level, + l.cluster, + l.area, + l.firstleafbrush, + l.numleafbrushes); +} + +bool mleaf_t::operator==(const mleaf_t &other) const +{ + return tuple(*this) == tuple(other); +} + // darea_t void darea_t::stream_write(std::ostream &s) const diff --git a/include/common/bspfile_generic.hh b/include/common/bspfile_generic.hh index b1eee5ff..83af918d 100644 --- a/include/common/bspfile_generic.hh +++ b/include/common/bspfile_generic.hh @@ -275,6 +275,9 @@ struct mleaf_t int32_t area; uint32_t firstleafbrush; uint32_t numleafbrushes; + + // comparison operator for tests + bool operator==(const mleaf_t &other) const; }; struct darea_t diff --git a/tests/test_qbsp_q2.cc b/tests/test_qbsp_q2.cc index bc565985..854ab359 100644 --- a/tests/test_qbsp_q2.cc +++ b/tests/test_qbsp_q2.cc @@ -21,6 +21,10 @@ TEST_CASE("detail" * doctest::test_suite("testmaps_q2")) { // stats CHECK(1 == bsp.dmodels.size()); // Q2 reserves leaf 0 as an invalid leaf + CHECK(mleaf_t{.contents = Q2_CONTENTS_SOLID, .visofs = -1} == bsp.dleafs[0]); + // no areaportals except the placeholder + CHECK(1 == bsp.dareaportals.size()); + CHECK(2 == bsp.dareas.size()); // leafs: // 6 solid leafs outside the room (* can be more depending on when the "divider" is cut) @@ -81,17 +85,20 @@ TEST_CASE("detail" * doctest::test_suite("testmaps_q2")) { auto *empty_leaf_above_button = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], above_button); CHECK(0 == empty_leaf_above_button->contents); CHECK(0 == Leaf_Brushes(&bsp, empty_leaf_above_button).size()); + CHECK(1 == empty_leaf_above_button->area); auto *empty_leaf_side_room = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], side_room); CHECK(0 == empty_leaf_side_room->contents); CHECK(0 == Leaf_Brushes(&bsp, empty_leaf_side_room).size()); CHECK(empty_leaf_side_room->cluster != empty_leaf_above_button->cluster); + CHECK(1 == empty_leaf_side_room->area); auto *empty_leaf_beside_button = BSP_FindLeafAtPoint(&bsp, &bsp.dmodels[0], beside_button); CHECK(0 == empty_leaf_beside_button->contents); CHECK(-1 != empty_leaf_beside_button->cluster); CHECK(empty_leaf_above_button->cluster == empty_leaf_beside_button->cluster); CHECK(empty_leaf_above_button != empty_leaf_beside_button); + CHECK(1 == empty_leaf_beside_button->area); CHECK(prt->portals.size() == 5); CHECK(prt->portalleafs_real == 0); // not used by Q2