25 #ifdef DBUS_ENABLE_EMBEDDED_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++)
56 v = (*func) (&str, 0, _dbus_string_get_length (&str));
58 if (v != tests[i].expected)
60 _dbus_warn (
"Improper validation result %d for '%s'",
67 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_MISSING_ARRAY_ELEMENT_TYPE },
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 },
100 {
" ", DBUS_INVALID_UNKNOWN_TYPECODE },
101 {
"not a valid signature", DBUS_INVALID_UNKNOWN_TYPECODE },
102 {
"123", DBUS_INVALID_UNKNOWN_TYPECODE },
103 {
".", DBUS_INVALID_UNKNOWN_TYPECODE },
105 {
"a{(ii)i}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
106 {
"a{i}", DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD },
107 {
"{is}", DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY },
108 {
"a{isi}", DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS },
112 _dbus_marshal_validate_test (
void)
117 const char *valid_paths[] = {
123 const char *invalid_paths[] = {
139 const char *valid_interfaces[] = {
140 "org.freedesktop.Foo",
142 "Blah.Blah.Blah.Blah.Blah",
145 "a0.b1.c2.d3.e4.f5.g6",
148 const char *invalid_interfaces[] = {
176 const char *valid_unique_names[] = {
185 ":abce.freedesktop.blah" 187 const char *invalid_unique_names[] = {
201 const char *valid_members[] = {
209 const char *invalid_members[] = {
236 _dbus_string_get_length (&str)))
238 _dbus_warn (
"Path \"%s\" should have been valid", valid_paths[i]);
251 _dbus_string_get_length (&str)))
253 _dbus_warn (
"Path \"%s\" should have been invalid", invalid_paths[i]);
267 _dbus_string_get_length (&str)))
269 _dbus_warn (
"Interface \"%s\" should have been valid", valid_interfaces[i]);
282 _dbus_string_get_length (&str)))
284 _dbus_warn (
"Interface \"%s\" should have been invalid", invalid_interfaces[i]);
300 _dbus_string_get_length (&str)))
302 _dbus_warn (
"Bus name \"%s\" should have been valid", valid_interfaces[i]);
312 if (invalid_interfaces[i][0] !=
':')
317 _dbus_string_get_length (&str)))
319 _dbus_warn (
"Bus name \"%s\" should have been invalid", invalid_interfaces[i]);
334 _dbus_string_get_length (&str)))
336 _dbus_warn (
"Bus name \"%s\" should have been valid", valid_unique_names[i]);
349 _dbus_string_get_length (&str)))
351 _dbus_warn (
"Bus name \"%s\" should have been invalid", invalid_unique_names[i]);
367 _dbus_string_get_length (&str)))
369 _dbus_warn (
"Error name \"%s\" should have been valid", valid_interfaces[i]);
379 if (invalid_interfaces[i][0] !=
':')
384 _dbus_string_get_length (&str)))
386 _dbus_warn (
"Error name \"%s\" should have been invalid", invalid_interfaces[i]);
401 _dbus_string_get_length (&str)))
403 _dbus_warn (
"Member \"%s\" should have been valid", valid_members[i]);
416 _dbus_string_get_length (&str)))
418 _dbus_warn (
"Member \"%s\" should have been invalid", invalid_members[i]);
485 while (dbus_internal_do_not_use_generate_bodies (sequence,
494 _dbus_string_get_length (&body));
497 _dbus_warn (
"invalid code %d expected valid on sequence %d little endian",
510 while (dbus_internal_do_not_use_generate_bodies (sequence,
519 _dbus_string_get_length (&body));
522 _dbus_warn (
"invalid code %d expected valid on sequence %d big endian",
dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString.
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...
#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_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_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_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_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.
#define DBUS_BIG_ENDIAN
Code marking MSB-first byte order in the wire protocol.
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.
#define _DBUS_N_ELEMENTS(array)
Computes the number of elements in a fixed-size array using sizeof().
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.
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.
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.
DBUS_PRIVATE_EXPORT void _dbus_verbose_bytes_of_string(const DBusString *str, int start, int len)
Dump the given part of the string to verbose log.
#define DBUS_LITTLE_ENDIAN
Code marking LSB-first byte order in the wire protocol.