Skip to content

Commit e9e8558

Browse files
committed
Add a simple unit test for oscap_path_startswith
1 parent faa742a commit e9e8558

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/common/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
add_oscap_test_executable(test_oscap_util
22
"test_oscap_util.c"
3+
${CMAKE_SOURCE_DIR}/src/common/util.c
4+
${CMAKE_SOURCE_DIR}/src/common/error.c
5+
${CMAKE_SOURCE_DIR}/src/common/err_queue.c
36
)
47

58
add_oscap_test("test_oscap_util.sh")

tests/common/test_oscap_util.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,44 @@
2929
#include <string.h>
3030
#include "common/util.h"
3131

32+
int test_oscap_path_startswith(void);
3233
int test_oscap_strrm(void);
3334

35+
int test_oscap_path_startswith()
36+
{
37+
if (!oscap_path_startswith("/", "/"))
38+
return 1;
39+
if (!oscap_path_startswith("/aaa", "/"))
40+
return 2;
41+
if (!oscap_path_startswith("/aaa", "/aaa"))
42+
return 3;
43+
if (!oscap_path_startswith("/aaa/bbb", "/aaa"))
44+
return 4;
45+
if (!oscap_path_startswith("/aaa/bbb/ccc", "/aaa"))
46+
return 5;
47+
if (!oscap_path_startswith("/aaa/bbb/ccc/", "/aaa/"))
48+
return 6;
49+
if (!oscap_path_startswith("/aaa/bbb/ccc", "/aaa/bbb/ccc"))
50+
return 7;
51+
if (!oscap_path_startswith("/aaa/bbb/ccc", ""))
52+
return 8;
53+
if (!oscap_path_startswith("", ""))
54+
return 9;
55+
if (!oscap_path_startswith("", "/"))
56+
return 10;
57+
58+
if (oscap_path_startswith("/bbb", "/aaa"))
59+
return 101;
60+
if (oscap_path_startswith("/bbb/aaa", "/aaa"))
61+
return 102;
62+
if (oscap_path_startswith("/bbb/aaa/", "/aaa"))
63+
return 103;
64+
if (oscap_path_startswith("/bbb/aaa/", "/aaa/"))
65+
return 104;
66+
67+
return 0;
68+
}
69+
3470
int test_oscap_strrm()
3571
{
3672
char str[] = "abcdef12345678def90";
@@ -59,6 +95,8 @@ int main (int argc, char *argv[])
5995
{
6096
int retval = 0;
6197

98+
if ((retval = test_oscap_path_startswith()) != 0)
99+
return retval;
62100
if ((retval = test_oscap_strrm()) != 0)
63101
return retval;
64102

0 commit comments

Comments
 (0)