Greenbone Vulnerability Management Libraries 22.32.0
strings_tests.c File Reference
#include "strings.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for strings_tests.c:

Go to the source code of this file.

Functions

 Describe (strings)
 BeforeEach (strings)
 AfterEach (strings)
 Ensure (strings, gvm_append_string_appends_to_null_string)
 Ensure (strings, gvm_append_string_appends_to_existing_string)
 Ensure (strings, gvm_append_string_appends_empty_string)
 Ensure (strings, gvm_append_text_appends_to_null_string)
 Ensure (strings, gvm_append_text_appends_to_existing_string)
 Ensure (strings, gvm_append_text_appends_text_when_size_is_wrong)
 Ensure (strings, gvm_append_text_appends_partial_to_null)
 Ensure (strings, gvm_free_string_var_frees_string)
 Ensure (strings, gvm_free_string_var_frees_null_string)
 Ensure (strings, gvm_strip_space_strips_leading_spaces)
 Ensure (strings, gvm_strip_space_strips_trailing_spaces)
 Ensure (strings, gvm_strip_space_strips_both_ends)
 Ensure (strings, gvm_strip_space_strips_newlines)
 Ensure (strings, gvm_strip_space_empty_string)
 Ensure (strings, gvm_strip_space_only_spaces)
 Ensure (strings, gvm_strip_space_no_spaces)
int main (int argc, char **argv)

Function Documentation

◆ AfterEach()

AfterEach ( strings )

Definition at line 15 of file strings_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( strings )

Definition at line 12 of file strings_tests.c.

13{
14}

◆ Describe()

Describe ( strings )

◆ Ensure() [1/16]

Ensure ( strings ,
gvm_append_string_appends_empty_string  )

Definition at line 37 of file strings_tests.c.

38{
39 gchar *string = g_strdup ("test");
40 gvm_append_string (&string, "");
41 assert_that (string, is_equal_to_string ("test"));
42 g_free (string);
43}
void gvm_append_string(gchar **var, const gchar *string)
Append a string to a string variable.
Definition strings.c:36

References gvm_append_string().

Here is the call graph for this function:

◆ Ensure() [2/16]

Ensure ( strings ,
gvm_append_string_appends_to_existing_string  )

Definition at line 29 of file strings_tests.c.

30{
31 gchar *string = g_strdup ("test");
32 gvm_append_string (&string, "123");
33 assert_that (string, is_equal_to_string ("test123"));
34 g_free (string);
35}

References gvm_append_string().

Here is the call graph for this function:

◆ Ensure() [3/16]

Ensure ( strings ,
gvm_append_string_appends_to_null_string  )

Definition at line 21 of file strings_tests.c.

22{
23 gchar *string = NULL;
24 gvm_append_string (&string, "test");
25 assert_that (string, is_equal_to_string ("test"));
26 g_free (string);
27}

References gvm_append_string().

Here is the call graph for this function:

◆ Ensure() [4/16]

Ensure ( strings ,
gvm_append_text_appends_partial_to_null  )

Definition at line 73 of file strings_tests.c.

74{
75 gchar *string = NULL;
76 gvm_append_text (&string, "123456", 2);
77 // This only happens when the first arg is NULL. Size is supposed to be the
78 // length of the string.
79 assert_that (string, is_equal_to_string ("12"));
80 g_free (string);
81}
void gvm_append_text(gchar **var, const gchar *string, gsize length)
Append a string of a known length to a string variable.
Definition strings.c:66

References gvm_append_text().

Here is the call graph for this function:

◆ Ensure() [5/16]

Ensure ( strings ,
gvm_append_text_appends_text_when_size_is_wrong  )

Definition at line 63 of file strings_tests.c.

64{
65 gchar *string = g_strdup ("test");
66 // Size is supposed to be the length of the string, but it's only used when
67 // the first arg is NULL.
68 gvm_append_text (&string, "123456", 2);
69 assert_that (string, is_equal_to_string ("test123456"));
70 g_free (string);
71}

References gvm_append_text().

Here is the call graph for this function:

◆ Ensure() [6/16]

Ensure ( strings ,
gvm_append_text_appends_to_existing_string  )

Definition at line 55 of file strings_tests.c.

56{
57 gchar *string = g_strdup ("test");
58 gvm_append_text (&string, "123", 3);
59 assert_that (string, is_equal_to_string ("test123"));
60 g_free (string);
61}

References gvm_append_text().

Here is the call graph for this function:

◆ Ensure() [7/16]

Ensure ( strings ,
gvm_append_text_appends_to_null_string  )

Definition at line 47 of file strings_tests.c.

48{
49 gchar *string = NULL;
50 gvm_append_text (&string, "test", 4);
51 assert_that (string, is_equal_to_string ("test"));
52 g_free (string);
53}

References gvm_append_text().

Here is the call graph for this function:

◆ Ensure() [8/16]

Ensure ( strings ,
gvm_free_string_var_frees_null_string  )

Definition at line 92 of file strings_tests.c.

