mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
torture_tokens.c: Add tests for new token functions
Functions `ssh_remove_all_matching` and `ssh_prefix_without_duplicates` were added; a little test suite will suite them. Signed-off-by: Norbert Pocs <npocs@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
61218df5d5
commit
53fa00abeb
@ -265,6 +265,68 @@ static void torture_append_without_duplicate(UNUSED_PARAM(void **state))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void torture_remove_all_matching (UNUSED_PARAM(void** state)) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching(NULL, NULL);
|
||||||
|
assert_null(p);
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching("don't remove", NULL);
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "don't remove");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching("a,b,c", "b");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "a,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching("a,b,c", "a,b");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching("a,b,c", "d");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "a,b,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_remove_all_matching("a,b,c", "a,b,c");
|
||||||
|
assert_null(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void torture_prefix_without_duplicates (UNUSED_PARAM(void** state)) {
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates(NULL, NULL);
|
||||||
|
assert_null(p);
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates("a,b,c", NULL);
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "a,b,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates("a,b,c", "a");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "a,b,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates("a,b,c", "b");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "b,a,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates("a,b,c", "x");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "x,a,b,c");
|
||||||
|
free(p);
|
||||||
|
|
||||||
|
p = ssh_prefix_without_duplicates("a,b,c", "c,x");
|
||||||
|
assert_non_null(p);
|
||||||
|
assert_string_equal(p, "c,x,a,b");
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int torture_run_tests(void)
|
int torture_run_tests(void)
|
||||||
{
|
{
|
||||||
@ -275,6 +337,8 @@ int torture_run_tests(void)
|
|||||||
cmocka_unit_test(torture_find_all_matching),
|
cmocka_unit_test(torture_find_all_matching),
|
||||||
cmocka_unit_test(torture_remove_duplicate),
|
cmocka_unit_test(torture_remove_duplicate),
|
||||||
cmocka_unit_test(torture_append_without_duplicate),
|
cmocka_unit_test(torture_append_without_duplicate),
|
||||||
|
cmocka_unit_test(torture_remove_all_matching),
|
||||||
|
cmocka_unit_test(torture_prefix_without_duplicates),
|
||||||
};
|
};
|
||||||
|
|
||||||
ssh_init();
|
ssh_init();
|
||||||
|
Reference in New Issue
Block a user