~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject/pjsip/src/test/tsx_basic_test.c

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tsx_basic_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
 
 
21
 
#include "test.h"
22
 
#include <pjsip.h>
23
 
#include <pjlib.h>
24
 
 
25
 
#define THIS_FILE   "tsx_basic_test.c"
26
 
 
27
 
static char TARGET_URI[PJSIP_MAX_URL_SIZE];
28
 
static char FROM_URI[PJSIP_MAX_URL_SIZE];
29
 
 
30
 
 
31
 
/* Test transaction layer. */
32
 
static int tsx_layer_test(void)
33
 
{
34
 
    pj_str_t target, from, tsx_key;
35
 
    pjsip_tx_data *tdata;
36
 
    pjsip_transaction *tsx, *found;
37
 
    pj_status_t status;
38
 
 
39
 
    PJ_LOG(3,(THIS_FILE, "  transaction layer test"));
40
 
 
41
 
    target = pj_str(TARGET_URI);
42
 
    from = pj_str(FROM_URI);
43
 
 
44
 
    status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
45
 
                                        &from, &target, NULL, NULL, -1, NULL,
46
 
                                        &tdata);
47
 
    if (status != PJ_SUCCESS) {
48
 
        app_perror("  error: unable to create request", status);
49
 
        return -110;
50
 
    }
51
 
 
52
 
    status = pjsip_tsx_create_uac(NULL, tdata, &tsx);
53
 
    if (status != PJ_SUCCESS) {
54
 
        app_perror("   error: unable to create transaction", status);
55
 
        return -120;
56
 
    }
57
 
 
58
 
    pj_strdup(tdata->pool, &tsx_key, &tsx->transaction_key);
59
 
 
60
 
    found = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_FALSE);
61
 
    if (found != tsx) {
62
 
        return -130;
63
 
    }
64
 
 
65
 
    pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
66
 
    flush_events(500);
67
 
 
68
 
    if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) {
69
 
        return -140;
70
 
    }
71
 
 
72
 
    return 0;
73
 
}
74
 
 
75
 
/* Double terminate test. */
76
 
static int double_terminate(void)
77
 
{
78
 
    pj_str_t target, from, tsx_key;
79
 
    pjsip_tx_data *tdata;
80
 
    pjsip_transaction *tsx;
81
 
    pj_status_t status;
82
 
 
83
 
    PJ_LOG(3,(THIS_FILE, "  double terminate test"));
84
 
 
85
 
    target = pj_str(TARGET_URI);
86
 
    from = pj_str(FROM_URI);
87
 
 
88
 
    /* Create request. */
89
 
    status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target,
90
 
                                        &from, &target, NULL, NULL, -1, NULL,
91
 
                                        &tdata);
92
 
    if (status != PJ_SUCCESS) {
93
 
        app_perror("  error: unable to create request", status);
94
 
        return -10;
95
 
    }
96
 
 
97
 
    /* Create transaction. */
98
 
    status = pjsip_tsx_create_uac(NULL, tdata, &tsx);
99
 
    if (status != PJ_SUCCESS) {
100
 
        app_perror("   error: unable to create transaction", status);
101
 
        return -20;
102
 
    }
103
 
 
104
 
    /* Save transaction key for later. */
105
 
    pj_strdup_with_null(tdata->pool, &tsx_key, &tsx->transaction_key);
106
 
 
107
 
    /* Add reference to transmit buffer (tsx_send_msg() will dec txdata). */
108
 
    pjsip_tx_data_add_ref(tdata);
109
 
 
110
 
    /* Send message to start timeout timer. */
111
 
    status = pjsip_tsx_send_msg(tsx, NULL);
112
 
 
113
 
    /* Terminate transaction. */
114
 
    status = pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
115
 
    if (status != PJ_SUCCESS) {
116
 
        app_perror("   error: unable to terminate transaction", status);
117
 
        return -30;
118
 
    }
119
 
 
120
 
    tsx = pjsip_tsx_layer_find_tsx(&tsx_key, PJ_TRUE);
121
 
    if (tsx) {
122
 
        /* Terminate transaction again. */
123
 
        pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED);
124
 
        if (status != PJ_SUCCESS) {
125
 
            app_perror("   error: unable to terminate transaction", status);
126
 
            return -40;
127
 
        }
128
 
        pj_mutex_unlock(tsx->mutex);
129
 
    }
130
 
 
131
 
    flush_events(500);
132
 
    if (pjsip_tx_data_dec_ref(tdata) != PJSIP_EBUFDESTROYED) {
133
 
        return -50;
134
 
    }
135
 
 
136
 
    return PJ_SUCCESS;
137
 
}
138
 
 
139
 
int tsx_basic_test(struct tsx_test_param *param)
140
 
{
141
 
    int status;
142
 
 
143
 
    pj_ansi_sprintf(TARGET_URI, "sip:bob@127.0.0.1:%d;transport=%s", 
144
 
                    param->port, param->tp_type);
145
 
    pj_ansi_sprintf(FROM_URI, "sip:alice@127.0.0.1:%d;transport=%s", 
146
 
                    param->port, param->tp_type);
147
 
 
148
 
    status = tsx_layer_test();
149
 
    if (status != 0)
150
 
        return status;
151
 
 
152
 
    status = double_terminate();
153
 
    if (status != 0)
154
 
        return status;
155
 
 
156
 
    return 0;
157
 
}