mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-20 12:40:05 +01:00
Add versionsort test
And make local versionsort testable even when the native one is present.
This commit is contained in:
parent
30d811ede7
commit
db2dd43c86
2 changed files with 33 additions and 7 deletions
|
|
@ -1,9 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#ifndef HAVE_VERSIONSORT
|
|
||||||
|
|
||||||
/* Copyright © 2005-2014 Rich Felker, et al.
|
/* Copyright © 2005-2014 Rich Felker, et al.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* 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.
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#if !defined(HAVE_VERSIONSORT) || defined(TEST_VERSIONSORT)
|
||||||
static int
|
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 *l = (const void *)l0;
|
||||||
const unsigned char *r = (const void *)r0;
|
const unsigned char *r = (const void *)r0;
|
||||||
|
|
@ -61,11 +60,20 @@ strverscmp(const char *l0, const char *r0)
|
||||||
|
|
||||||
return l[i] - r[i];
|
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
|
static int
|
||||||
versionsort(const struct dirent **a, const struct dirent **b)
|
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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@
|
||||||
|
|
||||||
#include "litest.h"
|
#include "litest.h"
|
||||||
#include "libinput-util.h"
|
#include "libinput-util.h"
|
||||||
|
#define TEST_VERSIONSORT
|
||||||
|
#include "libinput-versionsort.h"
|
||||||
|
|
||||||
static int open_restricted(const char *path, int flags, void *data)
|
static int open_restricted(const char *path, int flags, void *data)
|
||||||
{
|
{
|
||||||
|
|
@ -1756,6 +1758,21 @@ START_TEST(list_test_append)
|
||||||
}
|
}
|
||||||
END_TEST
|
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)
|
TEST_COLLECTION(misc)
|
||||||
{
|
{
|
||||||
litest_add_no_device("events:conversion", event_conversion_device_notify);
|
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_insert);
|
||||||
litest_add_deviceless("misc:list", list_test_append);
|
litest_add_deviceless("misc:list", list_test_append);
|
||||||
|
litest_add_deviceless("misc:versionsort", strverscmp_test);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue