source: trunk/src/cutest_slib.c@ 225

Last change on this file since 225 was 169, checked in by katerina, 17 years ago

Fixes for tickes #93 to #104 (yes, big commit, bad, bad,...).

File size: 1.7 KB
Line 
1
2#include "config_xor.h"
3
4#include <string.h>
5#include "CuTest.h"
6#include "samhain.h"
7
8void Test_sl_snprintf (CuTest *tc) {
9
10 int ret = 0;
11 char input[16];
12
13 memset (&input, 'X', 16);
14 ret = sl_snprintf(input, 10, "%s\n", "01234567890123456789");
15 CuAssertIntEquals(tc, ret, 0);
16 CuAssertTrue(tc, input[9] == '\0');
17 CuAssertTrue(tc, input[10] == 'X');
18
19 memset (&input, 'X', 16);
20 ret = sl_snprintf(input, 4, "%d\n", "012345");
21 CuAssertIntEquals(tc, ret, 0);
22 CuAssertTrue(tc, input[3] == '\0');
23 CuAssertTrue(tc, input[4] == 'X');
24}
25
26void Test_sl_strcasecmp (CuTest *tc) {
27 char one[64], two[64];
28 int res;
29
30 strcpy(one, "foo");
31 strcpy(two, "foo");
32 res = sl_strcasecmp(one, two);
33 CuAssertIntEquals(tc, 0, res);
34
35 strcpy(one, "fo");
36 strcpy(two, "foo");
37 res = sl_strcasecmp(one, two);
38 CuAssertIntEquals(tc, -1, res);
39
40 strcpy(one, "foo");
41 strcpy(two, "fo");
42 res = sl_strcasecmp(one, two);
43 CuAssertIntEquals(tc, 1, res);
44
45 strcpy(one, "1234");
46 strcpy(two, "2345");
47 res = sl_strcasecmp(one, two);
48 CuAssertIntEquals(tc, -1, res);
49
50 strcpy(one, "234");
51 strcpy(two, "123");
52 res = sl_strcasecmp(one, two);
53 CuAssertIntEquals(tc, 1, res);
54
55 strcpy(one, "");
56 strcpy(two, "123");
57 res = sl_strcasecmp(one, two);
58 CuAssertIntEquals(tc, -1, res);
59
60 strcpy(one, "234");
61 strcpy(two, "");
62 res = sl_strcasecmp(one, two);
63 CuAssertIntEquals(tc, 1, res);
64
65 strcpy(one, "");
66 strcpy(two, "");
67 res = sl_strcasecmp(one, two);
68 CuAssertTrue(tc, res == 0);
69
70#ifndef SL_FAIL_ON_ERROR
71 res = sl_strcasecmp(NULL, two);
72 CuAssertIntEquals(tc, -1, res);
73
74 res = sl_strcasecmp(one, NULL);
75 CuAssertIntEquals(tc, 1, res);
76
77 res = sl_strcasecmp(NULL, NULL);
78 CuAssertTrue(tc, res != 0);
79#endif
80}
Note: See TracBrowser for help on using the repository browser.