Skip to content

Commit 7dad0d5

Browse files
committed
Fix transcodetests to build with GCC 11.
1 parent 033773b commit 7dad0d5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

tests/transcodetests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target_link_libraries(
2020
transcodetests
2121
gtest
2222
ktx
23+
"$<${is_stdformat_unsupported}:fmt::fmt>"
2324
obj_basisu_cbind
2425
basisu_encoder
2526
${CMAKE_THREAD_LIBS_INIT}

tests/transcodetests/transcodetests.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ extern "C" {
2424
#include <vector>
2525
#include <cstring>
2626
#include <filesystem>
27+
#if defined(__cpp_lib_format)
28+
#include <format>
29+
#else
30+
// Sigh!! gcc11 does not support std::format though it has a g++20 option.
31+
// Use {fmt} instead.
32+
#include <fmt/ostream.h>
33+
#endif
2734

2835
#include "basisu_c_binding.h"
2936

30-
using namespace std;
37+
namespace {
38+
3139
namespace fs = std::filesystem;
40+
#if defined(__cpp_lib_format)
41+
using namespace std;
42+
#else
43+
using namespace fmt;
44+
#endif
3245

3346
fs::path basisResources, ktxResources;
3447

35-
namespace {
36-
3748
typedef struct {
38-
string ktxFile;
39-
string basisuFile;
49+
std::string ktxFile;
50+
std::string basisuFile;
4051
bool isPo2;
4152
bool hasAlpha;
4253
} TextureSet;
@@ -57,15 +68,15 @@ std::ostream& operator<<(std::ostream& out, const FormatFeature& h)
5768
return out << ktxTranscodeFormatString(h.format);
5869
}
5970

60-
vector<TextureSet> allTextureSets = {
71+
std::vector<TextureSet> allTextureSets = {
6172
{"color_grid_blze.ktx2","color_grid.basis",true,false},
6273
#if 1
6374
{"kodim17_blze.ktx2","kodim17.basis",false,false},
6475
{"alpha_simple_blze.ktx2","alpha_simple.basis",true,true}
6576
#endif
6677
};
6778

68-
vector<FormatFeature> allFormats = {
79+
std::vector<FormatFeature> allFormats = {
6980
#if 1
7081
{KTX_TTF_ETC1_RGB,true,true},
7182
{KTX_TTF_ETC2_RGBA,true,true},
@@ -91,15 +102,15 @@ vector<FormatFeature> allFormats = {
91102
};
92103

93104
class TextureCombinationsTest :
94-
public ::testing::TestWithParam<tuple<TextureSet,FormatFeature>> {};
105+
public ::testing::TestWithParam<std::tuple<TextureSet,FormatFeature>> {};
95106

96107
INSTANTIATE_TEST_SUITE_P(AllCombinations,
97108
TextureCombinationsTest,
98109
::testing::Combine(::testing::ValuesIn(allTextureSets),
99110
::testing::ValuesIn(allFormats)));
100111

101112
bool read_file( fs::path file, void** data, unsigned long *fsize ) {
102-
FILE *f = fopenUTF8(file.u8string(), string("rb"));
113+
FILE *f = fopenUTF8(file.u8string(), std::string("rb"));
103114
if(f==NULL) {
104115
return false;
105116
}
@@ -211,7 +222,7 @@ int main(int argc, char **argv) {
211222

212223
if (!::testing::FLAGS_gtest_list_tests) {
213224
if (argc != 2) {
214-
cerr << "Usage: " << argv[0] << " <test resources path>\n";
225+
std::cerr << "Usage: " << argv[0] << " <test resources path>\n";
215226
return -1;
216227
}
217228

0 commit comments

Comments
 (0)