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

« back to all changes in this revision

Viewing changes to tests/unit/check_chassis_path.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-path.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 Resolve a relative path against an absolute base directory.
40
 
 */
41
 
START_TEST(test_path_basedir) {
42
 
        gchar *filename;
43
 
        gchar *test_filename;
44
 
 
45
 
        filename = g_build_filename("some", "relative", "path", "file", NULL);
46
 
        
47
 
        /* resolving this path must lead to changing the filename */
48
 
        g_assert_cmpint(chassis_resolve_path(G_DIR_SEPARATOR_S "tmp", &filename), ==, 1);
49
 
        
50
 
        test_filename = g_build_filename(G_DIR_SEPARATOR_S "tmp", "some", "relative", "path", "file", NULL);
51
 
 
52
 
        g_assert_cmpstr(test_filename, ==, filename);
53
 
 
54
 
        g_free(filename);
55
 
        g_free(test_filename);
56
 
}
57
 
 
58
 
/**
59
 
 * @test Resolving a relative path against a missing base directory does not modify the relative directory.
60
 
 */
61
 
START_TEST(test_no_basedir) {
62
 
        gchar *filename;
63
 
        gchar *test_filename;
64
 
        
65
 
        filename = g_build_filename("some", "relative", "path", "file", NULL);
66
 
        test_filename = g_strdup(filename);
67
 
        
68
 
        /* resolving this path must not lead to changing the filename */
69
 
        g_assert_cmpint(chassis_resolve_path(NULL, &filename), ==, 0);
70
 
        
71
 
        g_assert_cmpstr(test_filename, ==, filename);
72
 
 
73
 
        g_free(filename);
74
 
        g_free(test_filename);
75
 
}
76
 
 
77
 
/**
78
 
 * @test Resolving an absolute path against an absolute basedir has no effect and does not change the directory to be resolved.
79
 
 */
80
 
START_TEST(test_abspath_basedir) {
81
 
        gchar *filename;
82
 
        gchar *test_filename;
83
 
        
84
 
        filename = g_build_filename(G_DIR_SEPARATOR_S "some", "relative", "path", "file", NULL);
85
 
        test_filename = g_strdup(filename);
86
 
        
87
 
        /* resolving this path must lead to no change in the filename */
88
 
        g_assert_cmpint(chassis_resolve_path(G_DIR_SEPARATOR_S "tmp", &filename), ==, 0);
89
 
        
90
 
        g_assert_cmpstr(test_filename, ==, filename);
91
 
 
92
 
        g_free(filename);
93
 
        g_free(test_filename);
94
 
}
95
 
/*@}*/
96
 
 
97
 
int main(int argc, char **argv) {
98
 
        g_thread_init(NULL);
99
 
 
100
 
        g_test_init(&argc, &argv, NULL);
101
 
        g_test_bug_base("http://bugs.mysql.com/");
102
 
        
103
 
        g_test_add_func("/core/basedir/relpath", test_path_basedir);
104
 
        g_test_add_func("/core/basedir/nobasedir", test_no_basedir);
105
 
        g_test_add_func("/core/basedir/abspath", test_abspath_basedir);
106
 
        
107
 
        return g_test_run();
108
 
}
109
 
#else
110
 
int main() {
111
 
        return 77;
112
 
}
113
 
#endif