00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <config.h>
00026 #include "dbus-sysdeps.h"
00027 #include "dbus-internals.h"
00028 #include "dbus-string.h"
00029 #include "dbus-test.h"
00030
00031 #ifdef DBUS_BUILD_TESTS
00032 #include <stdlib.h>
00033 static void
00034 check_dirname (const char *filename,
00035 const char *dirname)
00036 {
00037 DBusString f, d;
00038
00039 _dbus_string_init_const (&f, filename);
00040
00041 if (!_dbus_string_init (&d))
00042 _dbus_assert_not_reached ("no memory");
00043
00044 if (!_dbus_string_get_dirname (&f, &d))
00045 _dbus_assert_not_reached ("no memory");
00046
00047 if (!_dbus_string_equal_c_str (&d, dirname))
00048 {
00049 _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"\n",
00050 filename,
00051 _dbus_string_get_const_data (&d),
00052 dirname);
00053 exit (1);
00054 }
00055
00056 _dbus_string_free (&d);
00057 }
00058
00059 static void
00060 check_path_absolute (const char *path,
00061 dbus_bool_t expected)
00062 {
00063 DBusString p;
00064
00065 _dbus_string_init_const (&p, path);
00066
00067 if (_dbus_path_is_absolute (&p) != expected)
00068 {
00069 _dbus_warn ("For path \"%s\" expected absolute = %d got %d\n",
00070 path, expected, _dbus_path_is_absolute (&p));
00071 exit (1);
00072 }
00073 }
00074
00080 dbus_bool_t
00081 _dbus_sysdeps_test (void)
00082 {
00083 DBusString str;
00084 double val;
00085 int pos;
00086
00087 #ifdef DBUS_WIN
00088 check_dirname ("foo\\bar", "foo");
00089 check_dirname ("foo\\\\bar", "foo");
00090 check_dirname ("foo/\\/bar", "foo");
00091 check_dirname ("foo\\bar/", "foo");
00092 check_dirname ("foo//bar\\", "foo");
00093 check_dirname ("foo\\bar/", "foo");
00094 check_dirname ("foo/bar\\\\", "foo");
00095 check_dirname ("\\foo", "\\");
00096 check_dirname ("\\\\foo", "\\");
00097 check_dirname ("\\", "\\");
00098 check_dirname ("\\\\", "\\");
00099 check_dirname ("\\/", "\\");
00100 check_dirname ("/\\/", "/");
00101 check_dirname ("c:\\foo\\bar", "c:\\foo");
00102 check_dirname ("c:\\foo", "c:\\");
00103 check_dirname ("c:/foo", "c:/");
00104 check_dirname ("c:\\", "c:\\");
00105 check_dirname ("c:/", "c:/");
00106 check_dirname ("", ".");
00107 #else
00108 check_dirname ("foo", ".");
00109 check_dirname ("foo/bar", "foo");
00110 check_dirname ("foo//bar", "foo");
00111 check_dirname ("foo///bar", "foo");
00112 check_dirname ("foo/bar/", "foo");
00113 check_dirname ("foo//bar/", "foo");
00114 check_dirname ("foo///bar/", "foo");
00115 check_dirname ("foo/bar//", "foo");
00116 check_dirname ("foo//bar////", "foo");
00117 check_dirname ("foo///bar///////", "foo");
00118 check_dirname ("/foo", "/");
00119 check_dirname ("////foo", "/");
00120 check_dirname ("/foo/bar", "/foo");
00121 check_dirname ("/foo//bar", "/foo");
00122 check_dirname ("/foo///bar", "/foo");
00123 check_dirname ("/", "/");
00124 check_dirname ("///", "/");
00125 check_dirname ("", ".");
00126 #endif
00127
00128 _dbus_string_init_const (&str, "3.5");
00129 if (!_dbus_string_parse_double (&str,
00130 0, &val, &pos))
00131 {
00132 _dbus_warn ("Failed to parse double");
00133 exit (1);
00134 }
00135 if (ABS(3.5 - val) > 1e-6)
00136 {
00137 _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
00138 exit (1);
00139 }
00140 if (pos != 3)
00141 {
00142 _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
00143 exit (1);
00144 }
00145
00146 _dbus_string_init_const (&str, "0xff");
00147 if (_dbus_string_parse_double (&str,
00148 0, &val, &pos))
00149 {
00150 _dbus_warn ("Should not have parsed hex as double\n");
00151 exit (1);
00152 }
00153
00154 #ifdef DBUS_WIN
00155 check_path_absolute ("c:/", TRUE);
00156 check_path_absolute ("c:/foo", TRUE);
00157 check_path_absolute ("", FALSE);
00158 check_path_absolute ("foo", FALSE);
00159 check_path_absolute ("foo/bar", FALSE);
00160 check_path_absolute ("", FALSE);
00161 check_path_absolute ("foo\\bar", FALSE);
00162 check_path_absolute ("c:\\", TRUE);
00163 check_path_absolute ("c:\\foo", TRUE);
00164 check_path_absolute ("c:", TRUE);
00165 check_path_absolute ("c:\\foo\\bar", TRUE);
00166 check_path_absolute ("\\", TRUE);
00167 check_path_absolute ("/", TRUE);
00168 #else
00169 check_path_absolute ("/", TRUE);
00170 check_path_absolute ("/foo", TRUE);
00171 check_path_absolute ("", FALSE);
00172 check_path_absolute ("foo", FALSE);
00173 check_path_absolute ("foo/bar", FALSE);
00174 #endif
00175
00176 return TRUE;
00177 }
00178 #endif