YYCCommonplace/testbench/main.cpp
yyc12345 84228b5f8c feat: add some work
- add dialog parameter class for dialog helper. prepare to write real dialog popup function.
- refactor file filters class in dialog helper to make it no const syntax conflict.
- improve windows header import prefix and suffix header. remove the barrier limiting headers only can be imported once. fix define preprocessor usage bug.
- move crt warning and errors macro from project settings to internal headers.
- copy IronPad as ExceptionHandler but not adapted to this project.
2024-05-23 09:37:41 +08:00

74 lines
2.8 KiB
C++

#include <YYCCommonplace.hpp>
#include <cstdio>
namespace Testbench {
static void Assert(bool condition, const char* description) {
if (condition) {
YYCC::TerminalHelper::FPrintf(stdout, YYCC_TERMCOL_LIGHT_GREEN(u8"OK: %s\n"), description);
} else {
YYCC::TerminalHelper::FPrintf(stdout, YYCC_TERMCOL_LIGHT_RED(u8"Failed: %s\n"), description);
std::abort();
}
}
static void TerminalTestbench() {
YYCC::TerminalHelper::EnsureTerminalUTF8(stdout);
YYCC::TerminalHelper::FPuts(u8"你好世界\n", stdout);
YYCC::TerminalHelper::EnsureTerminalColor(stdout);
YYCC::TerminalHelper::FPuts(YYCC_TERMCOL_LIGHT_CYAN(u8"Colorful Terminal\n"), stdout);
}
static void StringTestbench() {
auto test_printf = YYCC::StringHelper::Printf(u8"%s == %s", u8"Hello World", u8"你好世界");
Assert(test_printf == u8"Hello World == 你好世界", "YYCC::StringHelper::Printf");
auto test_lower = YYCC::StringHelper::Lower("LOWER");
Assert(test_lower == "lower", "YYCC::StringHelper::Lower");
auto test_upper = YYCC::StringHelper::Upper("upper");
Assert(test_upper == "UPPER", "YYCC::StringHelper::Upper");
std::vector<std::string> test_join_container {
"", "1", "2", ""
};
auto test_join = YYCC::StringHelper::Join(test_join_container, ", ");
Assert(test_join == ", 1, 2, ", "YYCC::StringHelper::Join");
test_join = YYCC::StringHelper::Join(test_join_container, ", ", true);
Assert(test_join == ", 2, 1, ", "YYCC::StringHelper::Join");
auto test_split = YYCC::StringHelper::Split(", 1, 2, ", ", ");
Assert(test_split.size() == 4u, "YYCC::StringHelper::Split");
Assert(test_split[0] == "", "YYCC::StringHelper::Split");
Assert(test_split[1] == "1", "YYCC::StringHelper::Split");
Assert(test_split[2] == "2", "YYCC::StringHelper::Split");
Assert(test_split[3] == "", "YYCC::StringHelper::Split");
test_split = YYCC::StringHelper::Split("test", "-");
Assert(test_split.size() == 1u, "YYCC::StringHelper::Split");
Assert(test_split[0] == "test", "YYCC::StringHelper::Split");
test_split = YYCC::StringHelper::Split("test", "");
Assert(test_split.size() == 1u, "YYCC::StringHelper::Split");
Assert(test_split[0] == "test", "YYCC::StringHelper::Split");
}
static void DialogTestbench() {
YYCC::DialogHelper::FileFilters test;
test.Add("Microsoft Word (*.docx; *.doc)", {"*.docx", "*.doc"});
test.Add("Microsoft Excel (*.xlsx; *.xls)", {"*.xlsx", "*.xls"});
test.Add("Microsoft PowerPoint (*.pptx; *.ppt)", {"*.pptx", "*.ppt"});
test.Add("Text File (*.*)", {"*.txt"});
test.Add("All Files (*.*)", {"*.*"});
YYCC::DialogHelper::WinFileFilters win_file_filters;
bool ret = test.Generate(win_file_filters);
}
}
int main(int argc, char** args) {
Testbench::TerminalTestbench();
Testbench::StringTestbench();
Testbench::DialogTestbench();
}