• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer unit tests for the RTSP support library
2  * Copyright (C) 2010 Andy Wingo <wingo@oblong.com>
3  * Copyright (C) 2015 Tim-Philipp Müller <tim@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <gst/check/gstcheck.h>
26 
27 #include <gst/rtsp/rtsp.h>
28 #include <string.h>
29 
GST_START_TEST(test_rtsp_url_basic)30 GST_START_TEST (test_rtsp_url_basic)
31 {
32   GstRTSPUrl *url = NULL;
33   GstRTSPResult res;
34 
35   res = gst_rtsp_url_parse ("rtsp://localhost/foo/bar", &url);
36   fail_unless (res == GST_RTSP_OK);
37   fail_unless (url != NULL);
38   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_TCP);
39   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP);
40   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP_MCAST);
41   fail_unless (url->family == GST_RTSP_FAM_INET);
42   fail_unless (!url->user);
43   fail_unless (!url->passwd);
44   fail_unless (!strcmp (url->host, "localhost"));
45   /* fail_unless (url->port == GST_RTSP_DEFAULT_PORT); */
46   fail_unless (!strcmp (url->abspath, "/foo/bar"));
47   fail_unless (!url->query);
48 
49   gst_rtsp_url_free (url);
50 }
51 
52 GST_END_TEST;
53 
GST_START_TEST(test_rtsp_url_query)54 GST_START_TEST (test_rtsp_url_query)
55 {
56   GstRTSPUrl *url = NULL;
57   GstRTSPResult res;
58   gchar *uri;
59   const gchar *original_uri = "rtsp://localhost/foo/bar/?baz=fooo";
60   const gchar *original_uri_with_control =
61       "rtsp://localhost/foo/bar/video/stream1?baz=fooo";
62 
63   res = gst_rtsp_url_parse (original_uri, &url);
64   fail_unless (res == GST_RTSP_OK);
65   fail_unless (url != NULL);
66   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_TCP);
67   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP);
68   fail_unless (url->transports & GST_RTSP_LOWER_TRANS_UDP_MCAST);
69   fail_unless (url->family == GST_RTSP_FAM_INET);
70   fail_unless (!url->user);
71   fail_unless (!url->passwd);
72   fail_unless (!strcmp (url->host, "localhost"));
73   fail_unless (!strcmp (url->abspath, "/foo/bar/"));
74   fail_unless (!strcmp (url->query, "baz=fooo"));
75   uri = gst_rtsp_url_get_request_uri (url);
76   fail_unless (!strcmp (uri, original_uri));
77   g_free (uri);
78   uri = gst_rtsp_url_get_request_uri_with_control (url, "/video/stream1");
79   fail_unless (!strcmp (uri, original_uri_with_control));
80   g_free (uri);
81 
82   gst_rtsp_url_free (url);
83 }
84 
85 GST_END_TEST;
86 
GST_START_TEST(test_rtsp_url_components_1)87 GST_START_TEST (test_rtsp_url_components_1)
88 {
89   GstRTSPUrl *url = NULL;
90   GstRTSPResult res;
91   gchar **comps = NULL;
92 
93   res = gst_rtsp_url_parse ("rtsp://localhost/foo/bar", &url);
94   fail_unless (res == GST_RTSP_OK);
95   fail_unless (url != NULL);
96 
97   comps = gst_rtsp_url_decode_path_components (url);
98   fail_unless (comps != NULL);
99   fail_unless (g_strv_length (comps) == 3);
100   fail_unless (!strcmp (comps[0], ""));
101   fail_unless (!strcmp (comps[1], "foo"));
102   fail_unless (!strcmp (comps[2], "bar"));
103 
104   g_strfreev (comps);
105   gst_rtsp_url_free (url);
106 }
107 
108 GST_END_TEST;
109 
GST_START_TEST(test_rtsp_url_components_2)110 GST_START_TEST (test_rtsp_url_components_2)
111 {
112   GstRTSPUrl *url = NULL;
113   GstRTSPResult res;
114   gchar **comps = NULL;
115 
116   res = gst_rtsp_url_parse ("rtsp://localhost/foo%2Fbar/qux%20baz", &url);
117   fail_unless (res == GST_RTSP_OK);
118   fail_unless (url != NULL);
119 
120   comps = gst_rtsp_url_decode_path_components (url);
121   fail_unless (comps != NULL);
122   fail_unless (g_strv_length (comps) == 3);
123   fail_unless (!strcmp (comps[0], ""));
124   fail_unless (!strcmp (comps[1], "foo/bar"));
125   fail_unless (!strcmp (comps[2], "qux baz"));
126 
127   g_strfreev (comps);
128   gst_rtsp_url_free (url);
129 }
130 
131 GST_END_TEST;
132 
GST_START_TEST(test_rtsp_url_components_3)133 GST_START_TEST (test_rtsp_url_components_3)
134 {
135   GstRTSPUrl *url = NULL;
136   GstRTSPResult res;
137   gchar **comps = NULL;
138 
139   res = gst_rtsp_url_parse ("rtsp://localhost/foo%00bar/qux%20baz", &url);
140   fail_unless (res == GST_RTSP_OK);
141   fail_unless (url != NULL);
142 
143   comps = gst_rtsp_url_decode_path_components (url);
144   fail_unless (comps != NULL);
145   fail_unless (g_strv_length (comps) == 3);
146   fail_unless (!strcmp (comps[0], ""));
147   fail_unless (!strcmp (comps[1], "foo%00bar"));
148   fail_unless (!strcmp (comps[2], "qux baz"));
149 
150   g_strfreev (comps);
151   gst_rtsp_url_free (url);
152 }
153 
154 GST_END_TEST;
155 
GST_START_TEST(test_rtsp_range_npt)156 GST_START_TEST (test_rtsp_range_npt)
157 {
158   GstRTSPTimeRange *range;
159   GstClockTime min, max;
160   gchar *str;
161 
162   fail_unless (gst_rtsp_range_parse ("npt=", &range) == GST_RTSP_EINVAL);
163   fail_unless (gst_rtsp_range_parse ("npt=0", &range) == GST_RTSP_EINVAL);
164   fail_unless (gst_rtsp_range_parse ("npt=-", &range) == GST_RTSP_EINVAL);
165   fail_unless (gst_rtsp_range_parse ("npt=now", &range) == GST_RTSP_EINVAL);
166 
167   fail_unless (gst_rtsp_range_parse ("npt=-now", &range) == GST_RTSP_OK);
168   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
169   fail_unless (range->min.type == GST_RTSP_TIME_END);
170   fail_unless (range->max.type == GST_RTSP_TIME_NOW);
171   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
172   fail_unless (min == GST_CLOCK_TIME_NONE);
173   fail_unless (max == GST_CLOCK_TIME_NONE);
174   str = gst_rtsp_range_to_string (range);
175   fail_unless_equals_string ("npt=-now", str);
176   GST_DEBUG ("%s", str);
177   g_free (str);
178   gst_rtsp_range_free (range);
179 
180   fail_unless (gst_rtsp_range_parse ("npt=now-now", &range) == GST_RTSP_OK);
181   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
182   fail_unless (range->min.type == GST_RTSP_TIME_NOW);
183   fail_unless (range->max.type == GST_RTSP_TIME_NOW);
184   str = gst_rtsp_range_to_string (range);
185   fail_unless_equals_string ("npt=now-now", str);
186   GST_DEBUG ("%s", str);
187   g_free (str);
188   gst_rtsp_range_free (range);
189 
190   fail_unless (gst_rtsp_range_parse ("npt=now-", &range) == GST_RTSP_OK);
191   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
192   fail_unless (range->min.type == GST_RTSP_TIME_NOW);
193   fail_unless (range->max.type == GST_RTSP_TIME_END);
194   str = gst_rtsp_range_to_string (range);
195   fail_unless_equals_string ("npt=now-", str);
196   GST_DEBUG ("%s", str);
197   g_free (str);
198   gst_rtsp_range_free (range);
199 
200   fail_unless (gst_rtsp_range_parse ("npt=now-34.12", &range) == GST_RTSP_OK);
201   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
202   fail_unless (range->min.type == GST_RTSP_TIME_NOW);
203   fail_unless (range->max.type == GST_RTSP_TIME_SECONDS);
204   fail_unless (range->max.seconds == 34.12);
205   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
206   fail_unless (min == GST_CLOCK_TIME_NONE);
207   fail_unless (max == 34120000000);
208   str = gst_rtsp_range_to_string (range);
209   fail_unless_equals_string ("npt=now-34.12", str);
210   GST_DEBUG ("%s", str);
211   g_free (str);
212   gst_rtsp_range_free (range);
213 
214   fail_unless (gst_rtsp_range_parse ("npt=23,89-now", &range) == GST_RTSP_OK);
215   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
216   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
217   fail_unless (range->min.seconds == 23.89);
218   fail_unless (range->max.type == GST_RTSP_TIME_NOW);
219   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
220   fail_unless (min == 23890000000);
221   fail_unless (max == GST_CLOCK_TIME_NONE);
222   str = gst_rtsp_range_to_string (range);
223   fail_unless_equals_string ("npt=23.89-now", str);
224   GST_DEBUG ("%s", str);
225   g_free (str);
226   gst_rtsp_range_free (range);
227 
228   fail_unless (gst_rtsp_range_parse ("npt=-12.09", &range) == GST_RTSP_OK);
229   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
230   fail_unless (range->min.type == GST_RTSP_TIME_END);
231   fail_unless (range->max.type == GST_RTSP_TIME_SECONDS);
232   fail_unless (range->max.seconds == 12.09);
233   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
234   fail_unless (min == GST_CLOCK_TIME_NONE);
235   fail_unless (max == 12090000000);
236   str = gst_rtsp_range_to_string (range);
237   fail_unless_equals_string ("npt=-12.09", str);
238   GST_DEBUG ("%s", str);
239   g_free (str);
240   gst_rtsp_range_free (range);
241 
242   fail_unless (gst_rtsp_range_parse ("npt=0-", &range) == GST_RTSP_OK);
243   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
244   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
245   fail_unless (range->min.seconds == 0.0);
246   fail_unless (range->max.type == GST_RTSP_TIME_END);
247   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
248   fail_unless (min == 0);
249   fail_unless (max == GST_CLOCK_TIME_NONE);
250   str = gst_rtsp_range_to_string (range);
251   fail_unless_equals_string ("npt=0-", str);
252   GST_DEBUG ("%s", str);
253   g_free (str);
254   gst_rtsp_range_free (range);
255 
256 
257   fail_unless (gst_rtsp_range_parse ("npt=1.123-", &range) == GST_RTSP_OK);
258   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
259   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
260   fail_unless (range->min.seconds == 1.123);
261   fail_unless (range->max.type == GST_RTSP_TIME_END);
262   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
263   fail_unless (min == 1123000000);
264   fail_unless (max == GST_CLOCK_TIME_NONE);
265   str = gst_rtsp_range_to_string (range);
266   fail_unless_equals_string ("npt=1.123-", str);
267   GST_DEBUG ("%s", str);
268   g_free (str);
269   gst_rtsp_range_free (range);
270 
271   fail_unless (gst_rtsp_range_parse ("npt=10,20-20.10", &range) == GST_RTSP_OK);
272   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
273   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
274   fail_unless (range->min.seconds == 10.20);
275   fail_unless (range->max.type == GST_RTSP_TIME_SECONDS);
276   fail_unless (range->max.seconds == 20.10);
277   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
278   fail_unless (min == 10200000000);
279   fail_unless (max == 20100000000);
280   str = gst_rtsp_range_to_string (range);
281   fail_unless_equals_string ("npt=10.2-20.1", str);
282   GST_DEBUG ("%s", str);
283   g_free (str);
284   gst_rtsp_range_free (range);
285 
286   fail_unless (gst_rtsp_range_parse ("npt=500-15.001", &range) == GST_RTSP_OK);
287   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
288   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
289   fail_unless (range->min.seconds == 500);
290   fail_unless (range->max.type == GST_RTSP_TIME_SECONDS);
291   fail_unless (range->max.seconds == 15.001);
292   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
293   fail_unless (min == 500000000000);
294   fail_unless (max == 15001000000);
295   str = gst_rtsp_range_to_string (range);
296   fail_unless_equals_string ("npt=500-15.001", str);
297   GST_DEBUG ("%s", str);
298   g_free (str);
299   gst_rtsp_range_free (range);
300 
301   fail_unless (gst_rtsp_range_parse ("npt=20:34.23-",
302           &range) == GST_RTSP_EINVAL);
303   fail_unless (gst_rtsp_range_parse ("npt=10:20;34.23-",
304           &range) == GST_RTSP_EINVAL);
305   fail_unless (gst_rtsp_range_parse ("npt=0:4.23-", &range) == GST_RTSP_EINVAL);
306 
307   fail_unless (gst_rtsp_range_parse ("npt=20:12:34.23-21:45:00.01",
308           &range) == GST_RTSP_OK);
309   fail_unless (range->unit == GST_RTSP_RANGE_NPT);
310   fail_unless (range->min.type == GST_RTSP_TIME_SECONDS);
311   fail_unless (range->min.seconds == 72754.23);
312   fail_unless (range->max.type == GST_RTSP_TIME_SECONDS);
313   fail_unless (range->max.seconds == 78300.01);
314   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
315   fail_unless (min == 72754230000000);
316   fail_unless (max == 78300010000000);
317   str = gst_rtsp_range_to_string (range);
318   fail_unless_equals_string ("npt=72754.23-78300.01", str);
319   GST_DEBUG ("%s", str);
320   g_free (str);
321   gst_rtsp_range_free (range);
322 }
323 
324 GST_END_TEST;
325 
GST_START_TEST(test_rtsp_range_smpte)326 GST_START_TEST (test_rtsp_range_smpte)
327 {
328   GstClockTime min, max;
329   GstRTSPTimeRange *range;
330   gchar *str;
331 
332   fail_unless (gst_rtsp_range_parse ("smpte=", &range) == GST_RTSP_EINVAL);
333   fail_unless (gst_rtsp_range_parse ("smpte=10:34:23",
334           &range) == GST_RTSP_EINVAL);
335   fail_unless (gst_rtsp_range_parse ("smpte=-", &range) == GST_RTSP_EINVAL);
336   fail_unless (gst_rtsp_range_parse ("smpte=-12:09:34",
337           &range) == GST_RTSP_EINVAL);
338   fail_unless (gst_rtsp_range_parse ("smpte=12:09:34",
339           &range) == GST_RTSP_EINVAL);
340 
341   fail_unless (gst_rtsp_range_parse ("smpte=00:00:00-", &range) == GST_RTSP_OK);
342   fail_unless (range->unit == GST_RTSP_RANGE_SMPTE);
343   fail_unless (range->min.type == GST_RTSP_TIME_FRAMES);
344   fail_unless (range->min.seconds == 0.0);
345   fail_unless (range->min2.frames == 0.0);
346   fail_unless (range->max.type == GST_RTSP_TIME_END);
347   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
348   fail_unless (min == 0);
349   fail_unless (max == GST_CLOCK_TIME_NONE);
350   str = gst_rtsp_range_to_string (range);
351   fail_unless_equals_string ("smpte=0:00:00-", str);
352   GST_DEBUG ("%s", str);
353   g_free (str);
354   gst_rtsp_range_free (range);
355 
356   fail_unless (gst_rtsp_range_parse ("smpte=10:34:23-20:12:09:20.89",
357           &range) == GST_RTSP_OK);
358   fail_unless (range->unit == GST_RTSP_RANGE_SMPTE);
359   fail_unless (range->min.type == GST_RTSP_TIME_FRAMES);
360   fail_unless (range->min.seconds == 38063.0);
361   fail_unless (range->min2.frames == 0.0);
362   fail_unless (range->max.type == GST_RTSP_TIME_FRAMES);
363   fail_unless (range->max.seconds == 72729.0);
364   fail_unless (range->max2.frames == 20.89);
365   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
366   fail_unless (min == 38063000000000);
367   /* 20.89 * GST_SECOND * 1001 / 30003 */
368   fail_unless (max == 72729000000000 + 696959970);
369   str = gst_rtsp_range_to_string (range);
370   fail_unless_equals_string ("smpte=10:34:23-20:12:09:20.89", str);
371   GST_DEBUG ("%s", str);
372   g_free (str);
373   gst_rtsp_range_free (range);
374 
375   fail_unless (gst_rtsp_range_parse ("smpte-25=10:34:23-20:12:09:20.89",
376           &range) == GST_RTSP_OK);
377   fail_unless (range->unit == GST_RTSP_RANGE_SMPTE_25);
378   fail_unless (range->min.type == GST_RTSP_TIME_FRAMES);
379   fail_unless (range->min.seconds == 38063.0);
380   fail_unless (range->min2.frames == 0.0);
381   fail_unless (range->max.type == GST_RTSP_TIME_FRAMES);
382   fail_unless (range->max.seconds == 72729.0);
383   fail_unless (range->max2.frames == 20.89);
384   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
385   fail_unless (min == 38063000000000);
386   GST_DEBUG ("%" GST_TIME_FORMAT, GST_TIME_ARGS (max));
387   /* 20.89 * GST_SECOND * 1 / 25 */
388   fail_unless (max == 72729000000000 + 835600000);
389   str = gst_rtsp_range_to_string (range);
390   GST_DEBUG ("%s", str);
391   fail_unless_equals_string ("smpte-25=10:34:23-20:12:09:20.89", str);
392   g_free (str);
393   gst_rtsp_range_free (range);
394 
395   fail_unless (gst_rtsp_range_parse ("smpte-25=0:00:00:00.01-9:59:59:24.99",
396           &range) == GST_RTSP_OK);
397   fail_unless (range->unit == GST_RTSP_RANGE_SMPTE_25);
398   fail_unless (range->min.type == GST_RTSP_TIME_FRAMES);
399   fail_unless (range->min.seconds == 0);
400   fail_unless (range->min2.frames == 0.01);
401   fail_unless (range->max.type == GST_RTSP_TIME_FRAMES);
402   fail_unless (range->max.seconds == 35999);
403   fail_unless (range->max2.frames == 24.99);
404   fail_unless (gst_rtsp_range_get_times (range, &min, &max));
405   fail_unless (min == 400000);
406   GST_DEBUG ("%" GST_TIME_FORMAT, GST_TIME_ARGS (max));
407   /* 35999 + (24.99/25) */
408   fail_unless (max == 35999999600000);
409   str = gst_rtsp_range_to_string (range);
410   GST_DEBUG ("%s", str);
411   fail_unless_equals_string ("smpte-25=0:00:00:00.01-9:59:59:24.99", str);
412   g_free (str);
413   gst_rtsp_range_free (range);
414 }
415 
416 GST_END_TEST;
417 
GST_START_TEST(test_rtsp_range_clock)418 GST_START_TEST (test_rtsp_range_clock)
419 {
420   GstRTSPTimeRange *range;
421   gchar *str;
422 
423   fail_unless (gst_rtsp_range_parse ("clock=", &range) == GST_RTSP_EINVAL);
424   fail_unless (gst_rtsp_range_parse ("clock=20001010T120023Z",
425           &range) == GST_RTSP_EINVAL);
426   fail_unless (gst_rtsp_range_parse ("clock=-", &range) == GST_RTSP_EINVAL);
427   fail_unless (gst_rtsp_range_parse ("clock=-20001010T120934Z",
428           &range) == GST_RTSP_EINVAL);
429 
430   fail_unless (gst_rtsp_range_parse ("clock=20001010T122345Z-",
431           &range) == GST_RTSP_OK);
432   fail_unless (range->unit == GST_RTSP_RANGE_CLOCK);
433   fail_unless (range->min.type == GST_RTSP_TIME_UTC);
434   fail_unless (range->min2.year == 2000);
435   fail_unless (range->min2.month == 10);
436   fail_unless (range->min2.day == 10);
437   fail_unless (range->min.seconds == 44625.0);
438   fail_unless (range->max.type == GST_RTSP_TIME_END);
439   str = gst_rtsp_range_to_string (range);
440   fail_unless_equals_string ("clock=20001010T122345Z-", str);
441   GST_DEBUG ("%s", str);
442   g_free (str);
443   gst_rtsp_range_free (range);
444 
445   fail_unless (gst_rtsp_range_parse
446       ("clock=19700101T103423Z-30001230T201209.89Z", &range) == GST_RTSP_OK);
447   fail_unless (range->unit == GST_RTSP_RANGE_CLOCK);
448   fail_unless (range->min.type == GST_RTSP_TIME_UTC);
449   fail_unless (range->min2.year == 1970);
450   fail_unless (range->min2.month == 1);
451   fail_unless (range->min2.day == 1);
452   fail_unless (range->min.seconds == 38063.0);
453   fail_unless (range->max.type == GST_RTSP_TIME_UTC);
454   fail_unless (range->max2.year == 3000);
455   fail_unless (range->max2.month == 12);
456   fail_unless (range->max2.day == 30);
457   fail_unless (range->max.seconds == 72729.89);
458   str = gst_rtsp_range_to_string (range);
459   fail_unless_equals_string ("clock=19700101T103423Z-30001230T201209.89Z", str);
460   GST_DEBUG ("%s", str);
461   g_free (str);
462   gst_rtsp_range_free (range);
463 }
464 
465 GST_END_TEST;
466 
467 
GST_START_TEST(test_rtsp_range_convert)468 GST_START_TEST (test_rtsp_range_convert)
469 {
470   GstRTSPTimeRange *range;
471   gchar *str;
472 
473   fail_unless (gst_rtsp_range_parse ("npt=now-100", &range) == GST_RTSP_OK);
474   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
475   fail_unless (!gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
476   fail_unless (!gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
477   str = gst_rtsp_range_to_string (range);
478   fail_unless_equals_string (str, "npt=now-100");
479   g_free (str);
480   gst_rtsp_range_free (range);
481 
482   fail_unless (gst_rtsp_range_parse ("npt=0-100", &range) == GST_RTSP_OK);
483   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
484   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
485   str = gst_rtsp_range_to_string (range);
486   fail_unless_equals_string (str, "npt=0-100");
487   g_free (str);
488   gst_rtsp_range_free (range);
489 
490   fail_unless (gst_rtsp_range_parse ("npt=0-100", &range) == GST_RTSP_OK);
491   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE_25));
492   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
493   str = gst_rtsp_range_to_string (range);
494   fail_unless_equals_string (str, "npt=0-100");
495   g_free (str);
496   gst_rtsp_range_free (range);
497 
498   fail_unless (gst_rtsp_range_parse ("npt=0-100", &range) == GST_RTSP_OK);
499   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
500   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
501   str = gst_rtsp_range_to_string (range);
502   fail_unless_equals_string (str, "npt=0-100");
503   g_free (str);
504   gst_rtsp_range_free (range);
505 
506   fail_unless (gst_rtsp_range_parse ("smpte-25=10:07:00-10:07:33:05.01", &range)
507       == GST_RTSP_OK);
508   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
509   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE_25));
510   str = gst_rtsp_range_to_string (range);
511   fail_unless_equals_string (str, "smpte-25=10:07:00-10:07:33:05.01");
512   g_free (str);
513   gst_rtsp_range_free (range);
514 
515   fail_unless (gst_rtsp_range_parse ("smpte=77:07:59-", &range)
516       == GST_RTSP_OK);
517   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
518   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
519   str = gst_rtsp_range_to_string (range);
520   fail_unless_equals_string (str, "smpte=77:07:59-");
521   g_free (str);
522   gst_rtsp_range_free (range);
523 
524   fail_unless (gst_rtsp_range_parse ("smpte=10:07:00-10:07:33:05.01", &range)
525       == GST_RTSP_OK);
526   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
527   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
528   str = gst_rtsp_range_to_string (range);
529   fail_unless_equals_string (str, "smpte=10:07:00-10:07:33:05.01");
530   g_free (str);
531   gst_rtsp_range_free (range);
532 
533   fail_unless (gst_rtsp_range_parse ("smpte-25=10:07:00-10:07:33:05.01", &range)
534       == GST_RTSP_OK);
535   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
536   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE_25));
537   str = gst_rtsp_range_to_string (range);
538   fail_unless_equals_string (str, "smpte-25=10:07:00-10:07:33:05.01");
539   g_free (str);
540   gst_rtsp_range_free (range);
541 
542   fail_unless (gst_rtsp_range_parse ("smpte=10:07:00-10:07:33:05.01", &range)
543       == GST_RTSP_OK);
544   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
545   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
546   str = gst_rtsp_range_to_string (range);
547   fail_unless_equals_string (str, "smpte=10:07:00-10:07:33:05.01");
548   g_free (str);
549   gst_rtsp_range_free (range);
550 
551   fail_unless (gst_rtsp_range_parse
552       ("clock=20001010T120023Z-20320518T152245.12Z", &range)
553       == GST_RTSP_OK);
554   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_NPT));
555   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
556   str = gst_rtsp_range_to_string (range);
557   fail_unless_equals_string (str, "clock=20001010T120023Z-20320518T152245.12Z");
558   g_free (str);
559   gst_rtsp_range_free (range);
560 
561   fail_unless (gst_rtsp_range_parse
562       ("clock=20001010T120023Z-20320518T152245.12Z", &range)
563       == GST_RTSP_OK);
564   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_SMPTE));
565   fail_unless (gst_rtsp_range_convert_units (range, GST_RTSP_RANGE_CLOCK));
566   str = gst_rtsp_range_to_string (range);
567   fail_unless_equals_string (str, "clock=20001010T120023Z-20320518T152245.12Z");
568   g_free (str);
569   gst_rtsp_range_free (range);
570 }
571 
572 GST_END_TEST;
573 
GST_START_TEST(test_rtsp_message)574 GST_START_TEST (test_rtsp_message)
575 {
576   GstRTSPMessage *msg;
577   GstRTSPResult res;
578   gchar *val = NULL;
579 
580   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
581       "rtsp://foo.bar:8554/test");
582   fail_unless_equals_int (res, GST_RTSP_OK);
583 
584   res = gst_rtsp_message_add_header (msg, GST_RTSP_HDR_CSEQ, "3");
585   fail_unless_equals_int (res, GST_RTSP_OK);
586   res = gst_rtsp_message_add_header (msg, GST_RTSP_HDR_SERVER, "GStreamer");
587   fail_unless_equals_int (res, GST_RTSP_OK);
588   res = gst_rtsp_message_add_header (msg, GST_RTSP_HDR_TRANSPORT,
589       "RTP/AVP/TCP;unicast;interleaved=0-1");
590   fail_unless_equals_int (res, GST_RTSP_OK);
591   res = gst_rtsp_message_add_header (msg, GST_RTSP_HDR_SESSION, "xnb_NpaKEc");
592   fail_unless_equals_int (res, GST_RTSP_OK);
593 
594   res = gst_rtsp_message_add_header_by_name (msg, "FOO99-Version", "bar.0");
595   fail_unless_equals_int (res, GST_RTSP_OK);
596   res = gst_rtsp_message_add_header_by_name (msg, "Custom", "value");
597   fail_unless_equals_int (res, GST_RTSP_OK);
598   res = gst_rtsp_message_add_header_by_name (msg, "FOO99-Version", "bar.1");
599   fail_unless_equals_int (res, GST_RTSP_OK);
600   res = gst_rtsp_message_add_header_by_name (msg, "FOO99-Version", "bar.2");
601   fail_unless_equals_int (res, GST_RTSP_OK);
602 
603   /* make sure fields added via enum work as well */
604   res = gst_rtsp_message_get_header_by_name (msg, "CSeq", &val, 0);
605   fail_unless_equals_int (res, GST_RTSP_OK);
606   fail_unless_equals_string (val, "3");
607   res = gst_rtsp_message_get_header_by_name (msg, "CSeq", &val, 1);
608   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
609 
610   res = gst_rtsp_message_get_header (msg, GST_RTSP_HDR_CSEQ, &val, 0);
611   fail_unless_equals_int (res, GST_RTSP_OK);
612   fail_unless_equals_string (val, "3");
613   res = gst_rtsp_message_get_header (msg, GST_RTSP_HDR_CSEQ, &val, 1);
614   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
615 
616   res = gst_rtsp_message_get_header_by_name (msg, "DoesNotExist", &val, 0);
617   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
618 
619   res = gst_rtsp_message_get_header_by_name (msg, "Custom", &val, 1);
620   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
621   res = gst_rtsp_message_get_header_by_name (msg, "Custom", &val, 0);
622   fail_unless_equals_int (res, GST_RTSP_OK);
623   fail_unless_equals_string (val, "value");
624 
625   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 3);
626   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
627   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 1);
628   fail_unless_equals_int (res, GST_RTSP_OK);
629   fail_unless_equals_string (val, "bar.1");
630   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 2);
631   fail_unless_equals_int (res, GST_RTSP_OK);
632   fail_unless_equals_string (val, "bar.2");
633   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 0);
634   fail_unless_equals_int (res, GST_RTSP_OK);
635   fail_unless_equals_string (val, "bar.0");
636 
637   res = gst_rtsp_message_remove_header_by_name (msg, "FOO99-Version", 3);
638   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
639   res = gst_rtsp_message_remove_header_by_name (msg, "FOO99-Version", 1);
640   fail_unless_equals_int (res, GST_RTSP_OK);
641 
642   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 2);
643   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
644 
645   /* 2 shifted to position 1 */
646   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 1);
647   fail_unless_equals_int (res, GST_RTSP_OK);
648   fail_unless_equals_string (val, "bar.2");
649   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 0);
650   fail_unless_equals_int (res, GST_RTSP_OK);
651   fail_unless_equals_string (val, "bar.0");
652 
653   /* remove all headers for a name */
654   res = gst_rtsp_message_remove_header_by_name (msg, "FOO99-Version", -1);
655   fail_unless_equals_int (res, GST_RTSP_OK);
656   res = gst_rtsp_message_get_header_by_name (msg, "FOO99-Version", &val, 0);
657   fail_unless_equals_int (res, GST_RTSP_ENOTIMPL);
658 
659   /* gst_rtsp_message_dump (msg); */
660 
661   res = gst_rtsp_message_free (msg);
662   fail_unless_equals_int (res, GST_RTSP_OK);
663 
664   /* === */
665 
666   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
667       "rtsp://foo.bar:8554/test");
668   fail_unless_equals_int (res, GST_RTSP_OK);
669 
670   res = gst_rtsp_message_add_header_by_name (msg, "CSeq", "3");
671   fail_unless_equals_int (res, GST_RTSP_OK);
672 
673   res = gst_rtsp_message_get_header (msg, GST_RTSP_HDR_CSEQ, &val, 0);
674   fail_unless_equals_int (res, GST_RTSP_OK);
675   fail_unless_equals_string (val, "3");
676 
677   val = NULL;
678   res = gst_rtsp_message_get_header_by_name (msg, "cseq", &val, 0);
679   fail_unless_equals_int (res, GST_RTSP_OK);
680   fail_unless_equals_string (val, "3");
681 
682   res = gst_rtsp_message_free (msg);
683   fail_unless_equals_int (res, GST_RTSP_OK);
684 }
685 
686 GST_END_TEST;
687 
GST_START_TEST(test_rtsp_message_auth_credentials)688 GST_START_TEST (test_rtsp_message_auth_credentials)
689 {
690   GstRTSPMessage *msg;
691   GstRTSPResult res;
692   GstRTSPAuthCredential **credentials;
693   GstRTSPAuthCredential **credential;
694   GstRTSPAuthParam **param;
695 
696   /* Simple basic auth, no params */
697   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
698       "rtsp://foo.bar:8554/test");
699   fail_unless_equals_int (res, GST_RTSP_OK);
700   res =
701       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE, "Basic");
702   credentials =
703       gst_rtsp_message_parse_auth_credentials (msg,
704       GST_RTSP_HDR_WWW_AUTHENTICATE);
705   fail_unless (credentials != NULL);
706 
707   credential = credentials;
708   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
709   param = (*credential)->params;
710   fail_unless (param == NULL);
711   credential++;
712   fail_unless (*credential == NULL);
713 
714   gst_rtsp_auth_credentials_free (credentials);
715   res = gst_rtsp_message_free (msg);
716   fail_unless_equals_int (res, GST_RTSP_OK);
717 
718   /* Simple basic auth, digest auth, no params */
719   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
720       "rtsp://foo.bar:8554/test");
721   fail_unless_equals_int (res, GST_RTSP_OK);
722   res =
723       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
724       "Basic Digest");
725   credentials =
726       gst_rtsp_message_parse_auth_credentials (msg,
727       GST_RTSP_HDR_WWW_AUTHENTICATE);
728   fail_unless (credentials != NULL);
729 
730   credential = credentials;
731   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
732   param = (*credential)->params;
733   fail_unless (param == NULL);
734   credential++;
735   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_DIGEST);
736   param = (*credential)->params;
737   fail_unless (param == NULL);
738   credential++;
739   fail_unless (*credential == NULL);
740 
741   gst_rtsp_auth_credentials_free (credentials);
742   res = gst_rtsp_message_free (msg);
743   fail_unless_equals_int (res, GST_RTSP_OK);
744 
745   /* Simple basic auth */
746   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
747       "rtsp://foo.bar:8554/test");
748   fail_unless_equals_int (res, GST_RTSP_OK);
749   res =
750       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
751       "Basic foo=\"bar\", baz=foo");
752   credentials =
753       gst_rtsp_message_parse_auth_credentials (msg,
754       GST_RTSP_HDR_WWW_AUTHENTICATE);
755   fail_unless (credentials != NULL);
756 
757   credential = credentials;
758   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
759   param = (*credential)->params;
760   fail_unless (param != NULL);
761   fail_unless (*param != NULL);
762   fail_unless_equals_string ((*param)->name, "foo");
763   fail_unless_equals_string ((*param)->value, "bar");
764   param++;
765   fail_unless (*param != NULL);
766   fail_unless_equals_string ((*param)->name, "baz");
767   fail_unless_equals_string ((*param)->value, "foo");
768   param++;
769   fail_unless (*param == NULL);
770   credential++;
771   fail_unless (*credential == NULL);
772 
773   gst_rtsp_auth_credentials_free (credentials);
774   res = gst_rtsp_message_free (msg);
775   fail_unless_equals_int (res, GST_RTSP_OK);
776 
777   /* Two simple basic auth headers */
778   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
779       "rtsp://foo.bar:8554/test");
780   fail_unless_equals_int (res, GST_RTSP_OK);
781   res =
782       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
783       "Basic foo=\"bar\", baz=foo");
784   res =
785       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
786       "Basic foo1=\"bar\", baz1=foo");
787   credentials =
788       gst_rtsp_message_parse_auth_credentials (msg,
789       GST_RTSP_HDR_WWW_AUTHENTICATE);
790   fail_unless (credentials != NULL);
791 
792   credential = credentials;
793   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
794   param = (*credential)->params;
795   fail_unless (param != NULL);
796   fail_unless (*param != NULL);
797   fail_unless_equals_string ((*param)->name, "foo");
798   fail_unless_equals_string ((*param)->value, "bar");
799   param++;
800   fail_unless (*param != NULL);
801   fail_unless_equals_string ((*param)->name, "baz");
802   fail_unless_equals_string ((*param)->value, "foo");
803   param++;
804   fail_unless (*param == NULL);
805   credential++;
806   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
807   param = (*credential)->params;
808   fail_unless (param != NULL);
809   fail_unless (*param != NULL);
810   fail_unless_equals_string ((*param)->name, "foo1");
811   fail_unless_equals_string ((*param)->value, "bar");
812   param++;
813   fail_unless (*param != NULL);
814   fail_unless_equals_string ((*param)->name, "baz1");
815   fail_unless_equals_string ((*param)->value, "foo");
816   param++;
817   fail_unless (*param == NULL);
818   credential++;
819   fail_unless (*credential == NULL);
820 
821   gst_rtsp_auth_credentials_free (credentials);
822   res = gst_rtsp_message_free (msg);
823   fail_unless_equals_int (res, GST_RTSP_OK);
824 
825   /* Simple basic auth, digest auth in one header */
826   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
827       "rtsp://foo.bar:8554/test");
828   fail_unless_equals_int (res, GST_RTSP_OK);
829   res =
830       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
831       "Basic foo=\"bar\", baz=foo Digest foo1=\"bar\", baz1=foo");
832   credentials =
833       gst_rtsp_message_parse_auth_credentials (msg,
834       GST_RTSP_HDR_WWW_AUTHENTICATE);
835   fail_unless (credentials != NULL);
836 
837   credential = credentials;
838   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
839   param = (*credential)->params;
840   fail_unless (param != NULL);
841   fail_unless (*param != NULL);
842   fail_unless_equals_string ((*param)->name, "foo");
843   fail_unless_equals_string ((*param)->value, "bar");
844   param++;
845   fail_unless (*param != NULL);
846   fail_unless_equals_string ((*param)->name, "baz");
847   fail_unless_equals_string ((*param)->value, "foo");
848   param++;
849   fail_unless (*param == NULL);
850   credential++;
851   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_DIGEST);
852   param = (*credential)->params;
853   fail_unless (param != NULL);
854   fail_unless (*param != NULL);
855   fail_unless_equals_string ((*param)->name, "foo1");
856   fail_unless_equals_string ((*param)->value, "bar");
857   param++;
858   fail_unless (*param != NULL);
859   fail_unless_equals_string ((*param)->name, "baz1");
860   fail_unless_equals_string ((*param)->value, "foo");
861   param++;
862   fail_unless (*param == NULL);
863   credential++;
864   fail_unless (*credential == NULL);
865 
866   gst_rtsp_auth_credentials_free (credentials);
867   res = gst_rtsp_message_free (msg);
868   fail_unless_equals_int (res, GST_RTSP_OK);
869 
870   /* Simple basic auth, digest auth in one header, with random commas and spaces */
871   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
872       "rtsp://foo.bar:8554/test");
873   fail_unless_equals_int (res, GST_RTSP_OK);
874   res =
875       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
876       "Basic     foo=\"bar\",, , baz=foo, Digest , foo1=\"bar\",, baz1=foo");
877   credentials =
878       gst_rtsp_message_parse_auth_credentials (msg,
879       GST_RTSP_HDR_WWW_AUTHENTICATE);
880   fail_unless (credentials != NULL);
881 
882   credential = credentials;
883   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
884   param = (*credential)->params;
885   fail_unless (param != NULL);
886   fail_unless (*param != NULL);
887   fail_unless_equals_string ((*param)->name, "foo");
888   fail_unless_equals_string ((*param)->value, "bar");
889   param++;
890   fail_unless (*param != NULL);
891   fail_unless_equals_string ((*param)->name, "baz");
892   fail_unless_equals_string ((*param)->value, "foo");
893   param++;
894   fail_unless (*param == NULL);
895   credential++;
896   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_DIGEST);
897   param = (*credential)->params;
898   fail_unless (param != NULL);
899   fail_unless (*param != NULL);
900   fail_unless_equals_string ((*param)->name, "foo1");
901   fail_unless_equals_string ((*param)->value, "bar");
902   param++;
903   fail_unless (*param != NULL);
904   fail_unless_equals_string ((*param)->name, "baz1");
905   fail_unless_equals_string ((*param)->value, "foo");
906   param++;
907   fail_unless (*param == NULL);
908   credential++;
909   fail_unless (*credential == NULL);
910 
911   gst_rtsp_auth_credentials_free (credentials);
912   res = gst_rtsp_message_free (msg);
913   fail_unless_equals_int (res, GST_RTSP_OK);
914 
915   /* Simple basic auth */
916   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
917       "rtsp://foo.bar:8554/test");
918   fail_unless_equals_int (res, GST_RTSP_OK);
919   res =
920       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_AUTHORIZATION,
921       "Basic foobarbaz");
922   credentials =
923       gst_rtsp_message_parse_auth_credentials (msg, GST_RTSP_HDR_AUTHORIZATION);
924   fail_unless (credentials != NULL);
925 
926   credential = credentials;
927   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_BASIC);
928   param = (*credential)->params;
929   fail_unless (param == NULL);
930   fail_unless_equals_string ((*credential)->authorization, "foobarbaz");
931   credential++;
932   fail_unless (*credential == NULL);
933 
934   gst_rtsp_auth_credentials_free (credentials);
935   res = gst_rtsp_message_free (msg);
936   fail_unless_equals_int (res, GST_RTSP_OK);
937 
938   /* Simple digest auth */
939   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
940       "rtsp://foo.bar:8554/test");
941   fail_unless_equals_int (res, GST_RTSP_OK);
942   res =
943       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_AUTHORIZATION,
944       "Digest foo=\"bar\" baz=foo");
945   credentials =
946       gst_rtsp_message_parse_auth_credentials (msg, GST_RTSP_HDR_AUTHORIZATION);
947   fail_unless (credentials != NULL);
948 
949   credential = credentials;
950   fail_unless_equals_int ((*credential)->scheme, GST_RTSP_AUTH_DIGEST);
951   param = (*credential)->params;
952   fail_unless (param != NULL);
953   fail_unless (*param != NULL);
954   fail_unless_equals_string ((*param)->name, "foo");
955   fail_unless_equals_string ((*param)->value, "bar");
956   param++;
957   fail_unless (*param != NULL);
958   fail_unless_equals_string ((*param)->name, "baz");
959   fail_unless_equals_string ((*param)->value, "foo");
960   param++;
961   fail_unless (*param == NULL);
962   credential++;
963   fail_unless (*credential == NULL);
964 
965   gst_rtsp_auth_credentials_free (credentials);
966   res = gst_rtsp_message_free (msg);
967   fail_unless_equals_int (res, GST_RTSP_OK);
968 }
969 
970 GST_END_TEST;
971 
GST_START_TEST(test_rtsp_message_auth_credentials_boxed)972 GST_START_TEST (test_rtsp_message_auth_credentials_boxed)
973 {
974   GstRTSPAuthCredential **credentials, *credentials2;
975   GstRTSPAuthParam *param2;
976   GstRTSPMessage *msg;
977   GstRTSPResult res;
978 
979   res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
980       "rtsp://foo.bar:8554/test");
981   fail_unless_equals_int (res, GST_RTSP_OK);
982   res =
983       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
984       "Basic foo=\"bar\", baz=foo");
985   res =
986       gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
987       "Basic foo1=\"bar\", baz1=foo");
988   credentials =
989       gst_rtsp_message_parse_auth_credentials (msg,
990       GST_RTSP_HDR_WWW_AUTHENTICATE);
991 
992   credentials2 = g_boxed_copy (GST_TYPE_RTSP_AUTH_CREDENTIAL, credentials[0]);
993   gst_rtsp_auth_credentials_free (credentials);
994   gst_rtsp_message_free (msg);
995 
996   param2 = g_boxed_copy (GST_TYPE_RTSP_AUTH_PARAM, credentials2->params[0]);
997   g_boxed_free (GST_TYPE_RTSP_AUTH_CREDENTIAL, credentials2);
998   g_boxed_free (GST_TYPE_RTSP_AUTH_PARAM, param2);
999 }
1000 
1001 GST_END_TEST;
1002 
1003 static Suite *
rtsp_suite(void)1004 rtsp_suite (void)
1005 {
1006   Suite *s = suite_create ("rtsp support library");
1007   TCase *tc_chain = tcase_create ("general");
1008 
1009   suite_add_tcase (s, tc_chain);
1010   tcase_add_test (tc_chain, test_rtsp_url_basic);
1011   tcase_add_test (tc_chain, test_rtsp_url_query);
1012   tcase_add_test (tc_chain, test_rtsp_url_components_1);
1013   tcase_add_test (tc_chain, test_rtsp_url_components_2);
1014   tcase_add_test (tc_chain, test_rtsp_url_components_3);
1015   tcase_add_test (tc_chain, test_rtsp_range_npt);
1016   tcase_add_test (tc_chain, test_rtsp_range_smpte);
1017   tcase_add_test (tc_chain, test_rtsp_range_clock);
1018   tcase_add_test (tc_chain, test_rtsp_range_convert);
1019   tcase_add_test (tc_chain, test_rtsp_message);
1020   tcase_add_test (tc_chain, test_rtsp_message_auth_credentials);
1021   tcase_add_test (tc_chain, test_rtsp_message_auth_credentials_boxed);
1022 
1023   return s;
1024 }
1025 
1026 GST_CHECK_MAIN (rtsp);
1027