diff --git a/test/Helpers.cpp b/test/Helpers.cpp index 223fa9d23..72c4cb90d 100644 --- a/test/Helpers.cpp +++ b/test/Helpers.cpp @@ -3,7 +3,7 @@ #include #include -std::vector readFileToBuffer(const std::string& path) { +std::vector readFile(const std::string& path) { std::ifstream file(path, std::ios::binary); file >> std::skipws; auto size = std::filesystem::file_size(path); @@ -11,3 +11,9 @@ std::vector readFileToBuffer(const std::string& path) { file.read(reinterpret_cast(out.data()), static_cast(size)); return out; } + +void createFile(const std::string& name, const std::vector& data) { + std::ofstream out{name.data(), std::ios::binary | std::ios::trunc}; + out.unsetf(std::ios::skipws); + out.write(reinterpret_cast(data.data()), static_cast(data.size())); +} diff --git a/test/Helpers.h.in b/test/Helpers.h.in index 091cf22bb..ae5d635cd 100644 --- a/test/Helpers.h.in +++ b/test/Helpers.h.in @@ -6,4 +6,6 @@ #define ASSET_ROOT "${sourcepp_ASSET_ROOT}" -std::vector readFileToBuffer(const std::string& path); +std::vector readFile(const std::string& path); + +void createFile(const std::string& name, const std::vector& data); diff --git a/test/dmxpp.cpp b/test/dmxpp.cpp index 22cad617b..ad8a93962 100644 --- a/test/dmxpp.cpp +++ b/test/dmxpp.cpp @@ -8,21 +8,21 @@ using namespace dmxpp; // v1 and v2 are identical afaik... TEST(dmxpp, v2_read) { - DMX dmx{::readFileToBuffer(ASSET_ROOT "dmxpp/binary/v2.dmx")}; + DMX dmx{::readFile(ASSET_ROOT "dmxpp/binary/v2.dmx")}; ASSERT_TRUE(dmx); } TEST(dmxpp, v3_read) { - DMX dmx{::readFileToBuffer(ASSET_ROOT "dmxpp/binary/v3.dmx")}; + DMX dmx{::readFile(ASSET_ROOT "dmxpp/binary/v3.dmx")}; ASSERT_TRUE(dmx); } TEST(dmxpp, v4_read) { - DMX dmx{::readFileToBuffer(ASSET_ROOT "dmxpp/binary/v4.dmx")}; + DMX dmx{::readFile(ASSET_ROOT "dmxpp/binary/v4.dmx")}; ASSERT_TRUE(dmx); } TEST(dmxpp, v5_read) { - DMX dmx{::readFileToBuffer(ASSET_ROOT "dmxpp/binary/v5.dmx")}; + DMX dmx{::readFile(ASSET_ROOT "dmxpp/binary/v5.dmx")}; ASSERT_TRUE(dmx); } diff --git a/test/studiomodelpp.cpp b/test/studiomodelpp.cpp index 334860e9d..b8007ea68 100644 --- a/test/studiomodelpp.cpp +++ b/test/studiomodelpp.cpp @@ -8,24 +8,24 @@ using namespace studiomodelpp; TEST(studiomodelpp, v44_read) { StudioModel model; - bool opened = model.open(::readFileToBuffer(ASSET_ROOT "studiomodelpp/v44.mdl"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v44.vtx"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v44.vvd")); + bool opened = model.open(::readFile(ASSET_ROOT "studiomodelpp/v44.mdl"), + ::readFile(ASSET_ROOT "studiomodelpp/v44.vtx"), + ::readFile(ASSET_ROOT "studiomodelpp/v44.vvd")); ASSERT_TRUE(opened); } TEST(studiomodelpp, v47_read) { StudioModel model; - bool opened = model.open(::readFileToBuffer(ASSET_ROOT "studiomodelpp/v47.mdl"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v47.vtx"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v47.vvd")); + bool opened = model.open(::readFile(ASSET_ROOT "studiomodelpp/v47.mdl"), + ::readFile(ASSET_ROOT "studiomodelpp/v47.vtx"), + ::readFile(ASSET_ROOT "studiomodelpp/v47.vvd")); ASSERT_TRUE(opened); } TEST(studiomodelpp, v49_read) { StudioModel model; - bool opened = model.open(::readFileToBuffer(ASSET_ROOT "studiomodelpp/v49.mdl"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v49.vtx"), - ::readFileToBuffer(ASSET_ROOT "studiomodelpp/v49.vvd")); + bool opened = model.open(::readFile(ASSET_ROOT "studiomodelpp/v49.mdl"), + ::readFile(ASSET_ROOT "studiomodelpp/v49.vtx"), + ::readFile(ASSET_ROOT "studiomodelpp/v49.vvd")); ASSERT_TRUE(opened); } diff --git a/test/vtfpp.cpp b/test/vtfpp.cpp index bdbc7b4eb..b99851d13 100644 --- a/test/vtfpp.cpp +++ b/test/vtfpp.cpp @@ -8,20 +8,8 @@ using namespace vtfpp; #if 0 -#include - -namespace { - -void createFile(std::string_view name, const std::vector& data) { - std::ofstream out{name.data(), std::ios::binary | std::ios::trunc}; - out.unsetf(std::ios::skipws); - out.write(reinterpret_cast(data.data()), static_cast(data.size())); -} - -} // namespace - TEST(vtfpp, read_fmt_rgba8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_rgba8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_rgba8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -40,7 +28,7 @@ TEST(vtfpp, read_fmt_rgba8888) { } TEST(vtfpp, read_fmt_abgr8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_abgr8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_abgr8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -59,7 +47,7 @@ TEST(vtfpp, read_fmt_abgr8888) { } TEST(vtfpp, read_fmt_rgb888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_rgb888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_rgb888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -78,7 +66,7 @@ TEST(vtfpp, read_fmt_rgb888) { } TEST(vtfpp, read_fmt_bgr888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgr888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgr888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -97,7 +85,7 @@ TEST(vtfpp, read_fmt_bgr888) { } TEST(vtfpp, read_fmt_rgb565) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_rgb565.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_rgb565.vtf")}; ASSERT_TRUE(vtf); // Header @@ -116,7 +104,7 @@ TEST(vtfpp, read_fmt_rgb565) { } TEST(vtfpp, read_fmt_i8) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_i8.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_i8.vtf")}; ASSERT_TRUE(vtf); // Header @@ -135,7 +123,7 @@ TEST(vtfpp, read_fmt_i8) { } TEST(vtfpp, read_fmt_ia88) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_ia88.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_ia88.vtf")}; ASSERT_TRUE(vtf); // Header @@ -154,7 +142,7 @@ TEST(vtfpp, read_fmt_ia88) { } TEST(vtfpp, read_fmt_a8) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_a8.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_a8.vtf")}; ASSERT_TRUE(vtf); // Header @@ -173,7 +161,7 @@ TEST(vtfpp, read_fmt_a8) { } TEST(vtfpp, read_fmt_rgb888_bluescreen) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_rgb888_bluescreen.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_rgb888_bluescreen.vtf")}; ASSERT_TRUE(vtf); // Header @@ -192,7 +180,7 @@ TEST(vtfpp, read_fmt_rgb888_bluescreen) { } TEST(vtfpp, read_fmt_bgr888_bluescreen) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgr888_bluescreen.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgr888_bluescreen.vtf")}; ASSERT_TRUE(vtf); // Header @@ -211,7 +199,7 @@ TEST(vtfpp, read_fmt_bgr888_bluescreen) { } TEST(vtfpp, read_fmt_argb8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_argb8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_argb8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -230,7 +218,7 @@ TEST(vtfpp, read_fmt_argb8888) { } TEST(vtfpp, read_fmt_bgra8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgra8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgra8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -249,7 +237,7 @@ TEST(vtfpp, read_fmt_bgra8888) { } TEST(vtfpp, read_fmt_dxt1) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_dxt1.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_dxt1.vtf")}; ASSERT_TRUE(vtf); // Header @@ -268,7 +256,7 @@ TEST(vtfpp, read_fmt_dxt1) { } TEST(vtfpp, read_fmt_dxt3) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_dxt3.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_dxt3.vtf")}; ASSERT_TRUE(vtf); // Header @@ -287,7 +275,7 @@ TEST(vtfpp, read_fmt_dxt3) { } TEST(vtfpp, read_fmt_dxt5) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_dxt5.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_dxt5.vtf")}; ASSERT_TRUE(vtf); // Header @@ -306,7 +294,7 @@ TEST(vtfpp, read_fmt_dxt5) { } TEST(vtfpp, read_fmt_bgrx8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgrx8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgrx8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -325,7 +313,7 @@ TEST(vtfpp, read_fmt_bgrx8888) { } TEST(vtfpp, read_fmt_bgr565) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgr565.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgr565.vtf")}; ASSERT_TRUE(vtf); // Header @@ -344,7 +332,7 @@ TEST(vtfpp, read_fmt_bgr565) { } TEST(vtfpp, read_fmt_bgrx5551) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgrx5551.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgrx5551.vtf")}; ASSERT_TRUE(vtf); // Header @@ -363,7 +351,7 @@ TEST(vtfpp, read_fmt_bgrx5551) { } TEST(vtfpp, read_fmt_bgra4444) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgra4444.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgra4444.vtf")}; ASSERT_TRUE(vtf); // Header @@ -382,7 +370,7 @@ TEST(vtfpp, read_fmt_bgra4444) { } TEST(vtfpp, read_fmt_dxt1_one_bit_alpha) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_dxt1_one_bit_alpha.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_dxt1_one_bit_alpha.vtf")}; ASSERT_TRUE(vtf); // Header @@ -401,7 +389,7 @@ TEST(vtfpp, read_fmt_dxt1_one_bit_alpha) { } TEST(vtfpp, read_fmt_bgra5551) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_bgra5551.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_bgra5551.vtf")}; ASSERT_TRUE(vtf); // Header @@ -420,7 +408,7 @@ TEST(vtfpp, read_fmt_bgra5551) { } TEST(vtfpp, read_fmt_uv88) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_uv88.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_uv88.vtf")}; ASSERT_TRUE(vtf); // Header @@ -439,7 +427,7 @@ TEST(vtfpp, read_fmt_uv88) { } TEST(vtfpp, read_fmt_uvwq8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_uvwq8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_uvwq8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -458,7 +446,7 @@ TEST(vtfpp, read_fmt_uvwq8888) { } TEST(vtfpp, read_fmt_uvlx8888) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/fmt_uvlx8888.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/fmt_uvlx8888.vtf")}; ASSERT_TRUE(vtf); // Header @@ -479,7 +467,7 @@ TEST(vtfpp, read_fmt_uvlx8888) { #endif TEST(vtfpp, read_v70) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v70.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v70.vtf")}; ASSERT_TRUE(vtf); // Header @@ -517,7 +505,7 @@ TEST(vtfpp, read_v70) { } TEST(vtfpp, read_v70_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v70_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v70_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -555,7 +543,7 @@ TEST(vtfpp, read_v70_nomip) { } TEST(vtfpp, read_v70_nothumb) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v70_nothumb.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v70_nothumb.vtf")}; ASSERT_TRUE(vtf); // Header @@ -591,7 +579,7 @@ TEST(vtfpp, read_v70_nothumb) { } TEST(vtfpp, read_v70_nothumb_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v70_nothumb_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v70_nothumb_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -627,7 +615,7 @@ TEST(vtfpp, read_v70_nothumb_nomip) { } TEST(vtfpp, read_v71) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v71.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v71.vtf")}; ASSERT_TRUE(vtf); // Header @@ -665,7 +653,7 @@ TEST(vtfpp, read_v71) { } TEST(vtfpp, read_v71_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v71_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v71_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -703,7 +691,7 @@ TEST(vtfpp, read_v71_nomip) { } TEST(vtfpp, read_v71_nothumb) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v71_nothumb.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v71_nothumb.vtf")}; ASSERT_TRUE(vtf); // Header @@ -739,7 +727,7 @@ TEST(vtfpp, read_v71_nothumb) { } TEST(vtfpp, read_v71_nothumb_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v71_nothumb_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v71_nothumb_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -775,7 +763,7 @@ TEST(vtfpp, read_v71_nothumb_nomip) { } TEST(vtfpp, read_v72) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v72.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v72.vtf")}; ASSERT_TRUE(vtf); // Header @@ -813,7 +801,7 @@ TEST(vtfpp, read_v72) { } TEST(vtfpp, read_v72_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v72_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v72_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -851,7 +839,7 @@ TEST(vtfpp, read_v72_nomip) { } TEST(vtfpp, read_v72_nothumb) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v72_nothumb.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v72_nothumb.vtf")}; ASSERT_TRUE(vtf); // Header @@ -887,7 +875,7 @@ TEST(vtfpp, read_v72_nothumb) { } TEST(vtfpp, read_v72_nothumb_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v72_nothumb_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v72_nothumb_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -923,7 +911,7 @@ TEST(vtfpp, read_v72_nothumb_nomip) { } TEST(vtfpp, read_v75) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v75.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v75.vtf")}; ASSERT_TRUE(vtf); // Header @@ -974,7 +962,7 @@ TEST(vtfpp, read_v75) { } TEST(vtfpp, read_v75_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v75_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v75_nomip.vtf")}; ASSERT_TRUE(vtf); // Header @@ -1012,7 +1000,7 @@ TEST(vtfpp, read_v75_nomip) { } TEST(vtfpp, read_v75_nothumb) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v75_nothumb.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v75_nothumb.vtf")}; ASSERT_TRUE(vtf); // Header @@ -1048,7 +1036,7 @@ TEST(vtfpp, read_v75_nothumb) { } TEST(vtfpp, read_v75_nothumb_nomip) { - VTF vtf{::readFileToBuffer(ASSET_ROOT "vtfpp/v75_nothumb_nomip.vtf")}; + VTF vtf{::readFile(ASSET_ROOT "vtfpp/v75_nothumb_nomip.vtf")}; ASSERT_TRUE(vtf); // Header