[vlc-devel] [PATCH 2/2] vlc_strfilecmp: test cases
Rémi Denis-Courmont
remi at remlab.net
Tue Aug 30 11:53:12 CEST 2016
---
src/Makefile.am | 2 ++
src/test/strfilecmp.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 src/test/strfilecmp.c
diff --git a/src/Makefile.am b/src/Makefile.am
index eea70ca..145c273 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -534,6 +534,7 @@ check_PROGRAMS = \
test_interrupt \
test_md5 \
test_picture_pool \
+ test_strfilecmp \
test_timer \
test_url \
test_utf8 \
@@ -552,6 +553,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_strfilecmp_SOURCES = test/strfilecmp.c
test_timer_SOURCES = test/timer.c
test_url_SOURCES = test/url.c
test_utf8_SOURCES = test/utf8.c
diff --git a/src/test/strfilecmp.c b/src/test/strfilecmp.c
new file mode 100644
index 0000000..b325ea2
--- /dev/null
+++ b/src/test/strfilecmp.c
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * strfilecmp.c: Test for vlc_strfilecmp()
+ *****************************************************************************
+ * Copyright (C) 2016 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
+
+#undef NDEBUG
+/* Run locale-specific sanity tests. Need system support. */
+//#define TEST_FRENCH 1
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef TEST_FRENCH
+# include <locale.h>
+#endif
+
+#include <vlc_common.h>
+#include <vlc_strings.h>
+
+#define bigger(s1,s2) assert(vlc_strfilecmp((s1), (s2)) > 0)
+#define equal(s) assert(vlc_strfilecmp((s), (s)) == 0)
+
+int main(void)
+{
+#ifdef TEST_FRENCH
+ setlocale(LC_ALL, "fr_FR.UTF-8");
+#endif
+
+ equal("");
+ equal("0");
+ equal("1");
+ equal("-1");
+ equal("012345678901234567890123456789012345678901234567890123456789");
+ equal("012345678901234567890ABCDEFGHI012345678901234567890123456789");
+
+ bigger("0", "");
+ bigger("1", "0");
+ bigger("0001", "-000000001");
+ bigger("01234abc", "123abc");
+ bigger("-001234bcd", "-1234abc");
+ bigger("-001234abc", "-1235bcd");
+ bigger("123 abc 02", "123 abc 1");
+ bigger("123 abc +2", "123 abc -2");
+ bigger("123 abc +3", "123 abc 1");
+ bigger("123 abc 1", "123 abc -2");
+
+ bigger("12345678901234567890123456789012345678901234567890123456789",
+ "12345678901234567890123456789012345678901234567890123456788");
+ /* Arbitrarily large numbers cannot be handled numerically */
+ //bigger("012345678901234567890123456789012345678901234567890123456789",
+ // "12345678901234567890123456789012345678901234567890123456788");
+
+ bigger("b1", "a1");
+ bigger("01b", "1A");
+#ifdef TEST_FRENCH
+ bigger("01B", "1a");
+ bigger("01B", "1à");
+ bigger("01B", "1À");
+ bigger("01AB", "1ÀA");
+#endif
+
+ return 0;
+}
--
2.9.3
More information about the vlc-devel
mailing list