93{
94 gchar *string = NULL;
95 gvm_free_string_var (&string);
96 assert_that (string, is_null);
97}
void gvm_free_string_var(gchar **var)
Free a string variable.
Definition strings.c:87

References gvm_free_string_var().

Here is the call graph for this function:

◆ Ensure() [9/16]

Ensure ( strings ,
gvm_free_string_var_frees_string  )

Definition at line 85 of file strings_tests.c.

86{
87 gchar *string = g_strdup ("test");
88 gvm_free_string_var (&string);
89 assert_that (string, is_null);
90}

References gvm_free_string_var().

Here is the call graph for this function:

◆ Ensure() [10/16]

Ensure ( strings ,
gvm_strip_space_empty_string  )

Definition at line 133 of file strings_tests.c.

134{
135 char string[] = "";
136 char *end = string + strlen (string);
137 char *result = gvm_strip_space (string, end);
138 assert_that (result, is_equal_to_string (""));
139}
char * gvm_strip_space(char *string, char *end)
"Strip" space and newline characters from either end of some memory.
Definition strings.c:108

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [11/16]

Ensure ( strings ,
gvm_strip_space_no_spaces  )

Definition at line 149 of file strings_tests.c.

150{
151 char string[] = "test";
152 char *end = string + strlen (string);
153 char *result = gvm_strip_space (string, end);
154 assert_that (result, is_equal_to_string ("test"));
155}

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [12/16]

Ensure ( strings ,
gvm_strip_space_only_spaces  )

Definition at line 141 of file strings_tests.c.

142{
143 char string[] = " ";
144 char *end = string + strlen (string);
145 char *result = gvm_strip_space (string, end);
146 assert_that (result, is_equal_to_string (""));
147}

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [13/16]

Ensure ( strings ,
gvm_strip_space_strips_both_ends  )

Definition at line 117 of file strings_tests.c.

118{
119 char string[] = " test ";
120 char *end = string + strlen (string);
121 char *result = gvm_strip_space (string, end);
122 assert_that (result, is_equal_to_string ("test"));
123}

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [14/16]

Ensure ( strings ,
gvm_strip_space_strips_leading_spaces  )

Definition at line 101 of file strings_tests.c.

102{
103 char string[] = " test";
104 char *end = string + strlen (string);
105 char *result = gvm_strip_space (string, end);
106 assert_that (result, is_equal_to_string ("test"));
107}

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [15/16]

Ensure ( strings ,
gvm_strip_space_strips_newlines  )

Definition at line 125 of file strings_tests.c.

126{
127 char string[] = "\ntest\n";
128 char *end = string + strlen (string);
129 char *result = gvm_strip_space (string, end);
130 assert_that (result, is_equal_to_string ("test"));
131}

References gvm_strip_space().

Here is the call graph for this function:

◆ Ensure() [16/16]

Ensure ( strings ,
gvm_strip_space_strips_trailing_spaces  )

Definition at line 109 of file strings_tests.c.

110{
111 char string[] = "test ";
112 char *end = string + strlen (string);
113 char *result = gvm_strip_space (string, end);
114 assert_that (result, is_equal_to_string ("test"));
115}

References gvm_strip_space().

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 160 of file strings_tests.c.

161{
162 int ret;
163 TestSuite *suite;
164
165 suite = create_test_suite ();
166
167 add_test_with_context (suite, strings,
168 gvm_append_string_appends_to_null_string);
169 add_test_with_context (suite, strings,
170 gvm_append_string_appends_to_existing_string);
171 add_test_with_context (suite, strings,
172 gvm_append_string_appends_empty_string);
173
174 add_test_with_context (suite, strings,
175 gvm_append_text_appends_to_null_string);
176 add_test_with_context (suite, strings,
177 gvm_append_text_appends_to_existing_string);
178 add_test_with_context (suite, strings,
179 gvm_append_text_appends_text_when_size_is_wrong);
180 add_test_with_context (suite, strings,
181 gvm_append_text_appends_partial_to_null);
182
183 add_test_with_context (suite, strings, gvm_free_string_var_frees_string);
184 add_test_with_context (suite, strings, gvm_free_string_var_frees_null_string);
185
186 add_test_with_context (suite, strings, gvm_strip_space_strips_leading_spaces);
187 add_test_with_context (suite, strings,
188 gvm_strip_space_strips_trailing_spaces);
189 add_test_with_context (suite, strings, gvm_strip_space_strips_both_ends);
190 add_test_with_context (suite, strings, gvm_strip_space_strips_newlines);
191 add_test_with_context (suite, strings, gvm_strip_space_empty_string);
192 add_test_with_context (suite, strings, gvm_strip_space_only_spaces);
193 add_test_with_context (suite, strings, gvm_strip_space_no_spaces);
194
195 if (argc > 1)
196 ret = run_single_test (suite, argv[1], create_text_reporter ());
197 else
198 ret = run_test_suite (suite, create_text_reporter ());
199
200 destroy_test_suite (suite);
201
202 return ret;
203}