-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_sip_invite.rs
164 lines (153 loc) · 5.93 KB
/
test_sip_invite.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use sofia_sip::su;
use sofia_sip::Handle;
use sofia_sip::Nua;
use sofia_sip::NuaEvent;
use sofia_sip::Root;
use sofia_sip::Sip;
use sofia_sip::Tag;
use sofia_sip::TagBuilder;
use adorn::adorn;
use serial_test::serial;
fn wrap(f: fn()) {
/* manual deinit (because tests do not run atexit) */
if let Err(e) = std::panic::catch_unwind(|| {
su::init().unwrap();
su::init_default_root().unwrap();
f();
su::deinit_default_root();
su::deinit();
}) {
su::deinit_default_root();
su::deinit();
println!(
"******************************************************\n\
PANIC INSIDE WRAPPER\n\
`#[adorn(wrap)]` may give a wrong line that panicked\n\
******************************************************\n"
);
std::panic::resume_unwind(e);
}
}
#[test]
#[adorn(wrap)]
#[serial]
fn test_case_basic_call_incomplete() {
// see <lib-sofia-ua-c>/tests/test_basic_call.c::test_basic_call_1
// A B
// |-------INVITE------>|
// |<----100 Trying-----|
// | |
// |<----180 Ringing----|
// | |
// |<------200 OK-------|
// |--------ACK-------->|
// | |
// |<-------BYE---------|
// |-------200 OK------>|
// | |
// ______(NETWORK)_____
// / \
// A NUA STACK (A) NUA STACK (B) B
// | | | |
// | nua::handle(B) | | |
// |-------------------->| | |
// | | | |
// | handle::invite() | | |
// |------------------->[_] [INVITE/SDP] | |
// | [_]------------------>[_] IncomingInvite |
// | [_] [_]------------------->|
// | [_] [_] nua::handle(A) |
// | [_] [_] |
// | [_] [100 Trying] [_] |
// | [_]<------------------[_] |
// | [_] [180 Ringing] [_] |
// | [_]<------------------[_] |
// | [_] [_] handle::respond() |
// | [_] [200 OK] [_]<-------------------|
// | [_]<------------------[_] |
// | ReplyInvite [_] [_] |
// |<-------------------[_] [ACK] [_] |
// | [_]------------------>[_] IncomingActive |
// | IncomingActive [_] [_]------------------->|
// |<-------------------[_] [_] |
// | [_] [_] handle::bye() |
// | [_] [BYE] [_]<-------------------|
// | IncomingBye [_]<------------------[_] |
// |<-------------------[_] [200 OK] [_] |
// | [_]------------------>[_] |
// | | | |
// | | | |
let nua_a_url = "sip:127.0.0.1:5080";
let mut nua_a = {
let url = Tag::NuUrl(nua_a_url.into());
let tags = TagBuilder::default().tag(url).collect();
Nua::create(&tags).unwrap()
};
let nua_b_url = "sip:127.0.0.1:5081";
let mut nua_b = {
let url = Tag::NuUrl(nua_b_url.into());
let tags = TagBuilder::default().tag(url).collect();
Nua::create(&tags).unwrap()
};
{
/* NUA B */
nua_b.callback(
|nua: &mut Nua,
event: NuaEvent,
status: u32,
phrase: String,
handle: Option<&Handle>,
sip: Sip,
tags: Vec<Tag>| {
// dbg!(&nua, &event, &status, &phrase, &handle, &sip, &tags);
println!(
"[NUA _B]Event: {:?} // status: {:?} // phrase: {:?}",
&event, &status, &phrase
);
match event {
_ => {}
}
},
);
}
{
/* NUA A */
nua_a.callback(
|nua: &mut Nua,
event: NuaEvent,
status: u32,
phrase: String,
handle: Option<&Handle>,
sip: Sip,
tags: Vec<Tag>| {
// dbg!(&nua, &event, &status, &phrase, &handle, &sip, &tags);
println!(
"[NUA A_]Event: {:?} // status: {:?} // phrase: {:?}",
&event, &status, &phrase
);
match event {
_ => {}
}
},
);
}
let handle = {
let tags = TagBuilder::default()
.tag(Tag::SipToStr(nua_b_url.into()))
.tag(Tag::NuUrl(nua_b_url.into()))
.collect();
Handle::create(&nua_a, &tags).unwrap()
};
dbg!(&handle);
let tags = TagBuilder::default()
.tag(Tag::NuUrl(nua_b_url.into()))
.tag(Tag::SoaUserSdpStr("m=audio 5008 RTP/AVP 8".into()))
.tag(Tag::NuMUsername("a+a".into()))
.tag(Tag::NuMDisplay("Alice".into()))
.collect();
handle.invite(&tags);
Root::get_default_root().unwrap().step0();
Root::get_default_root().unwrap().step0();
println!("--> Test end");
// assert!(false);
}