]> git.sesse.net Git - vlc/commitdiff
Add a test about chain escaping escaping.
authorRémi Duraffort <ivoire@videolan.org>
Tue, 31 Aug 2010 19:51:02 +0000 (21:51 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Tue, 31 Aug 2010 19:58:42 +0000 (21:58 +0200)
test/Makefile.am
test/src/config/chain.c [new file with mode: 0644]

index 0b11a9bbac6de4948bd2e217b4af1bea4f9f39b3..e88f78c35ea11c4e565fb8c1f0cb6fa32f421e47 100644 (file)
@@ -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 (file)
index 0000000..531e60b
--- /dev/null
@@ -0,0 +1,79 @@
+/*****************************************************************************
+ * chain.c: test configuration chains
+ *****************************************************************************
+ * Copyright (C) 2010 VideoLAN and authors
+ * $Id$
+ *
+ * Authors: Rémi Duraffort <ivoire@videolan.org>
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+
+#include "../../libvlc/test.h"
+
+#include <vlc_common.h>
+#include <vlc_configuration.h>
+
+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();
+}