Commit db2dd43c authored by myfreeweb's avatar myfreeweb

Add versionsort test

And make local versionsort testable even when the native one is present.
parent 30d811ed
Pipeline #2330 failed with stages
in 17 minutes and 49 seconds
#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 <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;
......@@ -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
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment