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 check_dirname ("foo", ".");
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//bar////", "foo");
00094 check_dirname ("foo///bar///////", "foo");
00095 check_dirname ("/foo", "/");
00096 check_dirname ("////foo", "/");
00097 check_dirname ("/foo/bar", "/foo");
00098 check_dirname ("/foo//bar", "/foo");
00099 check_dirname ("/foo///bar", "/foo");
00100 check_dirname ("/", "/");
00101 check_dirname ("///", "/");
00102 check_dirname ("", ".");
00103
00104
00105 _dbus_string_init_const (&str, "3.5");
00106 if (!_dbus_string_parse_double (&str,
00107 0, &val, &pos))
00108 {
00109 _dbus_warn ("Failed to parse double");
00110 exit (1);
00111 }
00112 if (ABS(3.5 - val) > 1e-6)
00113 {
00114 _dbus_warn ("Failed to parse 3.5 correctly, got: %f", val);
00115 exit (1);
00116 }
00117 if (pos != 3)
00118 {
00119 _dbus_warn ("_dbus_string_parse_double of \"3.5\" returned wrong position %d", pos);
00120 exit (1);
00121 }
00122
00123 _dbus_string_init_const (&str, "0xff");
00124 if (!_dbus_string_parse_double (&str,
00125 0, &val, &pos))
00126 {
00127 _dbus_warn ("Failed to parse double");
00128 exit (1);
00129 }
00130 if (ABS (0xff - val) > 1e-6)
00131 {
00132 _dbus_warn ("Failed to parse 0xff correctly, got: %f\n", val);
00133 exit (1);
00134 }
00135 if (pos != 4)
00136 {
00137 _dbus_warn ("_dbus_string_parse_double of \"0xff\" returned wrong position %d", pos);
00138 exit (1);
00139 }
00140
00141 check_path_absolute ("/", TRUE);
00142 check_path_absolute ("/foo", TRUE);
00143 check_path_absolute ("", FALSE);
00144 check_path_absolute ("foo", FALSE);
00145 check_path_absolute ("foo/bar", FALSE);
00146
00147 return TRUE;
00148 }
00149 #endif