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'\n",
    67 static const ValidityTest signature_tests[] = {
    72   { 
"w", DBUS_INVALID_UNKNOWN_TYPECODE },
    73   { 
"a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    74   { 
"aaaaaa", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    75   { 
"ii(ii)a", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    76   { 
"ia", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    78   { 
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    79     DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION },
    80   { 
"((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((ii))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))",
    81     DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
    82   { 
")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
    83   { 
"i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
    84   { 
"a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    85   { 
"(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
    86   { 
"(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
    87   { 
"(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
    88   { 
"(ai", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
    89   { 
"()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
    90   { 
"(())", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
    91   { 
"a()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
    92   { 
"i()", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
    93   { 
"()i", DBUS_INVALID_STRUCT_HAS_NO_FIELDS },
    94   { 
"(a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    95   { 
"a{ia}", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
    96   { 
"a{}", DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS },
    97   { 
"a{aii}", DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE },
   104 _dbus_marshal_validate_test (
void)
   109   const char *valid_paths[] = {
   115   const char *invalid_paths[] = {
   131   const char *valid_interfaces[] = {
   132     "org.freedesktop.Foo",
   134     "Blah.Blah.Blah.Blah.Blah",
   137     "a0.b1.c2.d3.e4.f5.g6",
   140   const char *invalid_interfaces[] = {
   168   const char *valid_unique_names[] = {
   177     ":abce.freedesktop.blah"   179   const char *invalid_unique_names[] = {
   193   const char *valid_members[] = {
   201   const char *invalid_members[] = {
   216   const char *valid_signatures[] = {
   223   const char *invalid_signatures[] = {
   225     "not a valid signature",
   244                                 _dbus_string_get_length (&str)))
   246           _dbus_warn (
"Path \"%s\" should have been valid\n", valid_paths[i]);
   259                                _dbus_string_get_length (&str)))
   261           _dbus_warn (
"Path \"%s\" should have been invalid\n", invalid_paths[i]);
   275                                      _dbus_string_get_length (&str)))
   277           _dbus_warn (
"Interface \"%s\" should have been valid\n", valid_interfaces[i]);
   290                                     _dbus_string_get_length (&str)))
   292           _dbus_warn (
"Interface \"%s\" should have been invalid\n", invalid_interfaces[i]);
   308                                    _dbus_string_get_length (&str)))
   310           _dbus_warn (
"Bus name \"%s\" should have been valid\n", valid_interfaces[i]);
   320       if (invalid_interfaces[i][0] != 
':')
   325                                        _dbus_string_get_length (&str)))
   327               _dbus_warn (
"Bus name \"%s\" should have been invalid\n", invalid_interfaces[i]);
   342                                     _dbus_string_get_length (&str)))
   344           _dbus_warn (
"Bus name \"%s\" should have been valid\n", valid_unique_names[i]);
   357                                    _dbus_string_get_length (&str)))
   359           _dbus_warn (
"Bus name \"%s\" should have been invalid\n", invalid_unique_names[i]);
   375                                       _dbus_string_get_length (&str)))
   377           _dbus_warn (
"Error name \"%s\" should have been valid\n", valid_interfaces[i]);
   387       if (invalid_interfaces[i][0] != 
':')
   392                                          _dbus_string_get_length (&str)))
   394               _dbus_warn (
"Error name \"%s\" should have been invalid\n", invalid_interfaces[i]);
   409                                   _dbus_string_get_length (&str)))
   411           _dbus_warn (
"Member \"%s\" should have been valid\n", valid_members[i]);
   424                                  _dbus_string_get_length (&str)))
   426           _dbus_warn (
"Member \"%s\" should have been invalid\n", invalid_members[i]);
   440                                      _dbus_string_get_length (&str)))
   442           _dbus_warn (
"Signature \"%s\" should have been valid\n", valid_signatures[i]);
   455                                     _dbus_string_get_length (&str)))
   457           _dbus_warn (
"Signature \"%s\" should have been invalid\n", invalid_signatures[i]);
   528     while (dbus_internal_do_not_use_generate_bodies (sequence,
   537                                                     _dbus_string_get_length (&body));
   540             _dbus_warn (
"invalid code %d expected valid on sequence %d little endian\n",
   553     while (dbus_internal_do_not_use_generate_bodies (sequence,
   562                                                     _dbus_string_get_length (&body));
   565             _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. 
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_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_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.