diff options
author | saturneric <[email protected]> | 2023-12-13 10:01:06 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-13 10:01:06 +0000 |
commit | 42264ed0d7a3c91fbe9f307984964ffc9e5fe65c (patch) | |
tree | a3ddecbd6ad723e42d68cc2c5aed7a88c4e242a3 /src/test | |
parent | feat: move test to src and add submodule googletest (diff) | |
download | GpgFrontend-42264ed0d7a3c91fbe9f307984964ffc9e5fe65c.tar.gz GpgFrontend-42264ed0d7a3c91fbe9f307984964ffc9e5fe65c.zip |
refactor: improve the structure of main,core and test module
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/test/GpgFrontendTest.cpp | 25 | ||||
-rw-r--r-- | src/test/GpgFrontendTest.h | 21 | ||||
-rw-r--r-- | src/test/core/GpgCoreTest.cpp | 4 | ||||
-rw-r--r-- | src/test/core/GpgCoreTest.h | 4 |
5 files changed, 44 insertions, 14 deletions
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index c4d7bcf8..1eb710be 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -24,8 +24,8 @@ # SPDX-License-Identifier: GPL-3.0-or-later # Set configure for test -file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/test/conf DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/ FOLLOW_SYMLINK_CHAIN) -file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/test/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/test/ FOLLOW_SYMLINK_CHAIN) +file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/test/conf DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/ FOLLOW_SYMLINK_CHAIN) +file(COPY ${CMAKE_SOURCE_DIR}/resource/lfs/test/data DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test/ FOLLOW_SYMLINK_CHAIN) aux_source_directory(./core TEST_SOURCE) aux_source_directory(. TEST_SOURCE) diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp index 24e099a2..18157a00 100644 --- a/src/test/GpgFrontendTest.cpp +++ b/src/test/GpgFrontendTest.cpp @@ -28,14 +28,18 @@ #include "GpgFrontendTest.h" +#include <gtest/gtest.h> +#include <spdlog/sinks/rotating_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + #include <boost/date_time.hpp> #include <boost/dll.hpp> #include <filesystem> +#include "core/GpgCoreInit.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgContext.h" #include "spdlog/spdlog.h" -#include "type.h" namespace GpgFrontend::Test { @@ -66,6 +70,15 @@ void InitTestLoggingSystem(spdlog::level::level_enum level) { spdlog::set_default_logger(test_logger); } +void ShutdownTestLoggingSystem() { +#ifdef WINDOWS + // Under VisualStudio, this must be called before main finishes to workaround + // a known VS issue + spdlog::drop_all(); + spdlog::shutdown(); +#endif +} + auto GenerateRandomString(size_t length) -> std::string { const std::string characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -94,6 +107,8 @@ void ConfigureGpgContext() { std::filesystem::create_directory(db_path); } + SPDLOG_DEBUG("DEBUG--------<"); + GpgContext::CreateInstance( kGpgFrontendDefaultChannel, [&]() -> ChannelObjectPtr { GpgContextInitArgs args; @@ -104,11 +119,15 @@ void ConfigureGpgContext() { return ConvertToChannelObjectPtr<>(SecureCreateUniqueObject<GpgContext>( args, kGpgFrontendDefaultChannel)); }); + + SPDLOG_DEBUG("DEBUG-------->"); } -void ExecuteAllTestCase(InitArgs args) { - InitTestLoggingSystem(args.log_level); +auto ExecuteAllTestCase(GpgFrontendContext args) -> int { ConfigureGpgContext(); + + testing::InitGoogleTest(&args.argc, args.argv); + return RUN_ALL_TESTS(); } } // namespace GpgFrontend::Test
\ No newline at end of file diff --git a/src/test/GpgFrontendTest.h b/src/test/GpgFrontendTest.h index 55c6b734..897a8a05 100644 --- a/src/test/GpgFrontendTest.h +++ b/src/test/GpgFrontendTest.h @@ -28,14 +28,23 @@ #pragma once -#include <gtest/gtest.h> -#include <spdlog/sinks/rotating_file_sink.h> -#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/spdlog.h> +#include "GpgFrontendTestExport.h" -#include <libconfig.h++> +namespace GpgFrontend::Test { -#include "GpgFrontendTestExport.h" +struct GpgFrontendContext { + int argc; + char **argv; + spdlog::level::level_enum log_level; +}; + +void GPGFRONTEND_TEST_EXPORT +InitTestLoggingSystem(spdlog::level::level_enum level); + +void GPGFRONTEND_TEST_EXPORT ShutdownTestLoggingSystem(); + +auto GPGFRONTEND_TEST_EXPORT ExecuteAllTestCase(GpgFrontendContext args) -> int; -namespace GpgFrontend::Test {} // namespace GpgFrontend::Test +} // namespace GpgFrontend::Test diff --git a/src/test/core/GpgCoreTest.cpp b/src/test/core/GpgCoreTest.cpp index b4cf2f73..f2616573 100644 --- a/src/test/core/GpgCoreTest.cpp +++ b/src/test/core/GpgCoreTest.cpp @@ -30,6 +30,7 @@ #include "core/function/gpg/GpgKeyImportExporter.h" #include "core/utils/IOUtils.h" +#include "spdlog/spdlog.h" namespace GpgFrontend::Test { @@ -54,7 +55,8 @@ void GpgCoreTest::TearDown() {} void GpgCoreTest::SetUp() { libconfig::Config cfg; - ASSERT_NO_THROW(cfg.readFile(config_path_.c_str())); + SPDLOG_INFO("test case config file path: {}", config_path_.string()); + ASSERT_NO_THROW(cfg.readFile(config_path_.string())); auto& root = cfg.getRoot(); import_private_keys(root); } diff --git a/src/test/core/GpgCoreTest.h b/src/test/core/GpgCoreTest.h index bffaf9ad..5730b6e5 100644 --- a/src/test/core/GpgCoreTest.h +++ b/src/test/core/GpgCoreTest.h @@ -28,12 +28,13 @@ #pragma once +#include <gtest/gtest.h> + #include <boost/date_time.hpp> #include <boost/dll.hpp> #include <boost/dll/runtime_symbol_info.hpp> #include <filesystem> -#include "GpgFrontendTest.h" #include "core/function/GlobalSettingStation.h" #include "core/typedef/CoreTypedef.h" @@ -56,7 +57,6 @@ class GpgCoreTest : public ::testing::Test { // Data File Directory Location std::filesystem::path data_path_ = GlobalSettingStation::GetInstance().GetAppDir() / "test" / "data"; - }; } // namespace GpgFrontend::Test
\ No newline at end of file |