From: Rémi Duraffort Date: Tue, 31 Aug 2010 19:51:02 +0000 (+0200) Subject: Add a test about chain escaping escaping. X-Git-Tag: 1.2.0-pre1~5343 X-Git-Url: https://git.sesse.net/?p=vlc;a=commitdiff_plain;h=2d268697cdb889a102c580e12e1e1fdfd8f9db6b Add a test about chain escaping escaping. --- diff --git a/test/Makefile.am b/test/Makefile.am index 0b11a9bbac..e88f78c35e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -18,6 +18,7 @@ check_PROGRAMS = \ test_libvlc_media \ test_libvlc_media_list \ test_libvlc_media_player \ + test_src_config_chain \ test_src_misc_variables \ $(NULL) @@ -91,6 +92,11 @@ test_src_misc_variables_LDADD = $(top_builddir)/src/libvlc.la test_src_misc_variables_CFLAGS = $(CFLAGS_tests) test_src_misc_variables_LDFLAGS = $(LDFLAGS_tests) +test_src_config_chain_SOURCES = src/config/chain.c +test_src_config_chain_LDADD = $(top_builddir)/src/libvlc.la +test_src_config_chain_CFLAGS = $(CFLAGS_tests) +test_src_config_chain_LDFLAGS = $(LDFLAGS_tests) + checkall: $(MAKE) check_PROGRAMS="$(check_PROGRAMS) $(EXTRA_PROGRAMS)" check diff --git a/test/src/config/chain.c b/test/src/config/chain.c new file mode 100644 index 0000000000..531e60bce8 --- /dev/null +++ b/test/src/config/chain.c @@ -0,0 +1,79 @@ +/***************************************************************************** + * chain.c: test configuration chains + ***************************************************************************** + * Copyright (C) 2010 VideoLAN and authors + * $Id$ + * + * Authors: Rémi Duraffort + * + * 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 +#include + +#include "../../libvlc/test.h" + +#include +#include + +typedef struct +{ + const char *psz_string; + const char *psz_escaped; +}sample_t; + +static const sample_t samples[] = +{ + { "a", "a" }, + { "azertyuiop", "azertyuiop" }, + { " test ", " test " }, + { "it's", "it\\'s" }, + { "''''", "\\'\\'\\'\\'" }, + { "' a '", "\\' a \\'" }, + { "\"quote\"", "\\\"quote\\\"" }, + { " az\" ", " az\\\" " }, + { "\\test", "\\\\test" }, + { NULL, NULL } +}; + +static void test_config_StringEscape() +{ + for( int i = 0; samples[i].psz_string; i++ ) + { + char *psz_tmp = config_StringEscape( samples[i].psz_string ); + assert( !strcmp( psz_tmp, samples[i].psz_escaped ) ); + free( psz_tmp ); + } +} + +static void test_config_StringUnEscape() +{ + for( int i =0; samples[i].psz_string; i++ ) + { + char *psz_tmp = strdup( samples[i].psz_escaped ); + config_StringUnescape( psz_tmp ); + assert( !strcmp( psz_tmp, samples[i].psz_string ) ); + free( psz_tmp ); + } +} + +int main( void ) +{ + log( "Testing config chain escaping\n" ); + test_config_StringEscape(); + log( "Testing config chain un-escaping\n" ); + test_config_StringUnEscape(); +}