blob: 6cc829d59e92752d05aeaa87e86c9ee2d1e60a48 [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
52 pj_log_set_level(3);
53 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
54 PJ_LOG_HAS_MICRO_SEC);
Benny Prijonofb9d9872007-03-21 22:05:58 +000055
56 rc = pj_init();
57 if (rc != 0) {
58 app_perror("pj_init() error!!", rc);
59 return rc;
60 }
61
62 pj_dump_config();
63 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
64
65#if INCLUDE_ICE_TEST
66 DO_TEST(ice_test());
67#endif
68
69on_return:
70 return rc;
71}
72
73int test_main(void)
74{
75 PJ_USE_EXCEPTION;
76
77 PJ_TRY {
78 return test_inner();
79 }
80 PJ_CATCH_ANY {
81 int id = PJ_GET_EXCEPTION();
82 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
83 id, pj_exception_id_name(id)));
84 }
85 PJ_END;
86
87 return -1;
88}
89