aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-01-12 15:08:38 +0000
committersaturneric <[email protected]>2024-01-12 15:08:38 +0000
commit6983b5c1dd82d159236ebd06cf17f071cc9c1ee9 (patch)
treefc53f790e33546320b2ecd306a1a9ade6fbdfe7a /src/test
parentfix: slove a heap-use-after-free issue (diff)
downloadGpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.tar.gz
GpgFrontend-6983b5c1dd82d159236ebd06cf17f071cc9c1ee9.zip
refactor: remove boost and use QString instead of std::filesystem::path
Diffstat (limited to 'src/test')
-rw-r--r--src/test/GpgFrontendTest.cpp20
-rw-r--r--src/test/core/GpgCoreTest.h2
-rw-r--r--src/test/core/GpgCoreTestFileBasicOpera.cpp17
-rw-r--r--src/test/core/GpgCoreTestKeyModel.cpp19
-rw-r--r--src/test/core/GpgCoreTestKeygen.cpp6
5 files changed, 29 insertions, 35 deletions
diff --git a/src/test/GpgFrontendTest.cpp b/src/test/GpgFrontendTest.cpp
index b7f59336..34698863 100644
--- a/src/test/GpgFrontendTest.cpp
+++ b/src/test/GpgFrontendTest.cpp
@@ -30,10 +30,6 @@
#include <gtest/gtest.h>
-#include <boost/date_time.hpp>
-#include <boost/dll.hpp>
-#include <filesystem>
-
#include "core/GpgConstants.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/basic/ChannelObject.h"
@@ -64,7 +60,7 @@ void ConfigureGpgContext() {
db_path.path());
if (db_path.exists()) db_path.rmdir(".");
- db_path.mkdir(".");
+ db_path.mkpath(".");
GpgContext::CreateInstance(
kGpgFrontendDefaultChannel, [=]() -> ChannelObjectPtr {
@@ -103,18 +99,18 @@ void ImportPrivateKeys(const QString& data_path,
void SetupGlobalTestEnv() {
auto app_path = GlobalSettingStation::GetInstance().GetAppDir();
- auto test_path = app_path / "test";
- auto test_config_path = test_path / "conf" / "test.cfg";
- auto test_data_path = test_path / "data";
+ auto test_path = app_path + "/test";
+ auto test_config_path = test_path + "/conf/test.cfg";
+ auto test_data_path = test_path + "/data";
- GF_TEST_LOG_INFO("test config file path: {}", test_config_path.string());
- GF_TEST_LOG_INFO("test data file path: {}", test_data_path.string());
+ GF_TEST_LOG_INFO("test config file path: {}", test_config_path);
+ GF_TEST_LOG_INFO("test data file path: {}", test_data_path);
libconfig::Config cfg;
- ASSERT_NO_THROW(cfg.readFile(test_config_path.c_str()));
+ ASSERT_NO_THROW(cfg.readFile(test_config_path.toUtf8()));
auto& root = cfg.getRoot();
- ImportPrivateKeys(test_data_path.c_str(), root);
+ ImportPrivateKeys(test_data_path, root);
}
auto ExecuteAllTestCase(GpgFrontendContext args) -> int {
diff --git a/src/test/core/GpgCoreTest.h b/src/test/core/GpgCoreTest.h
index b436118a..26097f2c 100644
--- a/src/test/core/GpgCoreTest.h
+++ b/src/test/core/GpgCoreTest.h
@@ -30,8 +30,6 @@
#include <gtest/gtest.h>
-#include <boost/date_time.hpp>
-
namespace GpgFrontend::Test {
class GpgCoreTest : public ::testing::Test {
diff --git a/src/test/core/GpgCoreTestFileBasicOpera.cpp b/src/test/core/GpgCoreTestFileBasicOpera.cpp
index e409570f..029ff6fc 100644
--- a/src/test/core/GpgCoreTestFileBasicOpera.cpp
+++ b/src/test/core/GpgCoreTestFileBasicOpera.cpp
@@ -51,7 +51,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptDecrTest) {
auto output_file = GetTempFilePath();
GpgFileOpera::GetInstance().EncryptFile(
- {encrypt_key}, input_file.toStdString(), true, output_file.toStdString(),
+ {encrypt_key}, input_file, true, output_file,
[output_file, &callback_called_flag](GpgError err,
const DataObjectPtr& data_obj) {
ASSERT_TRUE((data_obj->Check<GpgEncryptResult>()));
@@ -62,7 +62,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptDecrTest) {
auto decrpypt_output_file = GetTempFilePath();
GpgFileOpera::GetInstance().DecryptFile(
- output_file.toStdString(), decrpypt_output_file.toStdString(),
+ output_file, decrpypt_output_file,
[decrpypt_output_file, &callback_called_flag](
GpgError err, const DataObjectPtr& data_obj) {
auto d_result = ExtractParams<GpgDecryptResult>(data_obj, 0);
@@ -96,7 +96,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSymmetricDecrTest) {
auto output_file = GetTempFilePath();
GpgFileOpera::GetInstance().EncryptFileSymmetric(
- input_file.toStdString(), true, output_file.toStdString(),
+ input_file, true, output_file,
[&callback_called_flag, output_file](GpgError err,
const DataObjectPtr& data_obj) {
ASSERT_TRUE((data_obj->Check<GpgEncryptResult>()));
@@ -106,7 +106,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSymmetricDecrTest) {
auto decrpypt_output_file = GetTempFilePath();
GpgFileOpera::GetInstance().DecryptFile(
- output_file.toStdString(), decrpypt_output_file.toStdString(),
+ output_file, decrpypt_output_file,
[&callback_called_flag, decrpypt_output_file](
GpgError err, const DataObjectPtr& data_obj) {
ASSERT_TRUE((data_obj->Check<GpgDecryptResult>()));
@@ -143,7 +143,7 @@ TEST_F(GpgCoreTest, CoreFileSignVerifyNormalTest) {
auto output_file = GetTempFilePath();
GpgFileOpera::GetInstance().SignFile(
- {sign_key}, input_file.toStdString(), true, output_file.toStdString(),
+ {sign_key}, input_file, true, output_file,
[&callback_called_flag, input_file, output_file](
GpgError err, const DataObjectPtr& data_obj) {
ASSERT_TRUE((data_obj->Check<GpgSignResult>()));
@@ -152,7 +152,7 @@ TEST_F(GpgCoreTest, CoreFileSignVerifyNormalTest) {
ASSERT_EQ(CheckGpgError(err), GPG_ERR_NO_ERROR);
GpgFileOpera::GetInstance().VerifyFile(
- input_file.toStdString(), output_file.toStdString(),
+ input_file, output_file,
[&callback_called_flag](GpgError err,
const DataObjectPtr& data_obj) {
auto d_result = ExtractParams<GpgVerifyResult>(data_obj, 0);
@@ -188,8 +188,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) {
ASSERT_TRUE(sign_key.IsHasActualSigningCapability());
GpgFileOpera::GetInstance().EncryptSignFile(
- {encrypt_key}, {sign_key}, input_file.toStdString(), true,
- output_file.toStdString(),
+ {encrypt_key}, {sign_key}, input_file, true, output_file,
[&callback_called_flag, output_file](GpgError err,
const DataObjectPtr& data_obj) {
ASSERT_TRUE((data_obj->Check<GpgEncryptResult, GpgSignResult>()));
@@ -201,7 +200,7 @@ TEST_F(GpgCoreTest, CoreFileEncryptSignDecrVerifyTest) {
auto decrpypt_output_file = GetTempFilePath();
GpgFileOpera::GetInstance().DecryptVerifyFile(
- output_file.toStdString(), decrpypt_output_file.toStdString(),
+ output_file, decrpypt_output_file,
[&callback_called_flag, decrpypt_output_file](
GpgError err, const DataObjectPtr& data_obj) {
ASSERT_TRUE(
diff --git a/src/test/core/GpgCoreTestKeyModel.cpp b/src/test/core/GpgCoreTestKeyModel.cpp
index 1f3a5292..cf1fd9ea 100644
--- a/src/test/core/GpgCoreTestKeyModel.cpp
+++ b/src/test/core/GpgCoreTestKeyModel.cpp
@@ -84,18 +84,18 @@ TEST_F(GpgCoreTest, GpgKeyTest) {
ASSERT_EQ(key.GetId(), "81704859182661FB");
ASSERT_EQ(key.GetFingerprint(), "9490795B78F8AFE9F93BD09281704859182661FB");
ASSERT_EQ(key.GetExpireTime(),
- boost::posix_time::from_iso_string("20230905T040000"));
+ QDateTime::fromString("20230905T040000", Qt::ISODate));
ASSERT_EQ(key.GetPublicKeyAlgo(), "RSA");
ASSERT_EQ(key.GetPrimaryKeyLength(), 3072);
ASSERT_EQ(key.GetLastUpdateTime(),
- boost::posix_time::from_iso_string("19700101T000000"));
+ QDateTime::fromString("19700101T000000", Qt::ISODate));
ASSERT_EQ(key.GetCreateTime(),
- boost::posix_time::from_iso_string("20210905T060153"));
+ QDateTime::fromString("20210905T060153", Qt::ISODate));
ASSERT_EQ(key.GetOwnerTrust(), "Unknown");
- ASSERT_EQ(key.IsExpired(), key.GetExpireTime() <
- boost::posix_time::second_clock::local_time());
+ ASSERT_EQ(key.IsExpired(),
+ key.GetExpireTime() < QDateTime::currentDateTime());
}
TEST_F(GpgCoreTest, GpgSubKeyTest) {
@@ -109,7 +109,7 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) {
ASSERT_FALSE(sub_key.IsRevoked());
ASSERT_FALSE(sub_key.IsDisabled());
ASSERT_EQ(sub_key.GetCreateTime(),
- boost::posix_time::from_iso_string("20210905T060153"));
+ QDateTime::fromString("20210905T060153", Qt::ISODate));
ASSERT_FALSE(sub_key.IsCardKey());
ASSERT_TRUE(sub_key.IsPrivateKey());
@@ -123,11 +123,10 @@ TEST_F(GpgCoreTest, GpgSubKeyTest) {
ASSERT_FALSE(sub_key.IsHasSigningCapability());
ASSERT_TRUE(sub_key.IsHasEncryptionCapability());
ASSERT_EQ(key.GetExpireTime(),
- boost::posix_time::from_iso_string("20230905T040000"));
+ QDateTime::fromString("20230905T040000", Qt::ISODate));
- ASSERT_EQ(
- sub_key.IsExpired(),
- sub_key.GetExpireTime() < boost::posix_time::second_clock::local_time());
+ ASSERT_EQ(sub_key.IsExpired(),
+ sub_key.GetExpireTime() < QDateTime::currentDateTime());
}
TEST_F(GpgCoreTest, GpgUIDTest) {
diff --git a/src/test/core/GpgCoreTestKeygen.cpp b/src/test/core/GpgCoreTestKeygen.cpp
index 93544d85..57e7cbb9 100644
--- a/src/test/core/GpgCoreTestKeygen.cpp
+++ b/src/test/core/GpgCoreTestKeygen.cpp
@@ -29,6 +29,8 @@
#include <gtest/gtest.h>
#include <qeventloop.h>
+#include <cstddef>
+
#include "GpgCoreTest.h"
#include "core/function/gpg/GpgKeyGetter.h"
#include "core/function/gpg/GpgKeyOpera.h"
@@ -92,8 +94,8 @@ TEST_F(GpgCoreTest, GenerateKeyTest_1) {
keygen_info->SetAlgo(std::get<1>(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->SetExpireTime(
+ QDateTime::currentDateTime().addSecs(static_cast<qint64>(24 * 3600)));
keygen_info->SetNonPassPhrase(false);
std::atomic_bool callback_called_flag{false};