diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-13 01:18:44 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-13 01:18:44 +0300 |
commit | 0a770cbaf0c9509415e6dabf880bf75d25a02606 (patch) | |
tree | 797c09e7e80bbee0e4af96d572684ac7cc4dff6d /cli/cli-test.c | |
parent | 0a8ee7a194e598d9c277b019503f7119b32bd17f (diff) | |
download | c-wares-0a770cbaf0c9509415e6dabf880bf75d25a02606.tar.gz c-wares-0a770cbaf0c9509415e6dabf880bf75d25a02606.zip |
cli: header with extra option implementations
For now just one, `struct cli_opt_data_size`.
Diffstat (limited to 'cli/cli-test.c')
-rw-r--r-- | cli/cli-test.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/cli/cli-test.c b/cli/cli-test.c index c7a74e9..3a89f53 100644 --- a/cli/cli-test.c +++ b/cli/cli-test.c @@ -1,4 +1,5 @@ #include "cli.h" +#include "cli-opts.h" #include "../utest/utest.h" #include "../utils.h" @@ -48,6 +49,33 @@ static void reset_opts(void) copt.value = 0; } +TEST_BEGIN(test_cli_opt_data_size_set) +{ + CLI_OPT_DATA_SIZE(opt, 0, NULL, NULL); + struct tcase { + const char *input; + uint64_t expected_val; + enum cli_rc expected_rc; + } cases[] = { + {"420", 420, CLI_RC_OK}, + {"4K", 4ull << 10, CLI_RC_OK}, + {"8M", 8ull << 20, CLI_RC_OK}, + {"12G", 12ull << 30, CLI_RC_OK}, + {"1T", 1ull << 40, CLI_RC_OK}, + {"1E", 0, CLI_RC_ERR}, + {"6m", 6ull << 20, CLI_RC_OK}, + {"16k", 16ull << 10, CLI_RC_OK}, + }; + for (size_t i = 0; i < ARRAY_SIZE(cases); i++) { + opt.bytes = 0; + int rc = opt.opt.set(&opt.opt, cases[i].input); + asserteq(rc, cases[i].expected_rc); + asserteq(opt.bytes, cases[i].expected_val); + } + TEST_OUT +} +TEST_END + TEST_BEGIN(test_parse_long) { struct tcase { @@ -441,4 +469,7 @@ TEST_BEGIN(test_parse_options) } TEST_END -RUN_TESTS(test_parse_long, test_parse_short, test_parse_options) +RUN_TESTS(test_cli_opt_data_size_set, + test_parse_long, + test_parse_short, + test_parse_options) |