"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/internals/misc-internals.c" between
dbus-1.13.12.tar.xz and dbus-1.13.14.tar.xz

About: D-Bus is an inter-process communication (IPC) system, allowing multiple, concurrently-running applications to communicate with one another. D-Bus supplies both a system daemon and a per-user-login-session daemon. Development version.

misc-internals.c  (dbus-1.13.12.tar.xz):misc-internals.c  (dbus-1.13.14.tar.xz)
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* /*
* Copyright 2002-2011 Red Hat, Inc. * Copyright 2002-2011 Red Hat, Inc.
* Copyright 2006 Julio M. Merino Vidal * Copyright 2006 Julio M. Merino Vidal
* Copyright 2006 Ralf Habacker * Copyright 2006 Ralf Habacker
* Copyright 2011-2018 Collabora Ltd. * Copyright 2011-2019 Collabora Ltd.
* Copyright 2012 Lennart Poettering
* *
* Licensed under the Academic Free License version 2.1 * Licensed under the Academic Free License version 2.1
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
skipping to change at line 35 skipping to change at line 36
#include <config.h> #include <config.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "dbus/dbus-connection-internal.h" #include "dbus/dbus-connection-internal.h"
#include "dbus/dbus-internals.h" #include "dbus/dbus-internals.h"
#include "dbus/dbus-test.h" #include "dbus/dbus-test.h"
#include "dbus/dbus-test-tap.h" #include "dbus/dbus-test-tap.h"
#include "test/test-utils.h" #include "test/test-utils.h"
#ifdef DBUS_UNIX
#include "dbus/dbus-userdb.h"
#endif
#include "misc-internals.h" #include "misc-internals.h"
static void static void
verify_list (DBusList **list) verify_list (DBusList **list)
{ {
DBusList *link; DBusList *link;
int length; int length;
link = *list; link = *list;
if (link == NULL) if (link == NULL)
return; return;
if (link->next == link) if (link->next == link)
{ {
_dbus_assert (link->prev == link); _dbus_test_check (link->prev == link);
_dbus_assert (*list == link); _dbus_test_check (*list == link);
return; return;
} }
length = 0; length = 0;
do do
{ {
length += 1; length += 1;
_dbus_assert (link->prev->next == link); _dbus_test_check (link->prev->next == link);
_dbus_assert (link->next->prev == link); _dbus_test_check (link->next->prev == link);
link = link->next; link = link->next;
} }
while (link != *list); while (link != *list);
_dbus_assert (length == _dbus_list_get_length (list)); _dbus_test_check (length == _dbus_list_get_length (list));
if (length == 1) if (length == 1)
_dbus_assert (_dbus_list_length_is_one (list)); _dbus_test_check (_dbus_list_length_is_one (list));
else else
_dbus_assert (!_dbus_list_length_is_one (list)); _dbus_test_check (!_dbus_list_length_is_one (list));
} }
static dbus_bool_t static dbus_bool_t
is_ascending_sequence (DBusList **list) is_ascending_sequence (DBusList **list)
{ {
DBusList *link; DBusList *link;
int prev; int prev;
prev = _DBUS_INT_MIN; prev = _DBUS_INT_MIN;
skipping to change at line 217 skipping to change at line 222
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("count not allocate for prepend"); _dbus_test_fatal ("count not allocate for prepend");
++i; ++i;
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
_dbus_assert (_dbus_list_get_length (&list1) == i); _dbus_test_check (_dbus_list_get_length (&list1) == i);
_dbus_assert (_dbus_list_get_length (&list2) == i); _dbus_test_check (_dbus_list_get_length (&list2) == i);
} }
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_assert (is_descending_sequence (&list2)); _dbus_test_check (is_descending_sequence (&list2));
/* Test list clear */ /* Test list clear */
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
/* Test get_first, get_last, pop_first, pop_last */ /* Test get_first, get_last, pop_first, pop_last */
skipping to change at line 258 skipping to change at line 263
void *data1; void *data1;
void *data2; void *data2;
got_data1 = _dbus_list_get_last (&list1); got_data1 = _dbus_list_get_last (&list1);
got_data2 = _dbus_list_get_first (&list2); got_data2 = _dbus_list_get_first (&list2);
data1 = _dbus_list_pop_last (&list1); data1 = _dbus_list_pop_last (&list1);
data2 = _dbus_list_pop_first (&list2); data2 = _dbus_list_pop_first (&list2);
_dbus_assert (got_data1 == data1); _dbus_test_check (got_data1 == data1);
_dbus_assert (got_data2 == data2); _dbus_test_check (got_data2 == data2);
_dbus_assert (_DBUS_POINTER_TO_INT (data1) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (data1) == i);
_dbus_assert (_DBUS_POINTER_TO_INT (data2) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (data2) == i);
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_assert (is_descending_sequence (&list2)); _dbus_test_check (is_descending_sequence (&list2));
--i; --i;
} }
_dbus_assert (list1 == NULL); _dbus_test_check (list1 == NULL);
_dbus_assert (list2 == NULL); _dbus_test_check (list2 == NULL);
/* Test get_first_link, get_last_link, pop_first_link, pop_last_link */ /* Test get_first_link, get_last_link, pop_first_link, pop_last_link */
i = 0; i = 0;
while (i < 10) while (i < 10)
{ {
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for prepend"); _dbus_test_fatal ("could not allocate for prepend");
skipping to change at line 303 skipping to change at line 308
void *data1_indirect; void *data1_indirect;
void *data1; void *data1;
void *data2; void *data2;
got_link1 = _dbus_list_get_last_link (&list1); got_link1 = _dbus_list_get_last_link (&list1);
got_link2 = _dbus_list_get_first_link (&list2); got_link2 = _dbus_list_get_first_link (&list2);
link2 = _dbus_list_pop_first_link (&list2); link2 = _dbus_list_pop_first_link (&list2);
_dbus_assert (got_link2 == link2); _dbus_test_check (got_link2 == link2);
data1_indirect = got_link1->data; data1_indirect = got_link1->data;
/* this call makes got_link1 invalid */ /* this call makes got_link1 invalid */
data1 = _dbus_list_pop_last (&list1); data1 = _dbus_list_pop_last (&list1);
_dbus_assert (data1 == data1_indirect); _dbus_test_check (data1 == data1_indirect);
data2 = link2->data; data2 = link2->data;
_dbus_list_free_link (link2); _dbus_list_free_link (link2);
_dbus_assert (_DBUS_POINTER_TO_INT (data1) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (data1) == i);
_dbus_assert (_DBUS_POINTER_TO_INT (data2) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (data2) == i);
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_assert (is_descending_sequence (&list2)); _dbus_test_check (is_descending_sequence (&list2));
--i; --i;
} }
_dbus_assert (list1 == NULL); _dbus_test_check (list1 == NULL);
_dbus_assert (list2 == NULL); _dbus_test_check (list2 == NULL);
/* Test iteration */ /* Test iteration */
i = 0; i = 0;
while (i < 10) while (i < 10)
{ {
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for prepend"); _dbus_test_fatal ("could not allocate for prepend");
++i; ++i;
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
_dbus_assert (_dbus_list_get_length (&list1) == i); _dbus_test_check (_dbus_list_get_length (&list1) == i);
_dbus_assert (_dbus_list_get_length (&list2) == i); _dbus_test_check (_dbus_list_get_length (&list2) == i);
} }
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_assert (is_descending_sequence (&list2)); _dbus_test_check (is_descending_sequence (&list2));
--i; --i;
link2 = _dbus_list_get_first_link (&list2); link2 = _dbus_list_get_first_link (&list2);
while (link2 != NULL) while (link2 != NULL)
{ {
verify_list (&link2); /* pretend this link is the head */ verify_list (&link2); /* pretend this link is the head */
_dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (link2->data) == i);
link2 = _dbus_list_get_next_link (&list2, link2); link2 = _dbus_list_get_next_link (&list2, link2);
--i; --i;
} }
i = 0; i = 0;
link1 = _dbus_list_get_first_link (&list1); link1 = _dbus_list_get_first_link (&list1);
while (link1 != NULL) while (link1 != NULL)
{ {
verify_list (&link1); /* pretend this link is the head */ verify_list (&link1); /* pretend this link is the head */
_dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (link1->data) == i);
link1 = _dbus_list_get_next_link (&list1, link1); link1 = _dbus_list_get_next_link (&list1, link1);
++i; ++i;
} }
--i; --i;
link1 = _dbus_list_get_last_link (&list1); link1 = _dbus_list_get_last_link (&list1);
while (link1 != NULL) while (link1 != NULL)
{ {
verify_list (&link1); /* pretend this link is the head */ verify_list (&link1); /* pretend this link is the head */
_dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (link1->data) == i);
link1 = _dbus_list_get_prev_link (&list1, link1); link1 = _dbus_list_get_prev_link (&list1, link1);
--i; --i;
} }
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
/* Test remove */ /* Test remove */
skipping to change at line 416 skipping to change at line 421
_dbus_test_fatal ("element should have been in list"); _dbus_test_fatal ("element should have been in list");
if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("element should have been in list"); _dbus_test_fatal ("element should have been in list");
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
} }
--i; --i;
} }
_dbus_assert (all_odd_values (&list1)); _dbus_test_check (all_odd_values (&list1));
_dbus_assert (all_odd_values (&list2)); _dbus_test_check (all_odd_values (&list2));
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
/* test removing the other half of the elements */ /* test removing the other half of the elements */
i = 0; i = 0;
while (i < 10) while (i < 10)
{ {
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
skipping to change at line 450 skipping to change at line 455
_dbus_test_fatal ("element should have been in list"); _dbus_test_fatal ("element should have been in list");
if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("element should have been in list"); _dbus_test_fatal ("element should have been in list");
verify_list (&list1); verify_list (&list1);
verify_list (&list2); verify_list (&list2);
} }
--i; --i;
} }
_dbus_assert (all_even_values (&list1)); _dbus_test_check (all_even_values (&list1));
_dbus_assert (all_even_values (&list2)); _dbus_test_check (all_even_values (&list2));
/* clear list using remove_link */ /* clear list using remove_link */
while (list1 != NULL) while (list1 != NULL)
{ {
_dbus_list_remove_link (&list1, list1); _dbus_list_remove_link (&list1, list1);
verify_list (&list1); verify_list (&list1);
} }
while (list2 != NULL) while (list2 != NULL)
{ {
_dbus_list_remove_link (&list2, list2); _dbus_list_remove_link (&list2, list2);
skipping to change at line 482 skipping to change at line 487
_dbus_test_fatal ("could not allocate for prepend"); _dbus_test_fatal ("could not allocate for prepend");
++i; ++i;
} }
--i; --i;
link2 = _dbus_list_get_first_link (&list2); link2 = _dbus_list_get_first_link (&list2);
while (link2 != NULL) while (link2 != NULL)
{ {
DBusList *next = _dbus_list_get_next_link (&list2, link2); DBusList *next = _dbus_list_get_next_link (&list2, link2);
_dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (link2->data) == i);
if ((i % 2) == 0) if ((i % 2) == 0)
_dbus_list_remove_link (&list2, link2); _dbus_list_remove_link (&list2, link2);
verify_list (&list2); verify_list (&list2);
link2 = next; link2 = next;
--i; --i;
} }
_dbus_assert (all_odd_values (&list2)); _dbus_test_check (all_odd_values (&list2));
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
i = 0; i = 0;
link1 = _dbus_list_get_first_link (&list1); link1 = _dbus_list_get_first_link (&list1);
while (link1 != NULL) while (link1 != NULL)
{ {
DBusList *next = _dbus_list_get_next_link (&list1, link1); DBusList *next = _dbus_list_get_next_link (&list1, link1);
_dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i); _dbus_test_check (_DBUS_POINTER_TO_INT (link1->data) == i);
if ((i % 2) != 0) if ((i % 2) != 0)
_dbus_list_remove_link (&list1, link1); _dbus_list_remove_link (&list1, link1);
verify_list (&list1); verify_list (&list1);
link1 = next; link1 = next;
++i; ++i;
} }
_dbus_assert (all_even_values (&list1)); _dbus_test_check (all_even_values (&list1));
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
/* Test copying a list */ /* Test copying a list */
i = 0; i = 0;
while (i < 10) while (i < 10)
{ {
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i))) if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
_dbus_test_fatal ("could not allocate for prepend"); _dbus_test_fatal ("could not allocate for prepend");
++i; ++i;
} }
/* bad pointers, because they are allowed in the copy dest */ /* bad pointers, because they are allowed in the copy dest */
copy1 = _DBUS_INT_TO_POINTER (0x342234); copy1 = _DBUS_INT_TO_POINTER (0x342234);
copy2 = _DBUS_INT_TO_POINTER (23); copy2 = _DBUS_INT_TO_POINTER (23);
_dbus_list_copy (&list1, &copy1); _dbus_list_copy (&list1, &copy1);
verify_list (&list1); verify_list (&list1);
verify_list (&copy1); verify_list (&copy1);
_dbus_assert (lists_equal (&list1, &copy1)); _dbus_test_check (lists_equal (&list1, &copy1));
_dbus_list_copy (&list2, &copy2); _dbus_list_copy (&list2, &copy2);
verify_list (&list2); verify_list (&list2);
verify_list (&copy2); verify_list (&copy2);
_dbus_assert (lists_equal (&list2, &copy2)); _dbus_test_check (lists_equal (&list2, &copy2));
/* Now test copying empty lists */ /* Now test copying empty lists */
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
_dbus_list_clear (&copy1); _dbus_list_clear (&copy1);
_dbus_list_clear (&copy2); _dbus_list_clear (&copy2);
/* bad pointers, because they are allowed in the copy dest */ /* bad pointers, because they are allowed in the copy dest */
copy1 = _DBUS_INT_TO_POINTER (0x342234); copy1 = _DBUS_INT_TO_POINTER (0x342234);
copy2 = _DBUS_INT_TO_POINTER (23); copy2 = _DBUS_INT_TO_POINTER (23);
_dbus_list_copy (&list1, &copy1); _dbus_list_copy (&list1, &copy1);
verify_list (&list1); verify_list (&list1);
verify_list (&copy1); verify_list (&copy1);
_dbus_assert (lists_equal (&list1, &copy1)); _dbus_test_check (lists_equal (&list1, &copy1));
_dbus_list_copy (&list2, &copy2); _dbus_list_copy (&list2, &copy2);
verify_list (&list2); verify_list (&list2);
verify_list (&copy2); verify_list (&copy2);
_dbus_assert (lists_equal (&list2, &copy2)); _dbus_test_check (lists_equal (&list2, &copy2));
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
_dbus_list_clear (&list2); _dbus_list_clear (&list2);
/* insert_after on empty list */ /* insert_after on empty list */
_dbus_list_insert_after (&list1, NULL, _dbus_list_insert_after (&list1, NULL,
_DBUS_INT_TO_POINTER (0)); _DBUS_INT_TO_POINTER (0));
verify_list (&list1); verify_list (&list1);
/* inserting after first element */ /* inserting after first element */
_dbus_list_insert_after (&list1, list1, _dbus_list_insert_after (&list1, list1,
_DBUS_INT_TO_POINTER (1)); _DBUS_INT_TO_POINTER (1));
verify_list (&list1); verify_list (&list1);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
/* inserting at the end */ /* inserting at the end */
_dbus_list_insert_after (&list1, list1->next, _dbus_list_insert_after (&list1, list1->next,
_DBUS_INT_TO_POINTER (2)); _DBUS_INT_TO_POINTER (2));
verify_list (&list1); verify_list (&list1);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
/* using insert_after to prepend */ /* using insert_after to prepend */
_dbus_list_insert_after (&list1, NULL, _dbus_list_insert_after (&list1, NULL,
_DBUS_INT_TO_POINTER (-1)); _DBUS_INT_TO_POINTER (-1));
verify_list (&list1); verify_list (&list1);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
/* using remove_last */ /* using remove_last */
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (2))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (2)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (1))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (1)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (3))) if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (3)))
_dbus_test_fatal ("could not allocate for append"); _dbus_test_fatal ("could not allocate for append");
_dbus_list_remove_last (&list1, _DBUS_INT_TO_POINTER (2)); _dbus_list_remove_last (&list1, _DBUS_INT_TO_POINTER (2));
verify_list (&list1); verify_list (&list1);
_dbus_assert (is_ascending_sequence (&list1)); _dbus_test_check (is_ascending_sequence (&list1));
_dbus_list_clear (&list1); _dbus_list_clear (&list1);
return TRUE; return TRUE;
} }
static dbus_bool_t static dbus_bool_t
_dbus_misc_test (const char *test_data_dir _DBUS_GNUC_UNUSED) _dbus_misc_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
{ {
int major, minor, micro; int major, minor, micro;
skipping to change at line 623 skipping to change at line 628
/* make sure we don't crash on NULL */ /* make sure we don't crash on NULL */
dbus_get_version (NULL, NULL, NULL); dbus_get_version (NULL, NULL, NULL);
/* Now verify that all the compile-time version stuff /* Now verify that all the compile-time version stuff
* is right and matches the runtime. These tests * is right and matches the runtime. These tests
* are mostly intended to catch various kinds of * are mostly intended to catch various kinds of
* typo (mixing up major and minor, that sort of thing). * typo (mixing up major and minor, that sort of thing).
*/ */
dbus_get_version (&major, &minor, &micro); dbus_get_version (&major, &minor, &micro);
_dbus_assert (major == DBUS_MAJOR_VERSION); _dbus_test_check (major == DBUS_MAJOR_VERSION);
_dbus_assert (minor == DBUS_MINOR_VERSION); _dbus_test_check (minor == DBUS_MINOR_VERSION);
_dbus_assert (micro == DBUS_MICRO_VERSION); _dbus_test_check (micro == DBUS_MICRO_VERSION);
#define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z)) #define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z))
/* check that MAKE_VERSION works and produces the intended ordering */ /* check that MAKE_VERSION works and produces the intended ordering */
_dbus_assert (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0)); _dbus_test_check (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0));
_dbus_assert (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0)); _dbus_test_check (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0));
_dbus_assert (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0)); _dbus_test_check (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0));
_dbus_assert (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1)); _dbus_test_check (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1));
_dbus_assert (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1)); _dbus_test_check (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1));
_dbus_assert (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1)); _dbus_test_check (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1));
/* check DBUS_VERSION */ /* check DBUS_VERSION */
_dbus_assert (MAKE_VERSION (major, minor, micro) == DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major, minor, micro) == DBUS_VERSION);
/* check that ordering works with DBUS_VERSION */ /* check that ordering works with DBUS_VERSION */
_dbus_assert (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION);
_dbus_assert (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION); _dbus_test_check (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION);
/* Check DBUS_VERSION_STRING */ /* Check DBUS_VERSION_STRING */
if (!_dbus_string_init (&str)) if (!_dbus_string_init (&str))
_dbus_test_fatal ("no memory"); _dbus_test_fatal ("no memory");
if (!(_dbus_string_append_int (&str, major) && if (!(_dbus_string_append_int (&str, major) &&
_dbus_string_append_byte (&str, '.') && _dbus_string_append_byte (&str, '.') &&
_dbus_string_append_int (&str, minor) && _dbus_string_append_int (&str, minor) &&
_dbus_string_append_byte (&str, '.') && _dbus_string_append_byte (&str, '.') &&
_dbus_string_append_int (&str, micro))) _dbus_string_append_int (&str, micro)))
_dbus_test_fatal ("no memory"); _dbus_test_fatal ("no memory");
_dbus_assert (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING)); _dbus_test_check (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING));
_dbus_string_free (&str); _dbus_string_free (&str);
return TRUE; return TRUE;
} }
static dbus_bool_t static dbus_bool_t
_dbus_server_test (const char *test_data_dir _DBUS_GNUC_UNUSED) _dbus_server_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
{ {
const char *valid_addresses[] = { const char *valid_addresses[] = {
skipping to change at line 696 skipping to change at line 701
{ {
DBusError error = DBUS_ERROR_INIT; DBusError error = DBUS_ERROR_INIT;
char *address; char *address;
char *id; char *id;
server = dbus_server_listen (valid_addresses[i], &error); server = dbus_server_listen (valid_addresses[i], &error);
if (server == NULL) if (server == NULL)
{ {
_dbus_warn ("server listen error: %s: %s", error.name, error.message); _dbus_warn ("server listen error: %s: %s", error.name, error.message);
dbus_error_free (&error); dbus_error_free (&error);
_dbus_assert_not_reached ("Failed to listen for valid address."); _dbus_test_fatal ("Failed to listen for valid address.");
} }
id = dbus_server_get_id (server); id = dbus_server_get_id (server);
_dbus_assert (id != NULL); _dbus_test_check (id != NULL);
address = dbus_server_get_address (server); address = dbus_server_get_address (server);
_dbus_assert (address != NULL); _dbus_test_check (address != NULL);
if (strstr (address, id) == NULL) if (strstr (address, id) == NULL)
{ {
_dbus_warn ("server id '%s' is not in the server address '%s'", _dbus_warn ("server id '%s' is not in the server address '%s'",
id, address); id, address);
_dbus_assert_not_reached ("bad server id or address"); _dbus_test_fatal ("bad server id or address");
} }
dbus_free (id); dbus_free (id);
dbus_free (address); dbus_free (address);
dbus_server_disconnect (server); dbus_server_disconnect (server);
dbus_server_unref (server); dbus_server_unref (server);
} }
return TRUE; return TRUE;
skipping to change at line 738 skipping to change at line 743
_dbus_signature_test (const char *test_data_dir _DBUS_GNUC_UNUSED) _dbus_signature_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
{ {
DBusSignatureIter iter; DBusSignatureIter iter;
DBusSignatureIter subiter; DBusSignatureIter subiter;
DBusSignatureIter subsubiter; DBusSignatureIter subsubiter;
DBusSignatureIter subsubsubiter; DBusSignatureIter subsubsubiter;
const char *sig; const char *sig;
dbus_bool_t boolres; dbus_bool_t boolres;
sig = ""; sig = "";
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
_dbus_assert (!dbus_signature_validate_single (sig, NULL)); _dbus_test_check (!dbus_signature_validate_single (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_INVALI D); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_IN VALID);
sig = DBUS_TYPE_STRING_AS_STRING; sig = DBUS_TYPE_STRING_AS_STRING;
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
_dbus_assert (dbus_signature_validate_single (sig, NULL)); _dbus_test_check (dbus_signature_validate_single (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING ); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ST RING);
sig = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_BYTE_AS_STRING; sig = DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRING ); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ST RING);
boolres = dbus_signature_iter_next (&iter); boolres = dbus_signature_iter_next (&iter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_BYTE); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_BY
TE);
sig = DBUS_TYPE_UINT16_AS_STRING sig = DBUS_TYPE_UINT16_AS_STRING
DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_UINT32_AS_STRING
DBUS_TYPE_VARIANT_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
DBUS_TYPE_DOUBLE_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING; DBUS_STRUCT_END_CHAR_AS_STRING;
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16 ); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UI NT16);
boolres = dbus_signature_iter_next (&iter); boolres = dbus_signature_iter_next (&iter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ST
); RUCT);
dbus_signature_iter_recurse (&iter, &subiter); dbus_signature_iter_recurse (&iter, &subiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STR ING); _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE _STRING);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UIN _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
T32); _UINT32);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_VAR _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
IANT); _VARIANT);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_DOU _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
BLE); _DOUBLE);
sig = DBUS_TYPE_UINT16_AS_STRING sig = DBUS_TYPE_UINT16_AS_STRING
DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_TYPE_UINT32_AS_STRING DBUS_TYPE_UINT32_AS_STRING
DBUS_TYPE_BYTE_AS_STRING DBUS_TYPE_BYTE_AS_STRING
DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_DOUBLE_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING
DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_TYPE_BYTE_AS_STRING DBUS_TYPE_BYTE_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING; DBUS_STRUCT_END_CHAR_AS_STRING;
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UINT16 ); _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_UI NT16);
boolres = dbus_signature_iter_next (&iter); boolres = dbus_signature_iter_next (&iter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_STRUCT _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ST
); RUCT);
dbus_signature_iter_recurse (&iter, &subiter); dbus_signature_iter_recurse (&iter, &subiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_UIN T32); _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE _UINT32);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_BYT _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
E); _BYTE);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_ARR _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
AY); _ARRAY);
_dbus_assert (dbus_signature_iter_get_element_type (&subiter) == DBUS_TYPE_ARR _dbus_test_check (dbus_signature_iter_get_element_type (&subiter) == DBUS_TYPE
AY); _ARRAY);
dbus_signature_iter_recurse (&subiter, &subsubiter); dbus_signature_iter_recurse (&subiter, &subsubiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ _dbus_test_check (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_T
ARRAY); YPE_ARRAY);
_dbus_assert (dbus_signature_iter_get_element_type (&subsubiter) == DBUS_TYPE_ _dbus_test_check (dbus_signature_iter_get_element_type (&subsubiter) == DBUS_T
DOUBLE); YPE_DOUBLE);
dbus_signature_iter_recurse (&subsubiter, &subsubsubiter); dbus_signature_iter_recurse (&subsubiter, &subsubsubiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subsubsubiter) == DBUS_TY PE_DOUBLE); _dbus_test_check (dbus_signature_iter_get_current_type (&subsubsubiter) == DBU S_TYPE_DOUBLE);
boolres = dbus_signature_iter_next (&subiter); boolres = dbus_signature_iter_next (&subiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE_STR _dbus_test_check (dbus_signature_iter_get_current_type (&subiter) == DBUS_TYPE
UCT); _STRUCT);
dbus_signature_iter_recurse (&subiter, &subsubiter); dbus_signature_iter_recurse (&subiter, &subsubiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ BYTE); _dbus_test_check (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_T YPE_BYTE);
sig = DBUS_TYPE_ARRAY_AS_STRING sig = DBUS_TYPE_ARRAY_AS_STRING
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_TYPE_INT16_AS_STRING DBUS_TYPE_INT16_AS_STRING
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING
DBUS_TYPE_VARIANT_AS_STRING; DBUS_TYPE_VARIANT_AS_STRING;
_dbus_assert (dbus_signature_validate (sig, NULL)); _dbus_test_check (dbus_signature_validate (sig, NULL));
_dbus_assert (!dbus_signature_validate_single (sig, NULL)); _dbus_test_check (!dbus_signature_validate_single (sig, NULL));
dbus_signature_iter_init (&iter, sig); dbus_signature_iter_init (&iter, sig);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_ARRAY) _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_AR
; RAY);
_dbus_assert (dbus_signature_iter_get_element_type (&iter) == DBUS_TYPE_DICT_E _dbus_test_check (dbus_signature_iter_get_element_type (&iter) == DBUS_TYPE_DI
NTRY); CT_ENTRY);
dbus_signature_iter_recurse (&iter, &subiter); dbus_signature_iter_recurse (&iter, &subiter);
dbus_signature_iter_recurse (&subiter, &subsubiter); dbus_signature_iter_recurse (&subiter, &subsubiter);
_dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ INT16); _dbus_test_check (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_T YPE_INT16);
boolres = dbus_signature_iter_next (&subsubiter); boolres = dbus_signature_iter_next (&subsubiter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_TYPE_ _dbus_test_check (dbus_signature_iter_get_current_type (&subsubiter) == DBUS_T
STRING); YPE_STRING);
boolres = dbus_signature_iter_next (&subsubiter); boolres = dbus_signature_iter_next (&subsubiter);
_dbus_assert (!boolres); _dbus_test_check (!boolres);
boolres = dbus_signature_iter_next (&iter); boolres = dbus_signature_iter_next (&iter);
_dbus_assert (boolres); _dbus_test_check (boolres);
_dbus_assert (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_VARIAN _dbus_test_check (dbus_signature_iter_get_current_type (&iter) == DBUS_TYPE_VA
T); RIANT);
boolres = dbus_signature_iter_next (&iter); boolres = dbus_signature_iter_next (&iter);
_dbus_assert (!boolres); _dbus_test_check (!boolres);
sig = DBUS_TYPE_DICT_ENTRY_AS_STRING; sig = DBUS_TYPE_DICT_ENTRY_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_TYPE_ARRAY_AS_STRING; sig = DBUS_TYPE_ARRAY_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_TYPE_UINT32_AS_STRING sig = DBUS_TYPE_UINT32_AS_STRING
DBUS_TYPE_ARRAY_AS_STRING; DBUS_TYPE_ARRAY_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_TYPE_ARRAY_AS_STRING sig = DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_DICT_ENTRY_AS_STRING; DBUS_TYPE_DICT_ENTRY_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING; sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_DICT_ENTRY_END_CHAR_AS_STRING; sig = DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_TYPE_INT32_AS_STRING; DBUS_TYPE_INT32_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING sig = DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
DBUS_TYPE_INT32_AS_STRING DBUS_TYPE_INT32_AS_STRING
DBUS_TYPE_STRING_AS_STRING; DBUS_TYPE_STRING_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_STRUCT_END_CHAR_AS_STRING sig = DBUS_STRUCT_END_CHAR_AS_STRING
DBUS_STRUCT_BEGIN_CHAR_AS_STRING; DBUS_STRUCT_BEGIN_CHAR_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
sig = DBUS_STRUCT_BEGIN_CHAR_AS_STRING sig = DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_TYPE_BOOLEAN_AS_STRING; DBUS_TYPE_BOOLEAN_AS_STRING;
_dbus_assert (!dbus_signature_validate (sig, NULL)); _dbus_test_check (!dbus_signature_validate (sig, NULL));
return TRUE; return TRUE;
#if 0 #if 0
oom: oom:
_dbus_test_fatal ("out of memory"); _dbus_test_fatal ("out of memory");
return FALSE; return FALSE;
#endif #endif
} }
#ifdef DBUS_UNIX #ifdef DBUS_UNIX
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static dbus_bool_t static dbus_bool_t
_dbus_transport_unix_test (const char *test_data_dir _DBUS_GNUC_UNUSED) _dbus_transport_unix_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
{ {
DBusConnection *c; DBusConnection *c;
DBusError error; DBusError error;
dbus_bool_t ret; dbus_bool_t ret;
const char *address; const char *address;
dbus_error_init (&error); dbus_error_init (&error);
c = dbus_connection_open ("unixexec:argv0=false,argv1=foobar,path=/bin/false", &error); c = dbus_connection_open ("unixexec:argv0=false,argv1=foobar,path=/bin/false", &error);
_dbus_assert (c != NULL); _dbus_test_check (c != NULL);
_dbus_assert (!dbus_error_is_set (&error)); _dbus_test_check (!dbus_error_is_set (&error));
address = _dbus_connection_get_address (c); address = _dbus_connection_get_address (c);
_dbus_assert (address != NULL); _dbus_test_check (address != NULL);
/* Let's see if the address got parsed, reordered and formatted correctly */ /* Let's see if the address got parsed, reordered and formatted correctly */
ret = strcmp (address, "unixexec:path=/bin/false,argv0=false,argv1=foobar") == 0; ret = strcmp (address, "unixexec:path=/bin/false,argv0=false,argv1=foobar") == 0;
dbus_connection_unref (c); dbus_connection_unref (c);
return ret; return ret;
} }
#endif #endif
/**
* Unit test for dbus-userdb.c.
*
* @returns #TRUE on success.
*/
static dbus_bool_t
_dbus_userdb_test (const char *test_data_dir)
{
const DBusString *username;
const DBusString *homedir;
dbus_uid_t uid;
unsigned long *group_ids;
int n_group_ids, i;
DBusError error;
if (!_dbus_username_from_current_process (&username))
_dbus_test_fatal ("didn't get username");
if (!_dbus_homedir_from_current_process (&homedir))
_dbus_test_fatal ("didn't get homedir");
if (!_dbus_get_user_id (username, &uid))
_dbus_test_fatal ("didn't get uid");
if (!_dbus_groups_from_uid (uid, &group_ids, &n_group_ids))
_dbus_test_fatal ("didn't get groups");
_dbus_test_diag (" Current user: %s homedir: %s gids:",
_dbus_string_get_const_data (username),
_dbus_string_get_const_data (homedir));
for (i=0; i<n_group_ids; i++)
_dbus_test_diag ("- %ld", group_ids[i]);
dbus_error_init (&error);
_dbus_test_diag ("Is Console user: %i",
_dbus_is_console_user (uid, &error));
_dbus_test_diag ("Invocation was OK: %s", error.message ? error.message : "yes
");
dbus_error_free (&error);
_dbus_test_diag ("Is Console user 4711: %i",
_dbus_is_console_user (4711, &error));
_dbus_test_diag ("Invocation was OK: %s", error.message ? error.message : "yes
");
dbus_error_free (&error);
dbus_free (group_ids);
return TRUE;
}
#endif
static DBusTestCase tests[] = static DBusTestCase tests[] =
{ {
{ "string", _dbus_string_test },
{ "sysdeps", _dbus_sysdeps_test },
{ "data-slot", _dbus_data_slot_test },
{ "misc", _dbus_misc_test }, { "misc", _dbus_misc_test },
{ "address", _dbus_address_test }, { "address", _dbus_address_test },
{ "server", _dbus_server_test }, { "server", _dbus_server_test },
{ "object-tree", _dbus_object_tree_test },
{ "signature", _dbus_signature_test }, { "signature", _dbus_signature_test },
{ "marshalling", _dbus_marshal_test },
{ "byteswap", _dbus_marshal_byteswap_test },
{ "memory", _dbus_memory_test },
{ "mem-pool", _dbus_mem_pool_test }, { "mem-pool", _dbus_mem_pool_test },
{ "list", _dbus_list_test }, { "list", _dbus_list_test },
{ "marshal-validate", _dbus_marshal_validate_test },
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
{ "auth", _dbus_auth_test },
{ "byteswap", _dbus_marshal_byteswap_test },
{ "credentials", _dbus_credentials_test }, { "credentials", _dbus_credentials_test },
{ "data-slot", _dbus_data_slot_test },
{ "keyring", _dbus_keyring_test }, { "keyring", _dbus_keyring_test },
{ "marshal-validate", _dbus_marshal_validate_test },
{ "marshalling", _dbus_marshal_test },
{ "memory", _dbus_memory_test },
{ "object-tree", _dbus_object_tree_test },
{ "sha", _dbus_sha_test }, { "sha", _dbus_sha_test },
{ "auth", _dbus_auth_test }, { "string", _dbus_string_test },
{ "sysdeps", _dbus_sysdeps_test },
#endif
#if defined(DBUS_UNIX) #if defined(DBUS_UNIX)
{ "userdb", _dbus_userdb_test }, { "userdb", _dbus_userdb_test },
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
{ "transport-unix", _dbus_transport_unix_test }, { "transport-unix", _dbus_transport_unix_test },
#endif #endif
#endif
{ NULL } { NULL }
}; };
int int
main (int argc, main (int argc,
char **argv) char **argv)
{ {
return _dbus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests, return _dbus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests,
DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS, DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS,
 End of changes. 100 change blocks. 
159 lines changed or deleted 223 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)