Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | 844653c | 2008-12-23 17:27:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 5 | * |
| 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 | |
| 36 | pj_pool_factory *mem; |
| 37 | |
| 38 | int param_echo_sock_type; |
| 39 | const char *param_echo_server = ECHO_SERVER_ADDRESS; |
| 40 | int param_echo_port = ECHO_SERVER_START_PORT; |
Benny Prijono | 37e8d33 | 2006-01-20 21:03:36 +0000 | [diff] [blame] | 41 | int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | |
| 42 | PJ_LOG_HAS_MICRO_SEC; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 43 | |
Benny Prijono | 42c5b9e | 2006-05-10 19:24:40 +0000 | [diff] [blame] | 44 | int null_func() |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 49 | int 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 Prijono | 37e8d33 | 2006-01-20 21:03:36 +0000 | [diff] [blame] | 59 | pj_log_set_decor(param_log_decor); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 60 | |
| 61 | rc = pj_init(); |
| 62 | if (rc != 0) { |
| 63 | app_perror("pj_init() error!!", rc); |
| 64 | return rc; |
| 65 | } |
| 66 | |
Benny Prijono | 42c5b9e | 2006-05-10 19:24:40 +0000 | [diff] [blame] | 67 | //pj_dump_config(); |
Benny Prijono | 8ab968f | 2007-07-20 08:08:30 +0000 | [diff] [blame] | 68 | pj_caching_pool_init( &caching_pool, NULL, 0 ); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 69 | |
| 70 | #if INCLUDE_ERRNO_TEST |
| 71 | DO_TEST( errno_test() ); |
| 72 | #endif |
| 73 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 74 | #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 Prijono | f137037 | 2008-07-14 16:58:11 +0000 | [diff] [blame] | 106 | #if INCLUDE_HASH_TEST |
| 107 | DO_TEST( hash_test() ); |
| 108 | #endif |
| 109 | |
Benny Prijono | 42c5b9e | 2006-05-10 19:24:40 +0000 | [diff] [blame] | 110 | #if INCLUDE_TIMESTAMP_TEST |
| 111 | DO_TEST( timestamp_test() ); |
| 112 | #endif |
| 113 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 114 | #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 Prijono | 5accbd0 | 2006-03-30 16:32:18 +0000 | [diff] [blame] | 158 | #if INCLUDE_IOQUEUE_UNREG_TEST |
| 159 | DO_TEST( udp_ioqueue_unreg_test() ); |
| 160 | #endif |
| 161 | |
Benny Prijono | 4bac2c1 | 2008-05-11 18:12:16 +0000 | [diff] [blame] | 162 | #if INCLUDE_ACTIVESOCK_TEST |
| 163 | DO_TEST( activesock_test() ); |
| 164 | #endif |
| 165 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 166 | #if INCLUDE_FILE_TEST |
| 167 | DO_TEST( file_test() ); |
| 168 | #endif |
| 169 | |
Nanang Izzuddin | ea6d3c4 | 2009-10-26 15:47:52 +0000 | [diff] [blame^] | 170 | #if INCLUDE_SSLSOCK_TEST |
| 171 | DO_TEST( ssl_sock_test() ); |
| 172 | #endif |
| 173 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 174 | #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 Prijono | 8ab968f | 2007-07-20 08:08:30 +0000 | [diff] [blame] | 181 | param_echo_sock_type = pj_SOCK_DGRAM(); |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 182 | |
| 183 | echo_client( param_echo_sock_type, |
| 184 | param_echo_server, |
| 185 | param_echo_port); |
| 186 | #endif |
| 187 | |
| 188 | goto on_return; |
| 189 | |
| 190 | on_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 Prijono | f70f639 | 2009-06-17 12:36:36 +0000 | [diff] [blame] | 204 | |
| 205 | pj_shutdown(); |
| 206 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
Benny Prijono | 8ab968f | 2007-07-20 08:08:30 +0000 | [diff] [blame] | 210 | #include <pj/sock.h> |
| 211 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 212 | int test_main(void) |
| 213 | { |
Benny Prijono | 8ab968f | 2007-07-20 08:08:30 +0000 | [diff] [blame] | 214 | int i; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 215 | PJ_USE_EXCEPTION; |
| 216 | |
Benny Prijono | 8ab968f | 2007-07-20 08:08:30 +0000 | [diff] [blame] | 217 | i = pj_AF_INET(); |
| 218 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 219 | PJ_TRY { |
| 220 | return test_inner(); |
| 221 | } |
Benny Prijono | 4f2be31 | 2005-11-21 17:01:06 +0000 | [diff] [blame] | 222 | PJ_CATCH_ANY { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 223 | 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 | } |