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