blob: 01eeb3c698c557a7b771f5d5bae6b7bbbc53b267 [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;
Benny Prijono37e8d332006-01-20 21:03:36 +000040int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
41 PJ_LOG_HAS_MICRO_SEC;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000042
Benny Prijono42c5b9e2006-05-10 19:24:40 +000043int null_func()
44{
45 return 0;
46}
47
Benny Prijono5dcb38d2005-11-21 01:55:47 +000048int test_inner(void)
49{
50 pj_caching_pool caching_pool;
51 const char *filename;
52 int line;
53 int rc = 0;
54
55 mem = &caching_pool.factory;
56
57 pj_log_set_level(3);
Benny Prijono37e8d332006-01-20 21:03:36 +000058 pj_log_set_decor(param_log_decor);
Benny Prijono5dcb38d2005-11-21 01:55:47 +000059
60 rc = pj_init();
61 if (rc != 0) {
62 app_perror("pj_init() error!!", rc);
63 return rc;
64 }
65
Benny Prijono42c5b9e2006-05-10 19:24:40 +000066 //pj_dump_config();
Benny Prijono5dcb38d2005-11-21 01:55:47 +000067 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
68
69#if INCLUDE_ERRNO_TEST
70 DO_TEST( errno_test() );
71#endif
72
Benny Prijono5dcb38d2005-11-21 01:55:47 +000073#if INCLUDE_EXCEPTION_TEST
74 DO_TEST( exception_test() );
75#endif
76
77#if INCLUDE_RAND_TEST
78 DO_TEST( rand_test() );
79#endif
80
81#if INCLUDE_LIST_TEST
82 DO_TEST( list_test() );
83#endif
84
85#if INCLUDE_POOL_TEST
86 DO_TEST( pool_test() );
87#endif
88
89#if INCLUDE_POOL_PERF_TEST
90 DO_TEST( pool_perf_test() );
91#endif
92
93#if INCLUDE_STRING_TEST
94 DO_TEST( string_test() );
95#endif
96
97#if INCLUDE_FIFOBUF_TEST
98 DO_TEST( fifobuf_test() );
99#endif
100
101#if INCLUDE_RBTREE_TEST
102 DO_TEST( rbtree_test() );
103#endif
104
Benny Prijono42c5b9e2006-05-10 19:24:40 +0000105#if INCLUDE_TIMESTAMP_TEST
106 DO_TEST( timestamp_test() );
107#endif
108
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000109#if INCLUDE_ATOMIC_TEST
110 DO_TEST( atomic_test() );
111#endif
112
113#if INCLUDE_MUTEX_TEST
114 DO_TEST( mutex_test() );
115#endif
116
117#if INCLUDE_TIMER_TEST
118 DO_TEST( timer_test() );
119#endif
120
121#if INCLUDE_SLEEP_TEST
122 DO_TEST( sleep_test() );
123#endif
124
125#if INCLUDE_THREAD_TEST
126 DO_TEST( thread_test() );
127#endif
128
129#if INCLUDE_SOCK_TEST
130 DO_TEST( sock_test() );
131#endif
132
133#if INCLUDE_SOCK_PERF_TEST
134 DO_TEST( sock_perf_test() );
135#endif
136
137#if INCLUDE_SELECT_TEST
138 DO_TEST( select_test() );
139#endif
140
141#if INCLUDE_UDP_IOQUEUE_TEST
142 DO_TEST( udp_ioqueue_test() );
143#endif
144
145#if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST
146 DO_TEST( tcp_ioqueue_test() );
147#endif
148
149#if INCLUDE_IOQUEUE_PERF_TEST
150 DO_TEST( ioqueue_perf_test() );
151#endif
152
Benny Prijono5accbd02006-03-30 16:32:18 +0000153#if INCLUDE_IOQUEUE_UNREG_TEST
154 DO_TEST( udp_ioqueue_unreg_test() );
155#endif
156
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000157#if INCLUDE_FILE_TEST
158 DO_TEST( file_test() );
159#endif
160
161#if INCLUDE_ECHO_SERVER
162 //echo_server();
163 //echo_srv_sync();
164 udp_echo_srv_ioqueue();
165
166#elif INCLUDE_ECHO_CLIENT
167 if (param_echo_sock_type == 0)
168 param_echo_sock_type = PJ_SOCK_DGRAM;
169
170 echo_client( param_echo_sock_type,
171 param_echo_server,
172 param_echo_port);
173#endif
174
175 goto on_return;
176
177on_return:
178
179 pj_caching_pool_destroy( &caching_pool );
180
181 PJ_LOG(3,("test", ""));
182
183 pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
184 PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
185 pj_thread_get_stack_max_usage(pj_thread_this()),
186 filename, line));
187 if (rc == 0)
188 PJ_LOG(3,("test", "Looks like everything is okay!.."));
189 else
190 PJ_LOG(3,("test", "Test completed with error(s)"));
191 return 0;
192}
193
194int test_main(void)
195{
196 PJ_USE_EXCEPTION;
197
198 PJ_TRY {
199 return test_inner();
200 }
Benny Prijono4f2be312005-11-21 17:01:06 +0000201 PJ_CATCH_ANY {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000202 int id = PJ_GET_EXCEPTION();
203 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
204 id, pj_exception_id_name(id)));
205 }
206 PJ_END;
207
208 return -1;
209}