Greenbone Vulnerability Management Libraries 22.8.0
nvti_tests.c File Reference
#include "nvti.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for nvti_tests.c:

Go to the source code of this file.

Functions

 Describe (nvti)
 
 BeforeEach (nvti)
 
 AfterEach (nvti)
 
 Ensure (nvti, nvti_new_never_returns_null)
 
 Ensure (nvti, nvti_set_solution_method_correct)
 
 Ensure (nvti, nvti_get_tag_gets_correct_value_one_tag)
 
 Ensure (nvti, nvti_get_tag_gets_correct_value_many_tags)
 
 Ensure (nvti, nvti_get_tag_handles_empty_tag)
 
 Ensure (nvti, nvti_get_tag_handles_null_nvti)
 
 Ensure (nvti, nvti_get_tag_handles_null_name)
 
 Ensure (nvti, nvtis_add_does_not_use_oid_as_key)
 
 Ensure (nvti, nvti_get_severity_vector_both)
 
 Ensure (nvti, nvti_get_severity_vector_no_cvss_base)
 
 Ensure (nvti, nvti_get_severity_vector_no_severity_vector)
 
int main (int argc, char **argv)
 

Function Documentation

◆ AfterEach()

AfterEach ( nvti  )

Definition at line 15 of file nvti_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( nvti  )

Definition at line 12 of file nvti_tests.c.

13{
14}

◆ Describe()

Describe ( nvti  )

◆ Ensure() [1/11]

Ensure ( nvti  ,
nvti_get_severity_vector_both   
)

Definition at line 132 of file nvti_tests.c.

133{
134 nvti_t *nvti;
135
136 nvti = nvti_new ();
137 nvti_set_tag (nvti, "cvss_base_vector=DEF");
138 nvti_set_tag (nvti, "severity_vector=ABC");
139
140 assert_that (nvti_severity_vector_from_tag (nvti),
141 is_equal_to_string ("ABC"));
142
143 nvti_free (nvti);
144}
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition: nvti.c:597
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition: nvti.c:1663
gchar * nvti_severity_vector_from_tag(const nvti_t *n)
Get the severity score.
Definition: nvti.c:938
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition: nvti.c:608
The structure of a information record that corresponds to a NVT.
Definition: nvti.c:394

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [2/11]

Ensure ( nvti  ,
nvti_get_severity_vector_no_cvss_base   
)

Definition at line 146 of file nvti_tests.c.

147{
148 nvti_t *nvti;
149
150 nvti = nvti_new ();
151 nvti_set_tag (nvti, "severity_vector=ABC");
152
153 assert_that (nvti_severity_vector_from_tag (nvti),
154 is_equal_to_string ("ABC"));
155
156 nvti_free (nvti);
157}

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [3/11]

Ensure ( nvti  ,
nvti_get_severity_vector_no_severity_vector   
)

Definition at line 159 of file nvti_tests.c.

160{
161 nvti_t *nvti;
162
163 nvti = nvti_new ();
164 nvti_set_tag (nvti, "cvss_base_vector=DEF");
165
166 assert_that (nvti_severity_vector_from_tag (nvti),
167 is_equal_to_string ("DEF"));
168
169 nvti_free (nvti);
170}

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [4/11]

Ensure ( nvti  ,
nvti_get_tag_gets_correct_value_many_tags   
)

Definition at line 59 of file nvti_tests.c.

60{
61 nvti_t *nvti;
62 gchar *tag;
63
64 nvti = nvti_new ();
65 nvti_set_tag (nvti, "a=1|b=2|c=3");
66 tag = nvti_get_tag (nvti, "b");
67
68 assert_that (tag, is_equal_to_string ("2"));
69
70 g_free (tag);
72}
gchar * nvti_get_tag(const nvti_t *n, const gchar *name)
Get a tag value by a tag name.
Definition: nvti.c:1020

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [5/11]

Ensure ( nvti  ,
nvti_get_tag_gets_correct_value_one_tag   
)

Definition at line 44 of file nvti_tests.c.

45{
46 nvti_t *nvti;
47 gchar *tag;
48
49 nvti = nvti_new ();
50 nvti_set_tag (nvti, "a=1");
51 tag = nvti_get_tag (nvti, "a");
52
53 assert_that (tag, is_equal_to_string ("1"));
54
55 g_free (tag);
57}

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [6/11]

Ensure ( nvti  ,
nvti_get_tag_handles_empty_tag   
)

Definition at line 74 of file nvti_tests.c.

75{
76 nvti_t *nvti;
77
78 nvti = nvti_new ();
79
80 assert_that (nvti_get_tag (nvti, "b"), is_null);
81
83}

References nvti_free(), nvti_get_tag(), and nvti_new().

Here is the call graph for this function:

◆ Ensure() [7/11]

Ensure ( nvti  ,
nvti_get_tag_handles_null_name   
)

