From 41c2af097ba001c491275be60df069126d383a46 Mon Sep 17 00:00:00 2001 From: Buck Yeh Date: Sat, 7 Dec 2024 14:38:41 +0800 Subject: [PATCH] [Change] Sync `test/archlinux/aur_poc/` with `test/` --- test/archlinux/aur_poc/CMakeLists.txt | 10 ++++ test/archlinux/aur_poc/smoke_cerrlog.cpp | 1 + test/archlinux/aur_poc/smoke_coutlog.cpp | 68 ++++++++++++++++++++++ test/archlinux/aur_poc/smoke_filelog.cpp | 4 +- test/archlinux/aur_poc/smoke_timelog.cpp | 4 +- test/archlinux/aur_poc/test_atomix.cpp | 2 - test/archlinux/aur_poc/test_ezargs.cpp | 6 +- test/archlinux/aur_poc/test_ezscape.cpp | 5 +- test/archlinux/aur_poc/test_logger.cpp | 2 - test/archlinux/aur_poc/test_paralog.cpp | 2 - test/archlinux/aur_poc/test_unicodecvt.cpp | 56 ++++++++++++++++++ 11 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 test/archlinux/aur_poc/test_unicodecvt.cpp diff --git a/test/archlinux/aur_poc/CMakeLists.txt b/test/archlinux/aur_poc/CMakeLists.txt index 4b07431..dad3811 100644 --- a/test/archlinux/aur_poc/CMakeLists.txt +++ b/test/archlinux/aur_poc/CMakeLists.txt @@ -132,6 +132,7 @@ else() target_link_libraries(test_ezargs PRIVATE bux Catch2::Catch2WithMain stdc++ m) endif() add_test(NAME test_ezargs_All COMMAND test_ezargs) + add_executable(test_ezscape test_ezscape.cpp) target_include_directories(test_ezscape PRIVATE ../include) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -158,3 +159,12 @@ else() target_link_libraries(test_paralog PRIVATE bux Catch2::Catch2WithMain stdc++ m pthread) endif() add_test(NAME test_paralog_All COMMAND test_paralog) + +add_executable(test_unicodecvt test_unicodecvt.cpp) +target_include_directories(test_unicodecvt PRIVATE ../include) +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +target_link_libraries(test_unicodecvt PRIVATE bux Catch2::Catch2WithMain) +else() +target_link_libraries(test_unicodecvt PRIVATE bux Catch2::Catch2WithMain stdc++ m) +endif() +add_test(NAME test_unicodecvt_All COMMAND test_unicodecvt) diff --git a/test/archlinux/aur_poc/smoke_cerrlog.cpp b/test/archlinux/aur_poc/smoke_cerrlog.cpp index 58b7954..5432c0c 100644 --- a/test/archlinux/aur_poc/smoke_cerrlog.cpp +++ b/test/archlinux/aur_poc/smoke_cerrlog.cpp @@ -1,3 +1,4 @@ +//#define TURN_OFF_LOGGER_ //#define LOGGER_USE_LOCAL_TIME_ std::chrono::get_tzdb().current_zone() //#define LOGGER_USE_LOCAL_TIME_ std::chrono::get_tzdb().locate_zone("Asia/Taipei") #include // DEF_LOGGER_CERR() diff --git a/test/archlinux/aur_poc/smoke_coutlog.cpp b/test/archlinux/aur_poc/smoke_coutlog.cpp index d3f3524..a4102ec 100644 --- a/test/archlinux/aur_poc/smoke_coutlog.cpp +++ b/test/archlinux/aur_poc/smoke_coutlog.cpp @@ -1,9 +1,64 @@ +//#define TURN_OFF_LOGGER_ #include // DEF_LOGGER_COUT() #include // std::cout DEF_LOGGER_COUT() //DEF_LOGGER_COUT(LL_WARNING) +void fun9() +{ + FUNLOGX9('1','2','3','4','5','6','7','8','9'); + LOG1(LL_INFO, "End of indentation"); +} + +void fun8() +{ + FUNLOGX8('1','2','3','4','5','6','7','8'); + fun9(); +} + +void fun7() +{ + FUNLOGX7('1','2','3','4','5','6','7'); + fun8(); +} + +void fun6() +{ + FUNLOGX6('1','2','3','4','5','6'); + fun7(); +} + +void fun5() +{ + FUNLOGX5('1','2','3','4','5'); + fun6(); +} + +void fun4() +{ + FUNLOGX4('1','2','3','4'); + fun5(); +} + +void fun3() +{ + FUNLOGX3('1','2','3'); + fun4(); +} + +void fun2() +{ + FUNLOGX2('1','2'); + fun3(); +} + +void fun1() +{ + FUNLOGX1('1'); + fun2(); +} + int main() { LOG(LL_FATAL, "Hello fatal"); @@ -13,4 +68,17 @@ int main() FUNLOG; LOG(LL_INFO, "Hello info"); LOG(LL_VERBOSE, "Hello verbose"); + //--------------------------------- + LOG1(LL_INFO, "{}"); + //--------------------------------- + SCOPELOGX1("Indent", 1); + SCOPELOGX2("Indent", 1, 2); + SCOPELOGX3("Indent", 1, 2, 3); + SCOPELOGX4("Indent", 1, 2, 3, 4); + SCOPELOGX5("Indent", 1, 2, 3, 4, 5); + SCOPELOGX6("Indent", 1, 2, 3, 4, 5, 6); + SCOPELOGX7("Indent", 1, 2, 3, 4, 5, 6, 7); + SCOPELOGX8("Indent", 1, 2, 3, 4, 5, 6, 7, 8); + SCOPELOGX9("Indent", 1, 2, 3, 4, 5, 6, 7, 8, 9); + fun1(); } diff --git a/test/archlinux/aur_poc/smoke_filelog.cpp b/test/archlinux/aur_poc/smoke_filelog.cpp index f88fd82..1c1c62c 100644 --- a/test/archlinux/aur_poc/smoke_filelog.cpp +++ b/test/archlinux/aur_poc/smoke_filelog.cpp @@ -1,3 +1,4 @@ +//#define TURN_OFF_LOGGER_ //#define LOGGER_USE_LOCAL_TIME_ false #include // DEF_LOGGER_FILE() #include // std::ofstream @@ -6,9 +7,10 @@ DEF_LOGGER_FILE("log/test.log", LL_INFO) int main() { +#ifndef TURN_OFF_LOGGER_ if (bux::C_UseLog u{bux::logger()}) *u < // DEF_LOGGER_FILES(), DEF_FALLBACK_LOGGER_FILES() #include // bux::C_PathFmtLogSnap @@ -30,9 +31,10 @@ static const struct { bux::E_LogLevel ll; const char *msg; } LOG_SRC[] = { int main(int argc, const char *argv[]) { +#ifndef TURN_OFF_LOGGER_ if (bux::C_UseLog u{bux::logger()}) *u < TEST_CASE("Empty cache", "[Z]") diff --git a/test/archlinux/aur_poc/test_ezargs.cpp b/test/archlinux/aur_poc/test_ezargs.cpp index 61bcb28..0a6fd94 100644 --- a/test/archlinux/aur_poc/test_ezargs.cpp +++ b/test/archlinux/aur_poc/test_ezargs.cpp @@ -3,13 +3,10 @@ http://blog.wingman-sw.com/tdd-guided-by-zombies */ #include // bux::C_EZArgs, bux::C_ErrorOrIndex - -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include - #include // std::from_chars() #include // std::filesystem::* #include // std::ranges::views::empty<> +#include namespace { @@ -107,6 +104,7 @@ TEST_CASE("Scenario: Subcommand help", "[S]") // for commit 42ee62ad4e8c3139b978 REQUIRE(std::getline(in, line)); CHECK(line == "USAGE: test1.exe foo [-h]"); } + TEST_CASE("Scenario: Parse negative number as flag value", "[S]") { double x{}; diff --git a/test/archlinux/aur_poc/test_ezscape.cpp b/test/archlinux/aur_poc/test_ezscape.cpp index 4e413c5..d99b303 100644 --- a/test/archlinux/aur_poc/test_ezscape.cpp +++ b/test/archlinux/aur_poc/test_ezscape.cpp @@ -3,11 +3,8 @@ http://blog.wingman-sw.com/tdd-guided-by-zombies */ #include // bux::easy_escape(), bux::easy_unescape() - -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include - #include // curl_easy_escape(), curl_easy_unescape() +#include namespace { diff --git a/test/archlinux/aur_poc/test_logger.cpp b/test/archlinux/aur_poc/test_logger.cpp index f7e3e73..12cf3e3 100644 --- a/test/archlinux/aur_poc/test_logger.cpp +++ b/test/archlinux/aur_poc/test_logger.cpp @@ -6,8 +6,6 @@ */ #include // LOG(), LOG_RAW(), ... #include // std::mt19937 - -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include namespace { diff --git a/test/archlinux/aur_poc/test_paralog.cpp b/test/archlinux/aur_poc/test_paralog.cpp index 7d2e03b..f831333 100644 --- a/test/archlinux/aur_poc/test_paralog.cpp +++ b/test/archlinux/aur_poc/test_paralog.cpp @@ -5,8 +5,6 @@ #include // DEF_LOGGER_TAIL_, LOG(), LOG_RAW() #include // bux::C_ParaLog #include // std::mt19937 - -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include namespace bux { namespace user { // Mildly modified from definition of DEF_PARA_LOGGER diff --git a/test/archlinux/aur_poc/test_unicodecvt.cpp b/test/archlinux/aur_poc/test_unicodecvt.cpp new file mode 100644 index 0000000..888f443 --- /dev/null +++ b/test/archlinux/aur_poc/test_unicodecvt.cpp @@ -0,0 +1,56 @@ +/* + Test cases are organized according to ZOMBIES rules + http://blog.wingman-sw.com/tdd-guided-by-zombies +*/ +//#include // bux::asciiLiteral() +#include // bux::to_utf8(), bux::BOM() +#include + +TEST_CASE("Empty string to BOM", "[Z]") +{ + CHECK(bux::to_utf8(bux::BOM(L"")).empty()); + CHECK(bux::to_utf8(bux::BOM(U"")).empty()); + CHECK(bux::to_utf8(bux::BOM(u"")).empty()); + CHECK(bux::BOM(u8"") == u8"\uFEFF"); +} + +TEST_CASE("String to utf-8 vs stringview to utf-8", "[S]") +{ + using namespace std::literals; + wchar_t wstr[] = L"一律轉成 utf-8"; + CHECK(bux::to_utf8(wstr) == (const char*)u8"一律轉成 utf-8"); + for (auto &ch: wstr) + ch = std::byteswap(ch); + CHECK(bux::to_utf8(wstr) == (const char*)u8"一律轉成 utf-8"); + + char32_t u32str[] = U"一律轉成 utf-8"; + CHECK(bux::to_utf8(u32str) == (const char*)u8"一律轉成 utf-8"); + for (auto &ch: u32str) + ch = std::byteswap(ch); + CHECK(bux::to_utf8(u32str) == (const char*)u8"一律轉成 utf-8"); + + char16_t u16str[] = u"一律轉成 utf-8"; +#ifdef __unix__ + static constinit const char *const CHSETS_UTF16LE[] = {"UTF-16LE", "UTF16LE", "UCS-2LE", "USC2LE", 0}; + CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16LE) == (const char*)u8"一律轉成 utf-8"); + + static constinit const char *const CHSETS_UTF16[] = {"UCS-2", "UTF-16", "USC2", "UTF16", 0}; + CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16) == (const char*)u8"一律轉成 utf-8"); +#endif + CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8"); + for (auto &ch: u16str) + ch = std::byteswap(ch); + static constinit const char *const CHSETS_UTF16BE[] = {"UTF-16BE", "UTF16BE", "UCS-2BE", "USC2BE", 0}; + CHECK(bux::to_utf8(u16str, 0, CHSETS_UTF16BE) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8(u16str) == (const char*)u8"一律轉成 utf-8"); + + CHECK(bux::to_utf8(u8"一律轉成 utf-8", 0, bux::ENCODING_UTF8) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8(bux::BOM(u8"一律轉成 utf-8")) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8(u8"一律轉成 utf-8") == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8(u8"一律轉成 utf-8"s) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8(u8"一律轉成 utf-8"sv) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8("一律轉成 utf-8") == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8("一律轉成 utf-8"s) == (const char*)u8"一律轉成 utf-8"); + CHECK(bux::to_utf8("一律轉成 utf-8"sv) == (const char*)u8"一律轉成 utf-8"); +} +