~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to tests/unit/check_chassis_log.c

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3
 
 
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
7
 
 License.
8
 
 
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.
13
 
 
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
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ */
20
 
 
21
 
/** @addtogroup unittests Unit tests */
22
 
 
23
 
#include <stdio.h>
24
 
#include <stdlib.h>
25
 
#include <string.h>
26
 
 
27
 
#include <glib.h>
28
 
 
29
 
#include "chassis-log.h"
30
 
 
31
 
#if GLIB_CHECK_VERSION(2, 16, 0)
32
 
#define C(x) x, sizeof(x) - 1
33
 
 
34
 
#define START_TEST(x) void (x)(void)
35
 
 
36
 
/*@{*/
37
 
 
38
 
/**
39
 
 * @test Test log message coalescing.
40
 
 */
41
 
START_TEST(test_log_compress) {
42
 
        chassis_log *l;
43
 
        GLogFunc old_log_func;
44
 
 
45
 
        l = chassis_log_new();
46
 
 
47
 
        g_log_set_always_fatal(G_LOG_FATAL_MASK);
48
 
 
49
 
        old_log_func = g_log_set_default_handler(chassis_log_func, l);
50
 
 
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'");
55
 
 
56
 
        g_log_set_default_handler(old_log_func, NULL);
57
 
 
58
 
        chassis_log_free(l);
59
 
}
60
 
/*@}*/
61
 
 
62
 
/**
63
 
 * @test Test log timestamp resolution
64
 
 */
65
 
START_TEST(test_log_timestamp) {
66
 
        chassis_log *l;
67
 
        GLogFunc old_log_func;
68
 
 
69
 
        l = chassis_log_new();
70
 
        chassis_set_logtimestamp_resolution(l, CHASSIS_RESOLUTION_SEC);
71
 
 
72
 
        g_log_set_always_fatal(G_LOG_FATAL_MASK);
73
 
 
74
 
        old_log_func = g_log_set_default_handler(chassis_log_func, l);
75
 
 
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");
79
 
 
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));
87
 
 
88
 
        
89
 
 
90
 
        g_log_set_default_handler(old_log_func, NULL);
91
 
 
92
 
        chassis_log_free(l);
93
 
}
94
 
/*@}*/
95
 
 
96
 
int main(int argc, char **argv) {
97
 
        g_test_init(&argc, &argv, NULL);
98
 
        g_test_bug_base("http://bugs.mysql.com/");
99
 
 
100
 
        g_test_add_func("/core/log_compress", test_log_compress);
101
 
        g_test_add_func("/core/log_timestamp", test_log_timestamp);
102
 
 
103
 
        return g_test_run();
104
 
}
105
 
#else
106
 
int main() {
107
 
        return 77;
108
 
}
109
 
#endif