summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-10-15 02:15:19 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-15 12:09:38 +0200
commit32944d1c7a5444ccc72e957a2dd39c12b3ce625a (patch)
treea49ab223d73c76a13ec06358cb477c5c671605d0 /src/test
parentfs-util: make readlink_malloc() inline (diff)
downloadsystemd-32944d1c7a5444ccc72e957a2dd39c12b3ce625a.tar.xz
systemd-32944d1c7a5444ccc72e957a2dd39c12b3ce625a.zip
sd-json: introduce json_variant_new_devnum() and friends
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-json.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test-json.c b/src/test/test-json.c
index 32cd285841..fdf69ac2f7 100644
--- a/src/test/test-json.c
+++ b/src/test/test-json.c
@@ -1307,4 +1307,27 @@ TEST(pidref) {
pidref_done(&data.pid1);
}
+TEST(devnum) {
+ _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL;
+ dev_t dev = makedev(123, 456), parsed;
+
+ ASSERT_OK(json_variant_new_devnum(&v, dev));
+ ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL));
+ ASSERT_OK(json_dispatch_devnum("devnum", v, /* flags= */ 0, &parsed));
+ ASSERT_EQ(major(parsed), major(dev));
+ ASSERT_EQ(minor(parsed), minor(dev));
+ v = sd_json_variant_unref(v);
+
+ dev = makedev(1 << 12, 456);
+ ASSERT_OK(json_variant_new_devnum(&v, dev));
+ ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL));
+ ASSERT_FAIL(json_dispatch_devnum("devnum", v, /* flags= */ 0, &parsed));
+ v = sd_json_variant_unref(v);
+
+ dev = makedev(123, 1 << 20);
+ ASSERT_OK(json_variant_new_devnum(&v, dev));
+ ASSERT_OK(sd_json_variant_dump(v, SD_JSON_FORMAT_PRETTY_AUTO | SD_JSON_FORMAT_COLOR_AUTO, NULL, NULL));
+ ASSERT_FAIL(json_dispatch_devnum("devnum", v, /* flags= */ 0, &parsed));
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);