[vlc-commits] test: test filename comparison

Rémi Denis-Courmont git at videolan.org
Sun Jul 23 11:14:04 CEST 2017


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 23 12:13:46 2017 +0300| [6932aa500b6926e650d27cfad0e4a9b9b892392e] | committer: Rémi Denis-Courmont

test: test filename comparison

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6932aa500b6926e650d27cfad0e4a9b9b892392e
---

 src/Makefile.am |  2 ++
 src/test/sort.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/src/Makefile.am b/src/Makefile.am
index 6b661a655d..fac26a3d72 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -506,6 +506,7 @@ check_PROGRAMS = \
 	test_interrupt \
 	test_md5 \
 	test_picture_pool \
+	test_sort \
 	test_timer \
 	test_url \
 	test_utf8 \
@@ -525,6 +526,7 @@ test_interrupt_SOURCES = test/interrupt.c
 test_interrupt_LDADD = $(LDADD) $(LIBS_libvlccore) $(LIBPTHREAD)
 test_md5_SOURCES = test/md5.c
 test_picture_pool_SOURCES = test/picture_pool.c
+test_sort_SOURCES = test/sort.c
 test_timer_SOURCES = test/timer.c
 test_url_SOURCES = test/url.c
 test_utf8_SOURCES = test/utf8.c
diff --git a/src/test/sort.c b/src/test/sort.c
new file mode 100644
index 0000000000..0b9fcdae30
--- /dev/null
+++ b/src/test/sort.c
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * sort.c: Test for sorting
+ *****************************************************************************
+ * Copyright (C) 2017 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <vlc_common.h>
+#include <vlc_strings.h>
+
+static void test_smaller(const char *small, const char *big,
+                         int (*cmp)(const char *, const char *))
+{
+    int ret = cmp(small, big);
+    if (ret >= 0) {
+        fprintf(stderr, "Failure: \"%s\" %s \"%s\"\n",
+                small, ret ? ">" : "==", big);
+        exit(1);
+    }
+}
+
+static void test_equal(const char *s, int (*cmp)(const char *, const char *))
+{
+    int ret = cmp(s, s);
+    if (ret != 0) {
+        fprintf(stderr, "Failure: \"%s\" %s \"%s\"\n",
+                s, (ret < 0) ? "<" : ">", s);
+        exit(1);
+    }
+}
+
+
+int main (void)
+{
+    test_smaller("", "a", vlc_filenamecmp);
+    test_smaller("a", "b", vlc_filenamecmp);
+    test_smaller("foo1.ogg", "foo2.ogg", vlc_filenamecmp);
+    test_smaller("foo2.ogg", "foo10.ogg", vlc_filenamecmp);
+    test_smaller("foo1.ogg", "foo10.ogg", vlc_filenamecmp);
+    test_smaller("foo01.ogg", "foo1.ogg", vlc_filenamecmp);
+    test_equal("", vlc_filenamecmp);
+    test_equal("a", vlc_filenamecmp);
+    test_equal("123", vlc_filenamecmp);
+    return 0;
+}



More information about the vlc-commits mailing list