1
0

refactor: rename testbench to test.

- rename testbench to test.
- add benchmark for future development.
This commit is contained in:
2025-09-29 13:34:02 +08:00
parent 82c3ed5b32
commit e7a05b3488
44 changed files with 55 additions and 19 deletions

16
test/yycc/windows/com.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/windows/com.hpp>
#define COM ::yycc::windows::com
namespace yycctest::windows::com {
#if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL)
TEST(WindowsCom, IsInitialized) {
// COM environment should always be ready.
EXPECT_TRUE(COM::is_initialized());
}
#endif
}

View File

@ -0,0 +1,17 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/windows/console.hpp>
#define CONSOLE ::yycc::windows::console
namespace yycctest::windows::console {
#if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL)
TEST(WindowsConsole, ColorfulConsole) {
// Set colorful console should always be success.
auto rv = CONSOLE::colorful_console();
EXPECT_TRUE(rv.has_value());
}
#endif
}

View File

@ -0,0 +1,55 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/windows/dialog.hpp>
#define DIALOG ::yycc::windows::dialog
namespace yycctest::windows::dialog {
#if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL)
TEST(WindowsDialog, Normal) {
// TODO:
// I temporaryly disable all dialog open functions in this function after testing them.
// Because they need human to operate them to finish the test.
// Once I find a better way to do automatic test (maybe send message to these dialogs to close them?)
// I will add them back.
// Prepare parameters
DIALOG::FileDialog params;
auto& filters = params.configre_file_types();
filters.add_filter(u8"Microsoft Word (*.docx; *.doc)", {u8"*.docx", u8"*.doc"});
filters.add_filter(u8"Microsoft Excel (*.xlsx; *.xls)", {u8"*.xlsx", u8"*.xls"});
filters.add_filter(u8"Microsoft PowerPoint (*.pptx; *.ppt)", {u8"*.pptx", u8"*.ppt"});
filters.add_filter(u8"Text File (*.txt)", {u8"*.txt"});
filters.add_filter(u8"All Files (*.*)", {u8"*.*"});
params.set_default_file_type_index(1u);
//// Open file
//{
// auto rv = DIALOG::open_file(params);
// EXPECT_TRUE(rv.has_value());
//}
//// Open files
//{
// auto rv = DIALOG::open_files(params);
// EXPECT_TRUE(rv.has_value());
//}
//// Save file
//{
// auto rv = DIALOG::save_file(params);
// EXPECT_TRUE(rv.has_value());
//}
// Clear file filters for following operations
params.clear();
params.set_default_file_type_index(0u);
//// Open folder
//{
// auto rv = DIALOG::open_folder(params);
// EXPECT_TRUE(rv.has_value());
//}
}
#endif
}

View File

@ -0,0 +1,49 @@
#include <gtest/gtest.h>
#include <yycc.hpp>
#include <yycc/windows/winfct.hpp>
#define WINFCT ::yycc::windows::winfct
namespace yycctest::windows::winfct {
#if defined(YYCC_OS_WINDOWS)
TEST(WindowsWinFct, GetCurrentModule) {
auto rv = WINFCT::get_current_module();
EXPECT_TRUE(rv.has_value());
}
TEST(WindowsWinFct, GetTempDirectory) {
auto rv = WINFCT::get_temp_directory();
EXPECT_TRUE(rv.has_value());
}
TEST(WindowsWinFct, GetModuleFileName) {
auto handle = WINFCT::get_current_module();
ASSERT_TRUE(handle.has_value());
auto rv = WINFCT::get_module_file_name(handle.value());
EXPECT_TRUE(rv.has_value());
}
TEST(WindowsWinFct, IsValidCodePage) {
// Test valid code page
EXPECT_TRUE(WINFCT::is_valid_code_page(437));
EXPECT_TRUE(WINFCT::is_valid_code_page(65001));
// This code page must be invalid
EXPECT_FALSE(WINFCT::is_valid_code_page(6161));
}
#if defined(YYCC_STL_MSSTL)
TEST(WindowsWinFct, GetKnownPath) {
auto rv = WINFCT::get_known_path(WINFCT::KnownDirectory::LocalAppData);
EXPECT_TRUE(rv.has_value());
}
#endif
// YYC MARK:
// I can't test CopyFile, MoveFile and DeleteFile.
#endif
} // namespace yycctest::windows::winfct