Skip to content

Commit

Permalink
[Change] Sync test/archlinux/aur_poc/ with test/
Browse files Browse the repository at this point in the history
  • Loading branch information
buck-yeh committed Dec 7, 2024
1 parent 47e4c18 commit 41c2af0
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 16 deletions.
10 changes: 10 additions & 0 deletions test/archlinux/aur_poc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
1 change: 1 addition & 0 deletions test/archlinux/aur_poc/smoke_cerrlog.cpp
Original file line number Diff line number Diff line change
@@ -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 <bux/Logger.h> // DEF_LOGGER_CERR()
Expand Down
68 changes: 68 additions & 0 deletions test/archlinux/aur_poc/smoke_coutlog.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
//#define TURN_OFF_LOGGER_
#include <bux/Logger.h> // DEF_LOGGER_COUT()
#include <iostream> // 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");
Expand All @@ -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();
}
4 changes: 3 additions & 1 deletion test/archlinux/aur_poc/smoke_filelog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//#define TURN_OFF_LOGGER_
//#define LOGGER_USE_LOCAL_TIME_ false
#include <bux/Logger.h> // DEF_LOGGER_FILE()
#include <fstream> // std::ofstream
Expand All @@ -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 <<std::boolalpha <<"LOGGER_USE_LOCAL_TIME_: " <<LOGGER_USE_LOCAL_TIME_ <<"\n";

#endif
LOG(LL_FATAL, "Hello fatal");
FUNLOG;
LOG(LL_ERROR, "Hello error");
Expand Down
4 changes: 3 additions & 1 deletion test/archlinux/aur_poc/smoke_timelog.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//#define TURN_OFF_LOGGER_
//#define LOGGER_USE_LOCAL_TIME_ false
#include <bux/Logger.h> // DEF_LOGGER_FILES(), DEF_FALLBACK_LOGGER_FILES()
#include <bux/FileLog.h> // bux::C_PathFmtLogSnap
Expand Down Expand Up @@ -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 <<std::boolalpha <<"LOGGER_USE_LOCAL_TIME_: " <<LOGGER_USE_LOCAL_TIME_ <<"\n";

#endif
if (argc <= 1)
{
for (auto i: LOG_SRC)
Expand Down
2 changes: 0 additions & 2 deletions test/archlinux/aur_poc/test_atomix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
http://blog.wingman-sw.com/tdd-guided-by-zombies
*/
#include "bux/AtomiX.h"

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch_test_macros.hpp>

TEST_CASE("Empty cache", "[Z]")
Expand Down
6 changes: 2 additions & 4 deletions test/archlinux/aur_poc/test_ezargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
http://blog.wingman-sw.com/tdd-guided-by-zombies
*/
#include <bux/EZArgs.h> // 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 <catch2/catch_test_macros.hpp>

#include <charconv> // std::from_chars()
#include <filesystem> // std::filesystem::*
#include <ranges> // std::ranges::views::empty<>
#include <catch2/catch_test_macros.hpp>

namespace {

Expand Down Expand Up @@ -107,6 +104,7 @@ TEST_CASE("Scenario: Subcommand help", "[S]") // for commit 42ee62ad4e8c3139b978
REQUIRE(std::getline(in, line));
CHECK(line == "USAGE: test1.exe foo <eeny> [-h]");
}

TEST_CASE("Scenario: Parse negative number as flag value", "[S]")
{
double x{};
Expand Down
5 changes: 1 addition & 4 deletions test/archlinux/aur_poc/test_ezscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
http://blog.wingman-sw.com/tdd-guided-by-zombies
*/
#include <bux/EZScape.h> // 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 <catch2/catch_test_macros.hpp>

#include <curl/curl.h> // curl_easy_escape(), curl_easy_unescape()
#include <catch2/catch_test_macros.hpp>

namespace {

Expand Down
2 changes: 0 additions & 2 deletions test/archlinux/aur_poc/test_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
#include <bux/Logger.h> // LOG(), LOG_RAW(), ...
#include <random> // std::mt19937

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch_test_macros.hpp>

namespace {
Expand Down
2 changes: 0 additions & 2 deletions test/archlinux/aur_poc/test_paralog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <bux/Logger.h> // DEF_LOGGER_TAIL_, LOG(), LOG_RAW()
#include <bux/ParaLog.h> // bux::C_ParaLog
#include <random> // std::mt19937

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch_test_macros.hpp>

namespace bux { namespace user { // Mildly modified from definition of DEF_PARA_LOGGER
Expand Down
56 changes: 56 additions & 0 deletions test/archlinux/aur_poc/test_unicodecvt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Test cases are organized according to ZOMBIES rules
http://blog.wingman-sw.com/tdd-guided-by-zombies
*/
//#include <bux/LexBase.h> // bux::asciiLiteral()
#include <bux/UnicodeCvt.h> // bux::to_utf8(), bux::BOM()
#include <catch2/catch_test_macros.hpp>

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");
}

0 comments on commit 41c2af0

Please sign in to comment.