cleanup: remove dead code, fix bugs, refactor SSH dest parsing
- Remove debug printf calls from file.c - Remove dead code: chunk_print, chunk_format, chunk_data_create/delete - Remove unused config.use_single_send_per_file field - Fix server_delete() no-op (double-pointer) - Fix double cast (long)(long) -> ptrdiff_t in chunk.c - Fix thread return value: thrd_error instead of 1 - Remove unused config param from receive_chunk_enqueue() - Make queue_double_capacity() static - Move SSH dest parsing into config.c as config_parse_ssh_dest() - Fix test_config_ssh_dest to test parsing round-trip - Remove chunk_format test (obsolete format) - Replace chunk_data_delete with data_destroy in tests
This commit is contained in:
+1
-69
@@ -80,77 +80,9 @@ static void test_chunk_operations() {
|
||||
EXPECT_EQ_INT(memcmp(deserialized->items[0]->data->data, content1, len1), 0);
|
||||
EXPECT_EQ_INT(memcmp(deserialized->items[1]->data->data, content2, len2), 0);
|
||||
|
||||
chunk_data_delete(serialized);
|
||||
data_destroy(serialized);
|
||||
chunk_destroy(deserialized);
|
||||
|
||||
// Test chunk_format layout (old format)
|
||||
Data *formatted = chunk_format(chunk);
|
||||
EXPECT_NOT_NULL(formatted);
|
||||
|
||||
unsigned long long expected_size =
|
||||
(sizeof(int) + strlen(path1) + sizeof(int) + sizeof(unsigned long long) + len1) +
|
||||
(sizeof(int) + strlen(path2) + sizeof(int) + sizeof(unsigned long long) + len2);
|
||||
EXPECT_EQ_INT((int)formatted->size, (int)expected_size);
|
||||
|
||||
char *ptr = (char *)formatted->data;
|
||||
|
||||
// File 1
|
||||
int p_len1;
|
||||
memcpy(&p_len1, ptr, sizeof(int));
|
||||
ptr += sizeof(int);
|
||||
EXPECT_EQ_INT(p_len1, (int)strlen(path1));
|
||||
|
||||
char read_path1[256];
|
||||
memcpy(read_path1, ptr, p_len1);
|
||||
read_path1[p_len1] = '\0';
|
||||
ptr += p_len1;
|
||||
EXPECT_EQ_STR(read_path1, path1);
|
||||
|
||||
int meta_present1;
|
||||
memcpy(&meta_present1, ptr, sizeof(int));
|
||||
ptr += sizeof(int);
|
||||
EXPECT_EQ_INT(meta_present1, 0);
|
||||
|
||||
unsigned long long d_len1;
|
||||
memcpy(&d_len1, ptr, sizeof(unsigned long long));
|
||||
ptr += sizeof(unsigned long long);
|
||||
EXPECT_EQ_INT((int)d_len1, (int)len1);
|
||||
|
||||
char read_content1[256];
|
||||
memcpy(read_content1, ptr, d_len1);
|
||||
read_content1[d_len1] = '\0';
|
||||
ptr += d_len1;
|
||||
EXPECT_EQ_STR(read_content1, content1);
|
||||
|
||||
// File 2
|
||||
int p_len2;
|
||||
memcpy(&p_len2, ptr, sizeof(int));
|
||||
ptr += sizeof(int);
|
||||
EXPECT_EQ_INT(p_len2, (int)strlen(path2));
|
||||
|
||||
char read_path2[256];
|
||||
memcpy(read_path2, ptr, p_len2);
|
||||
read_path2[p_len2] = '\0';
|
||||
ptr += p_len2;
|
||||
EXPECT_EQ_STR(read_path2, path2);
|
||||
|
||||
int meta_present2;
|
||||
memcpy(&meta_present2, ptr, sizeof(int));
|
||||
ptr += sizeof(int);
|
||||
EXPECT_EQ_INT(meta_present2, 0);
|
||||
|
||||
unsigned long long d_len2;
|
||||
memcpy(&d_len2, ptr, sizeof(unsigned long long));
|
||||
ptr += sizeof(unsigned long long);
|
||||
EXPECT_EQ_INT((int)d_len2, (int)len2);
|
||||
|
||||
char read_content2[256];
|
||||
memcpy(read_content2, ptr, d_len2);
|
||||
read_content2[d_len2] = '\0';
|
||||
ptr += d_len2;
|
||||
EXPECT_EQ_STR(read_content2, content2);
|
||||
|
||||
chunk_data_delete(formatted);
|
||||
chunk_destroy(chunk);
|
||||
|
||||
unlink(path1);
|
||||
|
||||
+28
-3
@@ -26,12 +26,35 @@ static void test_config_lifecycle() {
|
||||
static void test_config_ssh_dest() {
|
||||
Config *cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("user@host:/dst"),
|
||||
true, false, false, false, false, 1, 4, false);
|
||||
cfg->transport = TRANSPORT_SSH;
|
||||
cfg->ssh_destination = str_dup("user@host:/dst");
|
||||
EXPECT_NOT_NULL(cfg);
|
||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
||||
EXPECT_NULL(cfg->ssh_destination);
|
||||
EXPECT_EQ_STR(cfg->receive_root_directory, "user@host:/dst");
|
||||
|
||||
config_parse_ssh_dest(cfg);
|
||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_SSH);
|
||||
EXPECT_EQ_STR(cfg->ssh_destination, "user@host:/dst");
|
||||
EXPECT_EQ_STR(cfg->receive_root_directory, "user@host:/dst");
|
||||
EXPECT_EQ_STR(cfg->receive_root_directory, "/dst");
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_config_ssh_dest_local_path() {
|
||||
Config *cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("/local/path"),
|
||||
true, false, false, false, false, 1, 4, false);
|
||||
config_parse_ssh_dest(cfg);
|
||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_TCP);
|
||||
EXPECT_NULL(cfg->ssh_destination);
|
||||
EXPECT_EQ_STR(cfg->receive_root_directory, "/local/path");
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
static void test_config_ssh_dest_no_user() {
|
||||
Config *cfg = config_create(str_dup("1.0"), str_dup("/src"), str_dup("host:/remote"),
|
||||
true, false, false, false, false, 1, 4, false);
|
||||
config_parse_ssh_dest(cfg);
|
||||
EXPECT_EQ_INT(cfg->transport, TRANSPORT_SSH);
|
||||
EXPECT_EQ_STR(cfg->ssh_destination, "host:/remote");
|
||||
EXPECT_EQ_STR(cfg->receive_root_directory, "/remote");
|
||||
config_delete(cfg);
|
||||
}
|
||||
|
||||
@@ -70,6 +93,8 @@ static void test_pipeline_receiver_lifecycle() {
|
||||
void test_config() {
|
||||
test_config_lifecycle();
|
||||
test_config_ssh_dest();
|
||||
test_config_ssh_dest_local_path();
|
||||
test_config_ssh_dest_no_user();
|
||||
test_pipeline_sender_lifecycle();
|
||||
test_pipeline_receiver_lifecycle();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user