2
Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; version 2 of the
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21
/** @addtogroup unittests Unit tests */
29
#include "chassis-log.h"
31
#if GLIB_CHECK_VERSION(2, 16, 0)
32
#define C(x) x, sizeof(x) - 1
34
#define START_TEST(x) void (x)(void)
39
* @test Test log message coalescing.
41
START_TEST(test_log_compress) {
43
GLogFunc old_log_func;
45
l = chassis_log_new();
47
g_log_set_always_fatal(G_LOG_FATAL_MASK);
49
old_log_func = g_log_set_default_handler(chassis_log_func, l);
51
g_critical("I am duplicate");
52
g_critical("I am duplicate");
53
g_critical("I am duplicate");
54
g_critical("above should be 'last message repeated 2 times'");
56
g_log_set_default_handler(old_log_func, NULL);
63
* @test Test log timestamp resolution
65
START_TEST(test_log_timestamp) {
67
GLogFunc old_log_func;
69
l = chassis_log_new();
70
chassis_set_logtimestamp_resolution(l, CHASSIS_RESOLUTION_SEC);
72
g_log_set_always_fatal(G_LOG_FATAL_MASK);
74
old_log_func = g_log_set_default_handler(chassis_log_func, l);
76
g_critical("this message has a second-resolution timestamp");
77
chassis_set_logtimestamp_resolution(l, CHASSIS_RESOLUTION_MS);
78
g_critical("this message has a millisecond-resolution timestamp");
80
g_assert_cmpint(CHASSIS_RESOLUTION_MS, ==, chassis_get_logtimestamp_resolution(l));
81
/* try an illegal value, we should see no change */
82
chassis_set_logtimestamp_resolution(l, -1);
83
g_assert_cmpint(CHASSIS_RESOLUTION_MS, ==, chassis_get_logtimestamp_resolution(l));
84
/* tset back top _SEC resolution */
85
chassis_set_logtimestamp_resolution(l, CHASSIS_RESOLUTION_SEC);
86
g_assert_cmpint(CHASSIS_RESOLUTION_SEC, ==, chassis_get_logtimestamp_resolution(l));
90
g_log_set_default_handler(old_log_func, NULL);
96
int main(int argc, char **argv) {
97
g_test_init(&argc, &argv, NULL);
98
g_test_bug_base("http://bugs.mysql.com/");
100
g_test_add_func("/core/log_compress", test_log_compress);
101
g_test_add_func("/core/log_timestamp", test_log_timestamp);