From: Greg V Date: Wed, 18 Jul 2018 18:37:25 +0000 (+0300) Subject: Add versionsort test X-Git-Tag: 1.11.901~41^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db2dd43c86b042f3794302d2d886364a258f49e3;p=platform%2Fupstream%2Flibinput.git Add versionsort test And make local versionsort testable even when the native one is present. --- diff --git a/src/libinput-versionsort.h b/src/libinput-versionsort.h index 356ec8da..62fc31ae 100644 --- a/src/libinput-versionsort.h +++ b/src/libinput-versionsort.h @@ -1,9 +1,5 @@ #pragma once -#include "config.h" - -#ifndef HAVE_VERSIONSORT - /* Copyright © 2005-2014 Rich Felker, et al. * * Permission is hereby granted, free of charge, to any person obtaining @@ -26,12 +22,15 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "config.h" + #include #include #include +#if !defined(HAVE_VERSIONSORT) || defined(TEST_VERSIONSORT) static int -strverscmp(const char *l0, const char *r0) +libinput_strverscmp(const char *l0, const char *r0) { const unsigned char *l = (const void *)l0; const unsigned char *r = (const void *)r0; @@ -61,11 +60,20 @@ strverscmp(const char *l0, const char *r0) return l[i] - r[i]; } +#endif + +/* Defined with libinput_ names for testing from platforms with native functions. */ + +#ifndef HAVE_VERSIONSORT +static int +strverscmp(const char *l0, const char *r0) +{ + return libinput_strverscmp(l0, r0); +} static int versionsort(const struct dirent **a, const struct dirent **b) { - return strverscmp((*a)->d_name, (*b)->d_name); + return libinput_strverscmp((*a)->d_name, (*b)->d_name); } - #endif diff --git a/test/test-misc.c b/test/test-misc.c index 93d20812..22571569 100644 --- a/test/test-misc.c +++ b/test/test-misc.c @@ -33,6 +33,8 @@ #include "litest.h" #include "libinput-util.h" +#define TEST_VERSIONSORT +#include "libinput-versionsort.h" static int open_restricted(const char *path, int flags, void *data) { @@ -1756,6 +1758,21 @@ START_TEST(list_test_append) } END_TEST +START_TEST(strverscmp_test) +{ + ck_assert_int_eq(libinput_strverscmp("", ""), 0); + ck_assert_int_gt(libinput_strverscmp("0.0.1", ""), 0); + ck_assert_int_lt(libinput_strverscmp("", "0.0.1"), 0); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.1"), 0); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.0.2"), -1); + ck_assert_int_eq(libinput_strverscmp("0.0.2", "0.0.1"), 1); + ck_assert_int_eq(libinput_strverscmp("0.0.1", "0.1.0"), -1); + ck_assert_int_eq(libinput_strverscmp("0.1.0", "0.0.1"), 1); +} +END_TEST + + + TEST_COLLECTION(misc) { litest_add_no_device("events:conversion", event_conversion_device_notify); @@ -1805,4 +1822,5 @@ TEST_COLLECTION(misc) litest_add_deviceless("misc:list", list_test_insert); litest_add_deviceless("misc:list", list_test_append); + litest_add_deviceless("misc:versionsort", strverscmp_test); }