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

Go to the source code of this file.

Functions

 Describe (osp)
 
 BeforeEach (osp)
 
 AfterEach (osp)
 
 Ensure (osp, osp_new_target_never_returns_null)
 
 Ensure (osp, osp_new_conn_ret_null)
 
 Ensure (osp, osp_get_vts_no_vts_ret_error)
 
 Ensure (osp, osp_get_vts_no_conn_ret_error)
 
 Ensure (osp, osp_target_add_alive_test_methods)
 
 Ensure (osp, target_append_as_xml)
 
int main (int argc, char **argv)
 

Function Documentation

◆ AfterEach()

AfterEach ( osp  )

Definition at line 15 of file osp_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( osp  )

Definition at line 12 of file osp_tests.c.

13{
14}

◆ Describe()

Describe ( osp  )

◆ Ensure() [1/6]

Ensure ( osp  ,
osp_get_vts_no_conn_ret_error   
)

Definition at line 35 of file osp_tests.c.

36{
37 assert_that (osp_get_vts (NULL, NULL), is_equal_to (1));
38}
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition: osp.c:621

References osp_get_vts().

Here is the call graph for this function:

◆ Ensure() [2/6]

Ensure ( osp  ,
osp_get_vts_no_vts_ret_error   
)

Definition at line 29 of file osp_tests.c.

30{
31 osp_connection_t *conn = g_malloc0 (sizeof (*conn));
32 assert_that (osp_get_vts (conn, NULL), is_equal_to (1));
33}
Struct holding options for OSP connection.
Definition: osp.c:36

References osp_get_vts().

Here is the call graph for this function:

◆ Ensure() [3/6]

Ensure ( osp  ,
osp_new_conn_ret_null   
)

Definition at line 24 of file osp_tests.c.

25{
26 assert_that (osp_connection_new ("/my/socket", 0, NULL, NULL, NULL), is_null);
27}
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)

References osp_connection_new().

Here is the call graph for this function:

◆ Ensure() [4/6]

Ensure ( osp  ,
osp_new_target_never_returns_null   
)

Definition at line 19 of file osp_tests.c.

20{
21 assert_that (osp_target_new (NULL, NULL, NULL, 0, 0, 0), is_not_null);
22}
osp_target_t * osp_target_new(const char *hosts, const char *ports, const char *exclude_hosts, int alive_test, int reverse_lookup_unify, int reverse_lookup_only)
Create a new OSP target.
Definition: osp.c:1694

References osp_target_new().

Here is the call graph for this function:

◆ Ensure() [5/6]

Ensure ( osp  ,
osp_target_add_alive_test_methods   
)

Definition at line 40 of file osp_tests.c.

41{
42 osp_target_t *target;
43
44 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
45 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, TRUE);
46
47 assert_true (target->icmp);
48 assert_true (target->tcp_syn);
49 assert_true (target->tcp_ack);
50 assert_true (target->arp);
51 assert_true (target->consider_alive);
52
53 osp_target_free (target);
54}
void osp_target_add_alive_test_methods(osp_target_t *target, gboolean icmp, gboolean tcp_syn, gboolean tcp_ack, gboolean arp, gboolean consider_alive)
Add alive test methods to OSP target.
Definition: osp.c:1756
void osp_target_free(osp_target_t *target)
Free an OSP target, including all added credentials.
Definition: osp.c:1733
Struct holding target information.
Definition: osp.c:71
gboolean tcp_syn
Definition: osp.c:81
gboolean arp
Definition: osp.c:83
gboolean icmp
Definition: osp.c:80
gboolean consider_alive
Definition: osp.c:84
gboolean tcp_ack
Definition: osp.c:82

References osp_target::arp, osp_target::consider_alive, osp_target::icmp, osp_target_add_alive_test_methods(), osp_target_free(), osp_target_new(), osp_target::tcp_ack, and osp_target::tcp_syn.

Here is the call graph for this function:

◆ Ensure() [6/6]

Ensure ( osp  ,
target_append_as_xml   
)

Definition at line 56 of file osp_tests.c.

57{
58 osp_target_t *target;
59 GString *target_xml;
60 gchar *expected_xml_string;
61
62 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
63 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, FALSE);
64
65 target_xml = g_string_sized_new (10240);
66
67 target_append_as_xml (target, target_xml);
68 expected_xml_string = "<target>"
69 "<hosts>127.0.0.1</hosts>"
70 "<exclude_hosts></exclude_hosts>"
71 "<finished_hosts></finished_hosts>"
72 "<ports>123</ports>"
73 "<alive_test_methods>"
74 "<icmp>1</icmp>"
75 "<tcp_syn>1</tcp_syn>"
76 "<tcp_ack>1</tcp_ack>"
77 "<arp>1</arp>"
78 "<consider_alive>0</consider_alive>"
79 "</alive_test_methods>"
80 "</target>";
81
82 assert_that (target_xml->str, is_equal_to_string (expected_xml_string));
83
84 osp_target_free (target);
85}
static void target_append_as_xml(osp_target_t *target, GString *xml_string)
Concatenate a target as XML.
Definition: osp.c:1144

References osp_target_add_alive_test_methods(), osp_target_free(), osp_target_new(), and target_append_as_xml().

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 90 of file osp_tests.c.

91{
92 TestSuite *suite;
93
94 suite = create_test_suite ();
95
96 add_test_with_context (suite, osp, osp_new_target_never_returns_null);
97 add_test_with_context (suite, osp, osp_get_vts_no_conn_ret_error);
98 add_test_with_context (suite, osp, osp_get_vts_no_vts_ret_error);
99 add_test_with_context (suite, osp, osp_new_conn_ret_null);
100 add_test_with_context (suite, osp, osp_target_add_alive_test_methods);
101 add_test_with_context (suite, osp, target_append_as_xml);
102
103 if (argc > 1)
104 return run_single_test (suite, argv[1], create_text_reporter ());
105
106 return run_test_suite (suite, create_text_reporter ());
107}

References osp_target_add_alive_test_methods(), and target_append_as_xml().

Here is the call graph for this function: