OpenVPN
test_search_and_replace.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <stdarg.h>
5 #include <string.h>
6 #include <setjmp.h>
7 #include <cmocka.h>
8 
9 #include "utils.h"
10 
11 static void
13 
14  char DUMMY[] = "DUMMY";
15 
16  assert_null(searchandreplace(NULL,DUMMY,DUMMY));
17  assert_null(searchandreplace(DUMMY,NULL,DUMMY));
18  assert_null(searchandreplace(DUMMY,DUMMY,NULL));
19 }
20 
21 static void
23 
24  char DUMMY[] = "DUMMY";
25  char EMPTY[] = "";
26 
27  assert_null(searchandreplace(EMPTY,DUMMY,DUMMY));
28  assert_null(searchandreplace(DUMMY,EMPTY,DUMMY));
29  assert_null(searchandreplace(DUMMY,DUMMY,EMPTY));
30 }
31 
32 static void
34  char *replaced = searchandreplace("X","X","Y");
35 
36  assert_non_null(replaced);
37  assert_string_equal("Y", replaced);
38 
39  free(replaced);
40 }
41 
42 static void
44  char *replaced = searchandreplace("XaX","X","Y");
45 
46  assert_non_null(replaced);
47  assert_string_equal("YaY", replaced);
48 
49  free(replaced);
50 }
51 
52 static void
54  char *replaced = searchandreplace("XXaXX","XX","YY");
55 
56  assert_non_null(replaced);
57  assert_string_equal("YYaYY", replaced);
58 
59  free(replaced);
60 }
61 
62 static void
64  char *replaced = searchandreplace("abc","X","Y");
65 
66  assert_non_null(replaced);
67  assert_string_equal("abc", replaced);
68 
69  free(replaced);
70 }
71 
72 
73 int
74 main(void) {
75  const struct CMUnitTest tests[] = {
82  };
83 
84  return cmocka_run_group_tests_name("searchandreplace", tests, NULL, NULL);
85 }
static void replace_single_char__one_time__match_is_replaced()
#define assert_non_null(c)
Definition: cmocka.h:1102
#define cmocka_unit_test(f)
Initializes a CMUnitTest structure.
Definition: cmocka.h:1653
static void replace_single_char__multiple_times__match_all_matches_are_replaced()
static void pass_any_empty_string__returns_null()
#define cmocka_run_group_tests_name(group_name, group_tests, group_setup, group_teardown)
Definition: cmocka.h:1818
#define assert_string_equal(a, b)
Definition: cmocka.h:1214
int main(void)
static void pass_any_null_param__returns_null()
char * searchandreplace(const char *tosearch, const char *searchfor, const char *replacewith)
Read &#39;tosearch&#39;, replace all occurrences of &#39;searchfor&#39; with &#39;replacewith&#39; and return a pointer to th...
Definition: utils.c:43
static void pattern_not_found__returns_original()
#define assert_null(c)
Definition: cmocka.h:1119
#define free
Definition: cmocka.c:1850
static void replace_longer_text__multiple_times__match_all_matches_are_replaced()