new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / tests / test_shared.c
1 /* Copyright (C) 2014 Trend Micro Inc.
2  * All rights reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #include <check.h>
11 #include <stdlib.h>
12
13 #include "../headers/custom_output_search.h"
14
15 Suite *test_suite(void);
16
17
18 START_TEST(test_searchAndReplace)
19 {
20     int i;
21     const char *tests[][4] = {
22         {"testMe", "nomatch", "", "testMe"},
23         {"test me", "ME", "me", "test me"},
24         {"test me", "me", "ME", "test ME"},
25         {"testMe", "test", "Tested", "TestedMe"},
26         {"Metest", "test", "Tested", "MeTested"},
27         {"A B CTeStD E F", "TeSt", "tEsT", "A B CtEsTD E F"},
28         {"TeStA B CTeStD E F", "TeSt", "tEsT", "tEsTA B CtEsTD E F"},
29         {"TeSt TeStA B CTeStD E F", "TeSt", "tEsT", "tEsT tEsTA B CtEsTD E F"},
30         {"A B CTeStD E FTeSt", "TeSt", "tEsT", "A B CtEsTD E FtEsT"},
31         {"A B CTeStD E FTeSt TeSt", "TeSt", "tEsT", "A B CtEsTD E FtEsT tEsT"},
32         {"TeSt++ TeSt++A B CTeSt++D E F", "TeSt++", "tEsT", "tEsT tEsTA B CtEsTD E F"},
33         {"A B CTeStD E FTeSt TeSt", "TeSt", "tEsT++", "A B CtEsT++D E FtEsT++ tEsT++"},
34         {NULL, NULL, NULL, NULL}
35     };
36
37     for (i = 0; tests[i][0] != NULL ; i++) {
38         char *result = searchAndReplace(tests[i][0], tests[i][1], tests[i][2]);
39         ck_assert_str_eq(result, tests[i][3]);
40         free(result);
41     }
42 }
43 END_TEST
44
45 Suite *test_suite(void)
46 {
47     Suite *s = suite_create("shared");
48
49     TCase *tc_searchAndReplace = tcase_create("searchAndReplace");
50     tcase_add_test(tc_searchAndReplace, test_searchAndReplace);
51
52     suite_add_tcase(s, tc_searchAndReplace);
53
54     return (s);
55 }
56
57 int main(void)
58 {
59     Suite *s = test_suite();
60     SRunner *sr = srunner_create(s);
61     srunner_run_all(sr, CK_NORMAL);
62     int number_failed = srunner_ntests_failed(sr);
63     srunner_free(sr);
64
65     return ((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
66 }