1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-sysdeps-util.c Tests for dbus-sysdeps.h API
4 * Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
5 * Copyright (C) 2003 CodeFactory AB
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "dbus-sysdeps.h"
27 #include "dbus-internals.h"
28 #include "dbus-string.h"
29 #include "dbus-test.h"
31 #ifdef DBUS_BUILD_TESTS
34 check_dirname (const char *filename,
39 _dbus_string_init_const (&f, filename);
41 if (!_dbus_string_init (&d))
42 _dbus_assert_not_reached ("no memory");
44 if (!_dbus_string_get_dirname (&f, &d))
45 _dbus_assert_not_reached ("no memory");
47 if (!_dbus_string_equal_c_str (&d, dirname))
49 _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"\n",
51 _dbus_string_get_const_data (&d),
56 _dbus_string_free (&d);
60 check_path_absolute (const char *path,
65 _dbus_string_init_const (&p, path);
67 if (_dbus_path_is_absolute (&p) != expected)
69 _dbus_warn ("For path \"%s\" expected absolute = %d got %d\n",
70 path, expected, _dbus_path_is_absolute (&p));
76 * Unit test for dbus-sysdeps.c.
78 * @returns #TRUE on success.
81 _dbus_sysdeps_test (void)
88 check_dirname ("foo\\bar", "foo");
89 check_dirname ("foo\\\\bar", "foo");
90 check_dirname ("foo/\\/bar", "foo");
91 check_dirname ("foo\\bar/", "foo");
92 check_dirname ("foo//bar\\", "foo");
93 check_dirname ("foo\\bar/", "foo");
94 check_dirname ("foo/bar\\\\", "foo");
95 check_dirname ("\\foo", "\\");
96 check_dirname ("\\\\foo", "\\");
97 check_dirname ("\\", "\\");
98 check_dirname ("\\\\", "\\");
99 check_dirname ("\\/", "\\");
100 check_dirname ("/\\/", "/");
101 check_dirname ("c:\\foo\\bar", "c:\\foo");
102 check_dirname ("c:\\foo", "c:\\");
103 check_dirname ("c:/foo", "c:/");
104 check_dirname ("c:\\", "c:\\");
105 check_dirname ("c:/", "c:/");
106 check_dirname ("", ".");
108 check_dirname ("foo", ".");
109 check_dirname ("foo/bar", "foo");
110 check_dirname ("foo//bar", "foo");
111 check_dirname ("foo///bar", "foo");
112 check_dirname ("foo/bar/", "foo");
113 check_dirname ("foo//bar/", "foo");
114 check_dirname ("foo///bar/", "foo");
115 check_dirname ("foo/bar//", "foo");
116 check_dirname ("foo//bar////", "foo");
117 check_dirname ("foo///bar///////", "foo");
118 check_dirname ("/foo", "/");
119 check_dirname ("////foo", "/");
120 check_dirname ("/foo/bar", "/foo");
121 check_dirname ("/foo//bar", "/foo");
122 check_dirname ("/foo///bar", "/foo");
123 check_dirname ("/", "/");
124 check_dirname ("///", "/");
125 check_dirname ("", ".");
128 _dbus_string_init_const (&str, "3.5");
129 if (!_dbus_string_parse_double (&str,
132 _dbus_warn ("Failed to parse double");
135 if (ABS(3.5 - val) > 1e-6)
137 _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
142 _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
146 _dbus_string_init_const (&str, "0xff");
147 if (_dbus_string_parse_double (&str,
150 _dbus_warn ("Should not have parsed hex as double\n");
155 check_path_absolute ("c:/", TRUE);
156 check_path_absolute ("c:/foo", TRUE);
157 check_path_absolute ("", FALSE);
158 check_path_absolute ("foo", FALSE);
159 check_path_absolute ("foo/bar", FALSE);
160 check_path_absolute ("", FALSE);
161 check_path_absolute ("foo\\bar", FALSE);
162 check_path_absolute ("c:\\", TRUE);
163 check_path_absolute ("c:\\foo", TRUE);
164 check_path_absolute ("c:", TRUE);
165 check_path_absolute ("c:\\foo\\bar", TRUE);
166 check_path_absolute ("\\", TRUE);
167 check_path_absolute ("/", TRUE);
169 check_path_absolute ("/", TRUE);
170 check_path_absolute ("/foo", TRUE);
171 check_path_absolute ("", FALSE);
172 check_path_absolute ("foo", FALSE);
173 check_path_absolute ("foo/bar", FALSE);
178 #endif /* DBUS_BUILD_TESTS */