From c649e3a0c8aa06eaad231e130feed2601eabb2ce Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 27 May 2023 17:05:41 -0600 Subject: [PATCH] tests: add ExportWad test --- testmaps/q1_extract_textures.map | 49 ++++++++++++++++++++++++++++++++ tests/test_bsputil.cc | 25 ++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 testmaps/q1_extract_textures.map diff --git a/testmaps/q1_extract_textures.map b/testmaps/q1_extract_textures.map new file mode 100644 index 00000000..b517c1bb --- /dev/null +++ b/testmaps/q1_extract_textures.map @@ -0,0 +1,49 @@ +// Game: Quake +// Format: Valve +// entity 0 +{ +"mapversion" "220" +"classname" "worldspawn" +"wad" "deprecated/fence.wad;deprecated/free_wad.wad" +// brush 0 +{ +( -64 -64 -16 ) ( -64 -63 -16 ) ( -64 -64 -15 ) bolt14 [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -64 -64 -16 ) ( -64 -64 -15 ) ( -63 -64 -16 ) bolt14 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -64 -64 -16 ) ( -63 -64 -16 ) ( -64 -63 -16 ) bolt14 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 64 16 ) ( 64 65 16 ) ( 65 64 16 ) bolt14 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 64 16 ) ( 65 64 16 ) ( 64 64 17 ) bolt14 [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( 64 64 16 ) ( 64 64 17 ) ( 64 65 16 ) bolt14 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +} +// brush 1 +{ +( -64 -192 -16 ) ( -64 -191 -16 ) ( -64 -192 -15 ) *swater4 [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -64 -192 -16 ) ( -64 -192 -15 ) ( -63 -192 -16 ) *swater4 [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -64 -192 -16 ) ( -63 -192 -16 ) ( -64 -191 -16 ) *swater4 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 -64 16 ) ( 64 -63 16 ) ( 65 -64 16 ) *swater4 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 -64 16 ) ( 65 -64 16 ) ( 64 -64 17 ) *swater4 [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( 64 -64 16 ) ( 64 -64 17 ) ( 64 -63 16 ) *swater4 [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +} +// brush 2 +{ +( -64 -64 144 ) ( -64 -63 144 ) ( -64 -64 145 ) sky3 [ 0 -1 0 0 ] [ 0 0 -1 32 ] 0 1 1 +( -64 -64 144 ) ( -64 -64 145 ) ( -63 -64 144 ) sky3 [ 1 0 0 0 ] [ 0 0 -1 32 ] 0 1 1 +( -64 -64 144 ) ( -63 -64 144 ) ( -64 -63 144 ) sky3 [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 64 176 ) ( 64 65 176 ) ( 65 64 176 ) sky3 [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( 64 64 176 ) ( 65 64 176 ) ( 64 64 177 ) sky3 [ -1 0 0 0 ] [ 0 0 -1 32 ] 0 1 1 +( 64 64 176 ) ( 64 64 177 ) ( 64 65 176 ) sky3 [ 0 1 0 0 ] [ 0 0 -1 32 ] 0 1 1 +} +// brush 3 +{ +( -144 -64 0 ) ( -144 -63 0 ) ( -144 -64 1 ) brownlight [ 0 -1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -144 0 0 ) ( -144 0 1 ) ( -143 0 0 ) brownlight [ 1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -144 -64 -208 ) ( -143 -64 -208 ) ( -144 -63 -208 ) brownlight [ -1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( -64 64 16 ) ( -64 65 16 ) ( -63 64 16 ) brownlight [ 1 0 0 0 ] [ 0 -1 0 0 ] 0 1 1 +( -64 64 16 ) ( -63 64 16 ) ( -64 64 17 ) brownlight [ -1 0 0 0 ] [ 0 0 -1 0 ] 0 1 1 +( -64 64 16 ) ( -64 64 17 ) ( -64 65 16 ) brownlight [ 0 1 0 0 ] [ 0 0 -1 0 ] 0 1 1 +} +} +// entity 1 +{ +"classname" "info_player_start" +"origin" "-32 -16 40" +} diff --git a/tests/test_bsputil.cc b/tests/test_bsputil.cc index 26a7f5ce..40f25b04 100644 --- a/tests/test_bsputil.cc +++ b/tests/test_bsputil.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include "testmaps.hh" #include "test_qbsp.hh" @@ -46,4 +47,28 @@ TEST_SUITE("bsputil") CHECK(face2_texinfo->vecs == face_texinfo->vecs); } } + + TEST_CASE("extract-textures") + { + const auto [bsp, bspx, prt] = LoadTestmapQ1("q1_extract_textures.map"); + + // extract .bsp textures to test.wad + std::ofstream wadfile("test.wad", std::ios::binary); + ExportWad(wadfile, &bsp); + + // reload .wad + fs::clear(); + img::clear(); + + auto ar = fs::addArchive("test.wad"); + REQUIRE(ar); + + for (std::string texname : {"*swater4", "bolt14", "sky3", "brownlight"}) { + INFO(texname); + fs::data data = ar->load(texname); + REQUIRE(data); + auto loaded_tex = img::load_mip(texname, data, false, bspver_q1.game); + CHECK(loaded_tex); + } + } }