summaryrefslogtreecommitdiff
path: root/dbus/dbus-test.c
blob: ae0b791c488d6b2ad7c2e5cb4a6c1bdf437aee11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-test.c  Program to run all tests
 *
 * Copyright (C) 2002, 2003, 2004, 2005  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include <config.h>
#include "dbus-test.h"
#include "dbus-sysdeps.h"
#include "dbus-internals.h"
#include <dbus/dbus-test-tap.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef DBUS_ENABLE_EMBEDDED_TESTS
typedef dbus_bool_t (*TestFunc)(void);
typedef dbus_bool_t (*TestDataFunc)(const char *data);

static void
run_test (const char             *test_name,
          const char             *specific_test,
          TestFunc                test)
{
  if (specific_test != NULL && strcmp (specific_test, test_name) != 0)
    {
      _dbus_test_skip ("%s - Only intending to run %s", test_name, specific_test);
      return;
    }

  _dbus_test_diag ("%s: running %s tests", "test-dbus", test_name);

  if (test ())
    _dbus_test_ok ("%s", test_name);
  else
    _dbus_test_not_ok ("%s", test_name);

  _dbus_test_check_memleaks (test_name);
}

static void
run_data_test (const char             *test_name,
               const char             *specific_test,
               TestDataFunc            test,
               const char             *test_data_dir)
{
  if (specific_test != NULL && strcmp (specific_test, test_name) != 0)
    {
      _dbus_test_skip ("%s - Only intending to run %s", test_name, specific_test);
      return;
    }

  _dbus_test_diag ("%s: running %s tests", "test-dbus", test_name);

  if (test (test_data_dir))
    _dbus_test_ok ("%s", test_name);
  else
    _dbus_test_not_ok ("%s", test_name);

  _dbus_test_check_memleaks (test_name);
}

/**
 * An exported symbol to be run in order to execute
 * unit tests. Should not be used by
 * any app other than our test app, this symbol
 * won't exist in some builds of the library.
 * (with --enable-tests=no)
 *
 * @param test_data_dir the directory with test data (test/data normally)
 * @param specific_test run specific test or #NULL to run all tests
 */
void
_dbus_run_tests (const char   *test_data_dir,
                 const char   *specific_test)
{
  if (!_dbus_threads_init_debug ())
    _dbus_test_fatal ("debug threads init failed");

  if (test_data_dir == NULL)
    test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");

  if (test_data_dir != NULL)
    _dbus_test_diag ("Test data in %s", test_data_dir);
  else
    _dbus_test_diag ("No test data!");

  run_test ("string", specific_test, _dbus_string_test);
  
  run_test ("sysdeps", specific_test, _dbus_sysdeps_test);
  
  run_test ("data-slot", specific_test, _dbus_data_slot_test);

  run_test ("misc", specific_test, _dbus_misc_test);
  
  run_test ("address", specific_test, _dbus_address_test);

  run_test ("server", specific_test, _dbus_server_test);

  run_test ("object-tree", specific_test, _dbus_object_tree_test);

  run_test ("signature", specific_test, _dbus_signature_test);
  
  run_test ("marshalling", specific_test, _dbus_marshal_test);

  run_test ("marshal-recursive", specific_test, _dbus_marshal_recursive_test);

  run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test);
  
  run_test ("memory", specific_test, _dbus_memory_test);

#if 1
  run_test ("mem-pool", specific_test, _dbus_mem_pool_test);
#endif
  
  run_test ("list", specific_test, _dbus_list_test);

  run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test);

  run_data_test ("message", specific_test, _dbus_message_test, test_data_dir);
  
  run_test ("hash", specific_test, _dbus_hash_test);

#if !defined(DBUS_WINCE)
  run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
#endif
  
  run_data_test ("credentials", specific_test, _dbus_credentials_test, test_data_dir);

#ifdef DBUS_UNIX
  run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);

  run_test ("transport-unix", specific_test, _dbus_transport_unix_test);
#endif
  
  run_test ("keyring", specific_test, _dbus_keyring_test);

  run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
  
  run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
}

#endif /* DBUS_ENABLE_EMBEDDED_TESTS */