aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt75
-rw-r--r--resource/lfs/test/conf/core.cfg (renamed from test/conf/core.cfg)0
-rw-r--r--resource/lfs/test/data/pv1.key (renamed from test/data/pv1.key)0
-rw-r--r--resource/lfs/test/data/pv2.key (renamed from test/data/pv2.key)0
-rw-r--r--resource/lfs/test/data/pv3.key (renamed from test/data/pv3.key)0
-rw-r--r--resource/lfs/test/data/pv4.key (renamed from test/data/pv4.key)0
-rw-r--r--src/CMakeLists.txt9
-rw-r--r--src/app.cpp2
-rw-r--r--src/cmd.cpp20
-rw-r--r--src/core/GpgConstants.h4
-rw-r--r--src/core/GpgCoreInit.cpp2
-rw-r--r--src/core/function/GlobalSettingStation.cpp5
-rw-r--r--src/core/function/GlobalSettingStation.h15
-rw-r--r--src/core/function/basic/ChannelObject.h4
-rw-r--r--src/core/function/basic/GpgFunctionObject.h2
-rw-r--r--src/core/function/gpg/GpgFileOpera.h10
-rw-r--r--src/core/module/GlobalModuleContext.cpp6
-rw-r--r--src/test/CMakeLists.txt (renamed from test/CMakeLists.txt)29
-rw-r--r--src/test/GpgFrontendCoreExport.h42
-rw-r--r--src/test/GpgFrontendTest.cpp114
-rw-r--r--src/test/GpgFrontendTest.h (renamed from test/GpgCoreTestImportExport.cpp)19
-rw-r--r--src/test/GpgFrontendTestExport.h42
-rw-r--r--src/test/core/GpgCoreTest.cpp61
-rw-r--r--src/test/core/GpgCoreTest.h62
-rw-r--r--src/test/core/GpgCoreTestBasicOpera.cpp (renamed from test/GpgCoreTestBasicOpera.cpp)160
-rw-r--r--src/test/core/GpgCoreTestImportExport.cpp (renamed from test/GpgCoreTest.cpp)13
-rw-r--r--src/test/core/GpgCoreTestKeyModel.cpp179
-rw-r--r--src/test/core/GpgCoreTestKeygen.cpp138
-rw-r--r--src/ui/main_window/MainWindowFileSlotFunction.cpp16
-rw-r--r--test/GpgCoreTestKeyModel.cpp171
-rw-r--r--test/GpgCoreTestKeyModelAlone.cpp162
-rw-r--r--test/GpgCoreTestKeygen.cpp132
-rw-r--r--test/GpgCoreTestKeygenAlone.cpp160
-rw-r--r--test/GpgFrontendTest.h206
-rw-r--r--third_party/CMakeLists.txt5
m---------third_party/googletest0
37 files changed, 823 insertions, 1045 deletions
diff --git a/.gitmodules b/.gitmodules
index 3463984f..951cfffe 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,6 @@
[submodule "third_party/mimalloc"]
path = third_party/mimalloc
url = https://github.com/microsoft/mimalloc.git
+[submodule "third_party/googletest"]
+ path = third_party/googletest
+ url = https://github.com/google/googletest.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fd05f30..17712e0d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -206,43 +206,12 @@ else()
endif()
-# Specify different compilation modes
-if (GPGFRONTEND_BUILD_CONFIG)
- # Test Build
- if (${GPGFRONTEND_BUILD_CONFIG} STREQUAL "test_core")
- message(STATUS "Switch Build Configure TEST_CORE_BUILD")
- set(TEST_CORE_BUILD 1)
- set(AppName GpgFrontendCoreTest)
- # Test Build With Coverage Test
- elseif (${GPGFRONTEND_BUILD_CONFIG} STREQUAL "test_core_coverage")
- message(STATUS "Switch Build Configure TEST_COVERAGE_BUILD")
- set(TEST_CORE_BUILD 1)
- if (USING_COMPILER_CLANG OR USING_COMPILER_GCC)
- set(TEST_COVERAGE_BUILD 1)
- set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
- else ()
- message(WARNING "Branch testing is disabled")
- message(WARNING "Please use gcc or clang for branch coverage test.")
- endif ()
- set(AppName GpgFrontendTest)
- # Test Build with minimum UI
- elseif (${GPGFRONTEND_BUILD_CONFIG} STREQUAL "test_ui")
- message(STATUS "Switch Build Configure TEST_MINIMUM_UI_BUILD")
- set(MINIMUM_BUILD_APPLICATION 1)
- set(AppName GpgFrontend)
- elseif (${GPGFRONTEND_BUILD_CONFIG} STREQUAL "test_all")
- message(STATUS "Switch Build Configure FULL_BUILD_APPLICATION")
- set(FULL_BUILD_APPLICATION 1)
- set(AppName GpgFrontend)
- endif ()
-else ()
- message(STATUS "Switch Build Configure STABLE_BUILD_APPLICATION")
- set(STABLE_BUILD_APPLICATION 1)
- set(AppName GpgFrontend)
-endif ()
+# Specify compilation mode
+message(STATUS "Switch Build Configure STABLE_BUILD_APPLICATION")
+set(STABLE_BUILD_APPLICATION 1)
+set(AppName GpgFrontend)
# Get Git Information
-
set(GIT_COMMIT_HASH "")
set(GIT_BRANCH_NAME "")
find_package(Git QUIET)
@@ -385,41 +354,16 @@ endif ()
set(BASIC_ENV_CONFIG 1)
set(QT_MOC_CONFIG 1)
-if (FULL_BUILD_APPLICATION)
- message("[+] Build Full Application")
- set(QT5_ENV_SUPPORT 1)
- set(BUILD_CORE 1)
- set(BUILD_UI 1)
- set(BUILD_MODULE 1)
- set(BUILD_APPLICATION 1)
- set(BASIC_ENV_CONFIG 1)
- set(SUPPORT_MULTI_LANG 1)
-elseif (MINIMUM_BUILD_APPLICATION)
- message("[+] Build Minimum Application")
- set(QT5_ENV_SUPPORT 1)
- set(BUILD_CORE 1)
- set(BUILD_UI 1)
- set(BUILD_MODULE 1)
- set(BUILD_APPLICATION 1)
- set(BASIC_ENV_CONFIG 1)
-elseif (STABLE_BUILD_APPLICATION)
+if (STABLE_BUILD_APPLICATION)
message("[+] Build Stable Application")
set(QT5_ENV_SUPPORT 1)
set(BUILD_CORE 1)
set(BUILD_UI 1)
set(BUILD_MODULE 1)
+ set(BUILD_TEST 1)
set(BUILD_APPLICATION 1)
set(BASIC_ENV_CONFIG 1)
set(SUPPORT_MULTI_LANG 1)
-elseif (TEST_CORE_BUILD)
- message("-] Build Test Cases")
-
- if (MODULES)
- else ()
- message(STATUS "Build Default Modules")
- set(BUILD_CORE 1)
- endif ()
-
endif ()
# For instance in order to select the highest version one
@@ -441,10 +385,3 @@ add_subdirectory(third_party)
# source code
add_subdirectory(src)
-
-# build to test gpgfrontend core
-if (TEST_CORE_BUILD)
- include(CTest)
- enable_testing()
- add_subdirectory(test)
-endif ()
diff --git a/test/conf/core.cfg b/resource/lfs/test/conf/core.cfg
index 7a9b76d6..7a9b76d6 100644
--- a/test/conf/core.cfg
+++ b/resource/lfs/test/conf/core.cfg
diff --git a/test/data/pv1.key b/resource/lfs/test/data/pv1.key
index 345fdf4f..345fdf4f 100644
--- a/test/data/pv1.key
+++ b/resource/lfs/test/data/pv1.key
diff --git a/test/data/pv2.key b/resource/lfs/test/data/pv2.key
index 54bea6f5..54bea6f5 100644
--- a/test/data/pv2.key
+++ b/resource/lfs/test/data/pv2.key
diff --git a/test/data/pv3.key b/resource/lfs/test/data/pv3.key
index 616bc4d8..616bc4d8 100644
--- a/test/data/pv3.key
+++ b/resource/lfs/test/data/pv3.key
diff --git a/test/data/pv4.key b/resource/lfs/test/data/pv4.key
index 8b79e893..8b79e893 100644
--- a/test/data/pv4.key
+++ b/resource/lfs/test/data/pv4.key
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 31b865d6..df0ae996 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -104,6 +104,13 @@ if (BUILD_MODULE)
add_subdirectory(module)
endif ()
+# build to test gpgfrontend core
+if (BUILD_TEST)
+ include(CTest)
+ enable_testing()
+ add_subdirectory(test)
+endif ()
+
if (BUILD_APPLICATION)
# Set Resource Output Path
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
@@ -476,7 +483,7 @@ endif ()
# link options for GpgFrontend
if (BUILD_APPLICATION)
- target_link_libraries(${AppName} gpgfrontend_ui gpgfrontend_module)
+ target_link_libraries(${AppName} gpgfrontend_ui gpgfrontend_module gpgfrontend_test)
if (MINGW)
message(STATUS "Link Application Library For MINGW")
target_link_libraries(${AppName} crypto)
diff --git a/src/app.cpp b/src/app.cpp
index b0c771d9..d12761fd 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -27,11 +27,9 @@
*/
#include <csetjmp>
-#include <csignal>
#include "core/GpgConstants.h"
#include "core/GpgCoreInit.h"
-#include "core/function/GlobalSettingStation.h"
#include "module/GpgFrontendModuleInit.h"
#include "ui/GpgFrontendApplication.h"
#include "ui/GpgFrontendUIInit.h"
diff --git a/src/cmd.cpp b/src/cmd.cpp
index 24080a08..f0d748e0 100644
--- a/src/cmd.cpp
+++ b/src/cmd.cpp
@@ -36,23 +36,23 @@
// GpgFrontend
#include "GpgFrontendBuildInfo.h"
-#include "spdlog/common.h"
+#include "type.h"
namespace po = boost::program_options;
auto PrintVersion() -> int {
std::cout << PROJECT_NAME << " "
<< "v" << VERSION_MAJOR << "." << VERSION_MINOR << "."
- << VERSION_PATCH << std::endl;
+ << VERSION_PATCH << '\n';
std::cout
- << "Copyright (C) 2021 Saturneric <[email protected]>" << std::endl
+ << "Copyright (C) 2021 Saturneric <[email protected]>" << '\n'
<< _("This is free software; see the source for copying conditions.")
- << std::endl
- << std::endl;
+ << '\n'
+ << '\n';
- std::cout << _("Build Timestamp: ") << BUILD_TIMESTAMP << std::endl
- << _("Build Version: ") << BUILD_VERSION << std::endl
- << _("Source Code Version: ") << GIT_VERSION << std::endl;
+ std::cout << _("Build Timestamp: ") << BUILD_TIMESTAMP << '\n'
+ << _("Build Version: ") << BUILD_VERSION << '\n'
+ << _("Source Code Version: ") << GIT_VERSION << '\n';
return 0;
}
@@ -77,4 +77,6 @@ auto ParseLogLevel(const po::variables_map& vm) -> spdlog::level::level_enum {
}
return spdlog::level::info;
-} \ No newline at end of file
+}
+
+auto RunTest(int argc, char** argv) {} \ No newline at end of file
diff --git a/src/core/GpgConstants.h b/src/core/GpgConstants.h
index 1f3a4981..c2125650 100644
--- a/src/core/GpgConstants.h
+++ b/src/core/GpgConstants.h
@@ -34,8 +34,8 @@ constexpr int kRestartCode = 1000; ///< only refresh ui
constexpr int kDeepRestartCode = 1001; // refresh core and ui
// Channels
-constexpr int kGpgfrontendDefaultChannel = 0; ///<
-constexpr int kGpgfrontendNonAsciiChannel = 2; ///<
+constexpr int kGpgFrontendDefaultChannel = 0; ///<
+constexpr int kGpgFrontendNonAsciiChannel = 2; ///<
// HEADER
constexpr const char* PGP_CRYPT_BEGIN = "-----BEGIN PGP MESSAGE-----"; ///<
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 6d96a50d..e2aa50ff 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -303,7 +303,7 @@ void InitGpgFrontendCore() {
// init ctx, also checking the basical env
auto& ctx = GpgFrontend::GpgContext::CreateInstance(
- kGpgfrontendDefaultChannel, [=]() -> ChannelObjectPtr {
+ kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
GpgFrontend::GpgContextInitArgs args;
// set key database path
diff --git a/src/core/function/GlobalSettingStation.cpp b/src/core/function/GlobalSettingStation.cpp
index 5dc10dc1..5031effe 100644
--- a/src/core/function/GlobalSettingStation.cpp
+++ b/src/core/function/GlobalSettingStation.cpp
@@ -28,6 +28,8 @@
#include "GlobalSettingStation.h"
+#include <qcoreapplication.h>
+
#include "core/utils/FilesystemUtils.h"
#include "core/utils/IOUtils.h"
@@ -216,11 +218,14 @@ class GlobalSettingStation::Impl
private:
std::filesystem::path app_path_ = QCoreApplication::applicationDirPath()
.toStdString(); ///< Program Location
+
std::filesystem::path app_data_path_ =
QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
.toStdString(); ///< Program Data Location
+
std::filesystem::path app_log_path_ =
app_data_path_ / "logs"; ///< Program Data Location
+
std::filesystem::path app_data_objs_path_ =
app_data_path_ / "data_objs"; ///< Object storage path
diff --git a/src/core/function/GlobalSettingStation.h b/src/core/function/GlobalSettingStation.h
index 18f42db1..66fc4b6a 100644
--- a/src/core/function/GlobalSettingStation.h
+++ b/src/core/function/GlobalSettingStation.h
@@ -91,6 +91,11 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
*/
[[nodiscard]] auto GetStandaloneDatabaseDir() const -> std::filesystem::path;
+ /**
+ * @brief Get the App Config Path object
+ *
+ * @return std::filesystem::path
+ */
[[nodiscard]] auto GetAppConfigPath() const -> std::filesystem::path;
/**
@@ -121,8 +126,18 @@ class GPGFRONTEND_CORE_EXPORT GlobalSettingStation
*/
[[nodiscard]] auto GetCertsDir() const -> std::filesystem::path;
+ /**
+ * @brief Get the Log Files Size object
+ *
+ * @return std::string
+ */
[[nodiscard]] auto GetLogFilesSize() const -> std::string;
+ /**
+ * @brief Get the Data Objects Files Size object
+ *
+ * @return std::string
+ */
[[nodiscard]] auto GetDataObjectsFilesSize() const -> std::string;
/**
diff --git a/src/core/function/basic/ChannelObject.h b/src/core/function/basic/ChannelObject.h
index 7bbd6d94..6fb315ae 100644
--- a/src/core/function/basic/ChannelObject.h
+++ b/src/core/function/basic/ChannelObject.h
@@ -28,12 +28,10 @@
#pragma once
+#include "core/GpgConstants.h"
#include "core/function/SecureMemoryAllocator.h"
namespace GpgFrontend {
-static constexpr int kGpgFrontendDefaultChannel =
- 0; ///< the default channel id
-
/**
* @brief object which in channel system is called "channel"
*
diff --git a/src/core/function/basic/GpgFunctionObject.h b/src/core/function/basic/GpgFunctionObject.h
index 619cad04..dd06608d 100644
--- a/src/core/function/basic/GpgFunctionObject.h
+++ b/src/core/function/basic/GpgFunctionObject.h
@@ -64,7 +64,7 @@ class SingletonFunctionObject : public ChannelObject {
* @param channel
* @return T&
*/
- static auto GetInstance(int channel = GpgFrontend::kGpgfrontendDefaultChannel)
+ static auto GetInstance(int channel = GpgFrontend::kGpgFrontendDefaultChannel)
-> T& {
static std::mutex g_channel_mutex_map_lock;
static std::map<int, std::mutex> g_channel_mutex_map;
diff --git a/src/core/function/gpg/GpgFileOpera.h b/src/core/function/gpg/GpgFileOpera.h
index b20fa7db..569ea51a 100644
--- a/src/core/function/gpg/GpgFileOpera.h
+++ b/src/core/function/gpg/GpgFileOpera.h
@@ -52,7 +52,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera {
*/
static auto EncryptFile(KeyListPtr keys, const std::string& in_path,
const std::string& out_path, GpgEncrResult& result,
- int channel = kGpgfrontendDefaultChannel)
+ int channel = kGpgFrontendDefaultChannel)
-> unsigned int;
/**
@@ -67,7 +67,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera {
static auto EncryptFileSymmetric(const std::string& in_path,
const std::string& out_path,
GpgEncrResult& result,
- int channel = kGpgfrontendDefaultChannel)
+ int channel = kGpgFrontendDefaultChannel)
-> unsigned int;
/**
@@ -94,7 +94,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera {
*/
static auto SignFile(KeyListPtr keys, const std::string& in_path,
const std::string& out_path, GpgSignResult& result,
- int channel = kGpgfrontendDefaultChannel) -> GpgError;
+ int channel = kGpgFrontendDefaultChannel) -> GpgError;
/**
* @brief Verify file with public key
@@ -107,7 +107,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera {
*/
static auto VerifyFile(const std::string& data_path,
const std::string& sign_path, GpgVerifyResult& result,
- int channel = kGpgfrontendDefaultChannel) -> GpgError;
+ int channel = kGpgFrontendDefaultChannel) -> GpgError;
/**
* @brief Encrypt and sign file with public key and private key
@@ -125,7 +125,7 @@ class GPGFRONTEND_CORE_EXPORT GpgFileOpera {
const std::string& in_path,
const std::string& out_path,
GpgEncrResult& encr_res, GpgSignResult& sign_res,
- int channel = kGpgfrontendDefaultChannel)
+ int channel = kGpgFrontendDefaultChannel)
-> GpgError;
/**
diff --git a/src/core/module/GlobalModuleContext.cpp b/src/core/module/GlobalModuleContext.cpp
index 88250a1e..9eddb57a 100644
--- a/src/core/module/GlobalModuleContext.cpp
+++ b/src/core/module/GlobalModuleContext.cpp
@@ -52,8 +52,8 @@ class GlobalModuleContext::Impl {
.total_milliseconds()),
default_task_runner_(std::move(task_runner)) {
// Initialize acquired channels with default values.
- acquired_channel_.insert(kGpgfrontendDefaultChannel);
- acquired_channel_.insert(kGpgfrontendNonAsciiChannel);
+ acquired_channel_.insert(kGpgFrontendDefaultChannel);
+ acquired_channel_.insert(kGpgFrontendNonAsciiChannel);
}
auto GetChannel(ModuleRawPtr module) -> int {
@@ -74,7 +74,7 @@ class GlobalModuleContext::Impl {
}
static auto GetDefaultChannel(ModuleRawPtr) -> int {
- return kGpgfrontendDefaultChannel;
+ return kGpgFrontendDefaultChannel;
}
auto GetTaskRunner(ModuleRawPtr module) -> std::optional<TaskRunnerPtr> {
diff --git a/test/CMakeLists.txt b/src/test/CMakeLists.txt
index 7cb41029..c4d7bcf8 100644
--- a/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -23,31 +23,24 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
-
-find_package(GTest REQUIRED)
-
# Set configure for test
-file(COPY ${CMAKE_SOURCE_DIR}/test/conf DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FOLLOW_SYMLINK_CHAIN)
-file(COPY ${CMAKE_SOURCE_DIR}/test/data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FOLLOW_SYMLINK_CHAIN)
+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)
+aux_source_directory(./core TEST_SOURCE)
aux_source_directory(. TEST_SOURCE)
-add_executable(
- ${AppName}
- ${TEST_SOURCE}
-)
+add_library(gpgfrontend_test SHARED ${TEST_SOURCE})
-if (GPG_CORE)
- target_link_libraries(${AppName} gpg_core)
-endif ()
+set(_export_file "${CMAKE_CURRENT_SOURCE_DIR}/GpgFrontendTestExport.h")
+generate_export_header(gpgfrontend_test EXPORT_FILE_NAME "${_export_file}")
-if (GPG_STANDALONE_MODE)
- file(COPY ${CMAKE_SOURCE_DIR}/test/gpg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FOLLOW_SYMLINK_CHAIN)
-endif ()
+target_link_libraries(gpgfrontend_test PRIVATE gtest)
+target_link_libraries(gpgfrontend_test PRIVATE gpgfrontend_core)
+target_link_libraries(gpgfrontend_test PRIVATE spdlog)
-target_link_libraries(${AppName} ${Boost_LIBRARIES} gtest gtest_main)
if (APPLE)
- target_link_libraries(${AppName} intl)
+ target_link_libraries(gpgfrontend_test intl)
endif ()
-add_test(AllTestsInGpgFrontend ${AppName})
+add_test(AllTestsInGpgFrontend gpgfrontend_test)
diff --git a/src/test/GpgFrontendCoreExport.h b/src/test/GpgFrontendCoreExport.h
new file mode 100644
index 00000000..4d1b2f0b
--- /dev/null
+++ b/src/test/GpgFrontendCoreExport.h
@@ -0,0 +1,42 @@
+
+#ifndef GPGFRONTEND_TEST_EXPORT_H
+#define GPGFRONTEND_TEST_EXPORT_H
+
+#ifdef GPGFRONTEND_TEST_STATIC_DEFINE
+# define GPGFRONTEND_TEST_EXPORT
+# define GPGFRONTEND_TEST_NO_EXPORT
+#else
+# ifndef GPGFRONTEND_TEST_EXPORT
+# ifdef gpgfrontend_test_EXPORTS
+ /* We are building this library */
+# define GPGFRONTEND_TEST_EXPORT __attribute__((visibility("default")))
+# else
+ /* We are using this library */
+# define GPGFRONTEND_TEST_EXPORT __attribute__((visibility("default")))
+# endif
+# endif
+
+# ifndef GPGFRONTEND_TEST_NO_EXPORT
+# define GPGFRONTEND_TEST_NO_EXPORT __attribute__((visibility("hidden")))
+# endif
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED
+# define GPGFRONTEND_TEST_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED_EXPORT
+# define GPGFRONTEND_TEST_DEPRECATED_EXPORT GPGFRONTEND_TEST_EXPORT GPGFRONTEND_TEST_DEPRECATED
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED_NO_EXPORT
+# define GPGFRONTEND_TEST_DEPRECATED_NO_EXPORT GPGFRONTEND_TEST_NO_EXPORT GPGFRONTEND_TEST_DEPRECATED
+#endif
+
+#if 0 /* DEFINE_NO_DEPRECATED */
+# ifndef GPGFRONTEND_TEST_NO_DEPRECATED
+# define GPGFRONTEND_TEST_NO_DEPRECATED
+# endif
+#endif
+
+#endif /* GPGFRONTEND_TEST_EXPORT_H */
diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp
new file mode 100644
index 00000000..24e099a2
--- /dev/null
+++ b/src/test/GpgFrontendTest.cpp
@@ -0,0 +1,114 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "GpgFrontendTest.h"
+
+#include <boost/date_time.hpp>
+#include <boost/dll.hpp>
+#include <filesystem>
+
+#include "core/function/GlobalSettingStation.h"
+#include "core/function/gpg/GpgContext.h"
+#include "spdlog/spdlog.h"
+#include "type.h"
+
+namespace GpgFrontend::Test {
+
+void InitTestLoggingSystem(spdlog::level::level_enum level) {
+ // get the log directory
+ auto logfile_path =
+ (GlobalSettingStation::GetInstance().GetLogDir() / "test");
+ logfile_path.replace_extension(".log");
+
+ // sinks
+ std::vector<spdlog::sink_ptr> sinks;
+ sinks.push_back(
+ SecureCreateSharedObject<spdlog::sinks::stderr_color_sink_mt>());
+ sinks.push_back(
+ SecureCreateSharedObject<spdlog::sinks::rotating_file_sink_mt>(
+ logfile_path.u8string(), 1048576 * 32, 8));
+
+ // logger
+ auto test_logger = SecureCreateSharedObject<spdlog::logger>(
+ "test", begin(sinks), end(sinks));
+ test_logger->set_pattern(
+ "[%H:%M:%S.%e] [T:%t] [%=6n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)");
+
+ // set the level of logger
+ test_logger->set_level(level);
+
+ // register it as default logger
+ spdlog::set_default_logger(test_logger);
+}
+
+auto GenerateRandomString(size_t length) -> std::string {
+ const std::string characters =
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+ std::random_device random_device;
+ std::mt19937 generator(random_device());
+ std::uniform_int_distribution<> distribution(0, characters.size() - 1);
+
+ std::string random_string;
+ for (size_t i = 0; i < length; ++i) {
+ random_string += characters[distribution(generator)];
+ }
+
+ return random_string;
+}
+
+void ConfigureGpgContext() {
+ auto db_path =
+ std::filesystem::temp_directory_path() / GenerateRandomString(12);
+ SPDLOG_DEBUG("setting up new database path for test case: {}",
+ db_path.string());
+
+ if (!std::filesystem::exists(db_path)) {
+ std::filesystem::create_directory(db_path);
+ } else {
+ std::filesystem::remove_all(db_path);
+ std::filesystem::create_directory(db_path);
+ }
+
+ GpgContext::CreateInstance(
+ kGpgFrontendDefaultChannel, [&]() -> ChannelObjectPtr {
+ GpgContextInitArgs args;
+ args.test_mode = true;
+ args.offline_mode = true;
+ args.db_path = db_path.string();
+
+ return ConvertToChannelObjectPtr<>(SecureCreateUniqueObject<GpgContext>(
+ args, kGpgFrontendDefaultChannel));
+ });
+}
+
+void ExecuteAllTestCase(InitArgs args) {
+ InitTestLoggingSystem(args.log_level);
+ ConfigureGpgContext();
+}
+
+} // namespace GpgFrontend::Test \ No newline at end of file
diff --git a/test/GpgCoreTestImportExport.cpp b/src/test/GpgFrontendTest.h
index 34f34ba0..55c6b734 100644
--- a/test/GpgCoreTestImportExport.cpp
+++ b/src/test/GpgFrontendTest.h
@@ -26,13 +26,16 @@
*
*/
-#include <string>
-#include <vector>
+#pragma once
-#include "GpgFrontendTest.h"
-#include "gpg/GpgConstants.h"
-#include "gpg/function/GpgKeyGetter.h"
-#include "gpg/function/GpgKeyImportExporter.h"
-#include "gpg/model/GpgKey.h"
+#include <gtest/gtest.h>
+#include <spdlog/sinks/rotating_file_sink.h>
+#include <spdlog/sinks/stdout_color_sinks.h>
+#include <spdlog/spdlog.h>
-TEST_F(GpgCoreTest, CoreExportSecretTest) {} \ No newline at end of file
+
+#include <libconfig.h++>
+
+#include "GpgFrontendTestExport.h"
+
+namespace GpgFrontend::Test {} // namespace GpgFrontend::Test
diff --git a/src/test/GpgFrontendTestExport.h b/src/test/GpgFrontendTestExport.h
new file mode 100644
index 00000000..4d1b2f0b
--- /dev/null
+++ b/src/test/GpgFrontendTestExport.h
@@ -0,0 +1,42 @@
+
+#ifndef GPGFRONTEND_TEST_EXPORT_H
+#define GPGFRONTEND_TEST_EXPORT_H
+
+#ifdef GPGFRONTEND_TEST_STATIC_DEFINE
+# define GPGFRONTEND_TEST_EXPORT
+# define GPGFRONTEND_TEST_NO_EXPORT
+#else
+# ifndef GPGFRONTEND_TEST_EXPORT
+# ifdef gpgfrontend_test_EXPORTS
+ /* We are building this library */
+# define GPGFRONTEND_TEST_EXPORT __attribute__((visibility("default")))
+# else
+ /* We are using this library */
+# define GPGFRONTEND_TEST_EXPORT __attribute__((visibility("default")))
+# endif
+# endif
+
+# ifndef GPGFRONTEND_TEST_NO_EXPORT
+# define GPGFRONTEND_TEST_NO_EXPORT __attribute__((visibility("hidden")))
+# endif
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED
+# define GPGFRONTEND_TEST_DEPRECATED __attribute__ ((__deprecated__))
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED_EXPORT
+# define GPGFRONTEND_TEST_DEPRECATED_EXPORT GPGFRONTEND_TEST_EXPORT GPGFRONTEND_TEST_DEPRECATED
+#endif
+
+#ifndef GPGFRONTEND_TEST_DEPRECATED_NO_EXPORT
+# define GPGFRONTEND_TEST_DEPRECATED_NO_EXPORT GPGFRONTEND_TEST_NO_EXPORT GPGFRONTEND_TEST_DEPRECATED
+#endif
+
+#if 0 /* DEFINE_NO_DEPRECATED */
+# ifndef GPGFRONTEND_TEST_NO_DEPRECATED
+# define GPGFRONTEND_TEST_NO_DEPRECATED
+# endif
+#endif
+
+#endif /* GPGFRONTEND_TEST_EXPORT_H */
diff --git a/src/test/core/GpgCoreTest.cpp b/src/test/core/GpgCoreTest.cpp
new file mode 100644
index 00000000..b4cf2f73
--- /dev/null
+++ b/src/test/core/GpgCoreTest.cpp
@@ -0,0 +1,61 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "GpgCoreTest.h"
+
+#include "core/function/gpg/GpgKeyImportExporter.h"
+#include "core/utils/IOUtils.h"
+
+namespace GpgFrontend::Test {
+
+void GpgCoreTest::import_private_keys(const libconfig::Setting& root) {
+ if (root.exists("load_keys.private_keys")) {
+ auto& private_keys = root.lookup("load_keys.private_keys");
+ for (auto& private_key : private_keys) {
+ if (private_key.exists("filename")) {
+ std::string filename;
+ private_key.lookupValue("filename", filename);
+ auto data_file_path = data_path_ / filename;
+ std::string data = ReadAllDataInFile(data_file_path.string());
+ auto secret_key_copy = std::make_unique<std::string>(data);
+ GpgKeyImportExporter::GetInstance(kGpgFrontendDefaultChannel)
+ .ImportKey(std::move(secret_key_copy));
+ }
+ }
+ }
+}
+
+void GpgCoreTest::TearDown() {}
+
+void GpgCoreTest::SetUp() {
+ libconfig::Config cfg;
+ ASSERT_NO_THROW(cfg.readFile(config_path_.c_str()));
+ auto& root = cfg.getRoot();
+ import_private_keys(root);
+}
+} // namespace GpgFrontend::Test
diff --git a/src/test/core/GpgCoreTest.h b/src/test/core/GpgCoreTest.h
new file mode 100644
index 00000000..bffaf9ad
--- /dev/null
+++ b/src/test/core/GpgCoreTest.h
@@ -0,0 +1,62 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#pragma once
+
+#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"
+
+namespace GpgFrontend::Test {
+
+class GpgCoreTest : public ::testing::Test {
+ public:
+ void SetUp() override;
+
+ void TearDown() override;
+
+ private:
+ void import_private_keys(const libconfig::Setting& root);
+
+ // Configure File Location
+ std::filesystem::path config_path_ =
+ GlobalSettingStation::GetInstance().GetAppDir() / "test" / "conf" /
+ "core.cfg";
+
+ // Data File Directory Location
+ std::filesystem::path data_path_ =
+ GlobalSettingStation::GetInstance().GetAppDir() / "test" / "data";
+
+};
+
+} // namespace GpgFrontend::Test \ No newline at end of file
diff --git a/test/GpgCoreTestBasicOpera.cpp b/src/test/core/GpgCoreTestBasicOpera.cpp
index 6980e700..59cb2fa2 100644
--- a/test/GpgCoreTestBasicOpera.cpp
+++ b/src/test/core/GpgCoreTestBasicOpera.cpp
@@ -26,64 +26,62 @@
*
*/
-#include <gtest/gtest.h>
+#include "GpgCoreTest.h"
+#include "core/GpgModel.h"
+#include "core/function/basic/ChannelObject.h"
+#include "core/function/gpg/GpgBasicOperator.h"
+#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/result_analyse/GpgDecryptResultAnalyse.h"
+#include "core/utils/GpgUtils.h"
-#include <string>
-#include <vector>
-
-#include "GpgFrontendTest.h"
-#include "gpg/GpgConstants.h"
-#include "gpg/function/GpgBasicOperator.h"
-#include "gpg/function/GpgKeyGetter.h"
-#include "gpg/result_analyse/GpgDecryptResultAnalyse.h"
-
-using namespace GpgFrontend;
+namespace GpgFrontend::Test {
TEST_F(GpgCoreTest, CoreEncryptDecrTest) {
- auto encrypt_key = GpgKeyGetter::GetInstance(default_channel)
+ auto encrypt_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetPubkey("467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
ByteArray encrypt_text = "Hello GpgFrontend!";
- ByteArrayPtr encr_out_data;
- GpgEncrResult e_result;
KeyListPtr keys = std::make_unique<KeyArgsList>();
keys->push_back(std::move(encrypt_key));
- auto err =
- BasicOperator::GetInstance(default_channel)
- .Encrypt(std::move(keys), encrypt_text, encr_out_data, e_result);
- ASSERT_EQ(e_result->invalid_recipients, nullptr);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
-
- GpgDecrResult d_result;
- ByteArrayPtr decr_out_data;
- err = BasicOperator::GetInstance(default_channel)
- .Decrypt(*encr_out_data, decr_out_data, d_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
- ASSERT_NE(d_result->recipients, nullptr);
- ASSERT_EQ(std::string(d_result->recipients->keyid), "F89C95A05088CC93");
- ASSERT_EQ(*decr_out_data, encrypt_text);
-}
-
-TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_1) {
- ByteArrayPtr encr_out_data = std::make_unique<ByteArray>(
- "-----BEGIN PGP MESSAGE-----\n"
- "\n"
- "hQEMA6UM/S9sZ32MAQf9Fb6gp6nvgKTQBv2mmjXia6ODXYq6kNeLsPVzLCbHyWOs\n"
- "0GDED11R1NksA3EQxFf4fzLkDpbo68r5bWy7c28c99Fr68IRET19Tw6Gu65MQezD\n"
- "Rdzo1oVqmK9sfKqOT3+0S2H+suFYw5kfBztMZLVGGl9R9fOXdKcj0fqGs2br3e9D\n"
- "ArBFqq07Bae2DD1J8mckWB2x9Uem4vjRiY+vEJcEdAS1N5xu1n7qzzyDgcRcS34X\n"
- "PNBQeTrFMc2RS7mnip2DbyZVEjORobhguK6xZyqXXbvFacStGWDLptV3dcCn4JRO\n"
- "dIORyt5wugqAtgE4qEGTvr/pJ/oXPw4Wve/trece/9I/AR38vW8ntVmDa/hV75iZ\n"
- "4QGAhQ8grD4kq31GHXHUOmBX51XXW9SINmplC8elEx3R460EUZJjjb0OvTih+eZH\n"
- "=8n2H\n"
- "-----END PGP MESSAGE-----");
-
- GpgDecrResult d_result;
- ByteArrayPtr decr_out_data;
- auto err = BasicOperator::GetInstance(default_channel)
- .Decrypt(*encr_out_data, decr_out_data, d_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_SECKEY);
- ASSERT_NE(d_result->recipients, nullptr);
- ASSERT_EQ(std::string(d_result->recipients->keyid), "A50CFD2F6C677D8C");
+ GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
+ .Encrypt(std::move(keys), encrypt_text,
+ [](GpgError err, const DataObjectPtr&) {
+
+ });
+
+ // ASSERT_EQ(e_result->invalid_recipients, nullptr);
+ // ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+
+ // GpgDecrResult d_result;
+ // ByteArrayPtr decr_out_data;
+ // err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
+ // .Decrypt(*encr_out_data, decr_out_data, d_result);
+ // ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
+ // ASSERT_NE(d_result->recipients, nullptr);
+ // ASSERT_EQ(std::string(d_result->recipients->keyid), "F89C95A05088CC93");
+ // ASSERT_EQ(*decr_out_data, encrypt_text);
+ // }
+
+ // TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_1) {
+ // ByteArrayPtr encr_out_data = std::make_unique<ByteArray>(
+ // "-----BEGIN PGP MESSAGE-----\n"
+ // "\n"
+ // "hQEMA6UM/S9sZ32MAQf9Fb6gp6nvgKTQBv2mmjXia6ODXYq6kNeLsPVzLCbHyWOs\n"
+ // "0GDED11R1NksA3EQxFf4fzLkDpbo68r5bWy7c28c99Fr68IRET19Tw6Gu65MQezD\n"
+ // "Rdzo1oVqmK9sfKqOT3+0S2H+suFYw5kfBztMZLVGGl9R9fOXdKcj0fqGs2br3e9D\n"
+ // "ArBFqq07Bae2DD1J8mckWB2x9Uem4vjRiY+vEJcEdAS1N5xu1n7qzzyDgcRcS34X\n"
+ // "PNBQeTrFMc2RS7mnip2DbyZVEjORobhguK6xZyqXXbvFacStGWDLptV3dcCn4JRO\n"
+ // "dIORyt5wugqAtgE4qEGTvr/pJ/oXPw4Wve/trece/9I/AR38vW8ntVmDa/hV75iZ\n"
+ // "4QGAhQ8grD4kq31GHXHUOmBX51XXW9SINmplC8elEx3R460EUZJjjb0OvTih+eZH\n"
+ // "=8n2H\n"
+ // "-----END PGP MESSAGE-----");
+
+ // GpgDecrResult d_result;
+ // ByteArrayPtr decr_out_data;
+ // auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
+ // .Decrypt(*encr_out_data, decr_out_data, d_result);
+ // ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_SECKEY);
+ // ASSERT_NE(d_result->recipients, nullptr);
+ // ASSERT_EQ(std::string(d_result->recipients->keyid), "A50CFD2F6C677D8C");
}
TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_ResultAnalyse) {
@@ -102,37 +100,37 @@ TEST_F(GpgCoreTest, CoreEncryptDecrTest_KeyNotFound_ResultAnalyse) {
GpgDecrResult d_result;
ByteArrayPtr decr_out_data;
- auto err = BasicOperator::GetInstance(default_channel)
+ auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Decrypt(*encr_out_data, decr_out_data, d_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_SECKEY);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_SECKEY);
ASSERT_NE(d_result->recipients, nullptr);
ASSERT_EQ(std::string(d_result->recipients->keyid), "A50CFD2F6C677D8C");
- DecryptResultAnalyse analyse{err, d_result};
- analyse.analyse();
- ASSERT_EQ(analyse.getStatus(), -1);
- ASSERT_FALSE(analyse.getResultReport().empty());
+ GpgDecryptResultAnalyse analyse{err, d_result};
+ analyse.Analyse();
+ ASSERT_EQ(analyse.GetStatus(), -1);
+ ASSERT_FALSE(analyse.GetResultReport().empty());
}
TEST_F(GpgCoreTest, CoreSignVerifyNormalTest) {
- auto encrypt_key = GpgKeyGetter::GetInstance(default_channel)
+ auto encrypt_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetPubkey("467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
ByteArray sign_text = "Hello GpgFrontend!";
ByteArrayPtr sign_out_data;
GpgSignResult s_result;
KeyListPtr keys = std::make_unique<KeyArgsList>();
keys->push_back(std::move(encrypt_key));
- auto err = BasicOperator::GetInstance(default_channel)
+ auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Sign(std::move(keys), sign_text, sign_out_data,
GPGME_SIG_MODE_NORMAL, s_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(s_result->invalid_signers, nullptr);
GpgVerifyResult v_result;
ByteArrayPtr sign_buff = nullptr;
- err = BasicOperator::GetInstance(default_channel)
+ err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Verify(*sign_out_data, sign_buff, v_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_NE(v_result->signatures, nullptr);
ASSERT_EQ(std::string(v_result->signatures->fpr),
"467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
@@ -140,23 +138,23 @@ TEST_F(GpgCoreTest, CoreSignVerifyNormalTest) {
}
TEST_F(GpgCoreTest, CoreSignVerifyDetachTest) {
- auto encrypt_key = GpgKeyGetter::GetInstance(default_channel)
+ auto encrypt_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetPubkey("467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
ByteArray sign_text = "Hello GpgFrontend!";
ByteArrayPtr sign_out_data;
GpgSignResult s_result;
KeyListPtr keys = std::make_unique<KeyArgsList>();
keys->push_back(std::move(encrypt_key));
- auto err = BasicOperator::GetInstance(default_channel)
+ auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Sign(std::move(keys), sign_text, sign_out_data,
GPGME_SIG_MODE_DETACH, s_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(s_result->invalid_signers, nullptr);
GpgVerifyResult v_result;
- err = BasicOperator::GetInstance(default_channel)
+ err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Verify(sign_text, sign_out_data, v_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_NE(v_result->signatures, nullptr);
ASSERT_EQ(std::string(v_result->signatures->fpr),
"467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
@@ -164,24 +162,24 @@ TEST_F(GpgCoreTest, CoreSignVerifyDetachTest) {
}
TEST_F(GpgCoreTest, CoreSignVerifyClearTest) {
- auto sign_key = GpgKeyGetter::GetInstance(default_channel)
+ auto sign_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetKey("467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
ByteArray sign_text = "Hello GpgFrontend!";
ByteArrayPtr sign_out_data;
GpgSignResult s_result;
KeyListPtr keys = std::make_unique<KeyArgsList>();
keys->push_back(std::move(sign_key));
- auto err = BasicOperator::GetInstance(default_channel)
+ auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Sign(std::move(keys), sign_text, sign_out_data,
GPGME_SIG_MODE_CLEAR, s_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(s_result->invalid_signers, nullptr);
GpgVerifyResult v_result;
ByteArrayPtr sign_buff = nullptr;
- err = BasicOperator::GetInstance(default_channel)
+ err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.Verify(*sign_out_data, sign_buff, v_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_NE(v_result->signatures, nullptr);
ASSERT_EQ(std::string(v_result->signatures->fpr),
"467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
@@ -189,14 +187,14 @@ TEST_F(GpgCoreTest, CoreSignVerifyClearTest) {
}
TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) {
- auto encrypt_key = GpgKeyGetter::GetInstance(default_channel)
+ auto encrypt_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetPubkey("467F14220CE8DCF780CF4BAD8465C55B25C9B7D1");
- auto sign_key = GpgKeyGetter::GetInstance(default_channel)
+ auto sign_key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
.GetKey("8933EB283A18995F45D61DAC021D89771B680FFB");
// Question?
// ASSERT_FALSE(encrypt_key.is_private_key());
- ASSERT_TRUE(sign_key.is_private_key());
- ASSERT_TRUE(sign_key.CanSignActual());
+ ASSERT_TRUE(sign_key.IsPrivateKey());
+ ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
ByteArray encrypt_text = "Hello GpgFrontend!";
ByteArrayPtr encr_out_data;
GpgEncrResult e_result;
@@ -207,19 +205,19 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) {
keys->push_back(std::move(encrypt_key));
sign_keys->push_back(std::move(sign_key));
- auto err = BasicOperator::GetInstance(default_channel)
+ auto err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.EncryptSign(std::move(keys), std::move(sign_keys),
encrypt_text, encr_out_data, e_result, s_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_EQ(e_result->invalid_recipients, nullptr);
ASSERT_EQ(s_result->invalid_signers, nullptr);
GpgDecrResult d_result;
GpgVerifyResult v_result;
ByteArrayPtr decr_out_data = nullptr;
- err = BasicOperator::GetInstance(default_channel)
+ err = GpgBasicOperator::GetInstance(kGpgFrontendDefaultChannel)
.DecryptVerify(*encr_out_data, decr_out_data, d_result, v_result);
- ASSERT_EQ(check_gpg_error_2_err_code(err), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
ASSERT_NE(d_result->recipients, nullptr);
ASSERT_EQ(std::string(d_result->recipients->keyid), "F89C95A05088CC93");
ASSERT_EQ(*decr_out_data, encrypt_text);
@@ -228,3 +226,5 @@ TEST_F(GpgCoreTest, CoreEncryptSignDecrVerifyTest) {
"8933EB283A18995F45D61DAC021D89771B680FFB");
ASSERT_EQ(v_result->signatures->next, nullptr);
}
+
+} // namespace GpgFrontend::Test
diff --git a/test/GpgCoreTest.cpp b/src/test/core/GpgCoreTestImportExport.cpp
index 2e18c76c..82e0bde4 100644
--- a/test/GpgCoreTest.cpp
+++ b/src/test/core/GpgCoreTestImportExport.cpp
@@ -26,7 +26,14 @@
*
*/
-#include "GpgFrontendTest.h"
+#include <string>
+#include <vector>
-// Should be used once and once-only
-INITIALIZE_EASYLOGGINGPP
+#include "GpgCoreTest.h"
+#include "core/GpgConstants.h"
+
+namespace GpgFrontend::Test {
+
+TEST_F(GpgCoreTest, CoreExportSecretTest) {}
+
+} // namespace GpgFrontend::Test \ No newline at end of file
diff --git a/src/test/core/GpgCoreTestKeyModel.cpp b/src/test/core/GpgCoreTestKeyModel.cpp
new file mode 100644
index 00000000..ff3fbbf8
--- /dev/null
+++ b/src/test/core/GpgCoreTestKeyModel.cpp
@@ -0,0 +1,179 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "GpgCoreTest.h"
+#include "core/function/gpg/GpgContext.h"
+#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/model/GpgData.h"
+#include "core/model/GpgKey.h"
+#include "core/utils/GpgUtils.h"
+
+namespace GpgFrontend::Test {
+
+TEST_F(GpgCoreTest, CoreInitTest) {
+ auto& ctx = GpgContext::GetInstance(kGpgFrontendDefaultChannel);
+ auto& ctx_default = GpgContext::GetInstance();
+ ASSERT_TRUE(ctx.Good());
+ ASSERT_TRUE(ctx_default.Good());
+}
+
+TEST_F(GpgCoreTest, GpgDataTest) {
+ auto data_buff = std::string(
+ "cqEh8fyKWtmiXrW2zzlszJVGJrpXDDpzgP7ZELGxhfZYFi8rMrSVKDwrpFZBSWMG");
+
+ GpgData data(data_buff.data(), data_buff.size());
+
+ auto out_buffer = data.Read2Buffer();
+ ASSERT_EQ(out_buffer->size(), 64);
+}
+
+TEST_F(GpgCoreTest, GpgKeyTest) {
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
+ ASSERT_TRUE(key.IsGood());
+ ASSERT_TRUE(key.IsPrivateKey());
+ ASSERT_TRUE(key.IsHasMasterKey());
+
+ ASSERT_FALSE(key.IsDisabled());
+ ASSERT_FALSE(key.IsRevoked());
+
+ ASSERT_EQ(key.GetProtocol(), "OpenPGP");
+
+ ASSERT_EQ(key.GetSubKeys()->size(), 2);
+ ASSERT_EQ(key.GetUIDs()->size(), 1);
+
+ ASSERT_TRUE(key.IsHasCertificationCapability());
+ ASSERT_TRUE(key.IsHasEncryptionCapability());
+ ASSERT_TRUE(key.IsHasSigningCapability());
+ ASSERT_FALSE(key.IsHasAuthenticationCapability());
+ ASSERT_TRUE(key.IsHasActualCertificationCapability());
+ ASSERT_TRUE(key.IsHasActualEncryptionCapability());
+ ASSERT_TRUE(key.IsHasActualSigningCapability());
+ ASSERT_FALSE(key.IsHasActualAuthenticationCapability());
+
+ ASSERT_EQ(key.GetName(), "GpgFrontendTest");
+ ASSERT_TRUE(key.GetComment().empty());
+ ASSERT_EQ(key.GetEmail(), "[email protected]");
+ ASSERT_EQ(key.GetId(), "81704859182661FB");
+ ASSERT_EQ(key.GetFingerprint(), "9490795B78F8AFE9F93BD09281704859182661FB");
+ ASSERT_EQ(key.GetExpireTime(),
+ boost::posix_time::from_iso_string("20230905T040000"));
+ ASSERT_EQ(key.GetPublicKeyAlgo(), "RSA");
+ ASSERT_EQ(key.GetPrimaryKeyLength(), 3072);
+ ASSERT_EQ(key.GetLastUpdateTime(),
+ boost::posix_time::from_iso_string("19700101T000000"));
+ ASSERT_EQ(key.GetCreateTime(),
+ boost::posix_time::from_iso_string("20210905T060153"));
+
+ ASSERT_EQ(key.GetOwnerTrust(), "Unknown");
+
+ ASSERT_EQ(key.IsExpired(), key.GetExpireTime() <
+ boost::posix_time::second_clock::local_time());
+}
+
+TEST_F(GpgCoreTest, GpgSubKeyTest) {
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
+ auto sub_keys = key.GetSubKeys();
+ ASSERT_EQ(sub_keys->size(), 2);
+
+ auto& sub_key = sub_keys->back();
+
+ ASSERT_FALSE(sub_key.IsRevoked());
+ ASSERT_FALSE(sub_key.IsDisabled());
+ ASSERT_EQ(sub_key.GetCreateTime(),
+ boost::posix_time::from_iso_string("20210905T060153"));
+
+ ASSERT_FALSE(sub_key.IsCardKey());
+ ASSERT_TRUE(sub_key.IsPrivateKey());
+ ASSERT_EQ(sub_key.GetID(), "2B36803235B5E25B");
+ ASSERT_EQ(sub_key.GetFingerprint(),
+ "50D37E8F8EE7340A6794E0592B36803235B5E25B");
+ ASSERT_EQ(sub_key.GetKeyLength(), 3072);
+ ASSERT_EQ(sub_key.GetPubkeyAlgo(), "RSA");
+ ASSERT_FALSE(sub_key.IsHasCertificationCapability());
+ ASSERT_FALSE(sub_key.IsHasAuthenticationCapability());
+ ASSERT_FALSE(sub_key.IsHasSigningCapability());
+ ASSERT_TRUE(sub_key.IsHasEncryptionCapability());
+ ASSERT_EQ(key.GetExpireTime(),
+ boost::posix_time::from_iso_string("20230905T040000"));
+
+ ASSERT_EQ(
+ sub_key.IsExpired(),
+ sub_key.GetExpireTime() < boost::posix_time::second_clock::local_time());
+}
+
+TEST_F(GpgCoreTest, GpgUIDTest) {
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
+ auto uids = key.GetUIDs();
+ ASSERT_EQ(uids->size(), 1);
+ auto& uid = uids->front();
+
+ ASSERT_EQ(uid.GetName(), "GpgFrontendTest");
+ ASSERT_TRUE(uid.GetComment().empty());
+ ASSERT_EQ(uid.GetEmail(), "[email protected]");
+ ASSERT_EQ(uid.GetUID(),
+ "GpgFrontendTest <[email protected]>");
+ ASSERT_FALSE(uid.GetInvalid());
+ ASSERT_FALSE(uid.GetRevoked());
+}
+
+TEST_F(GpgCoreTest, GpgKeySignatureTest) {
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
+ auto uids = key.GetUIDs();
+ ASSERT_EQ(uids->size(), 1);
+ auto& uid = uids->front();
+
+ auto signatures = uid.GetSignatures();
+ ASSERT_EQ(signatures->size(), 1);
+ auto& signature = signatures->front();
+
+ ASSERT_EQ(signature.GetName(), "GpgFrontendTest");
+ ASSERT_TRUE(signature.GetComment().empty());
+ ASSERT_EQ(signature.GetEmail(), "[email protected]");
+ ASSERT_EQ(signature.GetKeyID(), "81704859182661FB");
+ ASSERT_EQ(signature.GetPubkeyAlgo(), "RSA");
+
+ ASSERT_FALSE(signature.IsRevoked());
+ ASSERT_FALSE(signature.IsInvalid());
+ ASSERT_EQ(CheckGpgError(signature.GetStatus()), GPG_ERR_NO_ERROR);
+ ASSERT_EQ(signature.GetUID(),
+ "GpgFrontendTest <[email protected]>");
+}
+
+TEST_F(GpgCoreTest, GpgKeyGetterTest) {
+ auto key = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel)
+ .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
+ ASSERT_TRUE(key.IsGood());
+ auto keys = GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).FetchKey();
+ ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end());
+}
+
+} // namespace GpgFrontend::Test \ No newline at end of file
diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp
new file mode 100644
index 00000000..62c8a771
--- /dev/null
+++ b/src/test/core/GpgCoreTestKeygen.cpp
@@ -0,0 +1,138 @@
+/**
+ * Copyright (C) 2021 Saturneric <[email protected]>
+ *
+ * This file is part of GpgFrontend.
+ *
+ * GpgFrontend is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GpgFrontend is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The initial version of the source code is inherited from
+ * the gpg4usb project, which is under GPL-3.0-or-later.
+ *
+ * All the source code of GpgFrontend was modified and released by
+ * Saturneric <[email protected]> starting on May 12, 2021.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ *
+ */
+
+#include "GpgCoreTest.h"
+#include "core/function/gpg/GpgKeyGetter.h"
+#include "core/function/gpg/GpgKeyOpera.h"
+#include "core/function/result_analyse/GpgResultAnalyse.h"
+#include "core/model/GpgGenKeyInfo.h"
+#include "core/model/GpgKey.h"
+#include "core/utils/GpgUtils.h"
+
+namespace GpgFrontend::Test {
+
+TEST_F(GpgCoreTest, GenerateKeyTest) {
+ auto& key_opera = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel);
+ auto keygen_info = std::make_unique<GenKeyInfo>();
+ keygen_info->SetName("foo");
+ keygen_info->SetEmail("[email protected]");
+ keygen_info->SetComment("");
+ keygen_info->SetKeyLength(1024);
+ keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[0]);
+ keygen_info->SetNonExpired(true);
+ keygen_info->SetNonPassPhrase(true);
+
+ GpgGenKeyResult result = nullptr;
+ // auto err = CheckGpgError(key_opera.GenerateKey(keygen_info, result));
+ // ASSERT_EQ(err, GPG_ERR_NO_ERROR);
+
+ // auto* fpr = result->fpr;
+ // ASSERT_FALSE(fpr == nullptr);
+
+ // auto key =
+ // GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).GetKey(fpr);
+ // ASSERT_TRUE(key.IsGood());
+ // key_opera.DeleteKey(fpr);
+}
+
+TEST_F(GpgCoreTest, GenerateKeyTest_1) {
+ auto& key_opera = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel);
+ auto keygen_info = std::make_unique<GenKeyInfo>();
+ keygen_info->SetName("foo");
+ keygen_info->SetEmail("[email protected]");
+ keygen_info->SetComment("hello gpgfrontend");
+ keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[0]);
+ keygen_info->SetKeyLength(4096);
+ keygen_info->SetNonExpired(false);
+ keygen_info->SetExpireTime(boost::posix_time::second_clock::local_time() +
+ boost::posix_time::hours(24));
+ keygen_info->SetNonPassPhrase(false);
+
+ GpgGenKeyResult result = nullptr;
+ // auto err =
+ // CheckGpgError(key_opera.GenerateKey(keygen_info, result));
+ // ASSERT_EQ(err, GPG_ERR_NO_ERROR);
+
+ // auto fpr = result->fpr;
+ // ASSERT_FALSE(fpr == nullptr);
+
+ // auto key =
+ // GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).GetKey(fpr);
+ // ASSERT_TRUE(key.IsGood());
+ // key_opera.DeleteKey(fpr);
+}
+
+TEST_F(GpgCoreTest, GenerateKeyTest_4) {
+ auto& key_opera = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel);
+ auto keygen_info = std::make_unique<GenKeyInfo>();
+ keygen_info->SetName("foo");
+ keygen_info->SetEmail("[email protected]");
+ keygen_info->SetComment("");
+ keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[1]);
+ keygen_info->SetNonExpired(true);
+ keygen_info->SetNonPassPhrase(false);
+
+ GpgGenKeyResult result = nullptr;
+ // auto err =
+ // CheckGpgError(key_opera.GenerateKey(keygen_info, result));
+ // ASSERT_EQ(err, GPG_ERR_NO_ERROR);
+
+ // auto* fpr = result->fpr;
+ // ASSERT_FALSE(fpr == nullptr);
+
+ // auto key =
+ // GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).GetKey(fpr);
+ // ASSERT_TRUE(key.IsGood());
+ // key_opera.DeleteKey(fpr);
+}
+
+TEST_F(GpgCoreTest, GenerateKeyTest_5) {
+ auto& key_opera = GpgKeyOpera::GetInstance(kGpgFrontendDefaultChannel);
+ auto keygen_info = std::make_unique<GenKeyInfo>();
+ keygen_info->SetName("foo");
+ keygen_info->SetEmail("[email protected]");
+ keygen_info->SetComment("");
+ keygen_info->SetAlgo(keygen_info->GetSupportedKeyAlgo()[2]);
+ keygen_info->SetNonExpired(true);
+ keygen_info->SetNonPassPhrase(false);
+
+ GpgGenKeyResult result = nullptr;
+ // auto err =
+ // CheckGpgError(key_opera.GenerateKey(keygen_info, result));
+ // ASSERT_EQ(err, GPG_ERR_NO_ERROR);
+
+ // auto* fpr = result->fpr;
+ // ASSERT_FALSE(fpr == nullptr);
+
+ // auto key =
+ // GpgKeyGetter::GetInstance(kGpgFrontendDefaultChannel).GetKey(fpr);
+ // ASSERT_TRUE(key.IsGood());
+ // key_opera.DeleteKey(fpr);
+}
+
+} // namespace GpgFrontend::Test
diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp
index be0e8efe..e7a25396 100644
--- a/src/ui/main_window/MainWindowFileSlotFunction.cpp
+++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp
@@ -183,10 +183,10 @@ void MainWindow::SlotFileEncrypt() {
path = path + (file_info.isDir() ? ".tar" : "");
}
- auto _channel = kGpgfrontendDefaultChannel;
+ auto _channel = kGpgFrontendDefaultChannel;
auto _extension = ".asc";
if (non_ascii_when_export || file_info.isDir()) {
- _channel = kGpgfrontendNonAsciiChannel;
+ _channel = kGpgFrontendNonAsciiChannel;
_extension = ".gpg";
}
@@ -391,10 +391,10 @@ void MainWindow::SlotFileSign() {
GlobalSettingStation::GetInstance().LookupSettings(
"general.non_ascii_when_export", true);
- auto _channel = kGpgfrontendDefaultChannel;
+ auto _channel = kGpgFrontendDefaultChannel;
auto _extension = ".asc";
if (non_ascii_when_export) {
- _channel = kGpgfrontendNonAsciiChannel;
+ _channel = kGpgFrontendNonAsciiChannel;
_extension = ".sig";
}
@@ -464,9 +464,9 @@ void MainWindow::SlotFileVerify() {
GlobalSettingStation::GetInstance().LookupSettings(
"general.non_ascii_when_export", true);
- auto _channel = kGpgfrontendDefaultChannel;
+ auto _channel = kGpgFrontendDefaultChannel;
if (non_ascii_when_export) {
- _channel = kGpgfrontendNonAsciiChannel;
+ _channel = kGpgFrontendNonAsciiChannel;
}
if (in_path.extension() == ".gpg") {
@@ -579,10 +579,10 @@ void MainWindow::SlotFileEncryptSign() {
path = path + (file_info.isDir() ? ".tar" : "");
}
- auto channel = kGpgfrontendDefaultChannel;
+ auto channel = kGpgFrontendDefaultChannel;
const auto* extension = ".asc";
if (non_ascii_when_export || file_info.isDir()) {
- channel = kGpgfrontendNonAsciiChannel;
+ channel = kGpgFrontendNonAsciiChannel;
extension = ".gpg";
}
diff --git a/test/GpgCoreTestKeyModel.cpp b/test/GpgCoreTestKeyModel.cpp
deleted file mode 100644
index 079d18d1..00000000
--- a/test/GpgCoreTestKeyModel.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "GpgFrontendTest.h"
-#include "gpg/function/GpgKeyGetter.h"
-
-TEST_F(GpgCoreTest, CoreInitTest) {
- auto& ctx = GpgFrontend::GpgContext::GetInstance(default_channel);
- auto& ctx_default = GpgFrontend::GpgContext::GetInstance();
- ASSERT_TRUE(ctx.good());
- ASSERT_TRUE(ctx_default.good());
-}
-
-TEST_F(GpgCoreTest, GpgDataTest) {
- auto data_buff = std::string(
- "cqEh8fyKWtmiXrW2zzlszJVGJrpXDDpzgP7ZELGxhfZYFi8rMrSVKDwrpFZBSWMG");
-
- GpgFrontend::GpgData data(data_buff.data(), data_buff.size());
-
- auto out_buffer = data.Read2Buffer();
- ASSERT_EQ(out_buffer->size(), 64);
-}
-
-TEST_F(GpgCoreTest, GpgKeyTest) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_TRUE(key.good());
- ASSERT_TRUE(key.is_private_key());
- ASSERT_TRUE(key.has_master_key());
-
- ASSERT_FALSE(key.disabled());
- ASSERT_FALSE(key.revoked());
-
- ASSERT_EQ(key.protocol(), "OpenPGP");
-
- ASSERT_EQ(key.subKeys()->size(), 2);
- ASSERT_EQ(key.uids()->size(), 1);
-
- ASSERT_TRUE(key.can_certify());
- ASSERT_TRUE(key.can_encrypt());
- ASSERT_TRUE(key.can_sign());
- ASSERT_FALSE(key.can_authenticate());
- ASSERT_TRUE(key.CanEncrActual());
- ASSERT_TRUE(key.CanEncrActual());
- ASSERT_TRUE(key.CanSignActual());
- ASSERT_FALSE(key.CanAuthActual());
-
- ASSERT_EQ(key.name(), "GpgFrontendTest");
- ASSERT_TRUE(key.comment().empty());
- ASSERT_EQ(key.email(), "[email protected]");
- ASSERT_EQ(key.id(), "81704859182661FB");
- ASSERT_EQ(key.fpr(), "9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_EQ(key.expires(),
- boost::posix_time::from_iso_string("20230905T040000"));
- ASSERT_EQ(key.pubkey_algo(), "RSA");
- ASSERT_EQ(key.length(), 3072);
- ASSERT_EQ(key.last_update(),
- boost::posix_time::from_iso_string("19700101T000000"));
- ASSERT_EQ(key.create_time(),
- boost::posix_time::from_iso_string("20210905T060153"));
-
- ASSERT_EQ(key.owner_trust(), "Unknown");
-
- using namespace boost::posix_time;
- ASSERT_EQ(key.expired(), key.expires() < second_clock::local_time());
-}
-
-TEST_F(GpgCoreTest, GpgSubKeyTest) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto sub_keys = key.subKeys();
- ASSERT_EQ(sub_keys->size(), 2);
-
- auto& sub_key = sub_keys->back();
-
- ASSERT_FALSE(sub_key.revoked());
- ASSERT_FALSE(sub_key.disabled());
- ASSERT_EQ(sub_key.timestamp(),
- boost::posix_time::from_iso_string("20210905T060153"));
-
- ASSERT_FALSE(sub_key.is_cardkey());
- ASSERT_TRUE(sub_key.is_private_key());
- ASSERT_EQ(sub_key.id(), "2B36803235B5E25B");
- ASSERT_EQ(sub_key.fpr(), "50D37E8F8EE7340A6794E0592B36803235B5E25B");
- ASSERT_EQ(sub_key.length(), 3072);
- ASSERT_EQ(sub_key.pubkey_algo(), "RSA");
- ASSERT_FALSE(sub_key.can_certify());
- ASSERT_FALSE(sub_key.can_authenticate());
- ASSERT_FALSE(sub_key.can_sign());
- ASSERT_TRUE(sub_key.can_encrypt());
- ASSERT_EQ(key.expires(),
- boost::posix_time::from_iso_string("20230905T040000"));
-
- using namespace boost::posix_time;
- ASSERT_EQ(sub_key.expired(), sub_key.expires() < second_clock::local_time());
-}
-
-TEST_F(GpgCoreTest, GpgUIDTest) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto uids = key.uids();
- ASSERT_EQ(uids->size(), 1);
- auto& uid = uids->front();
-
- ASSERT_EQ(uid.name(), "GpgFrontendTest");
- ASSERT_TRUE(uid.comment().empty());
- ASSERT_EQ(uid.email(), "[email protected]");
- ASSERT_EQ(uid.uid(), "GpgFrontendTest <[email protected]>");
- ASSERT_FALSE(uid.invalid());
- ASSERT_FALSE(uid.revoked());
-}
-
-TEST_F(GpgCoreTest, GpgKeySignatureTest) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto uids = key.uids();
- ASSERT_EQ(uids->size(), 1);
- auto& uid = uids->front();
-
- auto signatures = uid.signatures();
- ASSERT_EQ(signatures->size(), 1);
- auto& signature = signatures->front();
-
- ASSERT_EQ(signature.name(), "GpgFrontendTest");
- ASSERT_TRUE(signature.comment().empty());
- ASSERT_EQ(signature.email(), "[email protected]");
- ASSERT_EQ(signature.keyid(), "81704859182661FB");
- ASSERT_EQ(signature.pubkey_algo(), "RSA");
-
- ASSERT_FALSE(signature.revoked());
- ASSERT_FALSE(signature.invalid());
- ASSERT_EQ(GpgFrontend::check_gpg_error_2_err_code(signature.status()),
- GPG_ERR_NO_ERROR);
- ASSERT_EQ(signature.uid(),
- "GpgFrontendTest <[email protected]>");
-}
-
-TEST_F(GpgCoreTest, GpgKeyGetterTest) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(default_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_TRUE(key.good());
- auto keys =
- GpgFrontend::GpgKeyGetter::GetInstance(default_channel).FetchKey();
- ASSERT_GE(keys->size(), secret_keys_.size());
- ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end());
-}
diff --git a/test/GpgCoreTestKeyModelAlone.cpp b/test/GpgCoreTestKeyModelAlone.cpp
deleted file mode 100644
index a438260e..00000000
--- a/test/GpgCoreTestKeyModelAlone.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "GpgFrontendTest.h"
-#include "gpg/function/GpgKeyGetter.h"
-
-TEST_F(GpgCoreTest, CoreInitTestAlone) {
- auto& ctx = GpgFrontend::GpgContext::GetInstance(gpg_alone_channel);
- ASSERT_TRUE(ctx.good());
-}
-
-TEST_F(GpgCoreTest, GpgDataTestAlone) {
- auto data_buff = std::string(
- "cqEh8fyKWtmiXrW2zzlszJVGJrpXDDpzgP7ZELGxhfZYFi8rMrSVKDwrpFZBSWMG");
-
- GpgFrontend::GpgData data(data_buff.data(), data_buff.size());
-
- auto out_buffer = data.Read2Buffer();
- ASSERT_EQ(out_buffer->size(), 64);
-}
-
-TEST_F(GpgCoreTest, GpgKeyFetchTestAlone) {
- auto keys =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).FetchKey();
- ASSERT_EQ(keys->size(), 4);
-}
-
-TEST_F(GpgCoreTest, GpgKeyTestAlone) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_TRUE(key.good());
- ASSERT_TRUE(key.is_private_key());
- ASSERT_TRUE(key.has_master_key());
-
- ASSERT_FALSE(key.disabled());
- ASSERT_FALSE(key.revoked());
-
- ASSERT_EQ(key.protocol(), "OpenPGP");
-
- ASSERT_EQ(key.subKeys()->size(), 2);
- ASSERT_EQ(key.uids()->size(), 1);
-
- ASSERT_TRUE(key.can_certify());
- ASSERT_TRUE(key.can_encrypt());
- ASSERT_TRUE(key.can_sign());
- ASSERT_FALSE(key.can_authenticate());
- ASSERT_TRUE(key.CanEncrActual());
- ASSERT_TRUE(key.CanEncrActual());
- ASSERT_TRUE(key.CanSignActual());
- ASSERT_FALSE(key.CanAuthActual());
-
- ASSERT_EQ(key.name(), "GpgFrontendTest");
- ASSERT_TRUE(key.comment().empty());
- ASSERT_EQ(key.email(), "[email protected]");
- ASSERT_EQ(key.id(), "81704859182661FB");
- ASSERT_EQ(key.fpr(), "9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_EQ(key.expires(),
- boost::posix_time::from_iso_string("20230905T040000"));
- ASSERT_EQ(key.pubkey_algo(), "RSA");
- ASSERT_EQ(key.length(), 3072);
- ASSERT_EQ(key.last_update(),
- boost::posix_time::from_iso_string("19700101T000000"));
- ASSERT_EQ(key.create_time(),
- boost::posix_time::from_iso_string("20210905T060153"));
-
- ASSERT_EQ(key.owner_trust(), "Unknown");
-
- using namespace boost::posix_time;
- ASSERT_EQ(key.expired(), key.expires() < second_clock::local_time());
-}
-
-TEST_F(GpgCoreTest, GpgSubKeyTestAlone) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto sub_keys = key.subKeys();
- ASSERT_EQ(sub_keys->size(), 2);
-
- auto& sub_key = sub_keys->back();
-
- ASSERT_FALSE(sub_key.revoked());
- ASSERT_FALSE(sub_key.disabled());
- ASSERT_EQ(sub_key.timestamp(),
- boost::posix_time::from_iso_string("20210905T060153"));
-
- ASSERT_FALSE(sub_key.is_cardkey());
- ASSERT_TRUE(sub_key.is_private_key());
- ASSERT_EQ(sub_key.id(), "2B36803235B5E25B");
- ASSERT_EQ(sub_key.fpr(), "50D37E8F8EE7340A6794E0592B36803235B5E25B");
- ASSERT_EQ(sub_key.length(), 3072);
- ASSERT_EQ(sub_key.pubkey_algo(), "RSA");
- ASSERT_FALSE(sub_key.can_certify());
- ASSERT_FALSE(sub_key.can_authenticate());
- ASSERT_FALSE(sub_key.can_sign());
- ASSERT_TRUE(sub_key.can_encrypt());
- ASSERT_EQ(key.expires(),
- boost::posix_time::from_iso_string("20230905T040000"));
-
- using namespace boost::posix_time;
- ASSERT_EQ(sub_key.expired(), sub_key.expires() < second_clock::local_time());
-}
-
-TEST_F(GpgCoreTest, GpgUIDTestAlone) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto uids = key.uids();
- ASSERT_EQ(uids->size(), 1);
- auto& uid = uids->front();
-
- ASSERT_EQ(uid.name(), "GpgFrontendTest");
- ASSERT_TRUE(uid.comment().empty());
- ASSERT_EQ(uid.email(), "[email protected]");
- ASSERT_EQ(uid.uid(), "GpgFrontendTest <[email protected]>");
- ASSERT_FALSE(uid.invalid());
- ASSERT_FALSE(uid.revoked());
-}
-
-TEST_F(GpgCoreTest, GpgKeySignatureTestAlone) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- auto uids = key.uids();
- ASSERT_EQ(uids->size(), 1);
- auto& uid = uids->front();
-
- // No key signature support
- auto signatures = uid.signatures();
- ASSERT_EQ(signatures->size(), 0);
-}
-
-TEST_F(GpgCoreTest, GpgKeyGetterTestAlone) {
- auto key = GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel)
- .GetKey("9490795B78F8AFE9F93BD09281704859182661FB");
- ASSERT_TRUE(key.good());
- auto keys =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).FetchKey();
- ASSERT_GE(keys->size(), secret_keys_.size());
- ASSERT_TRUE(find(keys->begin(), keys->end(), key) != keys->end());
-}
diff --git a/test/GpgCoreTestKeygen.cpp b/test/GpgCoreTestKeygen.cpp
deleted file mode 100644
index 763b8949..00000000
--- a/test/GpgCoreTestKeygen.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "GpgFrontendTest.h"
-#include "gpg/GpgGenKeyInfo.h"
-#include "gpg/function/GpgKeyGetter.h"
-#include "gpg/function/GpgKeyOpera.h"
-
-TEST_F(GpgCoreTest, GenerateKeyTest) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(default_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>();
- keygen_info->setName("foo");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("");
- keygen_info->setKeySize(1024);
- keygen_info->setAlgo("rsa");
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(true);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(default_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTest_1) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(default_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>();
- keygen_info->setName("foo");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hello gpgfrontend");
- keygen_info->setAlgo("rsa");
- keygen_info->setKeySize(4096);
- keygen_info->setNonExpired(false);
- keygen_info->setExpired(boost::posix_time::second_clock::local_time() +
- boost::posix_time::hours(24));
- keygen_info->setNonPassPhrase(false);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(default_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTest_4) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(default_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>();
- keygen_info->setName("foo");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("");
- keygen_info->setAlgo("dsa");
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(false);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(default_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTest_5) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(default_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>();
- keygen_info->setName("foo");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("");
- keygen_info->setAlgo("ed25519");
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(false);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(default_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
diff --git a/test/GpgCoreTestKeygenAlone.cpp b/test/GpgCoreTestKeygenAlone.cpp
deleted file mode 100644
index 4ad26596..00000000
--- a/test/GpgCoreTestKeygenAlone.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#include "GpgFrontendTest.h"
-#include "gpg/GpgGenKeyInfo.h"
-#include "gpg/function/GpgKeyGetter.h"
-#include "gpg/function/GpgKeyOpera.h"
-
-TEST_F(GpgCoreTest, GenerateKeyTestAlone) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(gpg_alone_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>(false, true);
- keygen_info->setName("foobar");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hello");
- keygen_info->setAlgo("rsa");
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(true);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTestAlone_1) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(gpg_alone_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>(false, true);
- keygen_info->setName("foobar");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hello gpgfrontend");
- keygen_info->setAlgo("rsa");
- keygen_info->setNonExpired(false);
- keygen_info->setPassPhrase("abcdefg");
- keygen_info->setExpired(boost::posix_time::second_clock::local_time() +
- boost::posix_time::hours(24));
- keygen_info->setNonPassPhrase(false);
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTestAlone_2) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(gpg_alone_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>(false, true);
- keygen_info->setName("foobar");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hi");
- keygen_info->setAlgo("rsa");
- keygen_info->setKeySize(3072);
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(false);
- keygen_info->setPassPhrase("abcdefg");
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTestAlone_3) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(gpg_alone_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>(false, true);
- keygen_info->setName("foo");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hello");
- keygen_info->setAlgo("rsa");
- keygen_info->setKeySize(4096);
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(false);
- keygen_info->setPassPhrase("abcdefg");
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-}
-
-TEST_F(GpgCoreTest, GenerateKeyTestAlone_4) {
- auto& key_opera = GpgFrontend::GpgKeyOpera::GetInstance(gpg_alone_channel);
- auto keygen_info = std::make_unique<GpgFrontend::GenKeyInfo>(false, true);
- keygen_info->setName("foobar");
- keygen_info->setEmail("[email protected]");
- keygen_info->setComment("hello");
- keygen_info->setAlgo("dsa");
- keygen_info->setNonExpired(true);
- keygen_info->setNonPassPhrase(false);
- keygen_info->setPassPhrase("abcdefg");
-
- GpgFrontend::GpgGenKeyResult result = nullptr;
- auto err = GpgFrontend::check_gpg_error_2_err_code(
- key_opera.GenerateKey(keygen_info, result));
- ASSERT_EQ(err, GPG_ERR_NO_ERROR);
-
- auto fpr = result->fpr;
- ASSERT_FALSE(fpr == nullptr);
-
- auto key =
- GpgFrontend::GpgKeyGetter::GetInstance(gpg_alone_channel).GetKey(fpr);
- ASSERT_TRUE(key.good());
- key_opera.DeleteKey(fpr);
-} \ No newline at end of file
diff --git a/test/GpgFrontendTest.h b/test/GpgFrontendTest.h
deleted file mode 100644
index a5e4ea25..00000000
--- a/test/GpgFrontendTest.h
+++ /dev/null
@@ -1,206 +0,0 @@
-/**
- * Copyright (C) 2021 Saturneric <[email protected]>
- *
- * This file is part of GpgFrontend.
- *
- * GpgFrontend is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GpgFrontend is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>.
- *
- * The initial version of the source code is inherited from
- * the gpg4usb project, which is under GPL-3.0-or-later.
- *
- * All the source code of GpgFrontend was modified and released by
- * Saturneric <[email protected]> starting on May 12, 2021.
- *
- * SPDX-License-Identifier: GPL-3.0-or-later
- *
- */
-
-#ifndef _GPGFRONTENDTEST_H
-#define _GPGFRONTENDTEST_H
-
-#include <easyloggingpp/easylogging++.h>
-#include <gpg-error.h>
-#include <gtest/gtest.h>
-
-#include <boost/date_time.hpp>
-#include <boost/dll.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-#include <libconfig.h++>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "gpg/GpgConstants.h"
-#include "gpg/function/GpgKeyImportExporter.h"
-#include "gpg/function/GpgKeyOpera.h"
-
-class GpgCoreTest : public ::testing::Test {
- protected:
- // Secret Keys Imported
- std::vector<GpgFrontend::StdBypeArrayPtr> secret_keys_;
-
- // Program Location
- boost::filesystem::path parent_path =
- boost::dll::program_location().parent_path();
-
- // Configure File Location
- boost::filesystem::path config_path = parent_path / "conf" / "core.cfg";
-
- // Data File Directory Location
- boost::filesystem::path data_path;
-
- const int default_channel = 0;
-
- const int gpg_alone_channel = 512;
-
- GpgCoreTest() = default;
-
- ~GpgCoreTest() override = default;
-
- void SetUp() override {
- el::Loggers::addFlag(el::LoggingFlag::AutoSpacing);
- el::Configurations defaultConf;
- defaultConf.setToDefault();
- el::Loggers::reconfigureLogger("default", defaultConf);
-
- defaultConf.setGlobally(el::ConfigurationType::Format,
- "%datetime %level %func %msg");
- el::Loggers::reconfigureLogger("default", defaultConf);
-
- using namespace libconfig;
- Config cfg;
- ASSERT_NO_THROW(cfg.readFile(config_path.c_str()));
- Setting& root = cfg.getRoot();
-
- if (root.exists("data_path")) {
- std::string relative_data_path;
- root.lookupValue("data_path", relative_data_path);
- data_path = parent_path / relative_data_path;
- };
-
- configure_independent_database(root);
-
- configure_alone_gpg(root);
-
- dealing_private_keys(root);
- import_data();
- import_data_alone();
- }
-
- void TearDown() override {
- auto key_ids = std::make_unique<GpgFrontend::KeyIdArgsList>();
- key_ids->push_back("81704859182661FB");
- key_ids->push_back("06F1C7E7240C94E8");
- key_ids->push_back("8465C55B25C9B7D1");
- key_ids->push_back("021D89771B680FFB");
- GpgFrontend::GpgKeyOpera::GetInstance(default_channel)
- .DeleteKeys(std::move(key_ids));
- }
-
- private:
- void import_data() {
- for (const auto& secret_key : secret_keys_) {
- auto secret_key_copy =
- std::make_unique<GpgFrontend::ByteArray>(*secret_key);
- GpgFrontend::GpgKeyImportExporter::GetInstance(default_channel)
- .ImportKey(std::move(secret_key_copy));
- }
- }
-
- void import_data_alone() {
- for (auto& secret_key : secret_keys_) {
- auto secret_key_copy =
- std::make_unique<GpgFrontend::ByteArray>(*secret_key);
- GpgFrontend::GpgKeyImportExporter::GetInstance(gpg_alone_channel)
- .ImportKey(std::move(secret_key_copy));
- }
- }
-
- void dealing_private_keys(const libconfig::Setting& root) {
- if (root.exists("load_keys.private_keys")) {
- auto& private_keys = root.lookup("load_keys.private_keys");
- for (auto it = private_keys.begin(); it != private_keys.end(); it++) {
- if (it->exists("filename")) {
- std::string filename;
- it->lookupValue("filename", filename);
- auto data_file_path = data_path / filename;
- std::string data =
- GpgFrontend::read_all_data_in_file(data_file_path.string());
- secret_keys_.push_back(std::make_unique<std::string>(data));
- }
- }
- }
- }
-
- void configure_alone_gpg(const libconfig::Setting& root) {
- bool alone_gpg = false;
- if (root.exists("alone_gpg")) {
- root.lookupValue("alone_gpg", alone_gpg);
- if (alone_gpg && root.exists("alone_gpg")) {
- std::string alone_gpg_path;
- root.lookupValue("alone_gpg_path", alone_gpg_path);
- auto gpg_path = parent_path / alone_gpg_path;
-
- std::string relative_db_path;
- root.lookupValue("alone_gpg_db_path", relative_db_path);
- auto db_path = parent_path / relative_db_path;
- if (!boost::filesystem::exists(db_path)) {
- boost::filesystem::create_directory(db_path);
- } else {
- boost::filesystem::remove_all(db_path);
- boost::filesystem::create_directory(db_path);
- }
- GpgFrontend::GpgContext::CreateInstance(
- gpg_alone_channel,
- [&]() -> std::unique_ptr<GpgFrontend::GpgContext> {
- GpgFrontend::GpgContextInitArgs args;
- args.gpg_alone = true;
- args.independent_database = true;
- args.db_path = db_path.u8string();
- args.gpg_path = gpg_path.u8string();
- args.test_mode = true;
- return std::make_unique<GpgFrontend::GpgContext>(args);
- });
- }
- }
- }
-
- void configure_independent_database(const libconfig::Setting& root) {
- bool independent_database = false;
- if (root.exists("independent_database")) {
- root.lookupValue("independent_database", independent_database);
- if (independent_database && root.exists("independent_db_path")) {
- std::string relative_db_path;
- root.lookupValue("independent_db_path", relative_db_path);
- auto db_path = parent_path / relative_db_path;
- if (!boost::filesystem::exists(db_path)) {
- boost::filesystem::create_directory(db_path);
- } else {
- boost::filesystem::remove_all(db_path);
- boost::filesystem::create_directory(db_path);
- }
-
- GpgFrontend::GpgContext::CreateInstance(
- default_channel, [&]() -> std::unique_ptr<GpgFrontend::GpgContext> {
- GpgFrontend::GpgContextInitArgs args;
- args.test_mode = true;
- return std::make_unique<GpgFrontend::GpgContext>(args);
- });
- }
- }
- }
-};
-
-#endif // _GPGFRONTENDTEST_H
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 0fdc8a16..4ad901c2 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -31,4 +31,7 @@ add_subdirectory(json EXCLUDE_FROM_ALL)
add_subdirectory(spdlog EXCLUDE_FROM_ALL)
set(MI_SECURE ON)
-add_subdirectory(mimalloc EXCLUDE_FROM_ALL) \ No newline at end of file
+add_subdirectory(mimalloc EXCLUDE_FROM_ALL)
+
+set(INSTALL_GTEST OFF)
+add_subdirectory(googletest EXCLUDE_FROM_ALL) \ No newline at end of file
diff --git a/third_party/googletest b/third_party/googletest
new file mode 160000
+Subproject b3a9ba2b8e975550799838332803d468797ae2e