blob: 223d57d812c623fda6c4e2ac07ff06542306cbbe [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id$ */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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#include <pjlib-util.h>
23
24void app_perror(const char *msg, pj_status_t rc)
25{
26 char errbuf[256];
27
28 PJ_CHECK_STACK();
29
30 pj_strerror(rc, errbuf, sizeof(errbuf));
31 PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
32}
33
34#define DO_TEST(test) do { \
35 PJ_LOG(3, ("test", "Running %s...", #test)); \
36 rc = test; \
37 PJ_LOG(3, ("test", \
38 "%s(%d)", \
39 (char*)(rc ? "..ERROR" : "..success"), rc)); \
40 if (rc!=0) goto on_return; \
41 } while (0)
42
43
44pj_pool_factory *mem;
45
46int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
47 PJ_LOG_HAS_MICRO_SEC;
48
49static int test_inner(void)
50{
51 pj_caching_pool caching_pool;
52 int rc = 0;
53
54 mem = &caching_pool.factory;
55
56 pj_log_set_level(3);
57 pj_log_set_decor(param_log_decor);
58
59 rc = pj_init();
60 if (rc != 0) {
61 app_perror("pj_init() error!!", rc);
62 return rc;
63 }
64
65 rc = pjlib_util_init();
66 pj_assert(rc == 0);
67
68 pj_dump_config();
69 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
70
71#if INCLUDE_XML_TEST
72 DO_TEST(xml_test());
73#endif
74
Alexandre Lision0e143012014-01-22 11:02:46 -050075#if INCLUDE_JSON_TEST
76 DO_TEST(json_test());
77#endif
78
Tristan Matthews0a329cc2013-07-17 13:20:14 -040079#if INCLUDE_ENCRYPTION_TEST
80 DO_TEST(encryption_test());
81 DO_TEST(encryption_benchmark());
82#endif
83
84#if INCLUDE_STUN_TEST
85 DO_TEST(stun_test());
86#endif
87
88#if INCLUDE_RESOLVER_TEST
89 DO_TEST(resolver_test());
90#endif
91
92#if INCLUDE_HTTP_CLIENT_TEST
93 DO_TEST(http_client_test());
94#endif
95
96on_return:
97 return rc;
98}
99
100int test_main(void)
101{
102 PJ_USE_EXCEPTION;
103
104 PJ_TRY {
105 return test_inner();
106 }
107 PJ_CATCH_ANY {
108 int id = PJ_GET_EXCEPTION();
109 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
110 id, pj_exception_id_name(id)));
111 }
112 PJ_END;
113
114 return -1;
115}
116