#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
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include "config.h"
+
#include <ctype.h>
#include <string.h>
#include <dirent.h>
+#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;
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
#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)
{
}
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);
litest_add_deviceless("misc:list", list_test_insert);
litest_add_deviceless("misc:list", list_test_append);
+ litest_add_deviceless("misc:versionsort", strverscmp_test);
}