Commit d1c7eefb authored by Havoc Pennington's avatar Havoc Pennington

2003-05-04 Havoc Pennington <hp@pobox.com>

	* dbus/dbus-message-handler.c (_dbus_message_handler_test): add
	unit test

	* dbus/dbus-marshal.c (_dbus_demarshal_string_array): fix this
	function, which assumed length was in # of strings, not bytes

	* dbus/dbus-message.c (_dbus_message_test): add tests for some
	missing coverage

	* dbus/dbus-connection.c
	(_dbus_connection_queue_received_message): disable function for
	now, we are only using it in test mode

	* dbus/dbus-message.c (_dbus_message_loader_queue_messages):
	remove a mistaken FIXME
parent 3d0dcbf5
2003-05-04 Havoc Pennington <hp@pobox.com>
* dbus/dbus-message-handler.c (_dbus_message_handler_test): add
unit test
* dbus/dbus-marshal.c (_dbus_demarshal_string_array): fix this
function, which assumed length was in # of strings, not bytes
* dbus/dbus-message.c (_dbus_message_test): add tests for some
missing coverage
* dbus/dbus-connection.c
(_dbus_connection_queue_received_message): disable function for
now, we are only using it in test mode
* dbus/dbus-message.c (_dbus_message_loader_queue_messages):
remove a mistaken FIXME
2003-05-04 Havoc Pennington <hp@pobox.com>
* dbus/dbus-connection.c (dbus_connection_preallocate_send):
......
......@@ -278,6 +278,10 @@ _dbus_auth_script_run (const DBusString *filename)
goto out;
}
/* test ref/unref */
_dbus_auth_ref (auth);
_dbus_auth_unref (auth);
_dbus_credentials_from_current_process (&creds);
_dbus_auth_set_credentials (auth, &creds);
}
......@@ -299,6 +303,10 @@ _dbus_auth_script_run (const DBusString *filename)
goto out;
}
/* test ref/unref */
_dbus_auth_ref (auth);
_dbus_auth_unref (auth);
_dbus_credentials_from_current_process (&creds);
_dbus_auth_set_credentials (auth, &creds);
_dbus_auth_set_context (auth, &context);
......
......@@ -221,6 +221,8 @@ _dbus_connection_wakeup_mainloop (DBusConnection *connection)
(*connection->wakeup_main_function) (connection->wakeup_main_data);
}
#ifdef DBUS_BUILD_TESTS
/* For now this function isn't used */
/**
* Adds a message to the incoming message queue, returning #FALSE
* if there's insufficient memory to queue the message.
......@@ -245,6 +247,7 @@ _dbus_connection_queue_received_message (DBusConnection *connection,
return TRUE;
}
#endif
/**
* Adds a message-containing list link to the incoming message queue,
......
......@@ -1094,6 +1094,8 @@ _dbus_hash_table_lookup_int (DBusHashTable *table,
return NULL;
}
#ifdef DBUS_BUILD_TESTS
/* disabled since it's only used for testing */
/**
* Looks up the value for a given integer in a hash table
* of type #DBUS_HASH_POINTER. Returns %NULL if the value
......@@ -1118,6 +1120,7 @@ _dbus_hash_table_lookup_pointer (DBusHashTable *table,
else
return NULL;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Looks up the value for a given integer in a hash table
......@@ -1200,6 +1203,8 @@ _dbus_hash_table_remove_int (DBusHashTable *table,
return FALSE;
}
#ifdef DBUS_BUILD_TESTS
/* disabled since it's only used for testing */
/**
* Removes the hash entry for the given key. If no hash entry
* for the key exists, does nothing.
......@@ -1227,7 +1232,7 @@ _dbus_hash_table_remove_pointer (DBusHashTable *table,
else
return FALSE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Removes the hash entry for the given key. If no hash entry
......@@ -1332,6 +1337,8 @@ _dbus_hash_table_insert_int (DBusHashTable *table,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
/* disabled since it's only used for testing */
/**
* Creates a hash entry with the given key and value.
* The key and value are not copied; they are stored
......@@ -1372,7 +1379,7 @@ _dbus_hash_table_insert_pointer (DBusHashTable *table,
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
/**
* Creates a hash entry with the given key and value.
......
......@@ -1138,6 +1138,14 @@ _dbus_keyring_test (void)
printf (" %d keys in test\n", ring1->n_keys);
/* Test ref/unref */
_dbus_keyring_ref (ring1);
_dbus_keyring_ref (ring2);
_dbus_keyring_unref (ring1);
_dbus_keyring_unref (ring2);
/* really unref */
_dbus_keyring_unref (ring1);
_dbus_keyring_unref (ring2);
......
......@@ -1004,9 +1004,9 @@ _dbus_demarshal_uint64 (const DBusString *str,
*/
char *
_dbus_demarshal_string (const DBusString *str,
int byte_order,
int pos,
int *new_pos)
int byte_order,
int pos,
int *new_pos)
{
int len;
char *retval;
......@@ -1330,12 +1330,14 @@ _dbus_demarshal_string_array (const DBusString *str,
char ***array,
int *array_len)
{
int len, i, j;
int bytes_len, i;
int len, allocated;
int end_pos;
char **retval;
len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (len == 0)
bytes_len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
if (bytes_len == 0)
{
*array_len = 0;
*array = NULL;
......@@ -1345,32 +1347,50 @@ _dbus_demarshal_string_array (const DBusString *str,
return TRUE;
}
len = 0;
allocated = 4;
end_pos = pos + bytes_len;
retval = dbus_new (char *, len + 1);
retval = dbus_new (char *, allocated);
if (!retval)
return FALSE;
retval[len] = NULL;
for (i = 0; i < len; i++)
while (pos < end_pos)
{
retval[i] = _dbus_demarshal_string (str, byte_order, pos, &pos);
if (retval[i] == 0)
retval[len] = _dbus_demarshal_string (str, byte_order, pos, &pos);
if (retval[len] == NULL)
goto error;
len += 1;
if (len >= allocated - 1) /* -1 for NULL termination */
{
char **newp;
newp = dbus_realloc (retval,
sizeof (char*) * allocated * 2);
if (newp == NULL)
goto error;
allocated *= 2;
retval = newp;
}
}
retval[len] = NULL;
if (new_pos)
if (new_pos)
*new_pos = pos;
*array = retval;
*array_len = len;
*array = retval;
*array_len = len;
return TRUE;
error:
for (j = 0; j < i; j++)
for (i = 0; i < len; i++)
dbus_free (retval[i]);
dbus_free (retval);
......
......@@ -1160,12 +1160,11 @@ _dbus_message_data_load (DBusString *dest,
"UINT32"))
{
SAVE_FOR_UNALIGN (dest, 4);
long val;
unsigned long val;
_dbus_string_delete_first_word (&line);
/* FIXME should have _dbus_string_parse_uint32 */
if (!_dbus_string_parse_int (&line, 0, &val, NULL))
if (!_dbus_string_parse_uint (&line, 0, &val, NULL))
goto parse_failed;
if (!_dbus_marshal_uint32 (dest, endian,
......
......@@ -25,6 +25,7 @@
#include "dbus-message-handler.h"
#include "dbus-list.h"
#include "dbus-threads.h"
#include "dbus-test.h"
#include "dbus-connection-internal.h"
/**
......@@ -318,3 +319,53 @@ dbus_message_handler_set_function (DBusMessageHandler *handler,
}
/** @} */
#ifdef DBUS_BUILD_TESTS
static DBusHandlerResult
test_handler (DBusMessageHandler *handler,
DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
return DBUS_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
}
static void
free_test_data (void *data)
{
/* does nothing */
}
/**
* @ingroup DBusMessageInternals
* Unit test for DBusMessageHandler.
*
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_message_handler_test (const char *test_data_dir)
{
DBusMessageHandler *handler;
#define TEST_DATA ((void*) 0xcafebabe)
handler = dbus_message_handler_new (test_handler,
TEST_DATA,
free_test_data);
_dbus_assert (handler != NULL);
_dbus_assert (handler->function == test_handler);
if (dbus_message_handler_get_data (handler) != TEST_DATA)
_dbus_assert_not_reached ("got wrong data");
dbus_message_handler_set_function (handler, NULL);
_dbus_assert (handler->function == NULL);
dbus_message_handler_ref (handler);
dbus_message_handler_unref (handler);
dbus_message_handler_unref (handler);
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
This diff is collapsed.
......@@ -301,6 +301,10 @@ _dbus_string_free (DBusString *str)
real->invalid = TRUE;
}
#ifdef DBUS_BUILD_TESTS
/* Not using this feature at the moment,
* so marked DBUS_BUILD_TESTS-only
*/
/**
* Locks a string such that any attempts to change the string will
* result in aborting the program. Also, if the string is wasting a
......@@ -338,6 +342,7 @@ _dbus_string_lock (DBusString *str)
}
}
}
#endif /* DBUS_BUILD_TESTS */
static dbus_bool_t
set_length (DBusRealString *real,
......
......@@ -1070,6 +1070,8 @@ _dbus_string_parse_int (const DBusString *str,
return TRUE;
}
#ifdef DBUS_BUILD_TESTS
/* Not currently used, so only built when tests are enabled */
/**
* Parses an unsigned integer contained in a DBusString. Either return
* parameter may be #NULL if you aren't interested in it. The integer
......@@ -1108,6 +1110,7 @@ _dbus_string_parse_uint (const DBusString *str,
return TRUE;
}
#endif /* DBUS_BUILD_TESTS */
static dbus_bool_t
ascii_isspace (char c)
......
......@@ -87,12 +87,6 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
die ("sysdeps");
check_memleaks ();
printf ("%s: running spawn tests\n", "dbus-test");
if (!_dbus_spawn_test (test_data_dir))
die ("spawn");
check_memleaks ();
printf ("%s: running data slot tests\n", "dbus-test");
if (!_dbus_data_slot_test ())
......@@ -112,12 +106,6 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
check_memleaks ();
printf ("%s: running message tests\n", "dbus-test");
if (!_dbus_message_test (test_data_dir))
die ("messages");
check_memleaks ();
printf ("%s: running memory pool tests\n", "dbus-test");
if (!_dbus_mem_pool_test ())
die ("memory pools");
......@@ -130,12 +118,30 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir)
check_memleaks ();
printf ("%s: running message tests\n", "dbus-test");
if (!_dbus_message_test (test_data_dir))
die ("messages");
check_memleaks ();
printf ("%s: running message handler tests\n", "dbus-test");
if (!_dbus_message_handler_test (test_data_dir))
die ("message handler");
check_memleaks ();
printf ("%s: running hash table tests\n", "dbus-test");
if (!_dbus_hash_test ())
die ("hash tables");
check_memleaks ();
printf ("%s: running spawn tests\n", "dbus-test");
if (!_dbus_spawn_test (test_data_dir))
die ("spawn");
check_memleaks ();
printf ("%s: running user database tests\n", "dbus-test");
if (!_dbus_userdb_test (test_data_dir))
die ("user database");
......
......@@ -35,22 +35,24 @@ typedef enum
_DBUS_MESSAGE_UNKNOWN
} DBusMessageValidity;
dbus_bool_t _dbus_hash_test (void);
dbus_bool_t _dbus_dict_test (void);
dbus_bool_t _dbus_list_test (void);
dbus_bool_t _dbus_marshal_test (void);
dbus_bool_t _dbus_mem_pool_test (void);
dbus_bool_t _dbus_string_test (void);
dbus_bool_t _dbus_address_test (void);
dbus_bool_t _dbus_message_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
dbus_bool_t _dbus_md5_test (void);
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
dbus_bool_t _dbus_keyring_test (void);
dbus_bool_t _dbus_data_slot_test (void);
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
dbus_bool_t _dbus_userdb_test (const char *test_data_dir);
dbus_bool_t _dbus_hash_test (void);
dbus_bool_t _dbus_dict_test (void);
dbus_bool_t _dbus_list_test (void);
dbus_bool_t _dbus_marshal_test (void);
dbus_bool_t _dbus_mem_pool_test (void);
dbus_bool_t _dbus_string_test (void);
dbus_bool_t _dbus_address_test (void);
dbus_bool_t _dbus_message_test (const char *test_data_dir);
dbus_bool_t _dbus_message_handler_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
dbus_bool_t _dbus_md5_test (void);
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
dbus_bool_t _dbus_keyring_test (void);
dbus_bool_t _dbus_data_slot_test (void);
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
dbus_bool_t _dbus_userdb_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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment