test: cover compression option equals forms
CI / lint (pull_request) Successful in 11s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 37s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 33s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 33s
CI / lint (pull_request) Successful in 11s
CI / sanitizers (address) (pull_request) Successful in 37s
CI / sanitizers (undefined) (pull_request) Successful in 37s
CI / fuzz-build (pull_request) Successful in 15s
CI / coverage (pull_request) Successful in 33s
CI / build-and-test (pull_request) Successful in 1m16s
CI / valgrind (pull_request) Successful in 33s
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -370,6 +371,52 @@ static void test_parse_args_compression_equals_and_none() {
|
|||||||
config_delete(cfg);
|
config_delete(cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_parse_args_compression_canonical_equals() {
|
||||||
|
Config* cfg = config_create();
|
||||||
|
char* argv[] = {"fastsync", "--compress-choice=zstd", "--compress-level=7", "/src", "/dst"};
|
||||||
|
int positional_args[2];
|
||||||
|
int positional_count = 0;
|
||||||
|
|
||||||
|
EXPECT_EQ_INT(parse_args(cfg, 5, argv, positional_args, &positional_count), 0);
|
||||||
|
EXPECT_EQ_STR(cfg->compress_choice, "zstd");
|
||||||
|
EXPECT_EQ_INT(cfg->compression_level, 7);
|
||||||
|
EXPECT_TRUE(cfg->use_compression);
|
||||||
|
EXPECT_EQ_INT(positional_count, 2);
|
||||||
|
|
||||||
|
config_delete(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_parse_args_compression_alias_equals() {
|
||||||
|
Config* cfg = config_create();
|
||||||
|
char* argv[] = {"fastsync", "--zc=zstd", "--zl=7", "/src", "/dst"};
|
||||||
|
int positional_args[2];
|
||||||
|
int positional_count = 0;
|
||||||
|
|
||||||
|
EXPECT_EQ_INT(parse_args(cfg, 5, argv, positional_args, &positional_count), 0);
|
||||||
|
EXPECT_EQ_STR(cfg->compress_choice, "zstd");
|
||||||
|
EXPECT_EQ_INT(cfg->compression_level, 7);
|
||||||
|
EXPECT_TRUE(cfg->use_compression);
|
||||||
|
EXPECT_EQ_INT(positional_count, 2);
|
||||||
|
|
||||||
|
config_delete(cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_parse_args_rejects_invalid_compression_level_equals() {
|
||||||
|
static const char* const values[] = {"0", "23", "invalid"};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); i++) {
|
||||||
|
Config* cfg = config_create();
|
||||||
|
char option[32];
|
||||||
|
snprintf(option, sizeof(option), "--compress-level=%s", values[i]);
|
||||||
|
char* argv[] = {"fastsync", option, "/src", "/dst"};
|
||||||
|
int positional_args[2];
|
||||||
|
int positional_count = 0;
|
||||||
|
|
||||||
|
EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), -1);
|
||||||
|
config_delete(cfg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void test_parse_args_rejects_invalid_compression_choice() {
|
static void test_parse_args_rejects_invalid_compression_choice() {
|
||||||
Config* cfg = config_create();
|
Config* cfg = config_create();
|
||||||
char* argv[] = {"fastsync", "--compress-choice=bogus", "/src", "/dst"};
|
char* argv[] = {"fastsync", "--compress-choice=bogus", "/src", "/dst"};
|
||||||
@@ -403,5 +450,8 @@ void test_client_cli() {
|
|||||||
test_parse_args_archive();
|
test_parse_args_archive();
|
||||||
test_parse_args_compression_aliases();
|
test_parse_args_compression_aliases();
|
||||||
test_parse_args_compression_equals_and_none();
|
test_parse_args_compression_equals_and_none();
|
||||||
|
test_parse_args_compression_canonical_equals();
|
||||||
|
test_parse_args_compression_alias_equals();
|
||||||
|
test_parse_args_rejects_invalid_compression_level_equals();
|
||||||
test_parse_args_rejects_invalid_compression_choice();
|
test_parse_args_rejects_invalid_compression_choice();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user