fix: refactoring and portability — issues #61, #51, #52

This commit is contained in:
2026-07-20 18:01:23 +02:00
parent 504a3a4d4f
commit f256e468a1
28 changed files with 877 additions and 70 deletions
+91
View File
@@ -0,0 +1,91 @@
#include "test_multiprocessing.h"
#include "multiprocessing.h"
#include "config.h"
#include "queue.h"
#include "utils.h"
#include "test_utils.h"
#include <stdlib.h>
#include <string.h>
static void test_pipeline_context_sender_create_destroy() {
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
false, false, false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg);
Queue* q_scanner = queue_create(10, free);
EXPECT_NOT_NULL(q_scanner);
Queue* q_loader = queue_create(10, free);
EXPECT_NOT_NULL(q_loader);
PipelineContextSender* ctx = pipeline_context_sender_create(cfg, q_scanner, q_loader);
EXPECT_NOT_NULL(ctx);
EXPECT_EQ_INT(ctx->scanner_done, false);
EXPECT_EQ_INT(ctx->loader_done, false);
EXPECT_NULL(ctx->manifest);
pipeline_context_sender_destroy(ctx);
// cfg, q_scanner, q_loader are destroyed by pipeline_context_sender_destroy
}
static void test_pipeline_context_sender_create_null_config() {
// Passing NULL config to pipeline_context_sender_create - it will be used
// and destroyed, so this should be tested carefully.
Queue* q_scanner = queue_create(10, free);
EXPECT_NOT_NULL(q_scanner);
Queue* q_loader = queue_create(10, free);
EXPECT_NOT_NULL(q_loader);
PipelineContextSender* ctx = pipeline_context_sender_create(NULL, q_scanner, q_loader);
EXPECT_NOT_NULL(ctx);
EXPECT_NULL(ctx->config);
// Destroy without config - config_delete(NULL) should be safe
pipeline_context_sender_destroy(ctx);
}
static void test_pipeline_context_sender_destroy_null() {
pipeline_context_sender_destroy(NULL);
}
static void test_pipeline_context_receiver_create_destroy() {
Config* cfg = config_create(str_dup(PROTOCOL_VERSION), str_dup("/tmp"), str_dup("/tmp"), false,
false, false, false, false, 0, false, 0);
EXPECT_NOT_NULL(cfg);
Queue* q = queue_create(10, free);
EXPECT_NOT_NULL(q);
PipelineContextReceiver* ctx = pipeline_context_receiver_create(cfg, q, 42);
EXPECT_NOT_NULL(ctx);
EXPECT_EQ_INT(ctx->file_descriptor, 42);
EXPECT_EQ_INT(ctx->receiver_done, false);
pipeline_context_receiver_destroy(ctx);
// cfg, q are destroyed by pipeline_context_receiver_destroy
}
static void test_pipeline_context_receiver_create_null_config() {
Queue* q = queue_create(10, free);
EXPECT_NOT_NULL(q);
PipelineContextReceiver* ctx = pipeline_context_receiver_create(NULL, q, -1);
EXPECT_NOT_NULL(ctx);
EXPECT_NULL(ctx->config);
EXPECT_EQ_INT(ctx->file_descriptor, -1);
pipeline_context_receiver_destroy(ctx);
}
static void test_pipeline_context_receiver_destroy_null() {
pipeline_context_receiver_destroy(NULL);
}
void test_multiprocessing() {
test_pipeline_context_sender_create_destroy();
test_pipeline_context_sender_create_null_config();
test_pipeline_context_sender_destroy_null();
test_pipeline_context_receiver_create_destroy();
test_pipeline_context_receiver_create_null_config();
test_pipeline_context_receiver_destroy_null();
}