Definition at line 90 of file nvti_tests.c.

91{
92 nvti_t *nvti;
93
94 nvti = nvti_new ();
95 nvti_set_tag (nvti, "example=1");
96
97 assert_that (nvti_get_tag (nvti, NULL), is_null);
98
100}

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [8/11]

Ensure ( nvti  ,
nvti_get_tag_handles_null_nvti   
)

Definition at line 85 of file nvti_tests.c.

86{
87 assert_that (nvti_get_tag (NULL, "example"), is_null);
88}

References nvti_get_tag().

Here is the call graph for this function:

◆ Ensure() [9/11]

Ensure ( nvti  ,
nvti_new_never_returns_null   
)

Definition at line 21 of file nvti_tests.c.

22{
23 assert_that (nvti_new (), is_not_null);
24}

References nvti_new().

Here is the call graph for this function:

◆ Ensure() [10/11]

Ensure ( nvti  ,
nvti_set_solution_method_correct   
)

Definition at line 28 of file nvti_tests.c.

29{
30 nvti_t *nvti;
31 gchar *solution_method;
32
33 nvti = nvti_new ();
34 nvti_set_solution_method (nvti, "DebianAPTUpgrade");
35 solution_method = nvti_solution_method (nvti);
36
37 assert_that (solution_method, is_equal_to_string ("DebianAPTUpgrade"));
38
40}
gchar * nvti_solution_method(const nvti_t *n)
Get the solution method.
Definition: nvti.c:990
int nvti_set_solution_method(nvti_t *n, const gchar *solution_method)
Set the solution method of a NVT.
Definition: nvti.c:1572

References nvti_free(), nvti_new(), nvti_set_solution_method(), and nvti_solution_method().

Here is the call graph for this function:

◆ Ensure() [11/11]

Ensure ( nvti  ,
nvtis_add_does_not_use_oid_as_key   
)

Definition at line 104 of file nvti_tests.c.

105{
106 nvtis_t *nvtis;
107 nvti_t *nvti;
108 gchar *oid;
109
110 nvtis = nvtis_new ();
111
112 nvti = nvti_new ();
113 nvti_set_oid (nvti, "1");
114
115 oid = nvti_oid (nvti);
116
117 /* This should not use the pointer nvti->oid as the key, because nvti_set_oid
118 * could free nvti->oid. */
119 nvtis_add (nvtis, nvti);
120
121 /* Change the first character of the OID. */
122 *oid = '2';
123
124 /* To check that the key is not the same pointer as nvti->oid, check
125 * that changing the first character of nvti->oid did not affect the key. */
126 assert_that (nvtis_lookup (nvtis, "1"), is_not_null);
127 assert_that (nvtis_lookup (nvtis, "2"), is_null);
128}
nvtis_t * nvtis_new(void)
Make a collection of NVT Infos.
Definition: nvti.c:2246
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition: nvti.c:1252
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition: nvti.c:649
nvti_t * nvtis_lookup(nvtis_t *nvtis, const char *oid)
Add an NVT Info to a collection of NVT Infos.
Definition: nvti.c:2288
void nvtis_add(nvtis_t *nvtis, nvti_t *nvti)
Add an NVT Info to a collection of NVT Infos.
Definition: nvti.c:2271
GHashTable nvtis_t
A collection of information records corresponding to NVTs.
Definition: nvti.h:252

References nvti_new(), nvti_oid(), nvti_set_oid(), nvtis_add(), nvtis_lookup(), and nvtis_new().

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 175 of file nvti_tests.c.

176{
177 TestSuite *suite;
178
179 suite = create_test_suite ();
180
181 add_test_with_context (suite, nvti, nvti_new_never_returns_null);
182
183 add_test_with_context (suite, nvti, nvti_get_tag_gets_correct_value_one_tag);
184 add_test_with_context (suite, nvti,
185 nvti_get_tag_gets_correct_value_many_tags);
186 add_test_with_context (suite, nvti, nvti_get_tag_handles_empty_tag);
187 add_test_with_context (suite, nvti, nvti_get_tag_handles_null_nvti);
188 add_test_with_context (suite, nvti, nvti_get_tag_handles_null_name);
189
190 add_test_with_context (suite, nvti, nvti_set_solution_method_correct);
191
192 add_test_with_context (suite, nvti, nvtis_add_does_not_use_oid_as_key);
193
194 add_test_with_context (suite, nvti, nvti_get_severity_vector_both);
195 add_test_with_context (suite, nvti,
196 nvti_get_severity_vector_no_severity_vector);
197 add_test_with_context (suite, nvti, nvti_get_severity_vector_no_cvss_base);
198
199 if (argc > 1)
200 return run_single_test (suite, argv[1], create_text_reporter ());
201
202 return run_test_suite (suite, create_text_reporter ());
203}