summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-string-util.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-06-10 04:54:45 +0000
committerHavoc Pennington <hp@redhat.com>2007-06-10 04:54:45 +0000
commita789b7b38cb4f4540a41444cbd64bf7ada2d60d2 (patch)
treedb5164def7f5d19266bc4ebfb4ce740f269d79e2 /dbus/dbus-string-util.c
parent7be5fd95cdccdca28937804f32ca8b1308887d09 (diff)
2007-06-09 Havoc Pennington <hp@redhat.com>
* dbus/dbus-string.c (_dbus_string_pop_line): fix this not to think an empty line is the end of the file. Also, fix some whitespace. * dbus/dbus-string-util.c: add more tests for _dbus_string_pop_line() revealing that it thinks an empty line is the end of the file, which broke dbus-auth-script.c so it didn't really run the scripts * dbus/dbus-auth.c: add ANONYMOUS mechanism * dbus/dbus-auth-script.c (_dbus_auth_script_run): fix to detect an empty/no-op auth script; add commands to check that we have or don't have the expected credentials
Diffstat (limited to 'dbus/dbus-string-util.c')
-rw-r--r--dbus/dbus-string-util.c112
1 files changed, 81 insertions, 31 deletions
diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c
index 16a79340..27bd23a1 100644
--- a/dbus/dbus-string-util.c
+++ b/dbus/dbus-string-util.c
@@ -705,43 +705,93 @@ _dbus_string_test (void)
_dbus_string_free (&str);
{
- int found,found_len;
- _dbus_string_init_const (&str, "012\r\n567\n90");
-
- if (!_dbus_string_find_eol(&str, 0, &found, &found_len) || found != 3 || found_len != 2)
- _dbus_assert_not_reached ("Did not find '\\r\\n'");
- if (found != 3 || found_len != 2)
- _dbus_assert_not_reached ("invalid return values");
-
- if (!_dbus_string_find_eol(&str, 5, &found, &found_len))
- _dbus_assert_not_reached ("Did not find '\\n'");
- if (found != 8 || found_len != 1)
- _dbus_assert_not_reached ("invalid return values");
-
- if (_dbus_string_find_eol(&str, 9, &found, &found_len))
- _dbus_assert_not_reached ("Found not expected '\\n'");
- else if (found != 11 || found_len != 0)
- _dbus_assert_not_reached ("invalid return values '\\n'");
-
- _dbus_string_free (&str);
- }
-
- return TRUE;
-}
-
-#endif /* DBUS_BUILD_TESTS */
-
-
-
-
-
-
+ int found, found_len;
+ _dbus_string_init_const (&str, "012\r\n567\n90");
+
+ if (!_dbus_string_find_eol (&str, 0, &found, &found_len) || found != 3 || found_len != 2)
+ _dbus_assert_not_reached ("Did not find '\\r\\n'");
+ if (found != 3 || found_len != 2)
+ _dbus_assert_not_reached ("invalid return values");
+
+ if (!_dbus_string_find_eol (&str, 5, &found, &found_len))
+ _dbus_assert_not_reached ("Did not find '\\n'");
+ if (found != 8 || found_len != 1)
+ _dbus_assert_not_reached ("invalid return values");
+
+ if (_dbus_string_find_eol (&str, 9, &found, &found_len))
+ _dbus_assert_not_reached ("Found not expected '\\n'");
+ else if (found != 11 || found_len != 0)
+ _dbus_assert_not_reached ("invalid return values '\\n'");
+
+ found = -1;
+ found_len = -1;
+ _dbus_string_init_const (&str, "");
+ if (_dbus_string_find_eol (&str, 0, &found, &found_len))
+ _dbus_assert_not_reached ("found an eol in an empty string");
+ _dbus_assert (found == 0);
+ _dbus_assert (found_len == 0);
+
+ found = -1;
+ found_len = -1;
+ _dbus_string_init_const (&str, "foobar");
+ if (_dbus_string_find_eol (&str, 0, &found, &found_len))
+ _dbus_assert_not_reached ("found eol in string that lacks one");
+ _dbus_assert (found == 6);
+ _dbus_assert (found_len == 0);
+
+ found = -1;
+ found_len = -1;
+ _dbus_string_init_const (&str, "foobar\n");
+ if (!_dbus_string_find_eol (&str, 0, &found, &found_len))
+ _dbus_assert_not_reached ("did not find eol in string that has one at end");
+ _dbus_assert (found == 6);
+ _dbus_assert (found_len == 1);
+ }
+ {
+ DBusString line;
+#define FIRST_LINE "this is a line"
+#define SECOND_LINE "this is a second line"
+ /* third line is empty */
+#define THIRD_LINE ""
+#define FOURTH_LINE "this is a fourth line"
+
+ if (!_dbus_string_init (&str))
+ _dbus_assert_not_reached ("no memory");
+ if (!_dbus_string_append (&str, FIRST_LINE "\n" SECOND_LINE "\r\n" THIRD_LINE "\n" FOURTH_LINE))
+ _dbus_assert_not_reached ("no memory");
+
+ if (!_dbus_string_init (&line))
+ _dbus_assert_not_reached ("no memory");
+
+ if (!_dbus_string_pop_line (&str, &line))
+ _dbus_assert_not_reached ("failed to pop first line");
+ _dbus_assert (_dbus_string_equal_c_str (&line, FIRST_LINE));
+
+ if (!_dbus_string_pop_line (&str, &line))
+ _dbus_assert_not_reached ("failed to pop second line");
+ _dbus_assert (_dbus_string_equal_c_str (&line, SECOND_LINE));
+
+ if (!_dbus_string_pop_line (&str, &line))
+ _dbus_assert_not_reached ("failed to pop third line");
+ _dbus_assert (_dbus_string_equal_c_str (&line, THIRD_LINE));
+
+ if (!_dbus_string_pop_line (&str, &line))
+ _dbus_assert_not_reached ("failed to pop fourth line");
+ _dbus_assert (_dbus_string_equal_c_str (&line, FOURTH_LINE));
+
+ _dbus_string_free (&str);
+ _dbus_string_free (&line);
+ }
+
+ return TRUE;
+}
+#endif /* DBUS_BUILD_TESTS */