source: trunk/src/cutest_slib.c@ 548

Last change on this file since 548 was 544, checked in by katerina, 6 years ago

Fix for ticket #436 (new gcc compiler options, including LTO).

File size: 2.9 KB
RevLine 
[21]1
2#include "config_xor.h"
3
4#include <string.h>
5#include "CuTest.h"
6#include "samhain.h"
7
[248]8void Test_sl_stale (CuTest *tc) {
9
10 extern int get_the_fd (SL_TICKET ticket);
11
12 int fd1, fd2, ret, line, val;
13 SL_TICKET tfd1, tfd2;
14 char * err1;
15 char err2[128];
16
17 line = __LINE__; tfd1 = sl_open_read(__FILE__, __LINE__, "/etc/group", SL_NOPRIV);
18 CuAssertTrue(tc, tfd1 > 0);
19
20 fd1 = get_the_fd(tfd1);
21 CuAssertTrue(tc, fd1 >= 0);
22
23 ret = close(fd1);
24 CuAssertTrue(tc, ret == 0);
25
26 tfd2 = sl_open_read(__FILE__, __LINE__, "/etc/group", SL_NOPRIV);
27 CuAssertTrue(tc, tfd2 > 0);
28 CuAssertTrue(tc, tfd2 != tfd1);
29
30 fd2 = get_the_fd(tfd2);
31 CuAssertIntEquals(tc, fd1, fd2);
32
33 err1 = sl_check_stale();
34 CuAssertTrue(tc, err1 != NULL);
35
36 sl_snprintf(err2, sizeof(err2),
37 "stale handle, %s, %d", __FILE__, line);
38 val = strcmp(err1, err2);
39 CuAssertIntEquals(tc, 0, val);
40}
41
[21]42void Test_sl_snprintf (CuTest *tc) {
43
44 int ret = 0;
45 char input[16];
46
47 memset (&input, 'X', 16);
48 ret = sl_snprintf(input, 10, "%s\n", "01234567890123456789");
49 CuAssertIntEquals(tc, ret, 0);
50 CuAssertTrue(tc, input[9] == '\0');
51 CuAssertTrue(tc, input[10] == 'X');
52
53 memset (&input, 'X', 16);
54 ret = sl_snprintf(input, 4, "%d\n", "012345");
55 CuAssertIntEquals(tc, ret, 0);
56 CuAssertTrue(tc, input[3] == '\0');
57 CuAssertTrue(tc, input[4] == 'X');
58}
59
[544]60void Test_sl_ts_strncmp (CuTest *tc) {
61 char one[64], two[64];
62 int res;
63
64 strcpy(one, "foo");
65 strcpy(two, "foo");
66 res = sl_ts_strncmp(one, two, 3);
67 CuAssertIntEquals(tc, 0, res);
68
69 strcpy(one, "fox");
70 strcpy(two, "foo");
71 res = sl_ts_strncmp(one, two, 2);
72 CuAssertIntEquals(tc, 0, res);
73
74 strcpy(one, "f9o");
75 strcpy(two, "foo");
76 res = sl_ts_strncmp(one, two, 3);
77 CuAssertTrue(tc, 0 != res);
78
79}
80
[169]81void Test_sl_strcasecmp (CuTest *tc) {
82 char one[64], two[64];
83 int res;
[21]84
[169]85 strcpy(one, "foo");
86 strcpy(two, "foo");
87 res = sl_strcasecmp(one, two);
88 CuAssertIntEquals(tc, 0, res);
89
90 strcpy(one, "fo");
91 strcpy(two, "foo");
92 res = sl_strcasecmp(one, two);
93 CuAssertIntEquals(tc, -1, res);
94
95 strcpy(one, "foo");
96 strcpy(two, "fo");
97 res = sl_strcasecmp(one, two);
98 CuAssertIntEquals(tc, 1, res);
99
100 strcpy(one, "1234");
101 strcpy(two, "2345");
102 res = sl_strcasecmp(one, two);
103 CuAssertIntEquals(tc, -1, res);
104
105 strcpy(one, "234");
106 strcpy(two, "123");
107 res = sl_strcasecmp(one, two);
108 CuAssertIntEquals(tc, 1, res);
109
110 strcpy(one, "");
111 strcpy(two, "123");
112 res = sl_strcasecmp(one, two);
113 CuAssertIntEquals(tc, -1, res);
114
115 strcpy(one, "234");
116 strcpy(two, "");
117 res = sl_strcasecmp(one, two);
118 CuAssertIntEquals(tc, 1, res);
119
120 strcpy(one, "");
121 strcpy(two, "");
122 res = sl_strcasecmp(one, two);
123 CuAssertTrue(tc, res == 0);
124
125#ifndef SL_FAIL_ON_ERROR
126 res = sl_strcasecmp(NULL, two);
127 CuAssertIntEquals(tc, -1, res);
128
129 res = sl_strcasecmp(one, NULL);
130 CuAssertIntEquals(tc, 1, res);
131
132 res = sl_strcasecmp(NULL, NULL);
133 CuAssertTrue(tc, res != 0);
134#endif
135}
Note: See TracBrowser for help on using the repository browser.