Skip to content

Commit fe90d2c

Browse files
authored
Merge pull request #300 from chaoticgd/test_refactor
Reformat the tests
2 parents 16afc8b + e0982fd commit fe90d2c

File tree

8 files changed

+115
-54
lines changed

8 files changed

+115
-54
lines changed

test/test_algorithm.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -19,7 +19,8 @@
1919
#include <catch2/catch_amalgamated.hpp>
2020
#include <core/algorithm.h>
2121

22-
TEST_CASE("mark_duplicates empty list", "[algorithm]") {
22+
TEST_CASE("mark_duplicates empty list", "[algorithm]")
23+
{
2324
std::vector<s32> empty;
2425
bool marked = false;
2526
mark_duplicates(empty,
@@ -28,7 +29,8 @@ TEST_CASE("mark_duplicates empty list", "[algorithm]") {
2829
REQUIRE(!marked);
2930
}
3031

31-
TEST_CASE("mark_duplicates integer list", "[algorithm]") {
32+
TEST_CASE("mark_duplicates integer list", "[algorithm]")
33+
{
3234
std::vector<s32> list = {1, 2, 3, 2, 4, 4};
3335
std::vector<s32> mark(list.size());
3436
mark_duplicates(list,

test/test_assetmgr.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -19,7 +19,8 @@
1919
#include <catch2/catch_amalgamated.hpp>
2020
#include <assetmgr/asset_types.h>
2121

22-
TEST_CASE("Asset System", "[assetmgr]") {
22+
TEST_CASE("Asset System", "[assetmgr]")
23+
{
2324
// Setup an asset forest.
2425
AssetForest forest;
2526
AssetBank& bank_a = forest.mount<MemoryAssetBank>();
@@ -42,22 +43,26 @@ TEST_CASE("Asset System", "[assetmgr]") {
4243
file_b.root().child<PlaceholderAsset>("reference");
4344

4445
// Test link resolution.
45-
SECTION("Absolute link lookup.") {
46+
SECTION("Absolute link lookup.")
47+
{
4648
Asset& asset = forest.lookup_asset("collection.binary_a", nullptr);
4749
REQUIRE(asset.absolute_link().to_string() == binary_a.absolute_link().to_string());
4850
}
4951

50-
SECTION("Relative link lookup.") {
52+
SECTION("Relative link lookup.")
53+
{
5154
Asset& asset = forest.lookup_asset("Collection:binary_a", &collection);
5255
REQUIRE(asset.absolute_link().to_string() == binary_a.absolute_link().to_string());
5356
}
5457

55-
SECTION("Double reference works.") {
58+
SECTION("Double reference works.")
59+
{
5660
Asset& asset = forest.lookup_asset("double_reference_1", nullptr);
5761
REQUIRE(asset.absolute_link().to_string() == binary_a.absolute_link().to_string());
5862
}
5963

60-
SECTION("Reference shadowed by placeholder still works.") {
64+
SECTION("Reference shadowed by placeholder still works.")
65+
{
6166
Asset& asset = forest.lookup_asset("reference", nullptr);
6267
REQUIRE(asset.absolute_link().to_string() == binary_a.absolute_link().to_string());
6368
}

test/test_compression.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -21,7 +21,8 @@
2121
#include <core/util.h>
2222
#include <engine/compression.h>
2323

24-
TEST_CASE("Compression and decompression yields same result", "[compression]") {
24+
TEST_CASE("Compression and decompression yields same result", "[compression]")
25+
{
2526
srand(time(NULL));
2627

2728
s32 data_size = GENERATE(10, 100, 1000, 10000, 100000);

test/test_cppparser.cpp

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -28,7 +28,8 @@ static bool test_parser(const char* src, CppType&& expected);
2828
static bool test_layout(const char* src, CppType&& expected);
2929
static bool compare_cpp_types(const CppType& lhs, const CppType& rhs);
3030

31-
TEST_CASE("c++ lexer" "[cpp]") {
31+
TEST_CASE("c++ lexer", "[cpp]")
32+
{
3233
CHECK(CPP_TEST_PASSED == test_lexer(
3334
"int dec_lit = 123;",
3435
{CPP_KEYWORD, CPP_IDENTIFIER, CPP_OPERATOR, CPP_INTEGER_LITERAL, CPP_OPERATOR}));
@@ -66,22 +67,24 @@ TEST_CASE("c++ lexer" "[cpp]") {
6667
{CPP_KEYWORD, CPP_IDENTIFIER, CPP_OPERATOR, CPP_IDENTIFIER, CPP_OPERATOR, CPP_INTEGER_LITERAL, CPP_OPERATOR}));
6768
}
6869

69-
static s32 test_lexer(const char* src, std::vector<CppTokenType>&& expected) {
70+
static s32 test_lexer(const char* src, std::vector<CppTokenType>&& expected)
71+
{
7072
std::string str(src);
7173
std::vector<CppToken> tokens = eat_cpp_file(&str[0]);
72-
for(size_t i = 0; i < std::max(tokens.size(), expected.size()); i++) {
74+
for (size_t i = 0; i < std::max(tokens.size(), expected.size()); i++) {
7375
print_token(tokens[i]);
74-
if(i >= tokens.size()) return -3;
75-
if(i >= expected.size()) return -4;
76-
if(tokens[i].type != expected[i]) {
76+
if (i >= tokens.size()) return -3;
77+
if (i >= expected.size()) return -4;
78+
if (tokens[i].type != expected[i]) {
7779
return (s32) i;
7880
}
7981
}
8082
return CPP_TEST_PASSED;
8183
}
8284

83-
static void print_token(const CppToken& token) {
84-
switch(token.type) {
85+
static void print_token(const CppToken& token)
86+
{
87+
switch (token.type) {
8588
case CPP_IDENTIFIER: {
8689
std::string str(token.str_begin, token.str_end);
8790
UNSCOPED_INFO(stringf("identifier %s\n", str.c_str()));
@@ -136,7 +139,8 @@ static void print_token(const CppToken& token) {
136139
}
137140
}
138141

139-
TEST_CASE("c++ parser" "[cpp]") {
142+
TEST_CASE("c++ parser", "[cpp]")
143+
{
140144
CHECK(test_parser(
141145
"struct SomeVars { int array_of_ints[5]; };",
142146
[]() {
@@ -254,21 +258,23 @@ TEST_CASE("c++ parser" "[cpp]") {
254258
));
255259
}
256260

257-
static bool test_parser(const char* src, CppType&& expected) {
261+
static bool test_parser(const char* src, CppType&& expected)
262+
{
258263
std::string str;
259264
str += "#pragma wrench parser on\n";
260265
str += src;
261266
std::vector<CppToken> tokens = eat_cpp_file(&str[0]);
262267
std::map<std::string, CppType> types;
263268
parse_cpp_types(types, tokens);
264-
if(types.size() != 1) {
269+
if (types.size() != 1) {
265270
UNSCOPED_INFO("types.size() != 1");
266271
return false;
267272
}
268273
return compare_cpp_types(types.begin()->second, expected);
269274
}
270275

271-
TEST_CASE("c++ layout" "[cpp]") {
276+
TEST_CASE("c++ layout", "[cpp]")
277+
{
272278
CHECK(test_layout(
273279
"struct S { int a; int b; int c; };",
274280
[]() {
@@ -402,13 +408,15 @@ TEST_CASE("c++ layout" "[cpp]") {
402408
));
403409
}
404410

405-
TEST_CASE("c++ bitfield operations" "[cpp]") {
411+
TEST_CASE("c++ bitfield operations", "[cpp]")
412+
{
406413
CHECK(cpp_unpack_unsigned_bitfield(0xff00, 8, 4) == 0xf);
407414
CHECK(cpp_pack_unsigned_bitfield(0xf, 8, 8) == 0xf00);
408415
CHECK(cpp_zero_bitfield(0xffff, 4, 4) == 0xff0f);
409416
}
410417

411-
static bool test_layout(const char* src, CppType&& expected) {
418+
static bool test_layout(const char* src, CppType&& expected)
419+
{
412420
std::string str;
413421
str += "#pragma wrench parser on\n";
414422
str += src;
@@ -423,19 +431,20 @@ static bool test_layout(const char* src, CppType&& expected) {
423431
return compare_cpp_types(types.begin()->second, expected);
424432
}
425433

426-
static bool compare_cpp_types(const CppType& lhs, const CppType& rhs) {
427-
if(lhs.name != rhs.name) { UNSCOPED_INFO("name"); return false; }
428-
if(lhs.offset != rhs.offset) { UNSCOPED_INFO("offset"); return false; }
429-
if(lhs.size != rhs.size) { UNSCOPED_INFO("size"); return false; }
430-
if(lhs.alignment != rhs.alignment) { UNSCOPED_INFO("alignment"); return false; }
431-
if(lhs.preprocessor_directives != rhs.preprocessor_directives) { UNSCOPED_INFO("preprocessor_directives"); return false; }
432-
if(lhs.descriptor != rhs.descriptor) { UNSCOPED_INFO("descriptor"); return false; }
433-
switch(lhs.descriptor) {
434+
static bool compare_cpp_types(const CppType& lhs, const CppType& rhs)
435+
{
436+
if (lhs.name != rhs.name) { UNSCOPED_INFO("name"); return false; }
437+
if (lhs.offset != rhs.offset) { UNSCOPED_INFO("offset"); return false; }
438+
if (lhs.size != rhs.size) { UNSCOPED_INFO("size"); return false; }
439+
if (lhs.alignment != rhs.alignment) { UNSCOPED_INFO("alignment"); return false; }
440+
if (lhs.preprocessor_directives != rhs.preprocessor_directives) { UNSCOPED_INFO("preprocessor_directives"); return false; }
441+
if (lhs.descriptor != rhs.descriptor) { UNSCOPED_INFO("descriptor"); return false; }
442+
switch (lhs.descriptor) {
434443
case CPP_ARRAY: {
435-
if(lhs.array.element_count != rhs.array.element_count) { UNSCOPED_INFO("array.element_count"); return false; }
444+
if (lhs.array.element_count != rhs.array.element_count) { UNSCOPED_INFO("array.element_count"); return false; }
436445
REQUIRE((lhs.array.element_type.get() && rhs.array.element_type.get()));
437446
bool comp_result = compare_cpp_types(*lhs.array.element_type.get(), *rhs.array.element_type.get());
438-
if(!comp_result) { UNSCOPED_INFO("array.element_type"); return false; }
447+
if (!comp_result) { UNSCOPED_INFO("array.element_type"); return false; }
439448
break;
440449
}
441450
case CPP_BITFIELD: {
@@ -446,17 +455,17 @@ static bool compare_cpp_types(const CppType& lhs, const CppType& rhs) {
446455
break;
447456
}
448457
case CPP_BUILT_IN: {
449-
if(lhs.built_in != rhs.built_in) { UNSCOPED_INFO("built_in"); return false; }
458+
if (lhs.built_in != rhs.built_in) { UNSCOPED_INFO("built_in"); return false; }
450459
break;
451460
}
452461
case CPP_ENUM: {
453-
if(lhs.enumeration.constants != rhs.enumeration.constants) { UNSCOPED_INFO("enum"); return false; }
462+
if (lhs.enumeration.constants != rhs.enumeration.constants) { UNSCOPED_INFO("enum"); return false; }
454463
break;
455464
}
456465
case CPP_STRUCT_OR_UNION: {
457-
if(lhs.struct_or_union.is_union != rhs.struct_or_union.is_union) { UNSCOPED_INFO("struct_or_union.is_union"); return false; }
458-
if(lhs.struct_or_union.fields.size() != rhs.struct_or_union.fields.size()) { UNSCOPED_INFO("struct_or_union.fields.size()"); return false; }
459-
for(s32 i = 0; i < (s32) lhs.struct_or_union.fields.size(); i++) {
466+
if (lhs.struct_or_union.is_union != rhs.struct_or_union.is_union) { UNSCOPED_INFO("struct_or_union.is_union"); return false; }
467+
if (lhs.struct_or_union.fields.size() != rhs.struct_or_union.fields.size()) { UNSCOPED_INFO("struct_or_union.fields.size()"); return false; }
468+
for (s32 i = 0; i < (s32) lhs.struct_or_union.fields.size(); i++) {
460469
bool comp_result = compare_cpp_types(lhs.struct_or_union.fields[i], rhs.struct_or_union.fields[i]);
461470
if(!comp_result) { UNSCOPED_INFO(stringf("struct_or_union.fields[%d]", i)); return false; }
462471
}
@@ -467,10 +476,10 @@ static bool compare_cpp_types(const CppType& lhs, const CppType& rhs) {
467476
return false;
468477
}
469478
case CPP_POINTER_OR_REFERENCE: {
470-
if(lhs.pointer_or_reference.is_reference != rhs.pointer_or_reference.is_reference) { UNSCOPED_INFO("pointer_or_reference.is_reference"); return false; }
479+
if (lhs.pointer_or_reference.is_reference != rhs.pointer_or_reference.is_reference) { UNSCOPED_INFO("pointer_or_reference.is_reference"); return false; }
471480
REQUIRE((lhs.pointer_or_reference.value_type.get() && rhs.pointer_or_reference.value_type.get()));
472481
bool comp_result = compare_cpp_types(*lhs.pointer_or_reference.value_type.get(), *rhs.pointer_or_reference.value_type.get());
473-
if(!comp_result) { UNSCOPED_INFO("pointer_or_reference.value_type"); return false; }
482+
if (!comp_result) { UNSCOPED_INFO("pointer_or_reference.value_type"); return false; }
474483
break;
475484
}
476485
}

test/test_elf.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -20,9 +20,10 @@
2020
#include <core/elf.h>
2121
#include <core/filesystem.h>
2222

23-
TEST_CASE("ELF file preserved") {
23+
TEST_CASE("ELF file preserved", "[elf]")
24+
{
2425
const char* path = "test/data/test.elf";
25-
if(!fs::exists(path)) {
26+
if (!fs::exists(path)) {
2627
return;
2728
}
2829
std::vector<u8> input = read_file(path);

test/test_engine.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3-
Copyright (C) 2019-2023 chaoticgd
3+
Copyright (C) 2019-2025 chaoticgd
44
55
This program is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -20,15 +20,17 @@
2020
#include <engine/occlusion.h>
2121
#include <core/filesystem.h>
2222

23-
TEST_CASE("Occlusion grid empty", "[engine]") {
23+
TEST_CASE("Occlusion grid empty", "[engine]")
24+
{
2425
std::vector<OcclusionOctant> input;
2526
std::vector<u8> buffer;
2627
write_occlusion_grid(buffer, input);
2728
std::vector<OcclusionOctant> output = read_occlusion_grid(buffer);
2829
REQUIRE(input.empty());
2930
}
3031

31-
TEST_CASE("Occlusion grid round trip", "[engine]") {
32+
TEST_CASE("Occlusion grid round trip", "[engine]")
33+
{
3234
std::vector<OcclusionOctant> input = {
3335
{1, 2, 3, {1, 2, 3}},
3436
{2, 3, 4, {1, 2, 3}},
@@ -40,7 +42,8 @@ TEST_CASE("Occlusion grid round trip", "[engine]") {
4042
REQUIRE(input == output);
4143
}
4244

43-
TEST_CASE("Occlusion octants round trip", "[engine]") {
45+
TEST_CASE("Occlusion octants round trip", "[engine]")
46+
{
4447
std::vector<OcclusionVector> input = {
4548
{1, 2, 3},
4649
{4, 5, 6}

test/test_gltf.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
/*
2+
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3+
Copyright (C) 2019-2025 chaoticgd
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
119
#include <catch2/catch_amalgamated.hpp>
220
#include <core/gltf.h>
321
#include <core/filesystem.h>
422

523
static bool test_model_file(const char* path, bool print_diff);
624

7-
TEST_CASE("read/write sample models", "[gltf]") {
25+
TEST_CASE("read/write sample models", "[gltf]")
26+
{
827
CHECK(test_model_file("test/data/suzanne.glb", true));
928
test_model_file("test/data/rigged_figure.glb", false);
1029
}
1130

12-
static bool test_model_file(const char* path, bool print_diff) {
31+
static bool test_model_file(const char* path, bool print_diff)
32+
{
1333
std::vector<u8> in = read_file(fs::path(std::string(path)));
1434
auto model = GLTF::read_glb(in);
1535
std::vector<u8> out = GLTF::write_glb(model);

test/test_tristrip.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
/*
2+
wrench - A set of modding tools for the Ratchet & Clank PS2 games.
3+
Copyright (C) 2019-2025 chaoticgd
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
119
#include <catch2/catch_amalgamated.hpp>
220
#include <core/tristrip.h>
321

4-
static s32 restart(s32 value) {
22+
static s32 restart(s32 value)
23+
{
524
return value | (1 << 31);
625
}
726

8-
TEST_CASE("triangle strip conversion", "[tristrip]") {
27+
TEST_CASE("triangle strip conversion", "[tristrip]")
28+
{
929
std::vector<s32> restart_strip = { 1, 2, 3, restart(4), 5, restart(6), 7, 8, restart(9), 10 };
1030
std::vector<s32> zero_area_strip = { 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10 };
1131
CHECK(restart_bit_strip_to_zero_area_tris(restart_strip) == zero_area_strip);

0 commit comments

Comments
 (0)