1 /* Copyright (C) 2009-2021 Greenbone Networks GmbH
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "osp.c"
21
22 #include <cgreen/cgreen.h>
23 #include <cgreen/mocks.h>
24
25 Describe (osp);
BeforeEach(osp)26 BeforeEach (osp)
27 {
28 }
AfterEach(osp)29 AfterEach (osp)
30 {
31 }
32
Ensure(osp,osp_new_target_never_returns_null)33 Ensure (osp, osp_new_target_never_returns_null)
34 {
35 assert_that (osp_target_new (NULL, NULL, NULL, 0, 0, 0), is_not_null);
36 }
37
Ensure(osp,osp_new_conn_ret_null)38 Ensure (osp, osp_new_conn_ret_null)
39 {
40 assert_that (osp_connection_new ("/my/socket", 0, NULL, NULL, NULL), is_null);
41 }
42
Ensure(osp,osp_get_vts_no_vts_ret_error)43 Ensure (osp, osp_get_vts_no_vts_ret_error)
44 {
45 osp_connection_t *conn = g_malloc0 (sizeof (*conn));
46 assert_that (osp_get_vts (conn, NULL), is_equal_to (1));
47 }
48
Ensure(osp,osp_get_vts_no_conn_ret_error)49 Ensure (osp, osp_get_vts_no_conn_ret_error)
50 {
51 assert_that (osp_get_vts (NULL, NULL), is_equal_to (1));
52 }
53
Ensure(osp,osp_target_add_alive_test_methods)54 Ensure (osp, osp_target_add_alive_test_methods)
55 {
56 osp_target_t *target;
57
58 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
59 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, TRUE);
60
61 assert_true (target->icmp);
62 assert_true (target->tcp_syn);
63 assert_true (target->tcp_ack);
64 assert_true (target->arp);
65 assert_true (target->consider_alive);
66
67 osp_target_free (target);
68 }
69
Ensure(osp,target_append_as_xml)70 Ensure (osp, target_append_as_xml)
71 {
72 osp_target_t *target;
73 GString *target_xml;
74 gchar *expected_xml_string;
75
76 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
77 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, FALSE);
78
79 target_xml = g_string_sized_new (10240);
80
81 target_append_as_xml (target, target_xml);
82 expected_xml_string = "<target>"
83 "<hosts>127.0.0.1</hosts>"
84 "<exclude_hosts></exclude_hosts>"
85 "<finished_hosts></finished_hosts>"
86 "<ports>123</ports>"
87 "<alive_test_methods>"
88 "<icmp>1</icmp>"
89 "<tcp_syn>1</tcp_syn>"
90 "<tcp_ack>1</tcp_ack>"
91 "<arp>1</arp>"
92 "<consider_alive>0</consider_alive>"
93 "</alive_test_methods>"
94 "</target>";
95
96 assert_that (target_xml->str, is_equal_to_string (expected_xml_string));
97
98 osp_target_free (target);
99 }
100
101 /* Test suite. */
102
103 int
main(int argc,char ** argv)104 main (int argc, char **argv)
105 {
106 TestSuite *suite;
107
108 suite = create_test_suite ();
109
110 add_test_with_context (suite, osp, osp_new_target_never_returns_null);
111 add_test_with_context (suite, osp, osp_get_vts_no_conn_ret_error);
112 add_test_with_context (suite, osp, osp_get_vts_no_vts_ret_error);
113 add_test_with_context (suite, osp, osp_new_conn_ret_null);
114 add_test_with_context (suite, osp, osp_target_add_alive_test_methods);
115 add_test_with_context (suite, osp, target_append_as_xml);
116
117 if (argc > 1)
118 return run_single_test (suite, argv[1], create_text_reporter ());
119
120 return run_test_suite (suite, create_text_reporter ());
121 }
122