blob: f8506fa917c56182680b6329c2f781b185ff061c [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include "test.h"
20#include <pjlib.h>
21#ifdef _MSC_VER
22# pragma warning(disable:4127)
23#endif
24
25#define DO_TEST(test) do { \
26 PJ_LOG(3, ("test", "Running %s...", #test)); \
27 rc = test; \
28 PJ_LOG(3, ("test", \
29 "%s(%d)", \
30 (rc ? "..ERROR" : "..success"), rc)); \
31 if (rc!=0) goto on_return; \
32 } while (0)
33
34
35pj_pool_factory *mem;
36
37int param_echo_sock_type;
38const char *param_echo_server = ECHO_SERVER_ADDRESS;
39int param_echo_port = ECHO_SERVER_START_PORT;
40
41int test_inner(void)
42{
43 pj_caching_pool caching_pool;
44 const char *filename;
45 int line;
46 int rc = 0;
47
48 mem = &caching_pool.factory;
49
50 pj_log_set_level(3);
51 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
52 PJ_LOG_HAS_MICRO_SEC);
53
54 rc = pj_init();
55 if (rc != 0) {
56 app_perror("pj_init() error!!", rc);
57 return rc;
58 }
59
60 pj_dump_config();
61 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
62
63#if INCLUDE_ERRNO_TEST
64 DO_TEST( errno_test() );
65#endif
66
67#if INCLUDE_TIMESTAMP_TEST
68 DO_TEST( timestamp_test() );
69#endif
70
71#if INCLUDE_EXCEPTION_TEST
72 DO_TEST( exception_test() );
73#endif
74
75#if INCLUDE_RAND_TEST
76 DO_TEST( rand_test() );
77#endif
78
79#if INCLUDE_LIST_TEST
80 DO_TEST( list_test() );
81#endif
82
83#if INCLUDE_POOL_TEST
84 DO_TEST( pool_test() );
85#endif
86
87#if INCLUDE_POOL_PERF_TEST
88 DO_TEST( pool_perf_test() );
89#endif
90
91#if INCLUDE_STRING_TEST
92 DO_TEST( string_test() );
93#endif
94
95#if INCLUDE_FIFOBUF_TEST
96 DO_TEST( fifobuf_test() );
97#endif
98
99#if INCLUDE_RBTREE_TEST
100 DO_TEST( rbtree_test() );
101#endif
102
103#if INCLUDE_ATOMIC_TEST
104 DO_TEST( atomic_test() );
105#endif
106
107#if INCLUDE_MUTEX_TEST
108 DO_TEST( mutex_test() );
109#endif
110
111#if INCLUDE_TIMER_TEST
112 DO_TEST( timer_test() );
113#endif
114
115#if INCLUDE_SLEEP_TEST
116 DO_TEST( sleep_test() );
117#endif
118
119#if INCLUDE_THREAD_TEST
120 DO_TEST( thread_test() );
121#endif
122
123#if INCLUDE_SOCK_TEST
124 DO_TEST( sock_test() );
125#endif
126
127#if INCLUDE_SOCK_PERF_TEST
128 DO_TEST( sock_perf_test() );
129#endif
130
131#if INCLUDE_SELECT_TEST
132 DO_TEST( select_test() );
133#endif
134
135#if INCLUDE_UDP_IOQUEUE_TEST
136 DO_TEST( udp_ioqueue_test() );
137#endif
138
139#if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST
140 DO_TEST( tcp_ioqueue_test() );
141#endif
142
143#if INCLUDE_IOQUEUE_PERF_TEST
144 DO_TEST( ioqueue_perf_test() );
145#endif
146
147#if INCLUDE_FILE_TEST
148 DO_TEST( file_test() );
149#endif
150
151#if INCLUDE_ECHO_SERVER
152 //echo_server();
153 //echo_srv_sync();
154 udp_echo_srv_ioqueue();
155
156#elif INCLUDE_ECHO_CLIENT
157 if (param_echo_sock_type == 0)
158 param_echo_sock_type = PJ_SOCK_DGRAM;
159
160 echo_client( param_echo_sock_type,
161 param_echo_server,
162 param_echo_port);
163#endif
164
165 goto on_return;
166
167on_return:
168
169 pj_caching_pool_destroy( &caching_pool );
170
171 PJ_LOG(3,("test", ""));
172
173 pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
174 PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
175 pj_thread_get_stack_max_usage(pj_thread_this()),
176 filename, line));
177 if (rc == 0)
178 PJ_LOG(3,("test", "Looks like everything is okay!.."));
179 else
180 PJ_LOG(3,("test", "Test completed with error(s)"));
181 return 0;
182}
183
184int test_main(void)
185{
186 PJ_USE_EXCEPTION;
187
188 PJ_TRY {
189 return test_inner();
190 }
Benny Prijono4f2be312005-11-21 17:01:06 +0000191 PJ_CATCH_ANY {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000192 int id = PJ_GET_EXCEPTION();
193 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
194 id, pj_exception_id_name(id)));
195 }
196 PJ_END;
197
198 return -1;
199}