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 *****************************************************************************/
30 #include <vlc_common.h>
31 #include "../input/mrl_helpers.h"
37 const char *results
[MAX_RESULT
];
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 },
62 { "!/he!llo.zip!/goodbye.rar",
71 for (size_t i
= 0; i
< ARRAY_SIZE(testcase
); ++i
)
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
);
80 assert(strcmp(extra
, testcase
[i
].extra
) == 0);
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;
101 vlc_array_clear(&out
);
105 assert(ret
!= VLC_SUCCESS
);