summaryrefslogtreecommitdiffstats
path: root/3rdparty/openpgm-svn-r1135/pgm/http_unittest.c
blob: 32ba11bcdf947b22caf31579c89724cb96a59f7f (plain) (blame)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* vim:ts=8:sts=8:sw=4:noai:noexpandtab
 *
 * unit tests for the HTTP administration interface.
 *
 * Copyright (c) 2009 Miru Limited.
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <check.h>

#include "pgm/transport.h"


/* mock state */
static const guint mock_pgm_major_version = 0;
static const guint mock_pgm_minor_version = 0;
static const guint mock_pgm_micro_version = 0;
static GStaticRWLock mock_pgm_transport_list_lock = G_STATIC_RW_LOCK_INIT;
static GSList* mock_pgm_transport_list = NULL;

static
gboolean
mock_pgm_tsi_equal (
	gconstpointer	v1,
	gconstpointer	v2
	)
{
	return memcmp (v1, v2, sizeof(struct pgm_tsi_t)) == 0;
}

static
void
mock_pgm_time_since_epoch (
	pgm_time_t*	pgm_time_t_time,
	time_t*		time_t_time
	)
{
	*time_t_time = pgm_to_secs (*pgm_time_t_time + 0);
}

static
void
mock_pgm_histogram_write_html_graph_all
	(
	GString*	string
	)
{
}


/* mock functions for external references */

#define pgm_major_version	mock_pgm_major_version
#define pgm_minor_version	mock_pgm_minor_version
#define pgm_micro_version	mock_pgm_micro_version
#define pgm_transport_list_lock	mock_pgm_transport_list_lock
#define pgm_transport_list	mock_pgm_transport_list
#define pgm_tsi_equal		mock_pgm_tsi_equal
#define pgm_time_since_epoch	mock_pgm_time_since_epoch
#define pgm_histogram_write_html_graph_all	mock_pgm_histogram_write_html_graph_all

#define HTTP_DEBUG
#include "http.c"


/* target:
 *	gboolean
 *	pgm_http_init (
 *		guint16*	http_port,
 *		GError**	error
 *	)
 */

START_TEST (test_init_pass_001)
{
	GError* err = NULL;
	fail_unless (TRUE == pgm_http_init (8080, &err));
	fail_unless (NULL == err);
}
END_TEST

/* duplicate servers */
START_TEST (test_init_fail_001)
{
	GError* err = NULL;
	fail_unless (TRUE == pgm_http_init (8080, &err));
	fail_unless (FALSE == pgm_http_init (8080, &err));
}
END_TEST

/* target:
 *	gboolean
 *	pgm_http_shutdown (void)
 */

START_TEST (test_shutdown_pass_001)
{
	GError* err = NULL;
	fail_unless (TRUE == pgm_http_init (8080, &err));
	fail_unless (NULL == err);
	fail_unless (TRUE == pgm_http_shutdown ());
}
END_TEST

/* repeatability
 */
START_TEST (test_shutdown_pass_002)
{
	GError* err = NULL;
	fail_unless (TRUE == pgm_http_init (8080, &err));
	fail_unless (NULL == err);
	fail_unless (TRUE == pgm_http_shutdown ());
	fail_unless (TRUE == pgm_http_init (8080, &err));
	fail_unless (NULL == err);
	fail_unless (TRUE == pgm_http_shutdown ());
}
END_TEST

/* no running server */
START_TEST (test_shutdown_fail_001)
{
	fail_unless (FALSE == pgm_http_shutdown ());
}
END_TEST


static
Suite*
make_test_suite (void)
{
	Suite* s;

	s = suite_create (__FILE__);

	TCase* tc_init = tcase_create ("init");
	suite_add_tcase (s, tc_init);
	tcase_add_test (tc_init, test_init_pass_001);
	tcase_add_test (tc_init, test_init_fail_001);

	TCase* tc_shutdown = tcase_create ("shutdown");
	suite_add_tcase (s, tc_shutdown);
	tcase_add_test (tc_shutdown, test_shutdown_pass_001);
	tcase_add_test (tc_shutdown, test_shutdown_pass_002);
	tcase_add_test (tc_shutdown, test_shutdown_fail_001);

	return s;
}

static
Suite*
make_master_suite (void)
{
	Suite* s = suite_create ("Master");
	return s;
}

int
main (void)
{
	SRunner* sr = srunner_create (make_master_suite ());
	srunner_add_suite (sr, make_test_suite ());
	srunner_run_all (sr, CK_ENV);
	int number_failed = srunner_ntests_failed (sr);
	srunner_free (sr);
	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

/* eof */