~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjnath/src/pjnath-test/test.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: test.c 3553 2011-05-05 06:14:19Z nanang $ */
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
 
 
23
 
void app_perror(const char *msg, pj_status_t rc)
24
 
{
25
 
    char errbuf[256];
26
 
 
27
 
    PJ_CHECK_STACK();
28
 
 
29
 
    pj_strerror(rc, errbuf, sizeof(errbuf));
30
 
    PJ_LOG(1,("test", "%s: [pj_status_t=%d] %s", msg, rc, errbuf));
31
 
}
32
 
 
33
 
pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg)
34
 
{
35
 
    pj_ioqueue_t *ioqueue;
36
 
    pj_timer_heap_t *timer_heap;
37
 
    pj_status_t status;
38
 
 
39
 
    status = pj_ioqueue_create(pool, 64, &ioqueue);
40
 
    if (status != PJ_SUCCESS) {
41
 
        app_perror("   pj_ioqueue_create()", status);
42
 
        return status;
43
 
    }
44
 
 
45
 
    status = pj_timer_heap_create(pool, 256, &timer_heap);
46
 
    if (status != PJ_SUCCESS) {
47
 
        app_perror("   pj_timer_heap_create()", status);
48
 
        pj_ioqueue_destroy(ioqueue);
49
 
        return status;
50
 
    }
51
 
 
52
 
    pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap);
53
 
 
54
 
    return PJ_SUCCESS;
55
 
}
56
 
 
57
 
void destroy_stun_config(pj_stun_config *stun_cfg)
58
 
{
59
 
    if (stun_cfg->timer_heap) {
60
 
        pj_timer_heap_destroy(stun_cfg->timer_heap);
61
 
        stun_cfg->timer_heap = NULL;
62
 
    }
63
 
    if (stun_cfg->ioqueue) {
64
 
        pj_ioqueue_destroy(stun_cfg->ioqueue);
65
 
        stun_cfg->ioqueue = NULL;
66
 
    }
67
 
}
68
 
 
69
 
void poll_events(pj_stun_config *stun_cfg, unsigned msec,
70
 
                 pj_bool_t first_event_only)
71
 
{
72
 
    pj_time_val stop_time;
73
 
    int count = 0;
74
 
 
75
 
    pj_gettimeofday(&stop_time);
76
 
    stop_time.msec += msec;
77
 
    pj_time_val_normalize(&stop_time);
78
 
 
79
 
    /* Process all events for the specified duration. */
80
 
    for (;;) {
81
 
        pj_time_val timeout = {0, 1}, now;
82
 
        int c;
83
 
 
84
 
        c = pj_timer_heap_poll( stun_cfg->timer_heap, NULL );
85
 
        if (c > 0)
86
 
            count += c;
87
 
 
88
 
        //timeout.sec = timeout.msec = 0;
89
 
        c = pj_ioqueue_poll( stun_cfg->ioqueue, &timeout);
90
 
        if (c > 0)
91
 
            count += c;
92
 
 
93
 
        pj_gettimeofday(&now);
94
 
        if (PJ_TIME_VAL_GTE(now, stop_time))
95
 
            break;
96
 
 
97
 
        if (first_event_only && count >= 0)
98
 
            break;
99
 
    }
100
 
}
101
 
 
102
 
void capture_pjlib_state(pj_stun_config *cfg, struct pjlib_state *st)
103
 
{
104
 
    pj_caching_pool *cp;
105
 
 
106
 
    st->timer_cnt = pj_timer_heap_count(cfg->timer_heap);
107
 
 
108
 
    cp = (pj_caching_pool*)mem;
109
 
    st->pool_used_cnt = cp->used_count;
110
 
}
111
 
 
112
 
int check_pjlib_state(pj_stun_config *cfg,
113
 
                      const struct pjlib_state *initial_st)
114
 
{
115
 
    struct pjlib_state current_state;
116
 
    int rc = 0;
117
 
 
118
 
    capture_pjlib_state(cfg, &current_state);
119
 
 
120
 
    if (current_state.timer_cnt > initial_st->timer_cnt) {
121
 
        PJ_LOG(3,("", "    error: possibly leaking timer"));
122
 
        rc |= ERR_TIMER_LEAK;
123
 
    }
124
 
 
125
 
    if (current_state.pool_used_cnt > initial_st->pool_used_cnt) {
126
 
        PJ_LOG(3,("", "    error: possibly leaking memory"));
127
 
        PJ_LOG(3,("", "    dumping memory pool:"));
128
 
        pj_pool_factory_dump(mem, PJ_TRUE);
129
 
        rc |= ERR_MEMORY_LEAK;
130
 
    }
131
 
 
132
 
    return rc;
133
 
}
134
 
 
135
 
 
136
 
#define DO_TEST(test)   do { \
137
 
                            PJ_LOG(3, ("test", "Running %s...", #test));  \
138
 
                            rc = test; \
139
 
                            PJ_LOG(3, ("test",  \
140
 
                                       "%s(%d)",  \
141
 
                                       (char*)(rc ? "..ERROR" : "..success"), rc)); \
142
 
                            if (rc!=0) goto on_return; \
143
 
                        } while (0)
144
 
 
145
 
 
146
 
pj_pool_factory *mem;
147
 
 
148
 
int param_log_decor = PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
149
 
                      PJ_LOG_HAS_MICRO_SEC;
150
 
 
151
 
static int test_inner(void)
152
 
{
153
 
    pj_caching_pool caching_pool;
154
 
    int rc = 0;
155
 
 
156
 
    mem = &caching_pool.factory;
157
 
 
158
 
#if 1
159
 
    pj_log_set_level(3);
160
 
    pj_log_set_decor(param_log_decor);
161
 
#endif
162
 
 
163
 
    rc = pj_init();
164
 
    if (rc != 0) {
165
 
        app_perror("pj_init() error!!", rc);
166
 
        return rc;
167
 
    }
168
 
 
169
 
    pj_dump_config();
170
 
    pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 );
171
 
 
172
 
    pjlib_util_init();
173
 
    pjnath_init();
174
 
 
175
 
#if INCLUDE_STUN_TEST
176
 
    DO_TEST(stun_test());
177
 
    DO_TEST(sess_auth_test());
178
 
#endif
179
 
 
180
 
#if INCLUDE_ICE_TEST
181
 
    DO_TEST(ice_test());
182
 
#endif
183
 
 
184
 
#if INCLUDE_STUN_SOCK_TEST
185
 
    DO_TEST(stun_sock_test());
186
 
#endif
187
 
 
188
 
#if INCLUDE_TURN_SOCK_TEST
189
 
    DO_TEST(turn_sock_test());
190
 
#endif
191
 
 
192
 
on_return:
193
 
    return rc;
194
 
}
195
 
 
196
 
int test_main(void)
197
 
{
198
 
    PJ_USE_EXCEPTION;
199
 
 
200
 
    PJ_TRY {
201
 
        return test_inner();
202
 
    }
203
 
    PJ_CATCH_ANY {
204
 
        int id = PJ_GET_EXCEPTION();
205
 
        PJ_LOG(3,("test", "FATAL: unhandled exception id %d (%s)",
206
 
                  id, pj_exception_id_name(id)));
207
 
    }
208
 
    PJ_END;
209
 
 
210
 
    return -1;
211
 
}