1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/* SPDX-FileCopyrightText: 2025 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "logging_domain.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
#include <fcntl.h>
#include <glib/gstdio.h>
Describe (logging_domain);
BeforeEach (logging_domain)
{
}
AfterEach (logging_domain)
{
}
Ensure (logging_domain, should_initalize_logging_domain)
{
gvm_logging_domain_t *log_domain_entry =
gvm_logging_domain_new (g_strdup ("test"));
assert_that (log_domain_entry, is_not_null);
assert_that (gvm_logging_domain_get_log_domain (log_domain_entry),
is_equal_to_string ("test"));
assert_that (gvm_logging_domain_get_log_file (log_domain_entry), is_null);
assert_that (gvm_logging_domain_get_prepend_string (log_domain_entry),
is_null);
assert_that (gvm_logging_domain_get_prepend_time_format (log_domain_entry),
is_null);
assert_that (gvm_logging_domain_get_default_level (log_domain_entry),
is_null);
assert_that (gvm_logging_domain_get_log_channel (log_domain_entry), is_null);
assert_that (gvm_logging_domain_get_syslog_facility (log_domain_entry),
is_null);
assert_that (gvm_logging_domain_get_syslog_ident (log_domain_entry), is_null);
assert_that (gvm_logging_domain_get_prepend_separator (log_domain_entry),
is_null);
gvm_logging_domain_free (log_domain_entry);
}
Ensure (logging_domain, should_allow_setting_properties)
{
gvm_logging_domain_t *log_domain_entry =
gvm_logging_domain_new (g_strdup ("test"));
assert_that (log_domain_entry, is_not_null);
assert_that (gvm_logging_domain_get_log_domain (log_domain_entry),
is_equal_to_string ("test"));
gvm_logging_domain_set_log_file (log_domain_entry, g_strdup ("logfile.log"));
assert_that (gvm_logging_domain_get_log_file (log_domain_entry),
is_equal_to_string ("logfile.log"));
gvm_logging_domain_set_prepend_string (log_domain_entry,
g_strdup ("prepend"));
assert_that (gvm_logging_domain_get_prepend_string (log_domain_entry),
is_equal_to_string ("prepend"));
gvm_logging_domain_set_prepend_time_format (log_domain_entry,
g_strdup ("%Y-%m-%d"));
assert_that (gvm_logging_domain_get_prepend_time_format (log_domain_entry),
is_equal_to_string ("%Y-%m-%d"));
gvm_logging_domain_set_default_level (log_domain_entry, G_LOG_LEVEL_DEBUG);
assert_that (*gvm_logging_domain_get_default_level (log_domain_entry),
is_equal_to (G_LOG_LEVEL_DEBUG));
GIOChannel *log_channel =
g_io_channel_new_file ("log_channel.log", "w", NULL);
gvm_logging_domain_set_log_channel (log_domain_entry, log_channel);
assert_that (gvm_logging_domain_get_log_channel (log_domain_entry),
is_equal_to (log_channel));
gvm_logging_domain_set_syslog_facility (log_domain_entry, g_strdup ("user"));
assert_that (gvm_logging_domain_get_syslog_facility (log_domain_entry),
is_equal_to_string ("user"));
gvm_logging_domain_set_syslog_ident (log_domain_entry, g_strdup ("ident"));
assert_that (gvm_logging_domain_get_syslog_ident (log_domain_entry),
is_equal_to_string ("ident"));
gvm_logging_domain_set_prepend_separator (log_domain_entry, g_strdup ("|"));
assert_that (gvm_logging_domain_get_prepend_separator (log_domain_entry),
is_equal_to_string ("|"));
gvm_logging_domain_free (log_domain_entry);
g_io_channel_unref (log_channel);
g_remove ("log_channel.log");
}
static TestSuite *
logging_test_suite ()
{
TestSuite *suite = create_test_suite ();
add_test_with_context (suite, logging_domain,
should_initalize_logging_domain);
add_test_with_context (suite, logging_domain,
should_allow_setting_properties);
return suite;
}
int
main (int argc, char **argv)
{
int ret;
TestSuite *suite;
suite = create_test_suite ();
add_suite (suite, logging_test_suite ());
if (argc > 1)
ret = run_single_test (suite, argv[1], create_text_reporter ());
else
ret = run_test_suite (suite, create_text_reporter ());
destroy_test_suite (suite);
return ret;
}
|