blob: fc1c124cd5cd4af16e8406b22ba8c6e0a320ff9e [file] [log] [blame]
Benny Prijonofb9d9872007-03-21 22:05:58 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2007 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
22void app_perror(const char *msg, pj_status_t rc)
23{
24 char errbuf[256];
25
26 PJ_CHECK_STACK();
27
28 pj_strerror(rc, errbuf, sizeof(errbuf));
29 PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
30}
31
32#define DO_TEST(test) do { \
33 PJ_LOG(3, ("test", "Running %s...", #test)); \
34 rc = test; \
35 PJ_LOG(3, ("test", \
36 "%s(%d)", \
37 (char*)(rc ? "..ERROR" : "..success"), rc)); \
38 if (rc!=0) goto on_return; \
39 } while (0)
40
41
42pj_pool_factory *mem;
43
44
45static int test_inner(void)
46{
47 pj_caching_pool caching_pool;
48 int rc = 0;
49
50 mem = &caching_pool.factory;
51
Benny Prijono0cb7bf12007-04-02 18:00:45 +000052#if 1
Benny Prijonofb9d9872007-03-21 22:05:58 +000053 pj_log_set_level(3);
54 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
55 PJ_LOG_HAS_MICRO_SEC);
Benny Prijonofd70c9b2007-03-27 11:00:38 +000056#endif
Benny Prijonofb9d9872007-03-21 22:05:58 +000057
58 rc = pj_init();
59 if (rc != 0) {
60 app_perror("pj_init() error!!", rc);
61 return rc;
62 }
63
64 pj_dump_config();
65 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
66
Benny Prijono1c064e62007-05-22 21:11:10 +000067 pjnath_init();
68
Benny Prijonoe2d0acb2007-09-18 19:33:33 +000069#if INCLUDE_STUN_TEST
70 DO_TEST(stun_test());
71#endif
72
Benny Prijonofb9d9872007-03-21 22:05:58 +000073#if INCLUDE_ICE_TEST
74 DO_TEST(ice_test());
75#endif
76
77on_return:
78 return rc;
79}
80
81int test_main(void)
82{
83 PJ_USE_EXCEPTION;
84
85 PJ_TRY {
86 return test_inner();
87 }
88 PJ_CATCH_ANY {
89 int id = PJ_GET_EXCEPTION();
90 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
91 id, pj_exception_id_name(id)));
92 }
93 PJ_END;
94
95 return -1;
96}
97