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-path.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 Resolve a relative path against an absolute base directory.
41
START_TEST(test_path_basedir) {
45
filename = g_build_filename("some", "relative", "path", "file", NULL);
47
/* resolving this path must lead to changing the filename */
48
g_assert_cmpint(chassis_resolve_path(G_DIR_SEPARATOR_S "tmp", &filename), ==, 1);
50
test_filename = g_build_filename(G_DIR_SEPARATOR_S "tmp", "some", "relative", "path", "file", NULL);
52
g_assert_cmpstr(test_filename, ==, filename);
55
g_free(test_filename);
59
* @test Resolving a relative path against a missing base directory does not modify the relative directory.
61
START_TEST(test_no_basedir) {
65
filename = g_build_filename("some", "relative", "path", "file", NULL);
66
test_filename = g_strdup(filename);
68
/* resolving this path must not lead to changing the filename */
69
g_assert_cmpint(chassis_resolve_path(NULL, &filename), ==, 0);
71
g_assert_cmpstr(test_filename, ==, filename);
74
g_free(test_filename);
78
* @test Resolving an absolute path against an absolute basedir has no effect and does not change the directory to be resolved.
80
START_TEST(test_abspath_basedir) {
84
filename = g_build_filename(G_DIR_SEPARATOR_S "some", "relative", "path", "file", NULL);
85
test_filename = g_strdup(filename);
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);
90
g_assert_cmpstr(test_filename, ==, filename);
93
g_free(test_filename);
97
int main(int argc, char **argv) {
100
g_test_init(&argc, &argv, NULL);
101
g_test_bug_base("http://bugs.mysql.com/");
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);