-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: unit tests for wildcard-comparison
Signed-off-by: Daniel Skinstad Drabitzius <[email protected]>
- Loading branch information
1 parent
9120eda
commit 816be69
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @file mender-test-client.c | ||
* @brief Test | ||
* | ||
* Copyright Northern.tech AS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdarg.h> | ||
#include <stddef.h> | ||
#include <setjmp.h> | ||
#include <cmocka.h> | ||
|
||
#include "mender-utils.h" | ||
#include "mender-client.h" | ||
|
||
typedef struct { | ||
char *string; | ||
char *wildcard_string; | ||
bool expected; | ||
} TestWildCard; | ||
|
||
static void | ||
test_wildcard_comparison(void **state) { | ||
|
||
TestWildCard test_wildcard[] = { { "wow", "wow", true }, | ||
{ "abc_123_def_456_ghi", "abc_123_def_456_g", false }, | ||
{ "abc_123_def_456_ghi", "abc*def*ghi", true }, | ||
{ "abc_123_def_456_ghi", "abc*123*def*ghi", true }, | ||
{ "abc_123_def_456_ghi", "*def*456*", true }, | ||
{ "abc_123_def_456_ghi", "abc*789*ghi", false }, | ||
{ "hello_world", "hello*world", true }, | ||
{ "hello_world", "hello*worlds", false }, | ||
{ "a_b_c", "a*_*b*", true }, | ||
{ "a_b_c", "a*c*b", false }, | ||
{ "abc", "*a*bc*", true }, | ||
{ "abcabcabc", "a*c*a*c*", true }, | ||
{ "test_key_1", "test_*", true }, | ||
{ "test_key_1", "test_", false }, | ||
{ "best_test_key_1", "test_*", false }, | ||
{ "test_key_1", "", false }, | ||
{ "", "", true }, | ||
{ "abc", "*", true }, | ||
{ "", "abc", false }, | ||
{ "", "abc*", false }, | ||
{ "", "*", true }, | ||
{ "abc", "xyz", false }, | ||
{ "abc", "abc*", true }, | ||
{ "abc", "*abc", true }, | ||
{ "abc", "a*xyz", false }, | ||
{ "test_string", "test_*test_*", false }, | ||
{ "test_string", "test_*string*", true }, | ||
{ "test_test_key", "***", true } }; | ||
|
||
for (size_t i = 0; i < sizeof(test_wildcard) / sizeof(test_wildcard[0]); i++) { | ||
bool result; | ||
mender_utils_compare_wildcard(test_wildcard[i].string, test_wildcard[i].wildcard_string, &result); | ||
assert_int_equal(result, test_wildcard[i].expected); | ||
} | ||
} | ||
|
||
int | ||
main(void) { | ||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(test_wildcard_comparison), | ||
}; | ||
|
||
return cmocka_run_group_tests(tests, NULL, NULL); | ||
} |