torture_sdp.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*
  2. * This file is part of the Sofia-SIP package
  3. *
  4. * Copyright (C) 2005 Nokia Corporation.
  5. *
  6. * Contact: Pekka Pessi <pekka.pessi@nokia.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. /**@internal
  25. *
  26. * @CFILE sdp_torture.c
  27. *
  28. * Torture testing sdp module.
  29. *
  30. * @author Pekka Pessi <Pekka.Pessi@nokia.com>
  31. * @author Kai Vehmanen <kai.vehmanen@nokia.com>
  32. *
  33. * @date Created: Tue Mar 6 18:33:42 2001 ppessi
  34. */
  35. #include "config.h"
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <stddef.h>
  39. #include <stdlib.h>
  40. #include <sofia-sip/su_types.h>
  41. #include <sofia-sip/su_string.h>
  42. #include <sofia-sip/sdp.h>
  43. #include <sofia-sip/su_tag.h>
  44. #include <sofia-sip/su_tag_io.h>
  45. #include <sofia-sip/sdp_tag.h>
  46. #define TSTFLAGS tstflags
  47. #include <sofia-sip/tstdef.h>
  48. int tstflags;
  49. char const *name = "torture_sdp.c";
  50. FILE *null;
  51. static char const e0_msg[] =
  52. "foo";
  53. static char const e1_msg[] =
  54. "v=1\n"
  55. "s=/sdp_torture\n"
  56. "o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
  57. "m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
  58. "a=rtpmap:96 X-AMR-WB/16000\n"
  59. "a=rtpmap:97 X-AMR/8000\n"
  60. "a=rtpmap:98 GSM-EFR/8000\n"
  61. "a=rtpmap:10 L16/16000\n"
  62. "a=rtpmap:99 G723/8000\n"
  63. "a=rtpmap:8 PCMA/8000\n"
  64. "a=rtpmap:0 PCMU/8000\n"
  65. "m=video 0 *";
  66. static int test_error(void)
  67. {
  68. su_home_t *home = su_home_create();
  69. sdp_parser_t *parser;
  70. BEGIN();
  71. su_home_check(home); TEST0(home);
  72. TEST_1((parser = sdp_parse(home, e0_msg, sizeof(e0_msg), 0)));
  73. TEST_1(sdp_session(parser) == NULL);
  74. TEST_1(sdp_parsing_error(parser));
  75. sdp_parser_free(parser);
  76. TEST_1((parser = sdp_parse(home, e1_msg, sizeof(e1_msg), 0)));
  77. TEST_1(sdp_session(parser) == NULL);
  78. TEST_1(sdp_parsing_error(parser));
  79. sdp_parser_free(parser);
  80. /* destroy the home objects */
  81. su_home_check(home); su_home_zap(home);
  82. END();
  83. }
  84. static char const s0_msg[] =
  85. "v=0\n"
  86. "s=/sdp_torture\n"
  87. "o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
  88. "m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
  89. "a=rtpmap:96 X-AMR-WB/16000\n"
  90. "a=rtpmap:97 X-AMR/8000\n"
  91. "a=rtpmap:98 GSM-EFR/8000\n"
  92. "a=rtpmap:10 L16/16000\n"
  93. "a=rtpmap:99 G723/8000\n"
  94. "a=rtpmap:8 PCMA/8000\n"
  95. "a=rtpmap:0 PCMU/8000\n"
  96. "m=video 0 *\n"
  97. "m=* 0 RTP/AVP *\n"
  98. ;
  99. static int test_session(void)
  100. {
  101. su_home_t *home = su_home_create(), *home2 = su_home_create();
  102. sdp_session_t *sdp_src, *sdp_target;
  103. sdp_session_t const *sdp = NULL;
  104. sdp_parser_t *parser;
  105. sdp_printer_t *printer;
  106. sdp_media_t *m;
  107. char buffer[512];
  108. tagi_t *lst, *dup;
  109. BEGIN();
  110. su_home_check(home);
  111. TEST_1(home);
  112. su_home_check(home2);
  113. TEST_1(home2);
  114. TEST_1((parser = sdp_parse(home, s0_msg, sizeof(s0_msg), sdp_f_config)));
  115. TEST_1((sdp_src = sdp_session(parser)));
  116. TEST_1(sdp_src->sdp_media);
  117. TEST_1(sdp_src->sdp_media->m_session);
  118. TEST_P(sdp_src->sdp_media->m_session, sdp_src);
  119. /* clone the session using 'home2' */
  120. TEST_1((sdp_target = sdp_session_dup(home2, sdp_src)));
  121. /* Check comparing */
  122. TEST(sdp_session_cmp(sdp_src, sdp_target), 0);
  123. /* check the cloned session */
  124. TEST_1(sdp_target->sdp_subject);
  125. TEST_S(sdp_target->sdp_subject, "/sdp_torture");
  126. strcpy((char*)sdp_target->sdp_subject, "garbage");
  127. TEST_S(sdp_src->sdp_subject, "/sdp_torture");
  128. TEST_1(sdp_target->sdp_origin);
  129. TEST_1(sdp_target->sdp_origin->o_username);
  130. TEST_S(sdp_target->sdp_origin->o_username, "sdp_torture");
  131. strcpy((char*)sdp_target->sdp_origin->o_username, "garbage");
  132. TEST_S(sdp_src->sdp_origin->o_username, "sdp_torture");
  133. TEST_1(m = sdp_target->sdp_media);
  134. TEST_P(m->m_session, sdp_target);
  135. TEST_1(sdp_src->sdp_media->m_session != sdp_target->sdp_media->m_session);
  136. TEST(m->m_type, sdp_media_audio);
  137. TEST_S(m->m_type_name, "audio");
  138. TEST(m->m_port, 0);
  139. TEST(m->m_number_of_ports, 0);
  140. TEST(m->m_proto, sdp_proto_rtp);
  141. TEST_S(m->m_proto_name, "RTP/AVP");
  142. /* FIXME: add more tests */
  143. /* frees all data created by the parser including 'sdp_src' */
  144. sdp_parser_free(parser);
  145. /* destroy the first home instance */
  146. su_home_check(home);
  147. su_home_unref(home);
  148. /* access all cloned data by printing it */
  149. printer = sdp_print(home2, sdp_target, buffer, sizeof(buffer), 0);
  150. if (printer != NULL) {
  151. char const *msg = sdp_message(printer);
  152. if (tstflags & tst_verbatim) {
  153. printf("sdp_torture.c: parsed SDP message:\"%s\".\n", msg);
  154. }
  155. sdp_printer_free(printer);
  156. }
  157. TEST_1(lst = tl_list(SDPTAG_SESSION(sdp_target), TAG_NULL()));
  158. TEST_1(dup = tl_adup(home2, lst));
  159. if (tstflags & tst_verbatim)
  160. tl_print(stdout, "dup:\n", dup);
  161. else
  162. tl_print(null, "dup:\n", dup);
  163. TEST(tl_gets(dup, SDPTAG_SESSION_REF(sdp), TAG_END()), 1);
  164. /* access all copied data by printing it */
  165. printer = sdp_print(home2, sdp, buffer, sizeof(buffer), 0);
  166. if (printer != NULL) {
  167. char const *msg = sdp_message(printer);
  168. if (tstflags & tst_verbatim) {
  169. printf("sdp_torture.c: "
  170. "SDP message passed through tag list:\n\"%s\".\n", msg);
  171. }
  172. sdp_printer_free(printer);
  173. }
  174. su_free(home2, dup);
  175. tl_vfree(lst);
  176. /* destroy the second home object */
  177. su_home_check(home2);
  178. su_home_unref(home2);
  179. END();
  180. }
  181. static char const s0_cmp_msg[] =
  182. "v=0\n"
  183. "s=/sdp_torture\n"
  184. "o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
  185. "b=AS:64\n"
  186. "b=CRASH:32\n"
  187. "m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
  188. "a=rtpmap:96 X-AMR-WB/16000\n"
  189. "a=rtpmap:97 X-AMR/8000\n"
  190. "a=rtpmap:98 GSM-EFR/8000\n"
  191. "a=rtpmap:10 L16/16000\n"
  192. "a=rtpmap:99 G723/8000\n"
  193. "a=rtpmap:8 PCMA/8000\n"
  194. "a=rtpmap:0 PCMU/8000\n"
  195. "m=video 0 *\n"
  196. "m=* 0 RTP/AVP *\n"
  197. ;
  198. static char const s1_cmp_msg[] =
  199. "v=0\n"
  200. "s=/sdp_torture\n"
  201. "o=sdp_torture 0 0 IN IP4 0.0.0.0\n"
  202. "b=AS:64\n"
  203. "m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
  204. "a=rtpmap:96 X-AMR-WB/16000\n"
  205. "a=rtpmap:97 X-AMR/8000\n"
  206. "a=rtpmap:98 GSM-EFR/8000\n"
  207. "a=rtpmap:10 L16/16000\n"
  208. "a=rtpmap:99 G723/8000\n"
  209. "a=rtpmap:8 PCMA/8000\n"
  210. "a=rtpmap:0 PCMU/8000\n"
  211. "m=video 0 *\n"
  212. "m=* 0 RTP/AVP *\n"
  213. ;
  214. static int test_sdp_session_cmp(void)
  215. {
  216. su_home_t *home = su_home_create(), *home2 = su_home_create();
  217. sdp_session_t *sdp_src, *sdp_target;
  218. sdp_session_t const *sdp = NULL;
  219. sdp_parser_t *parser, *parser2;
  220. BEGIN();
  221. su_home_check(home);
  222. TEST_1(home);
  223. su_home_check(home2);
  224. TEST_1(home2);
  225. TEST_1((parser = sdp_parse(home, s0_cmp_msg, sizeof(s0_cmp_msg), sdp_f_config)));
  226. TEST_1((sdp_src = sdp_session(parser)));
  227. TEST_1((parser2 = sdp_parse(home2, s1_cmp_msg, sizeof(s1_cmp_msg), sdp_f_config)));
  228. TEST_1((sdp_target = sdp_session(parser2)));
  229. /* Check comparing */
  230. TEST(sdp_session_cmp(sdp_src, sdp_target), 1);
  231. /* frees all data created by the parser including 'sdp_src' */
  232. sdp_parser_free(parser);
  233. /* destroy the first home instance */
  234. su_home_check(home);
  235. su_home_unref(home);
  236. /* frees all data created by the parser including 'sdp_target' */
  237. sdp_parser_free(parser2);
  238. /* destroy the second home object */
  239. su_home_check(home2);
  240. su_home_unref(home2);
  241. END();
  242. }
  243. static char const s1_msg[] =
  244. "v=0\r\n"
  245. "o=- 2435697 2435697 IN IP4 172.21.137.44\r\n"
  246. "s=-\r\n"
  247. "c=IN IP4 172.21.137.44\r\n"
  248. "t=0 0\r\n"
  249. "a=sendonly\r\n"
  250. "m=video 49154 RTP/AVP 96 24 25 26 28 31 32 33 34\r\n"
  251. "a=rtpmap:96 H263-1998/90000\r\n"
  252. "m=audio 49152 RTP/AVP 97 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\r\n"
  253. "a=rtpmap 97 AMR/8000\r\n"
  254. "a=fmtp:97 mode-set=\"0,1,2,3,4\"\r\n"
  255. "a=ptime:400\r\n";
  256. static char const s2_msg[] =
  257. "v=0\r\n"
  258. "o=- 308519342 2 IN IP4 172.168.1.55\r\n"
  259. "s=-\r\n"
  260. "c=IN IP4 172.168.1.55\r\n"
  261. "t=0 0\r\n"
  262. "a=recvonly\r\n"
  263. "m=video 59154 RTP/AVP 96\r\n"
  264. "b=AS:64\r\n"
  265. "a=rtpmap:96 H263-1998/90000\r\n"
  266. "a=framerate:8\r\n"
  267. "a=fmtp:96 QCIF=4\r\n"
  268. "m=audio 59152 RTP/AVP 97\r\n"
  269. "b=AS:8\r\n"
  270. "a=rtpmap:97 AMR/8000\r\n"
  271. "a=fmtp:97 mode-set=\"0\"\r\n"
  272. "a=maxptime:500\r\n";
  273. static int test_session2(void)
  274. {
  275. su_home_t *home = su_home_create();
  276. sdp_session_t const *sdp = NULL;
  277. sdp_parser_t *parser;
  278. sdp_media_t *m;
  279. sdp_rtpmap_t *rm;
  280. BEGIN();
  281. su_home_check(home); TEST_1(home);
  282. TEST_1((parser = sdp_parse(home, s1_msg, sizeof(s1_msg), 0)));
  283. TEST_1((sdp = sdp_session(parser)));
  284. TEST_1(m = sdp->sdp_media);
  285. TEST(m->m_mode, sdp_sendonly);
  286. TEST_P(m->m_session, sdp);
  287. TEST_1(rm = m->m_rtpmaps);
  288. TEST(rm->rm_pt, 96);
  289. TEST_S(rm->rm_encoding, "H263-1998");
  290. TEST(rm->rm_rate, 90000);
  291. {
  292. #define RTPMAP(pt, type, rate, params) \
  293. { sizeof(sdp_rtpmap_t), NULL, type, rate, (char *)params, NULL, 1, pt, 0 }
  294. /* rtpmaps for well-known video codecs */
  295. static sdp_rtpmap_t const
  296. sdp_rtpmap_celb = RTPMAP(25, "CelB", 90000, 0),
  297. sdp_rtpmap_jpeg = RTPMAP(26, "JPEG", 90000, 0),
  298. sdp_rtpmap_nv = RTPMAP(28, "nv", 90000, 0),
  299. sdp_rtpmap_h261 = RTPMAP(31, "H261", 90000, 0),
  300. sdp_rtpmap_mpv = RTPMAP(32, "MPV", 90000, 0),
  301. sdp_rtpmap_mp2t = RTPMAP(33, "MP2T", 90000, 0),
  302. sdp_rtpmap_h263 = RTPMAP(34, "H263", 90000, 0);
  303. TEST_1(rm = rm->rm_next);
  304. TEST_S(rm->rm_encoding, ""); TEST(rm->rm_rate, 0);
  305. TEST_1(rm = rm->rm_next);
  306. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_celb, rm), &sdp_rtpmap_celb);
  307. TEST_1(rm = rm->rm_next);
  308. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_jpeg, rm), &sdp_rtpmap_jpeg);
  309. TEST_1(rm = rm->rm_next);
  310. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_nv, rm), &sdp_rtpmap_nv);
  311. TEST_1(rm = rm->rm_next);
  312. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_h261, rm), &sdp_rtpmap_h261);
  313. TEST_1(rm = rm->rm_next);
  314. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mpv, rm), &sdp_rtpmap_mpv);
  315. TEST_1(rm = rm->rm_next);
  316. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mp2t, rm), &sdp_rtpmap_mp2t);
  317. TEST_1(rm = rm->rm_next);
  318. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_h263, rm), &sdp_rtpmap_h263);
  319. TEST_1(!rm->rm_next);
  320. }
  321. TEST_1(m = m->m_next);
  322. TEST(m->m_mode, sdp_sendonly);
  323. TEST_P(m->m_session, sdp);
  324. TEST_1(rm = m->m_rtpmaps);
  325. TEST(rm->rm_pt, 97);
  326. TEST_S(rm->rm_encoding, "AMR");
  327. TEST(rm->rm_rate, 8000);
  328. TEST_S(rm->rm_fmtp, "mode-set=\"0,1,2,3,4\"");
  329. {
  330. /* rtpmaps for well-known audio codecs */
  331. static sdp_rtpmap_t const
  332. sdp_rtpmap_pcmu = RTPMAP(0, "PCMU", 8000, "1"),
  333. sdp_rtpmap_1016 = RTPMAP(1, "1016", 8000, "1"),
  334. sdp_rtpmap_g721 = RTPMAP(2, "G721", 8000, "1"),
  335. sdp_rtpmap_gsm = RTPMAP(3, "GSM", 8000, "1"),
  336. sdp_rtpmap_g723 = RTPMAP(4, "G723", 8000, "1"),
  337. sdp_rtpmap_dvi4_8000 = RTPMAP(5, "DVI4", 8000, "1"),
  338. sdp_rtpmap_dvi4_16000 = RTPMAP(6, "DVI4", 16000, "1"),
  339. sdp_rtpmap_lpc = RTPMAP(7, "LPC", 8000, "1"),
  340. sdp_rtpmap_pcma = RTPMAP(8, "PCMA", 8000, "1"),
  341. sdp_rtpmap_g722 = RTPMAP(9, "G722", 8000, "1"),
  342. sdp_rtpmap_l16 = RTPMAP(10, "L16", 44100, "2"),
  343. sdp_rtpmap_l16_stereo = RTPMAP(11, "L16", 44100, "1"),
  344. sdp_rtpmap_qcelp = RTPMAP(12, "QCELP", 8000, "1"),
  345. sdp_rtpmap_cn = RTPMAP(13, "CN", 8000, "1"),
  346. sdp_rtpmap_mpa = RTPMAP(14, "MPA", 90000, 0),
  347. sdp_rtpmap_g728 = RTPMAP(15, "G728", 8000, "1"),
  348. sdp_rtpmap_dvi4_11025 = RTPMAP(16, "DVI4", 11025, "1"),
  349. sdp_rtpmap_dvi4_22050 = RTPMAP(17, "DVI4", 22050, "1"),
  350. sdp_rtpmap_g729 = RTPMAP(18, "G729", 8000, "1"),
  351. sdp_rtpmap_cn_reserved = RTPMAP(19, "CN", 8000, "1");
  352. TEST_1(rm = rm->rm_next);
  353. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_pcmu, rm));
  354. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_pcmu, rm), &sdp_rtpmap_pcmu);
  355. TEST_1(rm = rm->rm_next);
  356. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_1016, rm));
  357. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_1016, rm), &sdp_rtpmap_1016);
  358. TEST_1(rm = rm->rm_next);
  359. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g721, rm));
  360. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g721, rm), &sdp_rtpmap_g721);
  361. TEST_1(rm = rm->rm_next);
  362. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_gsm, rm));
  363. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_gsm, rm), &sdp_rtpmap_gsm);
  364. TEST_1(rm = rm->rm_next);
  365. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g723, rm));
  366. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g723, rm), &sdp_rtpmap_g723);
  367. TEST_1(rm = rm->rm_next);
  368. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_8000, rm));
  369. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_8000, rm),
  370. &sdp_rtpmap_dvi4_8000);
  371. TEST_1(rm = rm->rm_next);
  372. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_16000, rm));
  373. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_16000, rm),
  374. &sdp_rtpmap_dvi4_16000);
  375. TEST_1(rm = rm->rm_next);
  376. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_lpc, rm));
  377. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_lpc, rm), &sdp_rtpmap_lpc);
  378. TEST_1(rm = rm->rm_next);
  379. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_pcma, rm));
  380. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_pcma, rm), &sdp_rtpmap_pcma);
  381. TEST_1(rm = rm->rm_next);
  382. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g722, rm));
  383. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g722, rm), &sdp_rtpmap_g722);
  384. TEST_1(rm = rm->rm_next);
  385. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_l16, rm));
  386. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_l16, rm), &sdp_rtpmap_l16);
  387. TEST_1(rm = rm->rm_next);
  388. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_l16_stereo, rm));
  389. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_l16_stereo, rm),
  390. &sdp_rtpmap_l16_stereo);
  391. TEST_1(rm = rm->rm_next);
  392. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_qcelp, rm));
  393. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_qcelp, rm), &sdp_rtpmap_qcelp);
  394. TEST_1(rm = rm->rm_next);
  395. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_cn, rm));
  396. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_cn, rm), &sdp_rtpmap_cn);
  397. TEST_1(rm = rm->rm_next);
  398. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_mpa, rm));
  399. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_mpa, rm), &sdp_rtpmap_mpa);
  400. TEST_1(rm = rm->rm_next);
  401. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g728, rm));
  402. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g728, rm), &sdp_rtpmap_g728);
  403. TEST_1(rm = rm->rm_next);
  404. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_11025, rm));
  405. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_11025, rm),
  406. &sdp_rtpmap_dvi4_11025);
  407. TEST_1(rm = rm->rm_next);
  408. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_dvi4_22050, rm));
  409. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_dvi4_22050, rm),
  410. &sdp_rtpmap_dvi4_22050);
  411. TEST_1(rm = rm->rm_next);
  412. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_g729, rm));
  413. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_g729, rm), &sdp_rtpmap_g729);
  414. TEST_1(rm = rm->rm_next);
  415. TEST_1(sdp_rtpmap_match(&sdp_rtpmap_cn_reserved, rm));
  416. TEST_P(sdp_rtpmap_find_matching(&sdp_rtpmap_cn_reserved, rm),
  417. &sdp_rtpmap_cn_reserved);
  418. TEST_1(!rm->rm_next);
  419. }
  420. TEST_1((parser = sdp_parse(home, s2_msg, sizeof (s2_msg), 0)));
  421. TEST_1((sdp = sdp_session(parser)));
  422. TEST_1(m = sdp->sdp_media);
  423. TEST(m->m_mode, sdp_recvonly);
  424. TEST_P(m->m_session, sdp);
  425. TEST_1(m->m_rtpmaps);
  426. TEST(m->m_rtpmaps->rm_pt, 96);
  427. TEST_S(m->m_rtpmaps->rm_encoding, "H263-1998");
  428. TEST(m->m_rtpmaps->rm_rate, 90000);
  429. TEST_S(m->m_rtpmaps->rm_fmtp, "QCIF=4");
  430. TEST_1(m = sdp->sdp_media->m_next);
  431. TEST(m->m_mode, sdp_recvonly);
  432. TEST_P(m->m_session, sdp);
  433. TEST_1(m->m_rtpmaps);
  434. TEST(m->m_rtpmaps->rm_pt, 97);
  435. TEST_S(m->m_rtpmaps->rm_encoding, "AMR");
  436. TEST(m->m_rtpmaps->rm_rate, 8000);
  437. TEST_S(m->m_rtpmaps->rm_fmtp, "mode-set=\"0\"");
  438. su_home_unref(home);
  439. END();
  440. }
  441. static char const s3_msg[] =
  442. "v=0\r\n"
  443. "o=- 2435697 2435697 IN IP4 172.21.137.44\r\n"
  444. "s=-\r\n"
  445. "t=0 0\r\n"
  446. "m=video 49154 RTP/AVP 34\r\n"
  447. "c=IN IP4 172.21.137.44\r\n"
  448. "m=audio 49152 RTP/AVP 8 0\r\n"
  449. "c=IN IP4 172.21.137.44\r\n"
  450. "m=message 0 MSRP/TCP *\r\n"
  451. ;
  452. static int test_sanity(void)
  453. {
  454. su_home_t *home = su_home_create();
  455. sdp_parser_t *parser;
  456. BEGIN();
  457. su_home_check(home); TEST_1(home);
  458. TEST_1((parser = sdp_parse(home, s3_msg, sizeof(s3_msg) - 1, 0)));
  459. TEST_1(sdp_sanity_check(parser) == 0);
  460. su_home_unref(home);
  461. END();
  462. }
  463. static char const pint_msg[] =
  464. "v=0\r\n"
  465. "o=- 2353687640 2353687640 IN IP4 128.3.4.5\r\n"
  466. "s=marketing\r\n"
  467. "e=john.jones.3@chinet.net\r\n"
  468. "c=TN RFC2543 +1-201-406-4090\r\n"
  469. "t=2353687640 0\r\n"
  470. "m=audio 1 voice -\r\n"
  471. ;
  472. static char const pint_torture_msg[] =
  473. "v=0\r\n"
  474. "o=- 2353687640 2353687640 IN IP4 128.3.4.5\r\n"
  475. "s=marketing\r\n"
  476. "c= TN RFC2543 123\r\n"
  477. "a=phone-context:+97252\r\n"
  478. "t=2353687640 0\r\n"
  479. "m= text 1 fax plain\r\n"
  480. "a=fmtp:plain spr:fi6MeoclEjaF3EDfYHlkqx1zn8A1lMoiJFUHpQ5Xo\r\n"
  481. ;
  482. static int test_pint(void)
  483. {
  484. su_home_t *home = su_home_create();
  485. sdp_parser_t *parser;
  486. sdp_session_t *sdp;
  487. sdp_printer_t *printer;
  488. char const *m;
  489. BEGIN();
  490. su_home_check(home); TEST_1(home);
  491. TEST_1((parser = sdp_parse(home, pint_msg, sizeof(pint_msg) - 1, sdp_f_anynet)));
  492. TEST_1((sdp = sdp_session(parser)));
  493. TEST_1((printer = sdp_print(home, sdp, NULL, -1, 0)));
  494. TEST_1((m = sdp_message(printer)));
  495. TEST_S(m, pint_msg);
  496. TEST(sdp_message_size(printer), sizeof(pint_msg) - 1);
  497. TEST_1((parser = sdp_parse(home, pint_torture_msg, sizeof(pint_torture_msg) - 1,
  498. sdp_f_anynet)));
  499. TEST_1((sdp = sdp_session(parser)));
  500. su_home_check(home);
  501. su_home_unref(home);
  502. END();
  503. }
  504. static sdp_list_t const l0[1] = {{ sizeof(l0), NULL, "foo" }};
  505. static sdp_list_t const l1[1] = {{ sizeof(l1), (sdp_list_t *)l0, "bar" }};
  506. /** Test list things */
  507. int test_list(void)
  508. {
  509. su_home_t *home = su_home_create();
  510. sdp_list_t *l;
  511. BEGIN();
  512. su_home_check(home);
  513. TEST_1(home);
  514. TEST_1((l = sdp_list_dup(home, l0)));
  515. TEST_P(l->l_next, NULL);
  516. TEST_S(l->l_text, "foo");
  517. TEST_1((l = sdp_list_dup(home, l1)));
  518. TEST_1(l->l_next != NULL);
  519. TEST_1(l->l_next->l_next == NULL);
  520. TEST_S(l->l_text, "bar");
  521. TEST_S(l->l_next->l_text, "foo");
  522. su_home_check(home);
  523. su_home_unref(home);
  524. END();
  525. }
  526. static
  527. sdp_rtpmap_t const rm0[1] =
  528. {{
  529. sizeof(rm0), NULL, "AMR", 8000, "1",
  530. "mode-set=4,5,6 interleaving crc use-redundancy=1",
  531. 0, 96, 0
  532. }};
  533. static
  534. sdp_rtpmap_t const rm1[1] =
  535. {{
  536. sizeof(rm1), (sdp_rtpmap_t *)rm0, "PCMA", 8000, "1",
  537. NULL,
  538. 1, 8, 0,
  539. }};
  540. /** Test rtpmap-related things */
  541. int test_rtpmap(void)
  542. {
  543. su_home_t *home = su_home_create();
  544. sdp_rtpmap_t *rm;
  545. BEGIN();
  546. su_home_check(home);
  547. TEST_1(home);
  548. TEST_1((rm = sdp_rtpmap_dup(home, rm0)));
  549. TEST_P(rm->rm_next, NULL);
  550. TEST_S(rm->rm_encoding, "AMR");
  551. TEST_S(rm->rm_params, "1");
  552. TEST(rm->rm_pt, 96);
  553. TEST_S(rm->rm_fmtp, "mode-set=4,5,6 interleaving crc use-redundancy=1");
  554. TEST_1((rm = sdp_rtpmap_dup(home, rm1)));
  555. TEST_1(rm->rm_next != NULL);
  556. TEST_1(rm->rm_next->rm_next == NULL);
  557. TEST_S(rm->rm_encoding, "PCMA");
  558. TEST_S(rm->rm_params, "1");
  559. TEST(rm->rm_pt, 8);
  560. su_home_check(home);
  561. su_home_unref(home);
  562. END();
  563. }
  564. static sdp_attribute_t const a0[1] =
  565. {{ sizeof(a0), NULL, "foo", "2"}};
  566. static sdp_attribute_t const a1[1] =
  567. {{ sizeof(a1), (sdp_attribute_t *)a0, "bar", "1" }};
  568. static int test_attribute(void)
  569. {
  570. su_home_t *home = su_home_create();
  571. sdp_attribute_t *a, *a_new, *list, *replaced;
  572. BEGIN();
  573. su_home_check(home);
  574. TEST_1(home);
  575. TEST_1((a = sdp_attribute_dup(home, a0)));
  576. TEST_P(a->a_next, NULL);
  577. TEST_S(a->a_name, "foo");
  578. TEST_S(a->a_value, "2");
  579. strcpy((char *)a->a_name, "FOO");
  580. TEST_S(a0->a_name, "foo");
  581. strcpy((char *)a->a_value, "X");
  582. TEST_S(a0->a_value, "2");
  583. TEST_1((a = sdp_attribute_dup(home, a1)));
  584. TEST_1(a->a_next != NULL);
  585. TEST_1(a->a_next->a_next == NULL);
  586. TEST_S(a->a_name, "bar");
  587. TEST_S(a->a_value, "1");
  588. TEST_S(a->a_next->a_name, "foo");
  589. TEST_S(a->a_next->a_value, "2");
  590. list = a;
  591. TEST_P(sdp_attribute_remove(&list, NULL), NULL);
  592. TEST_P(sdp_attribute_remove(&list, "kuik"), NULL);
  593. TEST_P(sdp_attribute_remove(&list, "barf"), NULL);
  594. TEST_P(sdp_attribute_remove(&list, "bar"), a);
  595. TEST_1(a_new = sdp_attribute_dup(home, a));
  596. replaced = (void *)-1;
  597. TEST(sdp_attribute_replace(&list, NULL, &replaced), -1);
  598. TEST_P(replaced, NULL);
  599. TEST(sdp_attribute_replace(&list, a, &replaced), 0);
  600. TEST_P(replaced, NULL);
  601. TEST(sdp_attribute_replace(&list, a_new, &replaced), 1);
  602. TEST_P(replaced, a);
  603. TEST_VOID(sdp_attribute_append(&list, a));
  604. TEST_P(sdp_attribute_remove(&list, "bAr"), a_new);
  605. TEST_P(sdp_attribute_remove(&list, "BAR"), a);
  606. TEST_P(sdp_attribute_remove(&list, "bar"), NULL);
  607. su_home_check(home);
  608. su_home_unref(home);
  609. END();
  610. }
  611. static int test_connection(void)
  612. {
  613. BEGIN();
  614. END();
  615. }
  616. static char const media_msg[] =
  617. "v=0\n"
  618. "s=/sdp_torture\n"
  619. "o=sdp_torture 0 0 IN IP4 1.2.3.4\n"
  620. "c=IN IP4 1.2.3.4\n"
  621. "m=audio 0 RTP/AVP 96 97 98 10 99 8 0\n"
  622. "a=rtpmap:96 X-AMR-WB/16000\n"
  623. "a=rtpmap:97 X-AMR/8000\n"
  624. "a=rtpmap:98 GSM-EFR/8000\n"
  625. "a=rtpmap:10 L16/16000\n"
  626. "a=rtpmap:99 G723/8000\n"
  627. "a=rtpmap:8 PCMA/8000\n"
  628. "a=rtpmap:0 PCMU/8000\n"
  629. "m=video 0 RTP/AVP 31\n"
  630. "c=IN IP4 2.3.4.5\n";
  631. static sdp_media_t const m0[1] =
  632. {{ sizeof(m0),
  633. NULL,
  634. NULL,
  635. sdp_media_audio,
  636. NULL,
  637. 1234,
  638. 5,
  639. sdp_proto_udp,
  640. "udp",
  641. }};
  642. static int test_media(void)
  643. {
  644. su_home_t *home = su_home_create();
  645. sdp_media_t *media;
  646. sdp_session_t *sdp;
  647. sdp_parser_t *parser;
  648. BEGIN();
  649. su_home_check(home);
  650. TEST_1(home);
  651. TEST_1((parser = sdp_parse(home, media_msg, sizeof(media_msg), 0)));
  652. TEST_1((sdp = sdp_session(parser)));
  653. TEST_1((media = sdp_media_dup(home, m0, sdp)));
  654. /* Check comparing */
  655. TEST(sdp_media_cmp(media, m0), 0);
  656. TEST(media->m_type, sdp_media_audio);
  657. TEST(media->m_port, 1234);
  658. TEST(media->m_number_of_ports, 5);
  659. TEST_P(media->m_session, sdp);
  660. /* FIXME: add more tests */
  661. media->m_next = (sdp_media_t *)m0;
  662. TEST_1((media = sdp_media_dup_all(home, media, sdp)));
  663. TEST_P(media->m_connections, NULL);
  664. TEST_1(media->m_next);
  665. TEST_P(media->m_next->m_connections, NULL);
  666. TEST_P(sdp_media_connections(media), sdp->sdp_connection);
  667. TEST_P(sdp_media_connections(media->m_next), sdp->sdp_connection);
  668. sdp_parser_free(parser);
  669. su_home_check(home);
  670. su_home_unref(home);
  671. END();
  672. }
  673. static int test_origin(void)
  674. {
  675. BEGIN();
  676. END();
  677. }
  678. static int test_bandwidth(void)
  679. {
  680. BEGIN();
  681. END();
  682. }
  683. static char const t_msg[] =
  684. "v=0\n"
  685. "s=/sdp_torture\n"
  686. "o=sdp_torture 1 1 IN IP4 1.2.3.4\n"
  687. "c=IN IP4 1.2.3.4\n"
  688. "t=3309789956 3309793556\n"
  689. "t=3309789956 3309793557\n"
  690. "t=3309789955 3309793557\n"
  691. "r=604800 3600 0 90000\n"
  692. "z=2882844526 -1h 2898848070 0\n"
  693. "t=3309789955 3309793557\n"
  694. "r=604800 3600 0 90000\n"
  695. "z=2882844526 -1h 2898848070 0\n"
  696. ;
  697. static int test_time(void)
  698. {
  699. sdp_parser_t *parser;
  700. sdp_session_t *sdp;
  701. sdp_time_t *t, t1[1], t2[1];
  702. BEGIN();
  703. TEST_1((parser = sdp_parse(NULL, t_msg, sizeof(t_msg), 0)));
  704. TEST_1((sdp = sdp_session(parser)));
  705. TEST_1((t = sdp->sdp_time)); *t1 = *t; t1->t_next = NULL; *t2 = *t1;
  706. TEST_1(sdp_time_cmp(t1, t1) == 0);
  707. TEST_1(sdp_time_cmp(t1, t2) == 0);
  708. TEST_1(sdp_time_cmp(t2, t1) == 0);
  709. TEST_1((t = t->t_next)); *t1 = *t; t1->t_next = NULL;
  710. TEST_1(sdp_time_cmp(t1, t2) > 0);
  711. TEST_1(sdp_time_cmp(t2, t1) < 0);
  712. TEST_1((t = t->t_next)); *t2 = *t; t2->t_next = NULL;
  713. TEST_1(t2->t_zone); TEST_1(t2->t_repeat);
  714. TEST_1(sdp_time_cmp(t2, t2) == 0);
  715. TEST_1(sdp_time_cmp(t1, t2) > 0);
  716. TEST_1(sdp_time_cmp(t2, t1) < 0);
  717. TEST_1((t = t->t_next)); *t1 = *t; t1->t_next = NULL;
  718. TEST_1(t1->t_zone); TEST_1(t1->t_repeat);
  719. TEST_1(sdp_time_cmp(t1, t1) == 0);
  720. TEST_1(sdp_time_cmp(t2, t2) == 0);
  721. TEST_1(sdp_time_cmp(t1, t2) == 0);
  722. sdp_parser_free(parser);
  723. END();
  724. }
  725. static int test_key(void)
  726. {
  727. BEGIN();
  728. END();
  729. }
  730. #include <time.h>
  731. #include <stdlib.h>
  732. static int test_build(void)
  733. {
  734. sdp_session_t *sdp, *dup;
  735. sdp_origin_t *o;
  736. sdp_time_t *t;
  737. sdp_connection_t *c;
  738. sdp_media_t *m, *m1;
  739. sdp_rtpmap_t *rm;
  740. sdp_list_t *l, *l1;
  741. sdp_attribute_t *a;
  742. su_home_t *home;
  743. sdp_printer_t *printer;
  744. char const *data;
  745. BEGIN();
  746. srand(time(NULL));
  747. TEST_1(home = su_home_create());
  748. /*
  749. * Allocate an SDP structure using su_salloc().
  750. * su_salloc() puts memory area size to the beginning of structure
  751. * and zeroes rest of the structure.
  752. */
  753. TEST_1(sdp = su_salloc(home, sizeof(*sdp)));
  754. TEST_1(o = su_salloc(home, sizeof(*o)));
  755. TEST_1(t = su_salloc(home, sizeof(*t)));
  756. TEST_1(c = su_salloc(home, sizeof(*c)));
  757. TEST_1(m = su_salloc(home, sizeof(*m)));
  758. TEST_1(rm = su_salloc(home, sizeof(*rm)));
  759. sdp->sdp_origin = o;
  760. sdp->sdp_time = t; /* zero time is fine for SIP */
  761. sdp->sdp_connection = c;
  762. sdp->sdp_media = m;
  763. o->o_username = "test";
  764. o->o_id = rand();
  765. o->o_version = 1;
  766. o->o_address = c;
  767. c->c_nettype = sdp_net_in;
  768. c->c_addrtype = sdp_addr_ip4;
  769. c->c_address = "172.21.40.40";
  770. m->m_session = sdp;
  771. m->m_type = sdp_media_audio; m->m_type_name = "audio";
  772. m->m_port = 5004;
  773. m->m_proto = sdp_proto_rtp; m->m_proto_name = "RTP/AVP";
  774. m->m_rtpmaps = rm;
  775. rm->rm_predef = 1;
  776. rm->rm_pt = 8;
  777. rm->rm_encoding = "PCMA";
  778. rm->rm_rate = 8000;
  779. TEST_1(m1 = su_salloc(home, sizeof(*m1)));
  780. TEST_1(l = su_salloc(home, sizeof(*l)));
  781. TEST_1(l1 = su_salloc(home, sizeof(*l1)));
  782. TEST_1(a = su_salloc(home, sizeof(*a)));
  783. m->m_next = m1;
  784. m1->m_session = sdp;
  785. m1->m_type = sdp_media_message; m->m_type_name = "message";
  786. m1->m_port = 5060;
  787. m1->m_proto = sdp_proto_tcp; m->m_proto_name = "TCP";
  788. m1->m_format = l;
  789. m1->m_attributes = a;
  790. l->l_text = "sip";
  791. l->l_next = l1;
  792. l1->l_text = "cpim";
  793. a->a_name = "user";
  794. a->a_value = "chat-81273845";
  795. TEST_1(dup = sdp_session_dup(home, sdp));
  796. TEST_1(printer = sdp_print(home, dup, NULL, 0, 0));
  797. TEST_1(data = sdp_message(printer));
  798. if (tstflags & tst_verbatim)
  799. printf("sdp_torture.c: built SDP message:\"%s\".\n", data);
  800. sdp_printer_free(printer);
  801. END();
  802. }
  803. void usage(int exitcode)
  804. {
  805. fprintf(stderr, "usage: %s [-v] [-a]\n", name);
  806. exit(exitcode);
  807. }
  808. int main(int argc, char *argv[])
  809. {
  810. int retval = 0;
  811. int i;
  812. for (i = 1; argv[i]; i++) {
  813. if (su_strmatch(argv[i], "-v"))
  814. tstflags |= tst_verbatim;
  815. else if (su_strmatch(argv[i], "-a"))
  816. tstflags |= tst_abort;
  817. else
  818. usage(1);
  819. }
  820. null = fopen("/dev/null", "ab");
  821. retval |= test_error(); fflush(stdout);
  822. retval |= test_sdp_session_cmp(); fflush(stdout);
  823. retval |= test_session(); fflush(stdout);
  824. retval |= test_session2(); fflush(stdout);
  825. retval |= test_pint(); fflush(stdout);
  826. retval |= test_sanity(); fflush(stdout);
  827. retval |= test_list(); fflush(stdout);
  828. retval |= test_rtpmap(); fflush(stdout);
  829. retval |= test_origin(); fflush(stdout);
  830. retval |= test_connection(); fflush(stdout);
  831. retval |= test_bandwidth(); fflush(stdout);
  832. retval |= test_time(); fflush(stdout);
  833. retval |= test_key(); fflush(stdout);
  834. retval |= test_attribute(); fflush(stdout);
  835. retval |= test_media(); fflush(stdout);
  836. retval |= test_build(); fflush(stdout);
  837. return retval;
  838. }