-
Notifications
You must be signed in to change notification settings - Fork 36
/
test_parse_sdp.c
116 lines (105 loc) · 4.09 KB
/
test_parse_sdp.c
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
/*
Copyright (c) 2012, Paula Roquero Fuentes <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parse_sdp.h"
int main () {
int ret;
int err = 0;
SDP sdp;
char **sdp_ptr;
char packed_msg[1024];
char *sdp_ok[] = {
"m=video 5000 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\r\n\0",
"a=control:rtsp://uri/cacosa\r\n"
"m=video 5000 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\r\n\0",
"a=control:rtsp://uri/cacosa\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\r\n\0",
"a=control:rtsp://uri/cacosa\r\n"
"m=video 5000 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n\0",
0
};
char *sdp_err[] = {
"m=video 5000 asdf/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video 5000 RTP/AVP\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video 5000 RTP/AVP 1\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video 5000 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video 5000 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"m=video 5000 RTP/AVP 1\r\n"
"a=control:http://uri/cacosa/video\r\n"
"m=audio 5002 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\0",
"asldfaklsdajsd\0",
"\0",
0
};
sdp_ptr = sdp_ok;
do {
ret = unpack_sdp(&sdp, (unsigned char *)*sdp_ptr, strlen(*sdp_ptr));
if (!ret) {
err = 1;
fprintf(stderr, "Error unpacking sdp:\n%s\n", *sdp_ptr);
continue;
}
ret = pack_sdp(&sdp, (unsigned char *)packed_msg, 1024);
if (!ret) {
err = 1;
fprintf(stderr, "Error packing sdp:\n%s\n\n", *sdp_ptr);
continue;
}
if (strcmp(*sdp_ptr, packed_msg)) {
err = 1;
fprintf(stderr, "Error, different sdp:\n%s\n%s\n\n", *sdp_ptr, packed_msg);
}
if (sdp.medias) {
free(sdp.medias);
sdp.medias = 0;
}
} while (*(++sdp_ptr));
sdp_ptr = sdp_err;
do {
ret = unpack_sdp(&sdp, (unsigned char *)*sdp_ptr, strlen(*sdp_ptr));
if (ret) {
err = 1;
fprintf(stderr, "Unpacked incorrect sdp:\n%s\n\n", *sdp_ptr);
continue;
}
if (sdp.medias) {
free(sdp.medias);
sdp.medias = 0;
}
} while (*(++sdp_ptr));
if (!err)
fprintf(stderr, "Correct tests\n");
return 0;
}