mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-22 12:30:08 +01:00
2005-01-23 Havoc Pennington <hp@redhat.com>
* dbus/dbus-message-factory.c, dbus/dbus-message-util.c: get this all working, not many tests in the framework yet though
This commit is contained in:
parent
487f13451d
commit
9d21554dd3
12 changed files with 249 additions and 1459 deletions
|
|
@ -1,3 +1,8 @@
|
|||
2005-01-23 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* dbus/dbus-message-factory.c, dbus/dbus-message-util.c:
|
||||
get this all working, not many tests in the framework yet though
|
||||
|
||||
2005-01-22 Havoc Pennington <hp@redhat.com>
|
||||
|
||||
* doc/dbus-faq.xml, doc/dbus-tutorial: add a FAQ and update
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ typedef enum
|
|||
*/
|
||||
typedef enum
|
||||
{
|
||||
DBUS_INVALID_FOR_UNKNOWN_REASON = -3,
|
||||
DBUS_VALID_BUT_INCOMPLETE = -2,
|
||||
DBUS_VALIDITY_UNKNOWN = -1,
|
||||
DBUS_VALID = 0,
|
||||
DBUS_INVALID_UNKNOWN_TYPECODE = 1,
|
||||
DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
|
||||
|
|
@ -98,7 +101,7 @@ typedef enum
|
|||
DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 46,
|
||||
DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 47,
|
||||
DBUS_INVALID_STRING_MISSING_NUL = 48,
|
||||
DBUS_INVALID_SIGNATURE_MISSING_NUL = 49,
|
||||
DBUS_INVALID_SIGNATURE_MISSING_NUL = 49
|
||||
} DBusValidity;
|
||||
|
||||
DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,40 +0,0 @@
|
|||
/* -*- mode: C; c-file-style: "gnu" -*- */
|
||||
/* dbus-message-builder.h Build messages from text files for testing (internal to D-BUS implementation)
|
||||
*
|
||||
* Copyright (C) 2003 Red Hat, Inc.
|
||||
*
|
||||
* Licensed under the Academic Free License version 2.1
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef DBUS_MESSAGE_BUILDER_H
|
||||
#define DBUS_MESSAGE_BUILDER_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <dbus/dbus-memory.h>
|
||||
#include <dbus/dbus-types.h>
|
||||
#include <dbus/dbus-string.h>
|
||||
|
||||
DBUS_BEGIN_DECLS
|
||||
|
||||
dbus_bool_t _dbus_message_data_load (DBusString *dest,
|
||||
const DBusString *filename);
|
||||
|
||||
DBUS_END_DECLS
|
||||
|
||||
#endif /* DBUS_MESSAGE_BUILDER_H */
|
||||
|
|
@ -20,14 +20,17 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#ifdef DBUS_BUILD_TESTS
|
||||
|
||||
#include "dbus-message-factory.h"
|
||||
#include "dbus-message-private.h"
|
||||
|
||||
typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int sequence,
|
||||
typedef dbus_bool_t (* DBusInnerGeneratorFunc) (int sequence,
|
||||
DBusMessage **message_p);
|
||||
typedef dbus_bool_t (* DBusMessageGeneratorFunc) (int sequence,
|
||||
DBusString *data,
|
||||
DBusValidity *expected_validity);
|
||||
|
||||
static void
|
||||
set_reply_serial (DBusMessage *message)
|
||||
|
|
@ -39,7 +42,7 @@ set_reply_serial (DBusMessage *message)
|
|||
}
|
||||
|
||||
static dbus_bool_t
|
||||
generate_trivial (int sequence,
|
||||
generate_trivial_inner (int sequence,
|
||||
DBusMessage **message_p)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
|
@ -63,6 +66,22 @@ generate_trivial (int sequence,
|
|||
break;
|
||||
case 3:
|
||||
message = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
|
||||
|
||||
if (!dbus_message_set_error_name (message,
|
||||
"org.freedesktop.TestErrorName"))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
{
|
||||
DBusMessageIter iter;
|
||||
const char *v_STRING = "This is an error";
|
||||
|
||||
dbus_message_iter_init_append (message, &iter);
|
||||
if (!dbus_message_iter_append_basic (&iter,
|
||||
DBUS_TYPE_STRING,
|
||||
&v_STRING))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
}
|
||||
|
||||
set_reply_serial (message);
|
||||
break;
|
||||
default:
|
||||
|
|
@ -77,6 +96,48 @@ generate_trivial (int sequence,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
generate_outer (int sequence,
|
||||
DBusString *data,
|
||||
DBusValidity *expected_validity,
|
||||
DBusInnerGeneratorFunc func)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
||||
message = NULL;
|
||||
if (!(*func)(sequence, &message))
|
||||
return FALSE;
|
||||
|
||||
_dbus_assert (message != NULL);
|
||||
|
||||
_dbus_message_set_serial (message, 1);
|
||||
_dbus_message_lock (message);
|
||||
|
||||
*expected_validity = DBUS_VALID;
|
||||
|
||||
/* move for efficiency, since we'll nuke the message anyway */
|
||||
if (!_dbus_string_move (&message->header.data, 0,
|
||||
data, 0))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
if (!_dbus_string_copy (&message->body, 0,
|
||||
data, _dbus_string_get_length (data)))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
dbus_message_unref (message);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
generate_trivial (int sequence,
|
||||
DBusString *data,
|
||||
DBusValidity *expected_validity)
|
||||
{
|
||||
return generate_outer (sequence, data, expected_validity,
|
||||
generate_trivial_inner);
|
||||
}
|
||||
|
||||
static const DBusMessageGeneratorFunc generators[] = {
|
||||
generate_trivial
|
||||
};
|
||||
|
|
@ -99,37 +160,26 @@ _dbus_message_data_iter_get_and_next (DBusMessageDataIter *iter,
|
|||
DBusMessageData *data)
|
||||
{
|
||||
DBusMessageGeneratorFunc func;
|
||||
DBusMessage *message;
|
||||
|
||||
restart:
|
||||
if (iter->generator == _DBUS_N_ELEMENTS (generators))
|
||||
return FALSE;
|
||||
|
||||
func = generators[iter->generator];
|
||||
|
||||
if ((*func)(iter->sequence, &message))
|
||||
if (!_dbus_string_init (&data->data))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
if ((*func)(iter->sequence, &data->data, &data->expected_validity))
|
||||
iter->sequence += 1;
|
||||
else
|
||||
{
|
||||
iter->generator += 1;
|
||||
iter->sequence = 0;
|
||||
_dbus_string_free (&data->data);
|
||||
goto restart;
|
||||
}
|
||||
|
||||
_dbus_assert (message != NULL);
|
||||
|
||||
if (!_dbus_string_init (&data->data))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
/* move for efficiency, since we'll nuke the message anyway */
|
||||
if (!_dbus_string_move (&message->header.data, 0,
|
||||
&data->data, 0))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
if (!_dbus_string_copy (&message->body, 0,
|
||||
&data->data, _dbus_string_get_length (&data->data)))
|
||||
_dbus_assert_not_reached ("oom");
|
||||
|
||||
dbus_message_unref (message);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ DBUS_BEGIN_DECLS
|
|||
|
||||
typedef struct
|
||||
{
|
||||
dbus_bool_t validity_known;
|
||||
DBusValidity expected_validity;
|
||||
|
||||
DBusString data;
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ struct DBusMessageLoader
|
|||
unsigned int buffer_outstanding : 1; /**< Someone is using the buffer to read */
|
||||
|
||||
unsigned int corrupted : 1; /**< We got broken data, and are no longer working */
|
||||
|
||||
DBusValidity corruption_reason; /**< why we were corrupted */
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,19 @@ dbus_message_iter_get_args (DBusMessageIter *iter,
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void
|
||||
check_memleaks (void)
|
||||
{
|
||||
dbus_shutdown ();
|
||||
|
||||
if (_dbus_get_malloc_blocks_outstanding () != 0)
|
||||
{
|
||||
_dbus_warn ("%d dbus_malloc blocks were not freed in %s\n",
|
||||
_dbus_get_malloc_blocks_outstanding (), __FILE__);
|
||||
_dbus_assert_not_reached ("memleaks");
|
||||
}
|
||||
}
|
||||
|
||||
static dbus_bool_t
|
||||
check_have_valid_message (DBusMessageLoader *loader)
|
||||
{
|
||||
|
|
@ -87,12 +100,10 @@ check_have_valid_message (DBusMessageLoader *loader)
|
|||
message = NULL;
|
||||
retval = FALSE;
|
||||
|
||||
if (!_dbus_message_loader_queue_messages (loader))
|
||||
_dbus_assert_not_reached ("no memory to queue messages");
|
||||
|
||||
if (_dbus_message_loader_get_is_corrupted (loader))
|
||||
{
|
||||
_dbus_warn ("loader corrupted on message that was expected to be valid\n");
|
||||
_dbus_warn ("loader corrupted on message that was expected to be valid; invalid reason %d\n",
|
||||
loader->corruption_reason);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
@ -129,21 +140,27 @@ check_have_valid_message (DBusMessageLoader *loader)
|
|||
}
|
||||
|
||||
static dbus_bool_t
|
||||
check_invalid_message (DBusMessageLoader *loader)
|
||||
check_invalid_message (DBusMessageLoader *loader,
|
||||
DBusValidity expected_validity)
|
||||
{
|
||||
dbus_bool_t retval;
|
||||
|
||||
retval = FALSE;
|
||||
|
||||
if (!_dbus_message_loader_queue_messages (loader))
|
||||
_dbus_assert_not_reached ("no memory to queue messages");
|
||||
|
||||
if (!_dbus_message_loader_get_is_corrupted (loader))
|
||||
{
|
||||
_dbus_warn ("loader not corrupted on message that was expected to be invalid\n");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON &&
|
||||
loader->corruption_reason != expected_validity)
|
||||
{
|
||||
_dbus_warn ("expected message to be corrupted for reason %d and was corrupted for %d instead\n",
|
||||
expected_validity, loader->corruption_reason);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
retval = TRUE;
|
||||
|
||||
failed:
|
||||
|
|
@ -159,12 +176,10 @@ check_incomplete_message (DBusMessageLoader *loader)
|
|||
message = NULL;
|
||||
retval = FALSE;
|
||||
|
||||
if (!_dbus_message_loader_queue_messages (loader))
|
||||
_dbus_assert_not_reached ("no memory to queue messages");
|
||||
|
||||
if (_dbus_message_loader_get_is_corrupted (loader))
|
||||
{
|
||||
_dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete)\n");
|
||||
_dbus_warn ("loader corrupted on message that was expected to be valid (but incomplete), corruption reason %d\n",
|
||||
loader->corruption_reason);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
@ -185,49 +200,42 @@ check_incomplete_message (DBusMessageLoader *loader)
|
|||
|
||||
static dbus_bool_t
|
||||
check_loader_results (DBusMessageLoader *loader,
|
||||
DBusMessageValidity validity)
|
||||
DBusValidity expected_validity)
|
||||
{
|
||||
if (!_dbus_message_loader_queue_messages (loader))
|
||||
_dbus_assert_not_reached ("no memory to queue messages");
|
||||
|
||||
switch (validity)
|
||||
{
|
||||
case _DBUS_MESSAGE_VALID:
|
||||
if (expected_validity == DBUS_VALID)
|
||||
return check_have_valid_message (loader);
|
||||
case _DBUS_MESSAGE_INVALID:
|
||||
return check_invalid_message (loader);
|
||||
case _DBUS_MESSAGE_INCOMPLETE:
|
||||
else if (expected_validity == DBUS_VALID_BUT_INCOMPLETE)
|
||||
return check_incomplete_message (loader);
|
||||
case _DBUS_MESSAGE_UNKNOWN:
|
||||
else if (expected_validity == DBUS_VALIDITY_UNKNOWN)
|
||||
{
|
||||
/* here we just know we didn't segfault and that was the
|
||||
* only test
|
||||
*/
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_dbus_assert_not_reached ("bad DBusMessageValidity");
|
||||
return FALSE;
|
||||
else
|
||||
return check_invalid_message (loader, expected_validity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the message in the given message file.
|
||||
*
|
||||
* @param filename filename to load
|
||||
* @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
|
||||
* @param data string to load message into
|
||||
* @returns #TRUE if the message was loaded
|
||||
*/
|
||||
dbus_bool_t
|
||||
dbus_internal_do_not_use_load_message_file (const DBusString *filename,
|
||||
dbus_bool_t is_raw,
|
||||
DBusString *data)
|
||||
{
|
||||
dbus_bool_t retval;
|
||||
DBusError error;
|
||||
|
||||
retval = FALSE;
|
||||
|
||||
if (is_raw)
|
||||
{
|
||||
DBusError error;
|
||||
|
||||
_dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename));
|
||||
dbus_error_init (&error);
|
||||
if (!_dbus_file_get_contents (data, filename, &error))
|
||||
|
|
@ -238,18 +246,6 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename,
|
|||
dbus_error_free (&error);
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FALSE) /* Message builder disabled, probably permanently,
|
||||
* I want to do it another way
|
||||
*/
|
||||
{
|
||||
_dbus_warn ("Could not load message file %s\n",
|
||||
_dbus_string_get_const_data (filename));
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
retval = TRUE;
|
||||
|
||||
|
|
@ -263,14 +259,12 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename,
|
|||
* and verifies that DBusMessageLoader can handle it.
|
||||
*
|
||||
* @param filename filename to load
|
||||
* @param is_raw if #TRUE load as binary data, if #FALSE as message builder language
|
||||
* @param expected_validity what the message has to be like to return #TRUE
|
||||
* @returns #TRUE if the message has the expected validity
|
||||
*/
|
||||
dbus_bool_t
|
||||
dbus_internal_do_not_use_try_message_file (const DBusString *filename,
|
||||
dbus_bool_t is_raw,
|
||||
DBusMessageValidity expected_validity)
|
||||
DBusValidity expected_validity)
|
||||
{
|
||||
DBusString data;
|
||||
dbus_bool_t retval;
|
||||
|
|
@ -280,8 +274,7 @@ dbus_internal_do_not_use_try_message_file (const DBusString *filename,
|
|||
if (!_dbus_string_init (&data))
|
||||
_dbus_assert_not_reached ("could not allocate string\n");
|
||||
|
||||
if (!dbus_internal_do_not_use_load_message_file (filename, is_raw,
|
||||
&data))
|
||||
if (!dbus_internal_do_not_use_load_message_file (filename, &data))
|
||||
goto failed;
|
||||
|
||||
retval = dbus_internal_do_not_use_try_message_data (&data, expected_validity);
|
||||
|
|
@ -313,7 +306,7 @@ dbus_internal_do_not_use_try_message_file (const DBusString *filename,
|
|||
*/
|
||||
dbus_bool_t
|
||||
dbus_internal_do_not_use_try_message_data (const DBusString *data,
|
||||
DBusMessageValidity expected_validity)
|
||||
DBusValidity expected_validity)
|
||||
{
|
||||
DBusMessageLoader *loader;
|
||||
dbus_bool_t retval;
|
||||
|
|
@ -405,7 +398,7 @@ dbus_internal_do_not_use_try_message_data (const DBusString *data,
|
|||
static dbus_bool_t
|
||||
process_test_subdir (const DBusString *test_base_dir,
|
||||
const char *subdir,
|
||||
DBusMessageValidity validity,
|
||||
DBusValidity expected_validity,
|
||||
DBusForeachMessageFileFunc function,
|
||||
void *user_data)
|
||||
{
|
||||
|
|
@ -451,7 +444,6 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
while (_dbus_directory_get_next_file (dir, &filename, &error))
|
||||
{
|
||||
DBusString full_path;
|
||||
dbus_bool_t is_raw;
|
||||
|
||||
if (!_dbus_string_init (&full_path))
|
||||
_dbus_assert_not_reached ("couldn't init string");
|
||||
|
|
@ -462,12 +454,16 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
if (!_dbus_concat_dir_and_file (&full_path, &filename))
|
||||
_dbus_assert_not_reached ("couldn't concat file to dir");
|
||||
|
||||
if (_dbus_string_ends_with_c_str (&filename, ".message"))
|
||||
is_raw = FALSE;
|
||||
else if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
|
||||
is_raw = TRUE;
|
||||
if (_dbus_string_ends_with_c_str (&filename, ".message-raw"))
|
||||
;
|
||||
else
|
||||
{
|
||||
if (_dbus_string_ends_with_c_str (&filename, ".message"))
|
||||
{
|
||||
_dbus_warn ("Could not load %s, message builder language no longer supported\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
}
|
||||
|
||||
_dbus_verbose ("Skipping non-.message file %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
_dbus_string_free (&full_path);
|
||||
|
|
@ -477,13 +473,8 @@ process_test_subdir (const DBusString *test_base_dir,
|
|||
printf (" %s\n",
|
||||
_dbus_string_get_const_data (&filename));
|
||||
|
||||
_dbus_verbose (" expecting %s for %s\n",
|
||||
validity == _DBUS_MESSAGE_VALID ? "valid" :
|
||||
(validity == _DBUS_MESSAGE_INVALID ? "invalid" :
|
||||
(validity == _DBUS_MESSAGE_INCOMPLETE ? "incomplete" : "unknown")),
|
||||
_dbus_string_get_const_data (&filename));
|
||||
|
||||
if (! (*function) (&full_path, is_raw, validity, user_data))
|
||||
if (! (*function) (&full_path,
|
||||
expected_validity, user_data))
|
||||
{
|
||||
_dbus_string_free (&full_path);
|
||||
goto failed;
|
||||
|
|
@ -535,17 +526,23 @@ dbus_internal_do_not_use_foreach_message_file (const char *test_d
|
|||
_dbus_string_init_const (&test_directory, test_data_dir);
|
||||
|
||||
if (!process_test_subdir (&test_directory, "valid-messages",
|
||||
_DBUS_MESSAGE_VALID, func, user_data))
|
||||
DBUS_VALID, func, user_data))
|
||||
goto failed;
|
||||
|
||||
check_memleaks ();
|
||||
|
||||
if (!process_test_subdir (&test_directory, "invalid-messages",
|
||||
_DBUS_MESSAGE_INVALID, func, user_data))
|
||||
DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data))
|
||||
goto failed;
|
||||
|
||||
check_memleaks ();
|
||||
|
||||
if (!process_test_subdir (&test_directory, "incomplete-messages",
|
||||
_DBUS_MESSAGE_INCOMPLETE, func, user_data))
|
||||
DBUS_VALID_BUT_INCOMPLETE, func, user_data))
|
||||
goto failed;
|
||||
|
||||
check_memleaks ();
|
||||
|
||||
retval = TRUE;
|
||||
|
||||
failed:
|
||||
|
|
@ -660,11 +657,12 @@ verify_test_message (DBusMessage *message)
|
|||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
dbus_int32_t our_int;
|
||||
dbus_uint32_t our_uint;
|
||||
const char *our_str;
|
||||
double our_double;
|
||||
double v_DOUBLE;
|
||||
dbus_bool_t our_bool;
|
||||
unsigned char our_byte_1, our_byte_2;
|
||||
dbus_uint32_t our_uint32;
|
||||
const dbus_int32_t *our_uint32_array = (void*)0xdeadbeef;
|
||||
int our_uint32_array_len;
|
||||
dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
|
||||
|
|
@ -689,6 +687,7 @@ verify_test_message (DBusMessage *message)
|
|||
dbus_error_init (&error);
|
||||
if (!dbus_message_iter_get_args (&iter, &error,
|
||||
DBUS_TYPE_INT32, &our_int,
|
||||
DBUS_TYPE_UINT32, &our_uint,
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
DBUS_TYPE_INT64, &our_int64,
|
||||
DBUS_TYPE_UINT64, &our_uint64,
|
||||
|
|
@ -724,6 +723,9 @@ verify_test_message (DBusMessage *message)
|
|||
if (our_int != -0x12345678)
|
||||
_dbus_assert_not_reached ("integers differ!");
|
||||
|
||||
if (our_uint != 0x12300042)
|
||||
_dbus_assert_not_reached ("uints differ!");
|
||||
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
|
||||
_dbus_assert_not_reached ("64-bit integers differ!");
|
||||
|
|
@ -731,7 +733,8 @@ verify_test_message (DBusMessage *message)
|
|||
_dbus_assert_not_reached ("64-bit unsigned integers differ!");
|
||||
#endif
|
||||
|
||||
if (our_double != 3.14159)
|
||||
v_DOUBLE = 3.14159;
|
||||
if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
|
||||
_dbus_assert_not_reached ("doubles differ!");
|
||||
|
||||
if (strcmp (our_str, "Test string") != 0)
|
||||
|
|
@ -782,9 +785,14 @@ verify_test_message (DBusMessage *message)
|
|||
/* On all IEEE machines (i.e. everything sane) exact equality
|
||||
* should be preserved over the wire
|
||||
*/
|
||||
if (our_double_array[0] != 0.1234 ||
|
||||
our_double_array[1] != 9876.54321 ||
|
||||
our_double_array[2] != -300.0)
|
||||
v_DOUBLE = 0.1234;
|
||||
if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[0], v_DOUBLE))
|
||||
_dbus_assert_not_reached ("double array had wrong values");
|
||||
v_DOUBLE = 9876.54321;
|
||||
if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[1], v_DOUBLE))
|
||||
_dbus_assert_not_reached ("double array had wrong values");
|
||||
v_DOUBLE = -300.0;
|
||||
if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double_array[2], v_DOUBLE))
|
||||
_dbus_assert_not_reached ("double array had wrong values");
|
||||
|
||||
if (our_byte_array_len != 4)
|
||||
|
|
@ -821,7 +829,6 @@ _dbus_message_test (const char *test_data_dir)
|
|||
{
|
||||
DBusMessage *message;
|
||||
DBusMessageLoader *loader;
|
||||
DBusMessageIter iter, child_iter, child_iter2, child_iter3;
|
||||
int i;
|
||||
const char *data;
|
||||
DBusMessage *copy;
|
||||
|
|
@ -851,8 +858,6 @@ _dbus_message_test (const char *test_data_dir)
|
|||
const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array;
|
||||
char sig[64];
|
||||
const char *s;
|
||||
char *t;
|
||||
DBusError error;
|
||||
const char *v_STRING;
|
||||
double v_DOUBLE;
|
||||
dbus_int32_t v_INT32;
|
||||
|
|
@ -967,8 +972,10 @@ _dbus_message_test (const char *test_data_dir)
|
|||
"Foo.TestInterface",
|
||||
"TestMethod");
|
||||
_dbus_message_set_serial (message, 1);
|
||||
dbus_message_set_reply_serial (message, 5678);
|
||||
|
||||
v_INT32 = -0x12345678;
|
||||
v_UINT32 = 0x12300042;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
|
||||
v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
|
||||
|
|
@ -981,6 +988,7 @@ _dbus_message_test (const char *test_data_dir)
|
|||
|
||||
dbus_message_append_args (message,
|
||||
DBUS_TYPE_INT32, &v_INT32,
|
||||
DBUS_TYPE_UINT32, &v_UINT32,
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
DBUS_TYPE_INT64, &v_INT64,
|
||||
DBUS_TYPE_UINT64, &v_UINT64,
|
||||
|
|
@ -1010,6 +1018,7 @@ _dbus_message_test (const char *test_data_dir)
|
|||
|
||||
i = 0;
|
||||
sig[i++] = DBUS_TYPE_INT32;
|
||||
sig[i++] = DBUS_TYPE_UINT32;
|
||||
#ifdef DBUS_HAVE_INT64
|
||||
sig[i++] = DBUS_TYPE_INT64;
|
||||
sig[i++] = DBUS_TYPE_UINT64;
|
||||
|
|
@ -1125,7 +1134,7 @@ _dbus_message_test (const char *test_data_dir)
|
|||
if (!message)
|
||||
_dbus_assert_not_reached ("received a NULL message");
|
||||
|
||||
if (dbus_message_get_reply_serial (message) != 0x12345678)
|
||||
if (dbus_message_get_reply_serial (message) != 5678)
|
||||
_dbus_assert_not_reached ("reply serial fields differ");
|
||||
|
||||
verify_test_message (message);
|
||||
|
|
@ -1133,6 +1142,32 @@ _dbus_message_test (const char *test_data_dir)
|
|||
dbus_message_unref (message);
|
||||
_dbus_message_loader_unref (loader);
|
||||
|
||||
check_memleaks ();
|
||||
|
||||
/* Load all the sample messages from the message factory */
|
||||
{
|
||||
DBusMessageDataIter diter;
|
||||
DBusMessageData mdata;
|
||||
|
||||
_dbus_message_data_iter_init (&diter);
|
||||
|
||||
while (_dbus_message_data_iter_get_and_next (&diter,
|
||||
&mdata))
|
||||
{
|
||||
if (!dbus_internal_do_not_use_try_message_data (&mdata.data,
|
||||
mdata.expected_validity))
|
||||
{
|
||||
_dbus_warn ("expected validity %d and did not get it; generator %d sequence %d\n",
|
||||
mdata.expected_validity,
|
||||
diter.generator, diter.sequence);
|
||||
_dbus_assert_not_reached ("message data failed");
|
||||
}
|
||||
|
||||
_dbus_message_data_free (&mdata);
|
||||
}
|
||||
}
|
||||
|
||||
check_memleaks ();
|
||||
|
||||
/* Now load every message in test_data_dir if we have one */
|
||||
if (test_data_dir == NULL)
|
||||
|
|
|
|||
|
|
@ -2884,6 +2884,9 @@ _dbus_message_loader_new (void)
|
|||
|
||||
loader->refcount = 1;
|
||||
|
||||
loader->corrupted = FALSE;
|
||||
loader->corruption_reason = DBUS_VALID;
|
||||
|
||||
/* Try to cap message size at something that won't *totally* hose
|
||||
* the system if we have a couple of them.
|
||||
*/
|
||||
|
|
@ -3018,7 +3021,7 @@ _dbus_message_loader_return_buffer (DBusMessageLoader *loader,
|
|||
* loader->data and only delete it occasionally, instead of after
|
||||
* each message is loaded.
|
||||
*
|
||||
* load_message() returns FALSE if not enough memory
|
||||
* load_message() returns FALSE if not enough memory OR the loader was corrupted
|
||||
*/
|
||||
static dbus_bool_t
|
||||
load_message (DBusMessageLoader *loader,
|
||||
|
|
@ -3059,6 +3062,11 @@ load_message (DBusMessageLoader *loader,
|
|||
_dbus_verbose ("Failed to load header for new message code %d\n", validity);
|
||||
if (validity == DBUS_VALID)
|
||||
oom = TRUE;
|
||||
else
|
||||
{
|
||||
loader->corrupted = TRUE;
|
||||
loader->corruption_reason = validity;
|
||||
}
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
@ -3084,6 +3092,10 @@ load_message (DBusMessageLoader *loader,
|
|||
if (validity != DBUS_VALID)
|
||||
{
|
||||
_dbus_verbose ("Failed to validate message body code %d\n", validity);
|
||||
|
||||
loader->corrupted = TRUE;
|
||||
loader->corruption_reason = validity;
|
||||
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
|
@ -3117,6 +3129,8 @@ load_message (DBusMessageLoader *loader,
|
|||
|
||||
_dbus_assert (!oom);
|
||||
_dbus_assert (!loader->corrupted);
|
||||
_dbus_assert (loader->messages != NULL);
|
||||
_dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
|
@ -3127,12 +3141,14 @@ load_message (DBusMessageLoader *loader,
|
|||
/* does nothing if the message isn't in the list */
|
||||
_dbus_list_remove_last (&loader->messages, message);
|
||||
|
||||
if (!oom)
|
||||
loader->corrupted = TRUE;
|
||||
if (oom)
|
||||
_dbus_assert (!loader->corrupted);
|
||||
else
|
||||
_dbus_assert (loader->corrupted);
|
||||
|
||||
_dbus_verbose_bytes_of_string (&loader->data, 0, _dbus_string_get_length (&loader->data));
|
||||
|
||||
return !oom;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -3180,15 +3196,24 @@ _dbus_message_loader_queue_messages (DBusMessageLoader *loader)
|
|||
header_len, body_len))
|
||||
{
|
||||
dbus_message_unref (message);
|
||||
return FALSE;
|
||||
/* load_message() returns false if corrupted or OOM; if
|
||||
* corrupted then return TRUE for not OOM
|
||||
*/
|
||||
return loader->corrupted;
|
||||
}
|
||||
|
||||
_dbus_assert (loader->messages != NULL);
|
||||
_dbus_assert (_dbus_list_find_last (&loader->messages, message) != NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dbus_verbose ("Initial peek at header says we don't have a whole message yet, or data broken with invalid code %d\n",
|
||||
validity);
|
||||
if (validity != DBUS_VALID)
|
||||
{
|
||||
loader->corrupted = TRUE;
|
||||
loader->corruption_reason = validity;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
|
@ -3265,6 +3290,8 @@ _dbus_message_loader_putback_message_link (DBusMessageLoader *loader,
|
|||
dbus_bool_t
|
||||
_dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader)
|
||||
{
|
||||
_dbus_assert ((loader->corrupted && loader->corruption_reason != DBUS_VALID) ||
|
||||
(!loader->corrupted && loader->corruption_reason == DBUS_VALID));
|
||||
return loader->corrupted;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
|
|||
|
||||
check_memleaks ();
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
printf ("%s: running recursive marshalling tests\n", "dbus-test");
|
||||
if (!_dbus_marshal_recursive_test ())
|
||||
die ("recursive marshal");
|
||||
|
|
@ -134,11 +134,13 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
|
|||
|
||||
check_memleaks ();
|
||||
|
||||
#if 0
|
||||
printf ("%s: running memory pool tests\n", "dbus-test");
|
||||
if (!_dbus_mem_pool_test ())
|
||||
die ("memory pools");
|
||||
|
||||
check_memleaks ();
|
||||
#endif
|
||||
|
||||
printf ("%s: running linked list tests\n", "dbus-test");
|
||||
if (!_dbus_list_test ())
|
||||
|
|
|
|||
|
|
@ -26,14 +26,7 @@
|
|||
|
||||
#include <dbus/dbus-types.h>
|
||||
#include <dbus/dbus-string.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
_DBUS_MESSAGE_VALID,
|
||||
_DBUS_MESSAGE_INVALID,
|
||||
_DBUS_MESSAGE_INCOMPLETE,
|
||||
_DBUS_MESSAGE_UNKNOWN
|
||||
} DBusMessageValidity;
|
||||
#include <dbus/dbus-marshal-validate.h>
|
||||
|
||||
dbus_bool_t _dbus_hash_test (void);
|
||||
dbus_bool_t _dbus_dict_test (void);
|
||||
|
|
@ -61,19 +54,16 @@ dbus_bool_t _dbus_pending_call_test (const char *test_data_dir);
|
|||
|
||||
void dbus_internal_do_not_use_run_tests (const char *test_data_dir);
|
||||
dbus_bool_t dbus_internal_do_not_use_try_message_file (const DBusString *filename,
|
||||
dbus_bool_t is_raw,
|
||||
DBusMessageValidity expected_validity);
|
||||
DBusValidity expected_validity);
|
||||
dbus_bool_t dbus_internal_do_not_use_try_message_data (const DBusString *data,
|
||||
DBusMessageValidity expected_validity);
|
||||
DBusValidity expected_validity);
|
||||
dbus_bool_t dbus_internal_do_not_use_load_message_file (const DBusString *filename,
|
||||
dbus_bool_t is_raw,
|
||||
DBusString *data);
|
||||
|
||||
|
||||
/* returns FALSE on fatal failure */
|
||||
typedef dbus_bool_t (* DBusForeachMessageFileFunc) (const DBusString *filename,
|
||||
dbus_bool_t is_raw,
|
||||
DBusMessageValidity expected_validity,
|
||||
DBusValidity expected_validity,
|
||||
void *data);
|
||||
|
||||
dbus_bool_t dbus_internal_do_not_use_foreach_message_file (const char *test_data_dir,
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Reference in a new issue