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" 32 #include <dbus/dbus-test-tap.h> 34 #include "dbus-test.h" 44 run_validity_tests (
const ValidityTest *tests,
50 for (i = 0; i < n_tests; i++)
57 v = (*func) (&str, 0, _dbus_string_get_length (&str));
59 if (v != tests[i].expected)
60 _dbus_test_fatal (
"Improper validation result %d for '%s'", v, tests[i].data);
64 static const ValidityTest signature_tests[] = {
71 {
"w", DBUS_INVALID_UNKNOWN_TYPECODE },
72 {
"a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
73 {
"aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
74 {
"ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
75 {
"ia", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
77 {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
78 DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION },
79 {
"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ii))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))",
80 DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
81 {
")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
82 {
"i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
83 {
"a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
84 {
"(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
85 {
"(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
86 {
"(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
87 {
"(ai", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
88 {
"()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
89 {
"(())", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
90 {
"a()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
91 {
"i()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
92 {
"()i", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
93 {
"(a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
94 {
"a{ia}", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
95 {
"a{}", DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS },
96 {
"a{aii}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
97 {
" ", DBUS_INVALID_UNKNOWN_TYPECODE },
98 {
"not a valid signature", DBUS_INVALID_UNKNOWN_TYPECODE },
99 {
"123", DBUS_INVALID_UNKNOWN_TYPECODE },
100 {
".", DBUS_INVALID_UNKNOWN_TYPECODE },
102 {
"a{(ii)i}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
103 {
"a{i}", DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD },
104 {
"{is}", DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY },
105 {
"a{isi}", DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS },
109 _dbus_marshal_validate_test (
void)
114 const char *valid_paths[] = {
120 const char *invalid_paths[] = {
136 const char *valid_interfaces[] = {
137 "org.freedesktop.Foo",
139 "Blah.Blah.Blah.Blah.Blah",
142 "a0.b1.c2.d3.e4.f5.g6",
145 const char *invalid_interfaces[] = {
173 const char *valid_unique_names[] = {
182 ":abce.freedesktop.blah" 184 const char *invalid_unique_names[] = {
198 const char *valid_members[] = {
206 const char *invalid_members[] = {
233 _dbus_string_get_length (&str)))
234 _dbus_test_fatal (
"Path \"%s\" should have been valid", valid_paths[i]);
245 _dbus_string_get_length (&str)))
246 _dbus_test_fatal (
"Path \"%s\" should have been invalid", invalid_paths[i]);
258 _dbus_string_get_length (&str)))
259 _dbus_test_fatal (
"Interface \"%s\" should have been valid", valid_interfaces[i]);
270 _dbus_string_get_length (&str)))
271 _dbus_test_fatal (
"Interface \"%s\" should have been invalid", invalid_interfaces[i]);
285 _dbus_string_get_length (&str)))
286 _dbus_test_fatal (
"Bus name \"%s\" should have been valid", valid_interfaces[i]);
294 if (invalid_interfaces[i][0] !=
':')
299 _dbus_string_get_length (&str)))
300 _dbus_test_fatal (
"Bus name \"%s\" should have been invalid", invalid_interfaces[i]);
313 _dbus_string_get_length (&str)))
314 _dbus_test_fatal (
"Bus name \"%s\" should have been valid", valid_unique_names[i]);
325 _dbus_string_get_length (&str)))
326 _dbus_test_fatal (
"Bus name \"%s\" should have been invalid", invalid_unique_names[i]);
340 _dbus_string_get_length (&str)))
341 _dbus_test_fatal (
"Error name \"%s\" should have been valid", valid_interfaces[i]);
349 if (invalid_interfaces[i][0] !=
':')
354 _dbus_string_get_length (&str)))
355 _dbus_test_fatal (
"Error name \"%s\" should have been invalid", invalid_interfaces[i]);
368 _dbus_string_get_length (&str)))
369 _dbus_test_fatal (
"Member \"%s\" should have been valid", valid_members[i]);
380 _dbus_string_get_length (&str)))
381 _dbus_test_fatal (
"Member \"%s\" should have been invalid", invalid_members[i]);
389 _dbus_test_fatal (
"validated too-long string");
391 _dbus_test_fatal (
"validated too-long string");
393 _dbus_test_fatal (
"validated too-long string");
397 _dbus_test_fatal (
"validated too-long string");
401 _dbus_test_fatal (
"no memory");
405 _dbus_test_fatal (
"no memory");
408 _dbus_test_fatal (
"validated overmax string");
410 _dbus_test_fatal (
"validated overmax string");
412 _dbus_test_fatal (
"validated overmax string");
418 _dbus_test_fatal (
"no memory");
421 _dbus_test_fatal (
"validated overmax string");
428 _dbus_test_fatal (
"no memory");
431 _dbus_test_fatal (
"validated overmax string");
443 _dbus_test_fatal (
"oom");
454 _dbus_string_get_length (&body));
457 _dbus_warn (
"invalid code %d expected valid on sequence %d little endian",
461 _dbus_test_fatal (
"test failed");
478 _dbus_string_get_length (&body));
481 _dbus_warn (
"invalid code %d expected valid on sequence %d big endian",
485 _dbus_test_fatal (
"test failed");
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(), and fills it with the same contents as #_DBUS_STRING_I...
#define TRUE
Expands to "1".
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.