]> git.sesse.net Git - vlc/blob - test/src/config/chain.c
test_src_config_chain: fix missing return value.
[vlc] / test / src / config / chain.c
1 /*****************************************************************************
2  * chain.c: test configuration chains
3  *****************************************************************************
4  * Copyright (C) 2010 VideoLAN and authors
5  * $Id$
6  *
7  * Authors: RĂ©mi Duraffort <ivoire@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "../../libvlc/test.h"
28
29 #include <vlc_common.h>
30 #include <vlc_configuration.h>
31
32 typedef struct
33 {
34     const char *psz_string;
35     const char *psz_escaped;
36 }sample_t;
37
38 static const sample_t samples[] =
39 {
40     { "a",          "a" },
41     { "azertyuiop", "azertyuiop"    },
42     { "  test    ", "  test    "    },
43     { "it's",       "it\\'s"        },
44     { "''''",       "\\'\\'\\'\\'"  },
45     { "' a '",      "\\' a \\'"     },
46     { "\"quote\"",  "\\\"quote\\\"" },
47     { " az\" ",     " az\\\" "      },
48     { "\\test",     "\\\\test"      },
49     { NULL,   NULL }
50 };
51
52 static void test_config_StringEscape()
53 {
54     for( int i = 0; samples[i].psz_string; i++ )
55     {
56         char *psz_tmp = config_StringEscape( samples[i].psz_string );
57         assert( !strcmp( psz_tmp, samples[i].psz_escaped ) );
58         free( psz_tmp );
59     }
60 }
61
62 static void test_config_StringUnEscape()
63 {
64     for( int i =0; samples[i].psz_string; i++ )
65     {
66         char *psz_tmp = strdup( samples[i].psz_escaped );
67         config_StringUnescape( psz_tmp );
68         assert( !strcmp( psz_tmp, samples[i].psz_string ) );
69         free( psz_tmp );
70     }
71 }
72
73 int main( void )
74 {
75     log( "Testing config chain escaping\n" );
76     test_config_StringEscape();
77     log( "Testing config chain un-escaping\n" );
78     test_config_StringUnEscape();
79
80     return 0;
81 }