1 /* -*- mode: C; c-file-style: "gnu" -*- */
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "dbus-sysdeps.h"
25 #include "dbus-internals.h"
26 #include "dbus-string.h"
27 #include "dbus-test.h"
29 #ifdef DBUS_BUILD_TESTS
32 check_dirname (const char *filename,
37 _dbus_string_init_const (&f, filename);
39 if (!_dbus_string_init (&d))
40 _dbus_assert_not_reached ("no memory");
42 if (!_dbus_string_get_dirname (&f, &d))
43 _dbus_assert_not_reached ("no memory");
45 if (!_dbus_string_equal_c_str (&d, dirname))
47 _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"\n",
49 _dbus_string_get_const_data (&d),
54 _dbus_string_free (&d);
58 check_path_absolute (const char *path,
63 _dbus_string_init_const (&p, path);
65 if (_dbus_path_is_absolute (&p) != expected)
67 _dbus_warn ("For path \"%s\" expected absolute = %d got %d\n",
68 path, expected, _dbus_path_is_absolute (&p));
74 * Unit test for dbus-sysdeps.c.
76 * @returns #TRUE on success.
79 _dbus_sysdeps_test (void)
85 check_dirname ("foo", ".");
86 check_dirname ("foo/bar", "foo");
87 check_dirname ("foo//bar", "foo");
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 ("/foo/bar", "/foo");
98 check_dirname ("/foo//bar", "/foo");
99 check_dirname ("/foo///bar", "/foo");
100 check_dirname ("/", "/");
101 check_dirname ("///", "/");
102 check_dirname ("", ".");
105 _dbus_string_init_const (&str, "3.5");
106 if (!_dbus_string_parse_double (&str,
109 _dbus_warn ("Failed to parse double");
112 if (ABS(3.5 - val) > 1e-6)
114 _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
119 _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
123 _dbus_string_init_const (&str, "0xff");
124 if (!_dbus_string_parse_double (&str,
127 _dbus_warn ("Failed to parse double");
130 if (ABS (0xff - val) > 1e-6)
132 _dbus_warn ("Failed to parse 0xff correctly, got: %f\n", val);
137 _dbus_warn ("_dbus_string_parse_double of \"0xff\" returned wrong position %d", pos);
141 check_path_absolute ("/", TRUE);
142 check_path_absolute ("/foo", TRUE);
143 check_path_absolute ("", FALSE);
144 check_path_absolute ("foo", FALSE);
145 check_path_absolute ("foo/bar", FALSE);
149 #endif /* DBUS_BUILD_TESTS */