blob: d634cc8007cef44900d1256ecd5f9e807c22deb2 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C) 2003-2006 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
20
21#include "test.h"
22#include <pjlib.h>
23#include <pjsip_core.h>
24
Benny Prijono85598d92006-01-07 18:44:25 +000025#define THIS_FILE "test.c"
26
Benny Prijono5dcb38d2005-11-21 01:55:47 +000027#define DO_TEST(test) do { \
Benny Prijono85598d92006-01-07 18:44:25 +000028 PJ_LOG(3, (THIS_FILE, "Running %s...", #test)); \
Benny Prijono5dcb38d2005-11-21 01:55:47 +000029 rc = test; \
Benny Prijono85598d92006-01-07 18:44:25 +000030 PJ_LOG(3, (THIS_FILE, \
Benny Prijono5dcb38d2005-11-21 01:55:47 +000031 "%s(%d)", \
32 (rc ? "..ERROR" : "..success"), rc)); \
33 if (rc!=0) goto on_return; \
34 } while (0)
35
36
37
38pjsip_endpoint *endpt;
Benny Prijono9c1d9f52006-01-07 23:01:56 +000039int log_level = 5;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000040
41void app_perror(const char *msg, pj_status_t rc)
42{
43 char errbuf[256];
44
45 PJ_CHECK_STACK();
46
47 pjsip_strerror(rc, errbuf, sizeof(errbuf));
Benny Prijono85598d92006-01-07 18:44:25 +000048 PJ_LOG(3,(THIS_FILE, "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
Benny Prijono5dcb38d2005-11-21 01:55:47 +000049
50}
51
Benny Prijono85598d92006-01-07 18:44:25 +000052void flush_events(unsigned duration)
53{
54 pj_time_val stop_time;
55
56 pj_gettimeofday(&stop_time);
57 stop_time.msec += duration;
58 pj_time_val_normalize(&stop_time);
59
60 /* Process all events for the specified duration. */
61 for (;;) {
62 pj_time_val timeout = {0, 1}, now;
63
64 pjsip_endpt_handle_events(endpt, &timeout);
65
66 pj_gettimeofday(&now);
67 if (PJ_TIME_VAL_GTE(now, stop_time))
68 break;
69 }
70}
71
Benny Prijono5dcb38d2005-11-21 01:55:47 +000072pj_status_t register_static_modules(pj_size_t *count, pjsip_module **modules)
73{
74 *count = 0;
75 return PJ_SUCCESS;
76}
77
78int test_main(void)
79{
80 pj_status_t rc;
81 pj_caching_pool caching_pool;
82 const char *filename;
83 int line;
84
Benny Prijono9c1d9f52006-01-07 23:01:56 +000085 pj_log_set_level(log_level);
Benny Prijono85598d92006-01-07 18:44:25 +000086 /*
Benny Prijono5dcb38d2005-11-21 01:55:47 +000087 pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
88 PJ_LOG_HAS_MICRO_SEC);
Benny Prijono85598d92006-01-07 18:44:25 +000089 */
Benny Prijono5dcb38d2005-11-21 01:55:47 +000090
91 if ((rc=pj_init()) != PJ_SUCCESS) {
92 app_perror("pj_init", rc);
93 return rc;
94 }
95
96 pj_dump_config();
97
98 pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
99
100 rc = pjsip_endpt_create(&caching_pool.factory, "endpt", &endpt);
101 if (rc != PJ_SUCCESS) {
102 app_perror("pjsip_endpt_create", rc);
103 pj_caching_pool_destroy(&caching_pool);
104 return rc;
105 }
106
Benny Prijono85598d92006-01-07 18:44:25 +0000107 PJ_LOG(3,(THIS_FILE,""));
108
109 /* Init logger module. */
110 init_msg_logger();
111 msg_logger_set_enabled(1);
112
113 /* Start transaction layer module. */
114 rc = pjsip_tsx_layer_init(endpt);
115 if (rc != PJ_SUCCESS) {
116 app_perror(" Error initializing transaction module", rc);
117 goto on_return;
118 }
119
120 /* Create loop transport. */
121 rc = pjsip_loop_start(endpt, NULL);
122 if (rc != PJ_SUCCESS) {
123 app_perror(" error: unable to create datagram loop transport",
124 rc);
125 goto on_return;
126 }
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000127
Benny Prijonofa73e3e2006-01-05 23:35:46 +0000128 //DO_TEST(uri_test());
129 //DO_TEST(msg_test());
130 //DO_TEST(txdata_test());
131 //DO_TEST(transport_udp_test());
Benny Prijono85598d92006-01-07 18:44:25 +0000132 //DO_TEST(transport_loop_test());
133 //DO_TEST(tsx_basic_test());
Benny Prijonodbe337a2006-01-08 23:57:52 +0000134 //DO_TEST(tsx_uac_test());
135 DO_TEST(tsx_uas_test());
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000136
137on_return:
138
139 pjsip_endpt_destroy(endpt);
140 pj_caching_pool_destroy(&caching_pool);
141
Benny Prijono85598d92006-01-07 18:44:25 +0000142 PJ_LOG(3,(THIS_FILE, ""));
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000143
144 pj_thread_get_stack_info(pj_thread_this(), &filename, &line);
Benny Prijono85598d92006-01-07 18:44:25 +0000145 PJ_LOG(3,(THIS_FILE, "Stack max usage: %u, deepest: %s:%u",
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000146 pj_thread_get_stack_max_usage(pj_thread_this()),
147 filename, line));
148 if (rc == 0)
Benny Prijono85598d92006-01-07 18:44:25 +0000149 PJ_LOG(3,(THIS_FILE, "Looks like everything is okay!.."));
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000150 else
Benny Prijono85598d92006-01-07 18:44:25 +0000151 PJ_LOG(3,(THIS_FILE, "Test completed with error(s)"));
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000152
153 return 0;
154}
155