aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2024-11-25 13:39:35 +0000
committersaturneric <[email protected]>2024-11-25 13:39:35 +0000
commit50e2d5cb3deaf3359a68ceaebdaa2abdb2142fd6 (patch)
treeff0dc0b571bfeb8d3431c239bbffefce3fbb7300
parenttest: fix and add KeyGen & SubkeyGen test cases (diff)
downloadGpgFrontend-50e2d5cb3deaf3359a68ceaebdaa2abdb2142fd6.tar.gz
GpgFrontend-50e2d5cb3deaf3359a68ceaebdaa2abdb2142fd6.zip
fix: solve a race situation at unit test mode
-rw-r--r--src/GpgFrontendContext.h2
-rw-r--r--src/core/GpgCoreInit.cpp2
-rw-r--r--src/init.cpp20
-rw-r--r--src/init.h7
-rw-r--r--src/main.cpp7
5 files changed, 32 insertions, 6 deletions
diff --git a/src/GpgFrontendContext.h b/src/GpgFrontendContext.h
index 3e5947f5..ae3177aa 100644
--- a/src/GpgFrontendContext.h
+++ b/src/GpgFrontendContext.h
@@ -44,7 +44,7 @@ struct GpgFrontendContext {
char** argv;
bool gather_external_gnupg_info;
- bool load_default_gpg_context;
+ bool unit_test_mode;
/**
* @brief Construct a new Gpg Frontend Context object
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp
index 8a625f9d..bb0b75fe 100644
--- a/src/core/GpgCoreInit.cpp
+++ b/src/core/GpgCoreInit.cpp
@@ -484,7 +484,7 @@ auto InitGpgFrontendCore(CoreInitArgs args) -> int {
settings.value("gnupg/restart_gpg_agent_on_start", false).toBool();
// unit test mode
- if (!args.unit_test_mode) {
+ if (args.unit_test_mode) {
Module::UpsertRTValue("core", "env.state.basic", 1);
Module::UpsertRTValue("core", "env.state.all", 1);
CoreSignalStation::GetInstance()->SignalGoodGnupgEnv();
diff --git a/src/init.cpp b/src/init.cpp
index 59cd8a32..2c421040 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -29,6 +29,7 @@
#include "init.h"
#include "core/GpgCoreInit.h"
+#include "core/function/CoreSignalStation.h"
#include "core/function/GlobalSettingStation.h"
#include "core/function/gpg/GpgAdvancedOperator.h"
#include "core/module/ModuleInit.h"
@@ -127,7 +128,7 @@ void InitGlobalBasicEnv(const GFCxtWPtr &p_ctx, bool gui_mode) {
CoreInitArgs core_init_args;
core_init_args.gather_external_gnupg_info = ctx->gather_external_gnupg_info;
- core_init_args.unit_test_mode = ctx->load_default_gpg_context;
+ core_init_args.unit_test_mode = ctx->unit_test_mode;
InitGpgFrontendCoreAsync(core_init_args);
@@ -159,6 +160,23 @@ void InitLocale() {
QLocale::setDefault(target_locale);
}
+void InitGlobalBasicEnvSync(const GFCxtWPtr &p_ctx) {
+ QEventLoop loop;
+ QCoreApplication::connect(CoreSignalStation::GetInstance(),
+ &CoreSignalStation::SignalGoodGnupgEnv, &loop,
+ &QEventLoop::quit);
+ InitGlobalBasicEnv(p_ctx, false);
+
+ auto env_state =
+ Module::RetrieveRTValueTypedOrDefault<>("core", "env.state.all", 0);
+ if (env_state == 1) {
+ qDebug() << "global basic env initialized before the event loop start";
+ return;
+ }
+
+ loop.exec();
+}
+
void ShutdownGlobalBasicEnv(const GFCxtWPtr &p_ctx) {
GFCxtSPtr ctx = p_ctx.lock();
if (ctx == nullptr) {
diff --git a/src/init.h b/src/init.h
index 2adc3488..94a64004 100644
--- a/src/init.h
+++ b/src/init.h
@@ -56,6 +56,13 @@ void InitGlobalBasicEnv(const GFCxtWPtr &, bool);
*
* @param p_ctx
*/
+void InitGlobalBasicEnvSync(const GFCxtWPtr &p_ctx);
+
+/**
+ * @brief
+ *
+ * @param p_ctx
+ */
void ShutdownGlobalBasicEnv(const GFCxtWPtr &p_ctx);
} // namespace GpgFrontend \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index fbd53649..040269fb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -102,16 +102,17 @@ auto main(int argc, char* argv[]) -> int {
if (parser.isSet("t")) {
ctx->gather_external_gnupg_info = false;
- ctx->load_default_gpg_context = false;
+ ctx->unit_test_mode = true;
- InitGlobalBasicEnv(ctx, false);
+ InitGlobalBasicEnvSync(ctx);
rtn = RunTest(ctx);
ShutdownGlobalBasicEnv(ctx);
return rtn;
}
ctx->gather_external_gnupg_info = true;
- ctx->load_default_gpg_context = true;
+ ctx->unit_test_mode = false;
+
InitGlobalBasicEnv(ctx, true);
rtn = StartApplication(ctx);