From: Yu Watanabe Date: Fri, 15 Apr 2022 05:06:56 +0000 (+0900) Subject: test: add tests for sd_device_get_sysnum() X-Git-Tag: v251-rc2~117^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F23089%2Fhead;p=thirdparty%2Fsystemd.git test: add tests for sd_device_get_sysnum() --- diff --git a/src/libsystemd/sd-device/test-sd-device.c b/src/libsystemd/sd-device/test-sd-device.c index 7162aac72f5..7bc61354067 100644 --- a/src/libsystemd/sd-device/test-sd-device.c +++ b/src/libsystemd/sd-device/test-sd-device.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include "device-enumerator-private.h" @@ -163,7 +164,13 @@ static void test_sd_device_one(sd_device *d) { assert_se(r >= 0 || r == -ENOENT); r = sd_device_get_sysnum(d, &val); - assert_se(r >= 0 || r == -ENOENT); + if (r >= 0) { + assert_se(val > sysname); + assert_se(val < sysname + strlen(sysname)); + assert_se(in_charset(val, DIGITS)); + assert_se(!isdigit(val[-1])); + } else + assert_se(r == -ENOENT); r = sd_device_get_sysattr_value(d, "name_assign_type", &val); assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || IN_SET(r, -ENOENT, -EINVAL));