25 #ifdef DBUS_BUILD_TESTS
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 #include "dbus-internals.h"
30 #include "dbus-marshal-validate.h"
31 #include "dbus-marshal-recursive.h"
33 #include "dbus-test.h"
43 run_validity_tests (
const ValidityTest *tests,
49 for (i = 0; i < n_tests; i++)
58 if (v != tests[i].expected)
60 _dbus_warn (
"Improper validation result %d for '%s'\n",
69 static const ValidityTest signature_tests[] = {
74 {
"w", DBUS_INVALID_UNKNOWN_TYPECODE },
75 {
"a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
76 {
"aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
77 {
"ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
78 {
"ia", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
80 {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
81 DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION },
82 {
"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ii))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))",
83 DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
84 {
")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
85 {
"i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
86 {
"a)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
87 {
"(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
88 {
"(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
89 {
"(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
90 {
"(ai", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
91 {
"()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
92 {
"(())", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
93 {
"a()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
94 {
"i()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
95 {
"()i", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
96 {
"(a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
97 {
"a{ia}", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
98 {
"a{}", DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS },
99 {
"a{aii}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
106 _dbus_marshal_validate_test (
void)
111 const char *valid_paths[] = {
117 const char *invalid_paths[] = {
133 const char *valid_interfaces[] = {
134 "org.freedesktop.Foo",
136 "Blah.Blah.Blah.Blah.Blah",
139 "a0.b1.c2.d3.e4.f5.g6",
142 const char *invalid_interfaces[] = {
170 const char *valid_unique_names[] = {
179 ":abce.freedesktop.blah"
181 const char *invalid_unique_names[] = {
195 const char *valid_members[] = {
203 const char *invalid_members[] = {
218 const char *valid_signatures[] = {
225 const char *invalid_signatures[] = {
227 "not a valid signature",
248 _dbus_warn (
"Path \"%s\" should have been valid\n", valid_paths[i]);
263 _dbus_warn (
"Path \"%s\" should have been invalid\n", invalid_paths[i]);
279 _dbus_warn (
"Interface \"%s\" should have been valid\n", valid_interfaces[i]);
294 _dbus_warn (
"Interface \"%s\" should have been invalid\n", invalid_interfaces[i]);
312 _dbus_warn (
"Bus name \"%s\" should have been valid\n", valid_interfaces[i]);
322 if (invalid_interfaces[i][0] !=
':')
329 _dbus_warn (
"Bus name \"%s\" should have been invalid\n", invalid_interfaces[i]);
346 _dbus_warn (
"Bus name \"%s\" should have been valid\n", valid_unique_names[i]);
361 _dbus_warn (
"Bus name \"%s\" should have been invalid\n", invalid_unique_names[i]);
379 _dbus_warn (
"Error name \"%s\" should have been valid\n", valid_interfaces[i]);
389 if (invalid_interfaces[i][0] !=
':')
396 _dbus_warn (
"Error name \"%s\" should have been invalid\n", invalid_interfaces[i]);
413 _dbus_warn (
"Member \"%s\" should have been valid\n", valid_members[i]);
428 _dbus_warn (
"Member \"%s\" should have been invalid\n", invalid_members[i]);
444 _dbus_warn (
"Signature \"%s\" should have been valid\n", valid_signatures[i]);
459 _dbus_warn (
"Signature \"%s\" should have been invalid\n", invalid_signatures[i]);
530 while (dbus_internal_do_not_use_generate_bodies (sequence,
542 _dbus_warn (
"invalid code %d expected valid on sequence %d little endian\n",
555 while (dbus_internal_do_not_use_generate_bodies (sequence,
567 _dbus_warn (
"invalid code %d expected valid on sequence %d big endian\n",
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
#define NULL
A null pointer, defined appropriately for C or C++.
#define DBUS_MAXIMUM_NAME_LENGTH
Max length in bytes of a bus name, interface, or member (not object path, paths are unlimited)...
dbus_bool_t _dbus_validate_bus_name(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid bus name in the D-Bus protocol.
dbus_bool_t _dbus_validate_interface(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid interface name in the D-Bus protocol.
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string.
DBusValidity
This is primarily used in unit testing, so we can verify that each invalid message is invalid for the...
dbus_bool_t _dbus_validate_error_name(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid error name in the D-Bus protocol.
dbus_bool_t _dbus_validate_signature(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid message type signature in the D-Bus protocol...
dbus_bool_t _dbus_validate_member(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid member name in the D-Bus protocol.
dbus_bool_t _dbus_validate_path(const DBusString *str, int start, int len)
Checks that the given range of the string is a valid object path name in the D-Bus protocol...
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
void _dbus_string_init_const(DBusString *str, const char *value)
Initializes a constant string.
void _dbus_warn(const char *format,...)
Prints a warning message to stderr.
int _dbus_string_get_length(const DBusString *str)
Gets the length of a string (not including nul termination).
#define DBUS_BIG_ENDIAN
Code marking MSB-first byte order in the wire protocol.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
DBusValidity _dbus_validate_body_with_reason(const DBusString *expected_signature, int expected_signature_start, int byte_order, int *bytes_remaining, const DBusString *value_str, int value_pos, int len)
Verifies that the range of value_str from value_pos to value_end is a legitimate value of type expect...
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init().
#define TRUE
Expands to "1".
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
DBusValidity _dbus_validate_signature_with_reason(const DBusString *type_str, int type_pos, int len)
Verifies that the range of type_str from type_pos to type_end is a valid signature.
#define DBUS_LITTLE_ENDIAN
Code marking LSB-first byte order in the wire protocol.