-
Notifications
You must be signed in to change notification settings - Fork 345
/
libsemanage-tests.c
133 lines (117 loc) · 3.28 KB
/
libsemanage-tests.c
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
/* Authors: Christopher Ashworth <[email protected]>
* Caleb Case <[email protected]>
* Chad Sellers <[email protected]>
*
* Copyright (C) 2006 Tresys Technology, LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "test_semanage_store.h"
#include "test_utilities.h"
#include "test_handle.h"
#include "test_bool.h"
#include "test_fcontext.h"
#include "test_iface.h"
#include "test_ibendport.h"
#include "test_node.h"
#include "test_port.h"
#include "test_user.h"
#include "test_other.h"
#include <CUnit/Basic.h>
#include <CUnit/Console.h>
#include <CUnit/TestDB.h>
#include <stdbool.h>
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
#define DECLARE_SUITE(name) \
do { \
suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \
if (NULL == suite) { \
CU_cleanup_registry(); \
return CU_get_error(); \
} \
if (name##_add_tests(suite)) { \
CU_cleanup_registry(); \
return CU_get_error(); \
} \
} while (0)
static void usage(char *progname)
{
printf("usage: %s [options]\n", progname);
printf("options:\n");
printf("\t-v, --verbose\t\t\tverbose output\n");
printf("\t-i, --interactive\t\tinteractive console\n");
}
static bool do_tests(int interactive, int verbose)
{
CU_pSuite suite = NULL;
unsigned int num_failures;
/* Initialize the CUnit test registry. */
if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error();
DECLARE_SUITE(semanage_store);
DECLARE_SUITE(semanage_utilities);
DECLARE_SUITE(handle);
DECLARE_SUITE(boolean);
DECLARE_SUITE(fcontext);
DECLARE_SUITE(iface);
DECLARE_SUITE(ibendport);
DECLARE_SUITE(node);
DECLARE_SUITE(port);
DECLARE_SUITE(user);
DECLARE_SUITE(other);
if (verbose)
CU_basic_set_mode(CU_BRM_VERBOSE);
else
CU_basic_set_mode(CU_BRM_NORMAL);
if (interactive)
CU_console_run_tests();
else
CU_basic_run_tests();
num_failures = CU_get_number_of_tests_failed();
CU_cleanup_registry();
return CU_get_error() == CUE_SUCCESS && num_failures == 0;
}
/* The main function for setting up and running the libsemanage unit tests.
* Returns a CUE_SUCCESS on success, or a CUnit error code on failure.
*/
int main(int argc, char **argv)
{
int i, verbose = 1, interactive = 0;
struct option opts[] = {
{"verbose", 0, NULL, 'v'},
{"interactive", 0, NULL, 'i'},
{NULL, 0, NULL, 0}
};
while ((i = getopt_long(argc, argv, "vi", opts, NULL)) != -1) {
switch (i) {
case 'v':
verbose = 1;
break;
case 'i':
interactive = 1;
break;
case 'h':
default:{
usage(argv[0]);
exit(1);
}
}
}
if (!do_tests(interactive, verbose))
return -1;
return 0;
}