blob: 9d7c1ba438d559f59439fed891b20ca4b86b50b6 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include "test.h"
21#include <pjlib.h>
22#ifdef _MSC_VER
23# pragma warning(disable:4127)
24#endif
25
26#define DO_TEST(test) do { \
27 PJ_LOG(3, ("test", "Running %s...", #test)); \
28 rc = test; \
29 PJ_LOG(3, ("test", \
30 "%s(%d)", \
31 (rc ? "..ERROR" : "..success"), rc)); \
32 if (rc!=0) goto on_return; \
33 } while (0)
34
35
36pj_pool_factory *mem;
37
38int param_echo_sock_type;
39const char *param_echo_server = ECHO_SERVER_ADDRESS;
40int param_echo_port = ECHO_SERVER_START_PORT;
Benny Prijono37e8d332006-01-20 21:03:36 +000041int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
42 PJ_LOG_HAS_MICRO_SEC;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000043
Benny Prijono42c5b9e2006-05-10 19:24:40 +000044int null_func()
45{
46 return 0;
47}
48
Benny Prijono5dcb38d2005-11-21 01:55:47 +000049int test_inner(void)
50{
51 pj_caching_pool caching_pool;
52 const char *filename;
53 int line;
54 int rc = 0;
55
56 mem = &caching_pool.factory;
57
58 pj_log_set_level(3);
Benny Prijono37e8d332006-01-20 21:03:36 +000059 pj_log_set_decor(param_log_decor);
Benny Prijono5dcb38d2005-11-21 01:55:47 +000060
61 rc = pj_init();
62 if (rc != 0) {
63 app_perror("pj_init() error!!", rc);
64 return rc;
65 }
66
Benny Prijono42c5b9e2006-05-10 19:24:40 +000067 //pj_dump_config();
Benny Prijono8ab968f2007-07-20 08:08:30 +000068 pj_caching_pool_init( &caching_pool, NULL, 0 );
Benny Prijono5dcb38d2005-11-21 01:55:47 +000069
70#if INCLUDE_ERRNO_TEST
71 DO_TEST( errno_test() );
72#endif
73
Benny Prijono5dcb38d2005-11-21 01:55:47 +000074#if INCLUDE_EXCEPTION_TEST
75 DO_TEST( exception_test() );
76#endif
77
78#if INCLUDE_RAND_TEST
79 DO_TEST( rand_test() );
80#endif
81
82#if INCLUDE_LIST_TEST
83 DO_TEST( list_test() );
84#endif
85
86#if INCLUDE_POOL_TEST
87 DO_TEST( pool_test() );
88#endif
89
90#if INCLUDE_POOL_PERF_TEST
91 DO_TEST( pool_perf_test() );
92#endif
93
94#if INCLUDE_STRING_TEST
95 DO_TEST( string_test() );
96#endif
97
98#if INCLUDE_FIFOBUF_TEST
99 DO_TEST( fifobuf_test() );
100#endif
101
102#if INCLUDE_RBTREE_TEST
103 DO_TEST( rbtree_test() );
104#endif
105
Benny Prijonof1370372008-07-14 16:58:11 +0000106#if INCLUDE_HASH_TEST
107 DO_TEST( hash_test() );
108#endif
109
Benny Prijono42c5b9e2006-05-10 19:24:40 +0000110#if INCLUDE_TIMESTAMP_TEST
111 DO_TEST( timestamp_test() );
112#endif
113
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000114#if INCLUDE_ATOMIC_TEST
115 DO_TEST( atomic_test() );
116#endif
117
118#if INCLUDE_MUTEX_TEST
119 DO_TEST( mutex_test() );
120#endif
121
122#if INCLUDE_TIMER_TEST
123 DO_TEST( timer_test() );
124#endif
125
126#if INCLUDE_SLEEP_TEST
127 DO_TEST( sleep_test() );
128#endif
129
130#if INCLUDE_THREAD_TEST
131 DO_TEST( thread_test() );
132#endif
133
134#if INCLUDE_SOCK_TEST
135 DO_TEST( sock_test() );
136#endif
137
138#if INCLUDE_SOCK_PERF_TEST
139 DO_TEST( sock_perf_test() );
140#endif
141
142#if INCLUDE_SELECT_TEST
143 DO_TEST( select_test() );
144#endif
145
146#if INCLUDE_UDP_IOQUEUE_TEST
147 DO_TEST( udp_ioqueue_test() );
148#endif
149
150#if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST
151 DO_TEST( tcp_ioqueue_test() );
152#endif
153
154#if INCLUDE_IOQUEUE_PERF_TEST
155 DO_TEST( ioqueue_perf_test() );
156#endif
157
Benny Prijono5accbd02006-03-30 16:32:18 +0000158#if INCLUDE_IOQUEUE_UNREG_TEST
159 DO_TEST( udp_ioqueue_unreg_test() );
160#endif
161
Benny Prijono4bac2c12008-05-11 18:12:16 +0000162#if INCLUDE_ACTIVESOCK_TEST
163 DO_TEST( activesock_test() );
164#endif
165
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000166#if INCLUDE_FILE_TEST
167 DO_TEST( file_test() );
168#endif
169
Nanang Izzuddinea6d3c42009-10-26 15:47:52 +0000170#if INCLUDE_SSLSOCK_TEST
171 DO_TEST( ssl_sock_test() );
172#endif
173
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000174#if INCLUDE_ECHO_SERVER
175 //echo_server();
176 //echo_srv_sync();
177 udp_echo_srv_ioqueue();
178
179#elif INCLUDE_ECHO_CLIENT
180 if (param_echo_sock_type == 0)
Benny Prijono8ab968f2007-07-20 08:08:30 +0000181 param_echo_sock_type = pj_SOCK_DGRAM();
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000182
183 echo_client( param_echo_sock_type,
184 param_echo_server,
185 param_echo_port);
186#endif
187
188 goto on_return;
189
190on_return:
191
192 pj_caching_pool_destroy( &caching_pool );
193
194 PJ_LOG(3,("test", ""));
195
196 pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
197 PJ_LOG(3,("test", "Stack max usage: %u, deepest: %s:%u",
198 pj_thread_get_stack_max_usage(pj_thread_this()),
199 filename, line));
200 if (rc == 0)
201 PJ_LOG(3,("test", "Looks like everything is okay!.."));
202 else
203 PJ_LOG(3,("test", "Test completed with error(s)"));
Benny Prijonof70f6392009-06-17 12:36:36 +0000204
205 pj_shutdown();
206
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000207 return 0;
208}
209
Benny Prijono8ab968f2007-07-20 08:08:30 +0000210#include <pj/sock.h>
211
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000212int test_main(void)
213{
Benny Prijono8ab968f2007-07-20 08:08:30 +0000214 int i;
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000215 PJ_USE_EXCEPTION;
216
Benny Prijono8ab968f2007-07-20 08:08:30 +0000217 i = pj_AF_INET();
218
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000219 PJ_TRY {
220 return test_inner();
221 }
Benny Prijono4f2be312005-11-21 17:01:06 +0000222 PJ_CATCH_ANY {
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000223 int id = PJ_GET_EXCEPTION();
224 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
225 id, pj_exception_id_name(id)));
226 }
227 PJ_END;
228
229 return -1;
230}