26 #include "dbus-internals.h"
27 #include "dbus-string.h"
28 #define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
29 #include "dbus-string-private.h"
49 const unsigned char *ap;
50 const unsigned char *bp;
51 const unsigned char *a_end;
52 unsigned long c_str_len;
57 c_str_len = strlen (c_str);
58 if (((
unsigned long)real_a->
len) < c_str_len)
61 ap = real_a->
str + (real_a->
len - c_str_len);
62 bp = (
const unsigned char*) c_str;
63 a_end = real_a->
str + real_a->
len;
104 if (real->str[i] == byte)
118 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
119 #include "dbus-test.h"
123 test_hex_roundtrip (
const unsigned char *data,
152 _dbus_assert (_dbus_string_get_length (&encoded) == end);
158 printf (
"Original string %d bytes encoded %d bytes decoded %d bytes\n",
159 _dbus_string_get_length (&orig),
160 _dbus_string_get_length (&encoded),
161 _dbus_string_get_length (&decoded));
162 printf (
"Original: %s\n", data);
163 s = _dbus_string_get_const_data (&decoded);
164 printf (
"Decoded: %s\n", s);
173 typedef void (* TestRoundtripFunc) (
const unsigned char *data,
176 test_roundtrips (TestRoundtripFunc func)
178 (* func) (
"Hello this is a string\n", -1);
179 (* func) (
"Hello this is a string\n1", -1);
180 (* func) (
"Hello this is a string\n12", -1);
181 (* func) (
"Hello this is a string\n123", -1);
182 (* func) (
"Hello this is a string\n1234", -1);
183 (* func) (
"Hello this is a string\n12345", -1);
188 (* func) (
"1234", 4);
189 (* func) (
"12345", 5);
194 (* func) (
"1234", 5);
195 (* func) (
"12345", 6);
197 unsigned char buf[512];
226 _dbus_string_test (
void)
232 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 };
254 _dbus_assert (_dbus_string_get_length (&str) == (j - 1));
317 _dbus_assert (_dbus_string_get_length (&str) == i * 2 + 1);
322 _dbus_assert (_dbus_string_get_length (&str) == i * 2 + 2);
337 i = _dbus_string_get_length (&str);
352 i = _dbus_string_get_length (&str);
370 _dbus_assert (_dbus_string_get_length (&other) == i * 2);
379 _dbus_assert (_dbus_string_get_length (&other) == i * 3);
388 i = _dbus_string_get_length (&str);
403 _dbus_assert (_dbus_string_get_length (&other) == i * 2);
405 "Hello WorldHello World"));
411 _dbus_assert (_dbus_string_get_length (&other) == i * 3);
413 "Hello WorldHello WorldHello World"));
426 i = _dbus_string_get_length (&str);
432 &other, 0, _dbus_string_get_length (&other)))
444 _dbus_assert (_dbus_string_get_length (&other) == i * 2 - 1);
446 "HelloHello WorldWorld"));
451 _dbus_string_get_length (&other) - 1,
456 _dbus_assert (_dbus_string_get_length (&other) == i * 2 - 1);
458 "HelloHello WorldWorle"));
474 i = _dbus_string_get_length (&str);
482 a = _dbus_string_get_length (&other);
489 _dbus_assert (_dbus_string_get_length (&other) == a + 6);
491 "Foo Hello String"));
495 _dbus_string_get_length (&other),
500 _dbus_assert (_dbus_string_get_length (&other) == a + 6 + 6);
502 "Foo Hello String World"));
506 _dbus_string_get_length (&other) - 5,
511 _dbus_assert (_dbus_string_get_length (&other) == a + 6 + 6);
513 "Foo Hello String Hello"));
520 _dbus_assert (_dbus_string_get_length (&other) == a + 5);
529 _dbus_assert (_dbus_string_get_length (&other) == a + 3);
535 _dbus_string_get_length (&other) - 5,
540 _dbus_assert (_dbus_string_get_length (&other) == a + 3);
561 _dbus_string_set_byte (&str, 1,
'q');
595 i = _dbus_string_get_length (&str);
699 test_roundtrips (test_hex_roundtrip);
704 int found, found_len;
710 if (found != 3 || found_len != 2)
715 if (found != 8 || found_len != 1)
720 else if (found != 11 || found_len != 0)
751 #define FIRST_LINE "this is a line"
752 #define SECOND_LINE "this is a second line"
754 #define THIRD_LINE ""
755 #define FOURTH_LINE "this is a fourth line"
760 if (!
_dbus_string_append (&str, FIRST_LINE
"\n" SECOND_LINE
"\r\n" THIRD_LINE
"\n" FOURTH_LINE))
794 for (i = 0; i < 10000; i++)
847 const char two_strings[] =
"one\ttwo";
861 if (strcmp (_dbus_string_get_data (&str),
"one") != 0)
864 if (strcmp (_dbus_string_get_data (&other),
"two") != 0)
872 const char upper_string[] =
"TOUPPERSTRING";
873 const char lower_string[] =
"toupperstring";
874 const char lower2_string[] =
"toupperSTRING";
904 const char lower_string[] =
"toupperstring";
905 const char upper_string[] =
"TOUPPERSTRING";
906 const char upper2_string[] =
"TOUPPERstring";