Greenbone Vulnerability Management Libraries 22.32.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 40 of file osp_tests.c.

41{
42 assert_that (osp_get_vts (NULL, NULL), is_equal_to (1));
43}
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition osp.c:618

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 33 of file osp_tests.c.

34{
35 osp_connection_t *conn = g_malloc0 (sizeof (*conn));
36 assert_that (osp_get_vts (conn, NULL), is_equal_to (1));
37 g_free (conn);
38}
struct osp_connection osp_connection_t
Definition osp.h:20

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 28 of file osp_tests.c.

29{
30 assert_that (osp_connection_new ("/my/socket", 0, NULL, NULL, NULL), is_null);
31}
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 osp_target_t *target;
22
23 target = osp_target_new (NULL, NULL, NULL, 0, 0, 0);
24 assert_that (target, is_not_null);
25 osp_target_free (target);
26}
void osp_target_free(osp_target_t *target)
Free an OSP target, including all added credentials.
Definition osp.c:1730
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:1691
struct osp_target osp_target_t
Definition osp.h:24

References osp_target_free(), and osp_target_new().

Here is the call graph for this function:

◆ Ensure() [5/6]

Definition at line 45 of file osp_tests.c.

46{
47 osp_target_t *target;
48
49 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
50 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, TRUE);
51
52 assert_true (target->icmp);
53 assert_true (target->tcp_syn);
54 assert_true (target->tcp_ack);
55 assert_true (target->arp);
56 assert_true (target->consider_alive);
57
58 osp_target_free (target);
59}
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:1753
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 61 of file osp_tests.c.

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

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 96 of file osp_tests.c.

97{
98 int ret;
99 TestSuite *suite;
100
101 suite = create_test_suite ();
102
103 add_test_with_context (suite, osp, osp_new_target_never_returns_null);
104 add_test_with_context (suite, osp, osp_get_vts_no_conn_ret_error);
105 add_test_with_context (suite, osp, osp_get_vts_no_vts_ret_error);
106 add_test_with_context (suite, osp, osp_new_conn_ret_null);
107 add_test_with_context (suite, osp, osp_target_add_alive_test_methods);
108 add_test_with_context (suite, osp, target_append_as_xml);
109
110 if (argc > 1)
111 ret = run_single_test (suite, argv[1], create_text_reporter ());
112 else
113 ret = run_test_suite (suite, create_text_reporter ());
114
115 destroy_test_suite (suite);
116
117 return ret;
118}

References osp_target_add_alive_test_methods(), and target_append_as_xml().

Here is the call graph for this function: