Debian Codegraph @

Xpjproject/pjlib-util/src/pjlib-util-test/test.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
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 #include <pjlib-util.h>
22
23 #define THIS_FILE "test.c"
24
25 pj_pool_factory *mem;
26 struct test_app_t test_app = {
27 {0}, /* ut_app */
28 PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
29 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_INDENT,
30 /* param_log_decor */
31 };
32
33 void app_perror(const char *msg, pj_status_t rc)
34 {
35 char errbuf[256];
36
37 PJ_CHECK_STACK();
38
39 pj_strerror(rc, errbuf, sizeof(errbuf));
40 PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
41 }
42
43 static int test_inner(int argc, char *argv[])
44 {
45 pj_caching_pool caching_pool;
46 int rc = 0;
47 pj_bool_t pj_initialized = PJ_FALSE;
48 pj_bool_t ut_app_initialized = PJ_FALSE;
49
50 mem = &caching_pool.factory;
51
52 pj_log_set_level(3);
53 pj_log_set_decor(test_app.param_log_decor);
54
55 PJ_TEST_SUCCESS(pj_init(), NULL, { rc = 1; goto on_return; })
56 pj_initialized = PJ_TRUE;
57
58 PJ_TEST_SUCCESS(pjlib_util_init(), NULL, { rc = 2; goto on_return; });
59 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
60
61 if (ut_app_init1(&test_app.ut_app, mem) != PJ_SUCCESS) {
62 rc = 1;
63 goto on_return;
64 }
65 ut_app_initialized = PJ_TRUE;
66
67 if (test_app.ut_app.prm_config)
68 pj_dump_config();
69
70 #if INCLUDE_XML_TEST
71 UT_ADD_TEST(&test_app.ut_app, xml_test, 0);
72 #endif
73
74 #if INCLUDE_JSON_TEST
75 UT_ADD_TEST(&test_app.ut_app, json_test, 0);
76 #endif
77
78 #if INCLUDE_ENCRYPTION_TEST
79 UT_ADD_TEST(&test_app.ut_app, encryption_test, 0);
80 # if WITH_BENCHMARK
81 UT_ADD_TEST(&test_app.ut_app, encryption_benchmark, 0);
82 # endif
83 #endif
84
85 #if INCLUDE_STUN_TEST
86 UT_ADD_TEST(&test_app.ut_app, stun_test, 0);
87 #endif
88
89 #if INCLUDE_RESOLVER_TEST
90 UT_ADD_TEST(&test_app.ut_app, resolver_test, 0);
91 #endif
92
93 #if INCLUDE_HTTP_CLIENT_TEST
94 UT_ADD_TEST(&test_app.ut_app, http_client_test, 0);
95 #endif
96
97 #if INCLUDE_WEBSOCK_TEST
98 UT_ADD_TEST(&test_app.ut_app, websock_test, 0);
99 #endif
100
101 if (ut_run_tests(&test_app.ut_app, "pjlib-util tests", argc, argv)) {
102 rc = 1;
103 }
104
105 on_return:
106 if (ut_app_initialized) {
107 ut_app_destroy(&test_app.ut_app);
108 }
109
110 if (pj_initialized) {
111 pj_caching_pool_destroy(&caching_pool);
112 pj_shutdown();
113 }
114
115 return rc;
116 }
117
118 int test_main(int argc, char *argv[])
119 {
120 PJ_USE_EXCEPTION;
121
122 PJ_TRY {
123 return test_inner(argc, argv);
124 }
125 PJ_CATCH_ANY {
126 int id = PJ_GET_EXCEPTION();
127 PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
128 id, pj_exception_id_name(id)));
129 }
130 PJ_END;
131
132 return -1;
133 }
134