summaryrefslogtreecommitdiff
path: root/fs_mgr/libfiemap/image_test.cpp
diff options
context:
space:
mode:
authorJustin DeMartino <jjdemartino@google.com>2020-10-14 19:39:53 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-10-14 19:39:53 +0000
commit0d11af03e43f110b0bb160f7e20436d0043e3038 (patch)
tree48f8bcca856276ec73a86dd3fb26143d3ca64578 /fs_mgr/libfiemap/image_test.cpp
parent075666ebd0dee8d0c4a2efa54f7c324a3f67ee2a (diff)
parenta6c01e4e98d2b343dcecfc99611e2e6250c730db (diff)
Merge changes from topic "SP1A.200921.001" into s-keystone-qcom-dev
* changes: fs_mgr: adb-remount-test.sh: filter out more administrivia mounts. Merge SP1A.200921.001 Change-Id: I90b97c4e9fb10b1f45e74def404823eed5b1aaa8
Diffstat (limited to 'fs_mgr/libfiemap/image_test.cpp')
-rw-r--r--fs_mgr/libfiemap/image_test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/fs_mgr/libfiemap/image_test.cpp b/fs_mgr/libfiemap/image_test.cpp
index 66633916a..6d0975150 100644
--- a/fs_mgr/libfiemap/image_test.cpp
+++ b/fs_mgr/libfiemap/image_test.cpp
@@ -34,10 +34,13 @@
#include <libdm/dm.h>
#include <libfiemap/image_manager.h>
+#include "utility.h"
+
using namespace android::dm;
using namespace std::literals;
using android::base::unique_fd;
using android::fiemap::ImageManager;
+using android::fiemap::IsSubdir;
using android::fs_mgr::BlockDeviceInfo;
using android::fs_mgr::PartitionOpener;
using android::fs_mgr::WaitForFile;
@@ -131,6 +134,51 @@ TEST_F(NativeTest, GetMappedImageDevice) {
ASSERT_TRUE(manager_->UnmapImageDevice(base_name_));
}
+namespace {
+
+struct IsSubdirTestParam {
+ std::string child;
+ std::string parent;
+ bool result;
+};
+
+class IsSubdirTest : public ::testing::TestWithParam<IsSubdirTestParam> {};
+
+TEST_P(IsSubdirTest, Test) {
+ const auto& param = GetParam();
+ EXPECT_EQ(param.result, IsSubdir(param.child, param.parent))
+ << "IsSubdir(child=\"" << param.child << "\", parent=\"" << param.parent
+ << "\") != " << (param.result ? "true" : "false");
+}
+
+std::vector<IsSubdirTestParam> IsSubdirTestValues() {
+ // clang-format off
+ std::vector<IsSubdirTestParam> base_cases{
+ {"/foo/bar", "/foo", true},
+ {"/foo/bar/baz", "/foo", true},
+ {"/foo", "/foo", true},
+ {"/foo", "/", true},
+ {"/", "/", true},
+ {"/foo", "/foo/bar", false},
+ {"/foo", "/bar", false},
+ {"/foo-bar", "/foo", false},
+ {"/", "/foo", false},
+ };
+ // clang-format on
+ std::vector<IsSubdirTestParam> ret;
+ for (const auto& e : base_cases) {
+ ret.push_back(e);
+ ret.push_back({e.child + "/", e.parent, e.result});
+ ret.push_back({e.child, e.parent + "/", e.result});
+ ret.push_back({e.child + "/", e.parent + "/", e.result});
+ }
+ return ret;
+}
+
+INSTANTIATE_TEST_SUITE_P(IsSubdirTest, IsSubdirTest, ::testing::ValuesIn(IsSubdirTestValues()));
+
+} // namespace
+
bool Mkdir(const std::string& path) {
if (mkdir(path.c_str(), 0700) && errno != EEXIST) {
std::cerr << "Could not mkdir " << path << ": " << strerror(errno) << std::endl;