From 11f6405a68db5c2b2e351265ece7ad548e441178 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 24 Aug 2024 00:05:16 +0200 Subject: [PATCH] test: add tests for dir_entry_view::parent() --- test/compat_test.cpp | 27 +++++++++++++++++++++++++++ test/dwarfs_test.cpp | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/test/compat_test.cpp b/test/compat_test.cpp index 8aecf7e9c..daa759f40 100644 --- a/test/compat_test.cpp +++ b/test/compat_test.cpp @@ -1120,6 +1120,33 @@ void check_compat(logger& lgr, reader::filesystem_v2 const& fs, } EXPECT_EQ(expected, paths) << td; } + + { + auto dev = fs.find("foo/1/2/3/4/5/6/7/8/9/j"); + ASSERT_TRUE(dev); + EXPECT_EQ("j", dev->name()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_regular_file()); + dev = dev->parent(); + EXPECT_EQ("9", dev->name()); + EXPECT_EQ("foo/1/2/3/4/5/6/7/8/9", dev->unix_path()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + dev = dev->parent()->parent()->parent(); + EXPECT_EQ("6", dev->name()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + dev = dev->parent()->parent()->parent()->parent()->parent()->parent(); + EXPECT_EQ("foo", dev->name()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + dev = dev->parent(); + ASSERT_TRUE(dev); + EXPECT_EQ("", dev->name()); + EXPECT_TRUE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + EXPECT_FALSE(dev->parent()); + } } } // namespace diff --git a/test/dwarfs_test.cpp b/test/dwarfs_test.cpp index 67a1d98c4..6f4183cac 100644 --- a/test/dwarfs_test.cpp +++ b/test/dwarfs_test.cpp @@ -563,6 +563,25 @@ void basic_end_to_end_test( ASSERT_TRUE(info.count("root")); } } + + { + auto dev = fs.find("somedir/ipsum.py"); + ASSERT_TRUE(dev); + EXPECT_EQ("ipsum.py", dev->name()); + EXPECT_EQ("somedir/ipsum.py", dev->unix_path()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_regular_file()); + dev = dev->parent(); + EXPECT_EQ("somedir", dev->name()); + EXPECT_FALSE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + dev = dev->parent(); + ASSERT_TRUE(dev); + EXPECT_EQ("", dev->name()); + EXPECT_TRUE(dev->is_root()); + EXPECT_TRUE(dev->inode().is_directory()); + EXPECT_FALSE(dev->parent()); + } } std::vector const compressions{