url.c 2.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*****************************************************************************
 * url.c: Test for url encoding/decoding stuff
 *****************************************************************************
 * Copyright (C) 2006 Rémi Denis-Courmont
 * $Id$
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#include <vlc/vlc.h>
#include "vlc_url.h"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
24
#include "vlc_strings.h"
25

26
27
28
#include <stdio.h>
#include <stdlib.h>

29
30
31
typedef char * (*conv_t) (const char *);

static void test (conv_t f, const char *in, const char *out)
32
33
34
35
{
    char *res;

    printf ("\"%s\" -> \"%s\" ?\n", in, out);
36
    res = f (in);
37
38
39
40
    if (res == NULL)
        exit (1);

    if (strcmp (res, out))
41
42
    {
        printf (" ERROR: got \"%s\"\n", res);
43
        exit (2);
44
    }
45
46
47

    free (res);
}
48

49
50
51
52
53
54
55
56
57
58
static inline void test_decode (const char *in, const char *out)
{
    test (decode_URI_duplicate, in, out);
}

static inline void test_b64 (const char *in, const char *out)
{
    test (vlc_b64_encode, in, out);
}

59
60
int main (void)
{
61
62
63
64
65
66
67
68
69
70
    (void)setvbuf (stdout, NULL, _IONBF, 0);
    test_decode ("this_should_not_be_modified_1234",
                 "this_should_not_be_modified_1234");

    test_decode ("This+should+be+modified+1234!",
                 "This should be modified 1234!");

    test_decode ("This%20should%20be%20modified%201234!",
                 "This should be modified 1234!");

Rémi Denis-Courmont's avatar
Lalala    
Rémi Denis-Courmont committed
71
72
    test_decode ("%7E", "~");

73
74
75
76
77
78
    /* tests with invalid input */
    test_decode ("%", "%");
    test_decode ("%2", "%2");
    test_decode ("%0000", "");

    /* UTF-8 tests */
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
79
    test_decode ("T%C3%a9l%c3%A9vision+%e2%82%Ac", "Télévision €");
80
    test_decode ("T%E9l%E9vision", "T?l?vision");
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
81
    test_decode ("%C1%94%C3%a9l%c3%A9vision", "??élévision"); /* overlong */
82

83
84
    /* Base 64 tests */
    test_b64 ("", "");
85
86
87
88
89
90
    test_b64 ("f", "Zg==");
    test_b64 ("fo", "Zm8=");
    test_b64 ("foo", "Zm9v");
    test_b64 ("foob", "Zm9vYg==");
    test_b64 ("fooba", "Zm9vYmE=");
    test_b64 ("foobar", "Zm9vYmFy");
91

92
93
    return 0;
}