index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-string-util.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-string-util.c Would be in dbus-string.c, but not used in libdbus
00003
*
00004
* Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
00005
*
00006
* Licensed under the Academic Free License version 2.1
00007
*
00008
* This program is free software; you can redistribute it and/or modify
00009
* it under the terms of the GNU General Public License as published by
00010
* the Free Software Foundation; either version 2 of the License, or
00011
* (at your option) any later version.
00012
*
00013
* This program is distributed in the hope that it will be useful,
00014
* but WITHOUT ANY WARRANTY; without even the implied warranty of
00015
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016
* GNU General Public License for more details.
00017
*
00018
* You should have received a copy of the GNU General Public License
00019
* along with this program; if not, write to the Free Software
00020
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021
*
00022
*/
00023
00024
#include "dbus-internals.h"
00025
#include "dbus-string.h"
00026
#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
00027
#include "dbus-string-private.h"
00028
00043
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga0
00044
group__DBusString.html#ga0
_dbus_string_ends_with_c_str
(
const
structDBusString.html
DBusString
*a,
00045
const
char
*c_str)
00046 {
00047
const
unsigned
char
*ap;
00048
const
unsigned
char
*bp;
00049
const
unsigned
char
*a_end;
00050
unsigned
long
c_str_len;
00051
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
00052
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
00053
group__DBusInternalsUtils.html#ga130
_dbus_assert
(c_str !=
group__DBusMacros.html#ga4
NULL
);
00054
00055   c_str_len = strlen (c_str);
00056
if
(((
unsigned
long
)real_a->
structDBusRealString.html#o1
len
) < c_str_len)
00057
return
group__DBusMacros.html#ga3
FALSE
;
00058
00059   ap = real_a->
structDBusRealString.html#o0
str
+ (real_a->
structDBusRealString.html#o1
len
- c_str_len);
00060   bp = (
const
unsigned
char
*) c_str;
00061   a_end = real_a->
structDBusRealString.html#o0
str
+ real_a->
structDBusRealString.html#o1
len
;
00062
while
(ap != a_end)
00063     {
00064
if
(*ap != *bp)
00065
return
group__DBusMacros.html#ga3
FALSE
;
00066
00067       ++ap;
00068       ++bp;
00069     }
00070
00071
group__DBusInternalsUtils.html#ga130
_dbus_assert
(*ap ==
'\0'
);
00072
group__DBusInternalsUtils.html#ga130
_dbus_assert
(*bp ==
'\0'
);
00073
00074
return
group__DBusMacros.html#ga2
TRUE
;
00075 }
00076
00087
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga1
00088
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(
const
structDBusString.html
DBusString
*str,
00089
int
start,
00090
unsigned
char
byte,
00091
int
*found)
00092 {
00093
int
i;
00094
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00095
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00096
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00097
group__DBusInternalsUtils.html#ga130
_dbus_assert
(found !=
group__DBusMacros.html#ga4
NULL
);
00098
00099   i = start - 1;
00100
while
(i >= 0)
00101     {
00102
if
(real->str[i] == byte)
00103
break
;
00104
00105       --i;
00106     }
00107
00108
if
(found)
00109     *found = i;
00110
00111
return
i >= 0;
00112 }
00113
00122
void
group__DBusString.html#ga2
00123
group__DBusString.html#ga2
_dbus_string_skip_white
(
const
structDBusString.html
DBusString
*str,
00124
int
start,
00125
int
*end)
00126 {
00127
int
i;
00128
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00129
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00130
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00131
00132   i = start;
00133
while
(i < real->len)
00134     {
00135
if
(!(real->str[i] ==
' '
||
00136             real->str[i] ==
'\n'
||
00137             real->str[i] ==
'\r'
||
00138             real->str[i] ==
'\t'
))
00139
break
;
00140
00141       ++i;
00142     }
00143
00144
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == real->len || !(real->str[i] ==
' '
||
00145                                     real->str[i] ==
'\t'
));
00146
00147
if
(end)
00148     *end = i;
00149 }
00150
00153
#ifdef DBUS_BUILD_TESTS
00154
#include "dbus-test.h"
00155
#include <stdio.h>
00156
00157
static
void
00158 test_max_len (
structDBusString.html
DBusString
*str,
00159
int
max_len)
00160 {
00161
if
(max_len > 0)
00162     {
00163
if
(!
group__DBusString.html#ga21
_dbus_string_set_length
(str, max_len - 1))
00164
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"setting len to one less than max should have worked"
);
00165     }
00166
00167
if
(!
group__DBusString.html#ga21
_dbus_string_set_length
(str, max_len))
00168
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"setting len to max len should have worked"
);
00169
00170
if
(
group__DBusString.html#ga21
_dbus_string_set_length
(str, max_len + 1))
00171
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"setting len to one more than max len should not have worked"
);
00172
00173
if
(!
group__DBusString.html#ga21
_dbus_string_set_length
(str, 0))
00174
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"setting len to zero should have worked"
);
00175 }
00176
00177
static
void
00178 test_hex_roundtrip (
const
unsigned
char
*data,
00179
int
len)
00180 {
00181
structDBusString.html
DBusString
orig;
00182
structDBusString.html
DBusString
encoded;
00183
structDBusString.html
DBusString
decoded;
00184
int
end;
00185
00186
if
(len < 0)
00187     len = strlen (data);
00188
00189
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&orig))
00190
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00191
00192
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&encoded))
00193
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00194
00195
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&decoded))
00196
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00197
00198
if
(!
group__DBusString.html#ga34
_dbus_string_append_len
(&orig, data, len))
00199
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"couldn't append orig data"
);
00200
00201
if
(!
group__DBusString.html#ga53
_dbus_string_hex_encode
(&orig, 0, &encoded, 0))
00202
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not encode"
);
00203
00204
if
(!
group__DBusString.html#ga54
_dbus_string_hex_decode
(&encoded, 0, &end, &decoded, 0))
00205
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not decode"
);
00206
00207
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&encoded) == end);
00208
00209
if
(!
group__DBusString.html#ga49
_dbus_string_equal
(&orig, &decoded))
00210     {
00211
const
char
*s;
00212
00213       printf (
"Original string %d bytes encoded %d bytes decoded %d bytes\n"
,
00214               _dbus_string_get_length (&orig),
00215               _dbus_string_get_length (&encoded),
00216               _dbus_string_get_length (&decoded));
00217       printf (
"Original: %s\n"
, data);
00218       s = _dbus_string_get_const_data (&decoded);
00219       printf (
"Decoded: %s\n"
, s);
00220
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"original string not the same as string decoded from hex"
);
00221     }
00222
00223
group__DBusString.html#ga9
_dbus_string_free
(&orig);
00224
group__DBusString.html#ga9
_dbus_string_free
(&encoded);
00225
group__DBusString.html#ga9
_dbus_string_free
(&decoded);
00226 }
00227
00228
typedef
void (* TestRoundtripFunc) (
const
unsigned
char
*data,
00229
int
len);
00230
static
void
00231 test_roundtrips (TestRoundtripFunc func)
00232 {
00233   (* func) (
"Hello this is a string\n"
, -1);
00234   (* func) (
"Hello this is a string\n1"
, -1);
00235   (* func) (
"Hello this is a string\n12"
, -1);
00236   (* func) (
"Hello this is a string\n123"
, -1);
00237   (* func) (
"Hello this is a string\n1234"
, -1);
00238   (* func) (
"Hello this is a string\n12345"
, -1);
00239   (* func) (
""
, 0);
00240   (* func) (
"1"
, 1);
00241   (* func) (
"12"
, 2);
00242   (* func) (
"123"
, 3);
00243   (* func) (
"1234"
, 4);
00244   (* func) (
"12345"
, 5);
00245   (* func) (
""
, 1);
00246   (* func) (
"1"
, 2);
00247   (* func) (
"12"
, 3);
00248   (* func) (
"123"
, 4);
00249   (* func) (
"1234"
, 5);
00250   (* func) (
"12345"
, 6);
00251   {
00252
unsigned
char
buf[512];
00253
int
i;
00254
00255     i = 0;
00256
while
(i <
group__DBusInternalsUtils.html#ga132
_DBUS_N_ELEMENTS
(buf))
00257       {
00258         buf[i] = i;
00259         ++i;
00260       }
00261     i = 0;
00262
while
(i <
group__DBusInternalsUtils.html#ga132
_DBUS_N_ELEMENTS
(buf))
00263       {
00264         (* func) (buf, i);
00265         ++i;
00266       }
00267   }
00268 }
00269
00270
#ifdef DBUS_BUILD_TESTS
00271
/* The max length thing is sort of a historical artifact
00272
* from a feature that turned out to be dumb; perhaps
00273
* we should purge it entirely. The problem with
00274
* the feature is that it looks like memory allocation
00275
* failure, but is not a transient or resolvable failure.
00276
*/
00277
static
void
00278 set_max_length (
structDBusString.html
DBusString
*str,
00279
int
max_length)
00280 {
00281
structDBusRealString.html
DBusRealString
*real;
00282
00283   real = (
structDBusRealString.html
DBusRealString
*) str;
00284
00285   real->
structDBusRealString.html#o3
max_length
= max_length;
00286 }
00287
#endif
/* DBUS_BUILD_TESTS */
00288
00299
group__DBusTypes.html#ga2
dbus_bool_t
00300 _dbus_string_test (
void
)
00301 {
00302
structDBusString.html
DBusString
str;
00303
structDBusString.html
DBusString
other;
00304
int
i, end;
00305
long
v;
00306
double
d;
00307
int
lens[] = { 0, 1, 2, 3, 4, 5, 10, 16, 17, 18, 25, 31, 32, 33, 34, 35, 63, 64, 65, 66, 67, 68, 69, 70, 71, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136 };
00308
char
*s;
00309   dbus_unichar_t ch;
00310
00311   i = 0;
00312
while
(i <
group__DBusInternalsUtils.html#ga132
_DBUS_N_ELEMENTS
(lens))
00313     {
00314
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00315
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00316
00317       set_max_length (&str, lens[i]);
00318
00319       test_max_len (&str, lens[i]);
00320
group__DBusString.html#ga9
_dbus_string_free
(&str);
00321
00322       ++i;
00323     }
00324
00325
/* Test shortening and setting length */
00326   i = 0;
00327
while
(i <
group__DBusInternalsUtils.html#ga132
_DBUS_N_ELEMENTS
(lens))
00328     {
00329
int
j;
00330
00331
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00332
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00333
00334       set_max_length (&str, lens[i]);
00335
00336
if
(!
group__DBusString.html#ga21
_dbus_string_set_length
(&str, lens[i]))
00337
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to set string length"
);
00338
00339       j = lens[i];
00340
while
(j > 0)
00341         {
00342
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == j);
00343
if
(j > 0)
00344             {
00345
group__DBusString.html#ga20
_dbus_string_shorten
(&str, 1);
00346
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == (j - 1));
00347             }
00348           --j;
00349         }
00350
00351
group__DBusString.html#ga9
_dbus_string_free
(&str);
00352
00353       ++i;
00354     }
00355
00356
/* Test equality */
00357
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00358
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"oom"
);
00359
00360
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00361
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"oom"
);
00362
00363
group__DBusString.html#ga7
_dbus_string_init_const
(&other,
"H"
);
00364
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 0, 1, &other, 0));
00365
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 1, 0, &other, 1));
00366
group__DBusString.html#ga7
_dbus_string_init_const
(&other,
"Hello"
);
00367
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 0, 5, &other, 0));
00368
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 1, 4, &other, 1));
00369
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 2, 3, &other, 2));
00370
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 3, 2, &other, 3));
00371
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 4, 1, &other, 4));
00372
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 5, 0, &other, 5));
00373
00374
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 0, 5, &str, 0));
00375
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 1, 4, &str, 1));
00376
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 2, 3, &str, 2));
00377
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 3, 2, &str, 3));
00378
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 4, 1, &str, 4));
00379
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 5, 0, &str, 5));
00380
00381
00382
group__DBusString.html#ga7
_dbus_string_init_const
(&other,
"World"
);
00383
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 6,  5, &other, 0));
00384
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 7,  4, &other, 1));
00385
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 8,  3, &other, 2));
00386
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 9,  2, &other, 3));
00387
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 10, 1, &other, 4));
00388
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&str, 11, 0, &other, 5));
00389
00390
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 0, 5, &str, 6));
00391
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 1, 4, &str, 7));
00392
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 2, 3, &str, 8));
00393
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 3, 2, &str, 9));
00394
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 4, 1, &str, 10));
00395
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga50
_dbus_string_equal_substring
(&other, 5, 0, &str, 11));
00396
00397
group__DBusString.html#ga9
_dbus_string_free
(&str);
00398
00399
/* Test appending data */
00400
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00401
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00402
00403   i = 0;
00404
while
(i < 10)
00405     {
00406
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"a"
))
00407
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append string to string\n"
);
00408
00409
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i * 2 + 1);
00410
00411
if
(!
group__DBusString.html#ga35
_dbus_string_append_byte
(&str,
'b'
))
00412
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append byte to string\n"
);
00413
00414
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i * 2 + 2);
00415
00416       ++i;
00417     }
00418
00419
group__DBusString.html#ga9
_dbus_string_free
(&str);
00420
00421
/* Check steal_data */
00422
00423
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00424
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00425
00426
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00427
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00428
00429   i = _dbus_string_get_length (&str);
00430
00431
if
(!
group__DBusString.html#ga16
_dbus_string_steal_data
(&str, &s))
00432
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to steal data"
);
00433
00434
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == 0);
00435
group__DBusInternalsUtils.html#ga130
_dbus_assert
(((
int
)strlen (s)) == i);
00436
00437
group__DBusMemory.html#ga3
dbus_free
(s);
00438
00439
/* Check move */
00440
00441
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00442
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00443
00444   i = _dbus_string_get_length (&str);
00445
00446
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&other))
00447
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00448
00449
if
(!
group__DBusString.html#ga39
_dbus_string_move
(&str, 0, &other, 0))
00450
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not move"
);
00451
00452
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == 0);
00453
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i);
00454
00455
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00456
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00457
00458
if
(!
group__DBusString.html#ga39
_dbus_string_move
(&str, 0, &other, _dbus_string_get_length (&other)))
00459
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not move"
);
00460
00461
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == 0);
00462
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 2);
00463
00464
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00465
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00466
00467
if
(!
group__DBusString.html#ga39
_dbus_string_move
(&str, 0, &other, _dbus_string_get_length (&other) / 2))
00468
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not move"
);
00469
00470
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == 0);
00471
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 3);
00472
00473
group__DBusString.html#ga9
_dbus_string_free
(&other);
00474
00475
/* Check copy */
00476
00477
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00478
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00479
00480   i = _dbus_string_get_length (&str);
00481
00482
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&other))
00483
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00484
00485
if
(!
group__DBusString.html#ga40
_dbus_string_copy
(&str, 0, &other, 0))
00486
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not copy"
);
00487
00488
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00489
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i);
00490
00491
if
(!
group__DBusString.html#ga40
_dbus_string_copy
(&str, 0, &other, _dbus_string_get_length (&other)))
00492
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not copy"
);
00493
00494
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00495
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 2);
00496
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga51
_dbus_string_equal_c_str
(&other,
00497
"Hello WorldHello World"
));
00498
00499
if
(!
group__DBusString.html#ga40
_dbus_string_copy
(&str, 0, &other, _dbus_string_get_length (&other) / 2))
00500
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not copy"
);
00501
00502
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00503
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 3);
00504
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga51
_dbus_string_equal_c_str
(&other,
00505
"Hello WorldHello WorldHello World"
));
00506
00507
group__DBusString.html#ga9
_dbus_string_free
(&str);
00508
group__DBusString.html#ga9
_dbus_string_free
(&other);
00509
00510
/* Check replace */
00511
00512
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00513
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00514
00515
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello World"
))
00516
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not append to string"
);
00517
00518   i = _dbus_string_get_length (&str);
00519
00520
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&other))
00521
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00522
00523
if
(!
group__DBusString.html#ga43
_dbus_string_replace_len
(&str, 0, _dbus_string_get_length (&str),
00524                                  &other, 0, _dbus_string_get_length (&other)))
00525
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not replace"
);
00526
00527
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00528
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i);
00529
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga51
_dbus_string_equal_c_str
(&other,
"Hello World"
));
00530
00531
if
(!
group__DBusString.html#ga43
_dbus_string_replace_len
(&str, 0, _dbus_string_get_length (&str),
00532                                  &other, 5, 1))
00533
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not replace center space"
);
00534
00535
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00536
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 2 - 1);
00537
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga51
_dbus_string_equal_c_str
(&other,
00538
"HelloHello WorldWorld"
));
00539
00540
00541
if
(!
group__DBusString.html#ga43
_dbus_string_replace_len
(&str, 1, 1,
00542                                  &other,
00543                                  _dbus_string_get_length (&other) - 1,
00544                                  1))
00545
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not replace end character"
);
00546
00547
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&str) == i);
00548
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (&other) == i * 2 - 1);
00549
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
group__DBusString.html#ga51
_dbus_string_equal_c_str
(&other,
00550
"HelloHello WorldWorle"
));
00551
00552
group__DBusString.html#ga9
_dbus_string_free
(&str);
00553
group__DBusString.html#ga9
_dbus_string_free
(&other);
00554
00555
/* Check append/get unichar */
00556
00557
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00558
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00559
00560   ch = 0;
00561
if
(!_dbus_string_append_unichar (&str, 0xfffc))
00562
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append unichar"
);
00563
00564   _dbus_string_get_unichar (&str, 0, &ch, &i);
00565
00566
group__DBusInternalsUtils.html#ga130
_dbus_assert
(ch == 0xfffc);
00567
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == _dbus_string_get_length (&str));
00568
00569
group__DBusString.html#ga9
_dbus_string_free
(&str);
00570
00571
/* Check insert/set/get byte */
00572
00573
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00574
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00575
00576
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello"
))
00577
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append Hello"
);
00578
00579
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 0) ==
'H'
);
00580
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 1) ==
'e'
);
00581
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 2) ==
'l'
);
00582
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 3) ==
'l'
);
00583
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 4) ==
'o'
);
00584
00585   _dbus_string_set_byte (&str, 1,
'q'
);
00586
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 1) ==
'q'
);
00587
00588
if
(!
group__DBusString.html#ga14
_dbus_string_insert_bytes
(&str, 0, 1, 255))
00589
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"can't insert byte"
);
00590
00591
if
(!
group__DBusString.html#ga14
_dbus_string_insert_bytes
(&str, 2, 4,
'Z'
))
00592
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"can't insert byte"
);
00593
00594
if
(!
group__DBusString.html#ga14
_dbus_string_insert_bytes
(&str, _dbus_string_get_length (&str), 1,
'W'
))
00595
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"can't insert byte"
);
00596
00597
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 0) == 255);
00598
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 1) ==
'H'
);
00599
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 2) ==
'Z'
);
00600
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 3) ==
'Z'
);
00601
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 4) ==
'Z'
);
00602
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 5) ==
'Z'
);
00603
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 6) ==
'q'
);
00604
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 7) ==
'l'
);
00605
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 8) ==
'l'
);
00606
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 9) ==
'o'
);
00607
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_byte (&str, 10) ==
'W'
);
00608
00609
group__DBusString.html#ga9
_dbus_string_free
(&str);
00610
00611
/* Check append/parse int/double */
00612
00613
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00614
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00615
00616
if
(!
group__DBusString.html#ga60
_dbus_string_append_int
(&str, 27))
00617
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append int"
);
00618
00619   i = _dbus_string_get_length (&str);
00620
00621
if
(!
group__DBusString.html#ga62
_dbus_string_parse_int
(&str, 0, &v, &end))
00622
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to parse int"
);
00623
00624
group__DBusInternalsUtils.html#ga130
_dbus_assert
(v == 27);
00625
group__DBusInternalsUtils.html#ga130
_dbus_assert
(end == i);
00626
00627
group__DBusString.html#ga9
_dbus_string_free
(&str);
00628
00629
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00630
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00631
00632
if
(!_dbus_string_append_double (&str, 50.3))
00633
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to append float"
);
00634
00635   i = _dbus_string_get_length (&str);
00636
00637
if
(!_dbus_string_parse_double (&str, 0, &d, &end))
00638
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to parse float"
);
00639
00640
group__DBusInternalsUtils.html#ga130
_dbus_assert
(d > (50.3 - 1e-6) && d < (50.3 + 1e-6));
00641
group__DBusInternalsUtils.html#ga130
_dbus_assert
(end == i);
00642
00643
group__DBusString.html#ga9
_dbus_string_free
(&str);
00644
00645
/* Test find */
00646
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&str))
00647
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"failed to init string"
);
00648
00649
if
(!
group__DBusString.html#ga27
_dbus_string_append
(&str,
"Hello"
))
00650
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"couldn't append to string"
);
00651
00652
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"He"
, &i))
00653
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'He'"
);
00654
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 0);
00655
00656
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"Hello"
, &i))
00657
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'Hello'"
);
00658
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 0);
00659
00660
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"ello"
, &i))
00661
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'ello'"
);
00662
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 1);
00663
00664
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"lo"
, &i))
00665
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'lo'"
);
00666
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 3);
00667
00668
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 2,
"lo"
, &i))
00669
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'lo'"
);
00670
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 3);
00671
00672
if
(
group__DBusString.html#ga44
_dbus_string_find
(&str, 4,
"lo"
, &i))
00673
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"did find 'lo'"
);
00674
00675
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"l"
, &i))
00676
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'l'"
);
00677
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 2);
00678
00679
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"H"
, &i))
00680
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find 'H'"
);
00681
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 0);
00682
00683
if
(!
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
""
, &i))
00684
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"didn't find ''"
);
00685
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 0);
00686
00687
if
(
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"Hello!"
,
group__DBusMacros.html#ga4
NULL
))
00688
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'Hello!'"
);
00689
00690
if
(
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"Oh, Hello"
,
group__DBusMacros.html#ga4
NULL
))
00691
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'Oh, Hello'"
);
00692
00693
if
(
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"ill"
,
group__DBusMacros.html#ga4
NULL
))
00694
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'ill'"
);
00695
00696
if
(
group__DBusString.html#ga44
_dbus_string_find
(&str, 0,
"q"
,
group__DBusMacros.html#ga4
NULL
))
00697
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'q'"
);
00698
00699
if
(!
group__DBusString.html#ga45
_dbus_string_find_to
(&str, 0, 2,
"He"
,
group__DBusMacros.html#ga4
NULL
))
00700
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Didn't find 'He'"
);
00701
00702
if
(
group__DBusString.html#ga45
_dbus_string_find_to
(&str, 0, 2,
"Hello"
,
group__DBusMacros.html#ga4
NULL
))
00703
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'Hello'"
);
00704
00705
if
(!
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(&str, _dbus_string_get_length (&str),
'H'
, &i))
00706
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did not find 'H'"
);
00707
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 0);
00708
00709
if
(!
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(&str, _dbus_string_get_length (&str),
'o'
, &i))
00710
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did not find 'o'"
);
00711
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == _dbus_string_get_length (&str) - 1);
00712
00713
if
(
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(&str, _dbus_string_get_length (&str) - 1,
'o'
, &i))
00714
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'o'"
);
00715
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == -1);
00716
00717
if
(
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(&str, 1,
'e'
, &i))
00718
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Did find 'e'"
);
00719
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == -1);
00720
00721
if
(!
group__DBusString.html#ga1
_dbus_string_find_byte_backward
(&str, 2,
'e'
, &i))
00722
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"Didn't find 'e'"
);
00723
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == 1);
00724
00725
group__DBusString.html#ga9
_dbus_string_free
(&str);
00726
00727
/* Hex encoding */
00728
group__DBusString.html#ga7
_dbus_string_init_const
(&str,
"cafebabe, this is a bogus hex string"
);
00729
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&other))
00730
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"could not init string"
);
00731
00732
if
(!
group__DBusString.html#ga54
_dbus_string_hex_decode
(&str, 0, &end, &other, 0))
00733
group__DBusInternalsUtils.html#ga131
_dbus_assert_not_reached
(
"deccoded bogus hex string with no error"
);
00734
00735
group__DBusInternalsUtils.html#ga130
_dbus_assert
(end == 8);
00736
00737
group__DBusString.html#ga9
_dbus_string_free
(&other);
00738
00739   test_roundtrips (test_hex_roundtrip);
00740
00741
group__DBusString.html#ga9
_dbus_string_free
(&str);
00742
00743
return
group__DBusMacros.html#ga2
TRUE
;
00744 }
00745
00746
#endif
/* DBUS_BUILD_TESTS */
Generated on Tue Sep 13 01:28:07 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
