summaryrefslogtreecommitdiff
path: root/tests/unit_tests/openvpn/test_argv.c
diff options
context:
space:
mode:
authorBernhard Schmidt <berni@debian.org>2020-09-01 16:52:17 +0200
committerBernhard Schmidt <berni@debian.org>2020-09-01 16:52:17 +0200
commit9fc3b98112217f2d92a67977dbde0987cc7a1803 (patch)
tree29fcc8654ee65d9dd89ade797bea2f3d9dfd9cfd /tests/unit_tests/openvpn/test_argv.c
parenta8758c0e03eed188dcb9da0e4fd781a67c25bf1e (diff)
parent69b02b1f7fd609d84ace13ab04697158de2418a9 (diff)
Merge branch 'debian/experimental-2.5'
Diffstat (limited to 'tests/unit_tests/openvpn/test_argv.c')
-rw-r--r--tests/unit_tests/openvpn/test_argv.c123
1 files changed, 106 insertions, 17 deletions
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c
index 0fdd3f0..3dc470a 100644
--- a/tests/unit_tests/openvpn/test_argv.c
+++ b/tests/unit_tests/openvpn/test_argv.c
@@ -9,6 +9,7 @@
#include <setjmp.h>
#include <cmocka.h>
#include <assert.h>
+#include <stdbool.h>
#include "argv.h"
#include "buffer.h"
@@ -38,7 +39,7 @@ argv_printf__multiple_spaces_in_format__parsed_as_one(void **state)
argv_printf(&a, " %s %s %d ", PATH1, PATH2, 42);
assert_int_equal(a.argc, 3);
- argv_reset(&a);
+ argv_free(&a);
}
static void
@@ -50,7 +51,30 @@ argv_printf_cat__multiple_spaces_in_format__parsed_as_one(void **state)
argv_printf_cat(&a, " %s %s", PATH2, PARAM1);
assert_int_equal(a.argc, 3);
- argv_reset(&a);
+ argv_free(&a);
+}
+
+static void
+argv_printf__embedded_format_directive__replaced_in_output(void **state)
+{
+ struct argv a = argv_new();
+
+ argv_printf(&a, "<p1:%s>", PATH1);
+ assert_int_equal(a.argc, 1);
+ assert_string_equal(a.argv[0], "<p1:" PATH1 ">");
+
+ argv_free(&a);
+}
+
+static void
+argv_printf__group_sep_in_arg__fail_no_ouput(void **state)
+{
+ struct argv a = argv_new();
+
+ assert_false(argv_printf(&a, "tool --do %s", "this\035--harmful"));
+ assert_int_equal(a.argc, 0);
+
+ argv_free(&a);
}
static void
@@ -58,16 +82,61 @@ argv_printf__combined_path_with_spaces__argc_correct(void **state)
{
struct argv a = argv_new();
- argv_printf(&a, "%s%sc", PATH1, PATH2);
+ argv_printf(&a, "%s%s", PATH1, PATH2);
assert_int_equal(a.argc, 1);
- argv_printf(&a, "%s%sc %d", PATH1, PATH2, 42);
+ argv_printf(&a, "%s%s %d", PATH1, PATH2, 42);
assert_int_equal(a.argc, 2);
- argv_printf(&a, "foo %s%sc %s x y", PATH2, PATH1, "foo");
+ argv_printf(&a, "foo %s%s %s x y", PATH2, PATH1, "foo");
assert_int_equal(a.argc, 5);
- argv_reset(&a);
+ argv_free(&a);
+}
+
+static void
+argv_printf__empty_parameter__argc_correct(void **state)
+{
+ struct argv a = argv_new();
+
+ argv_printf(&a, "%s", "");
+ assert_int_equal(a.argc, 1);
+
+ argv_printf(&a, "%s %s", PATH1, "");
+ assert_int_equal(a.argc, 2);
+
+ argv_printf(&a, "%s %s %s", PATH1, "", PARAM1);
+ assert_int_equal(a.argc, 3);
+
+ argv_printf(&a, "%s %s %s %s", PATH1, "", "", PARAM1);
+ assert_int_equal(a.argc, 4);
+
+ argv_printf(&a, "%s %s", "", PARAM1);
+ assert_int_equal(a.argc, 2);
+
+ argv_free(&a);
+}
+
+static void
+argv_printf__long_args__data_correct(void **state)
+{
+ int i;
+ struct argv a = argv_new();
+ const char *args[] = {
+ "good_tools_have_good_names_even_though_it_might_impair_typing",
+ "--long-opt=looooooooooooooooooooooooooooooooooooooooooooooooong",
+ "--long-cat=loooooooooooooooooooooooooooooooooooooooooooooooooooonger",
+ "file_with_very_descriptive_filename_that_leaves_no_questions_open.jpg.exe"
+ };
+
+ argv_printf(&a, "%s %s %s %s", args[0], args[1], args[2], args[3]);
+ assert_int_equal(a.argc, 4);
+ for (i = 0; i < a.argc; i++)
+ {
+ assert_string_equal(a.argv[i], args[i]);
+ }
+
+ argv_free(&a);
}
static void
@@ -78,7 +147,7 @@ argv_parse_cmd__command_string__argc_correct(void **state)
argv_parse_cmd(&a, SCRIPT_CMD);
assert_int_equal(a.argc, 3);
- argv_reset(&a);
+ argv_free(&a);
}
static void
@@ -90,7 +159,7 @@ argv_parse_cmd__command_and_extra_options__argc_correct(void **state)
argv_printf_cat(&a, "bar baz %d %s", 42, PATH1);
assert_int_equal(a.argc, 7);
- argv_reset(&a);
+ argv_free(&a);
}
static void
@@ -103,7 +172,21 @@ argv_printf_cat__used_twice__argc_correct(void **state)
argv_printf_cat(&a, "foo");
assert_int_equal(a.argc, 5);
- argv_reset(&a);
+ argv_free(&a);
+}
+
+static void
+argv_str__empty_argv__empty_output(void **state)
+{
+ struct argv a = argv_new();
+ struct gc_arena gc = gc_new();
+ const char *output;
+
+ output = argv_str(&a, &gc, PA_BRACKET);
+ assert_string_equal(output, "");
+
+ argv_free(&a);
+ gc_free(&gc);
}
static void
@@ -113,7 +196,7 @@ argv_str__multiple_argv__correct_output(void **state)
struct gc_arena gc = gc_new();
const char *output;
- argv_printf(&a, "%s%sc", PATH1, PATH2);
+ argv_printf(&a, "%s%s", PATH1, PATH2);
argv_printf_cat(&a, "%s", PARAM1);
argv_printf_cat(&a, "%s", PARAM2);
argv_printf_cat(&a, "%d", -1);
@@ -121,9 +204,9 @@ argv_str__multiple_argv__correct_output(void **state)
argv_printf_cat(&a, "%lu", 1L );
output = argv_str(&a, &gc, PA_BRACKET);
assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
- " [-1] [4294967295] [1]");
+ " [-1] [4294967295] [1]");
- argv_reset(&a);
+ argv_free(&a);
gc_free(&gc);
}
@@ -136,9 +219,9 @@ argv_insert_head__empty_argv__head_only(void **state)
b = argv_insert_head(&a, PATH1);
assert_int_equal(b.argc, 1);
assert_string_equal(b.argv[0], PATH1);
- argv_reset(&b);
+ argv_free(&b);
- argv_reset(&a);
+ argv_free(&a);
}
static void
@@ -151,7 +234,8 @@ argv_insert_head__non_empty_argv__head_added(void **state)
argv_printf(&a, "%s", PATH2);
b = argv_insert_head(&a, PATH1);
assert_int_equal(b.argc, a.argc + 1);
- for (i = 0; i < b.argc; i++) {
+ for (i = 0; i < b.argc; i++)
+ {
if (i == 0)
{
assert_string_equal(b.argv[i], PATH1);
@@ -161,9 +245,9 @@ argv_insert_head__non_empty_argv__head_added(void **state)
assert_string_equal(b.argv[i], a.argv[i - 1]);
}
}
- argv_reset(&b);
+ argv_free(&b);
- argv_reset(&a);
+ argv_free(&a);
}
int
@@ -172,10 +256,15 @@ main(void)
const struct CMUnitTest tests[] = {
cmocka_unit_test(argv_printf__multiple_spaces_in_format__parsed_as_one),
cmocka_unit_test(argv_printf_cat__multiple_spaces_in_format__parsed_as_one),
+ cmocka_unit_test(argv_printf__embedded_format_directive__replaced_in_output),
+ cmocka_unit_test(argv_printf__group_sep_in_arg__fail_no_ouput),
cmocka_unit_test(argv_printf__combined_path_with_spaces__argc_correct),
+ cmocka_unit_test(argv_printf__empty_parameter__argc_correct),
+ cmocka_unit_test(argv_printf__long_args__data_correct),
cmocka_unit_test(argv_parse_cmd__command_string__argc_correct),
cmocka_unit_test(argv_parse_cmd__command_and_extra_options__argc_correct),
cmocka_unit_test(argv_printf_cat__used_twice__argc_correct),
+ cmocka_unit_test(argv_str__empty_argv__empty_output),
cmocka_unit_test(argv_str__multiple_argv__correct_output),
cmocka_unit_test(argv_insert_head__non_empty_argv__head_added),
};