demux: adaptive: fix cancellation during refresh playlist
[vlc.git] / src / test / mrl_helpers.c
blob3439116fecf12a56ae6eb4b915ae99a1d43c4b35
1 /*****************************************************************************
2 * mrl_helpers.c: test src/input/mrl_helpers.h
3 *****************************************************************************
4 * Copyright (C) 2016 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
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 Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <stdio.h>
26 #include <string.h>
27 #undef NDEBUG
28 #include <assert.h>
30 #include <vlc_common.h>
31 #include "../input/mrl_helpers.h"
33 #define MAX_RESULT 10
35 static const struct {
36 const char *payload;
37 const char *results[MAX_RESULT];
38 const char *extra;
39 bool success;
40 } testcase[] = {
41 /* successful tests: */
42 { "!/hello.zip!/goodbye.rar",
43 { "hello.zip", "goodbye.rar" }, NULL, true },
45 { "!/hello.zip!/goodbye.rar?t=0&s=0",
46 { "hello.zip", "goodbye.rar" }, "t=0&s=0", true },
48 { "!/hello.zip!/goodbye.rar?",
49 { "hello.zip", "goodbye.rar" }, "", true },
51 { "!/he%20%25""llo.zip!/good%2520bye.rar",
52 { "he %llo.zip", "good%20bye.rar" }, NULL, true },
54 { "",
55 {}, NULL, true },
57 { "?extra",
58 {}, "?extra", true },
60 /* failing tests: */
62 { "!/he!llo.zip!/goodbye.rar",
63 {}, NULL, false },
65 { "!/hello.zip!/!",
66 {}, NULL, false },
69 int main (void)
71 for (size_t i = 0; i < ARRAY_SIZE(testcase); ++i)
73 vlc_array_t out;
74 const char *extra = NULL;
75 int ret = mrl_FragmentSplit(&out, &extra, testcase[i].payload);
76 if (testcase[i].success)
78 assert(ret == VLC_SUCCESS);
79 if (extra != NULL)
80 assert(strcmp(extra, testcase[i].extra) == 0);
81 else
82 assert(testcase[i].extra == NULL);
84 const char *p = testcase[i].payload + 2;
85 for (size_t j = 0; testcase[i].results[j] != NULL; ++j)
87 assert(j < vlc_array_count(&out) && j < MAX_RESULT);
88 char *res = vlc_array_item_at_index(&out, j);
90 assert(strcmp(testcase[i].results[j], res) == 0);
92 char *res_escaped = NULL;
93 ret = mrl_EscapeFragmentIdentifier(&res_escaped, res);
94 assert(ret == VLC_SUCCESS && res_escaped != NULL);
95 assert(strncmp(p, res_escaped, strlen(res_escaped)) == 0);
96 p += strlen(res_escaped) + 2;
98 free(res_escaped);
99 free(res);
101 vlc_array_clear(&out);
103 else
105 assert(ret != VLC_SUCCESS);
108 return 0;