bool TestEnsureAndRemove() { BEGIN_TEST; PathFixture fixture; ASSERT_TRUE(fixture.Create()); Path path; ASSERT_EQ(ZX_OK, path.Push(fixture.path())); ASSERT_EQ(ZX_OK, path.Push("foo/ba/z/qu")); EXPECT_EQ(ZX_OK, path.Ensure("")); EXPECT_NE(ZX_OK, path.Ensure("x")); EXPECT_EQ(ZX_OK, path.Ensure("ux")); EXPECT_EQ(ZX_OK, path.Ensure("corge")); EXPECT_EQ(ZX_OK, path.Ensure("g/rault")); EXPECT_EQ(ZX_OK, path.Ensure("g/arply")); EXPECT_NE(ZX_OK, path.Remove("")); EXPECT_EQ(ZX_OK, path.Remove("a")); EXPECT_EQ(ZX_OK, path.Remove("x")); EXPECT_NE(ZX_OK, path.Push("x")); EXPECT_EQ(ZX_OK, path.Remove("corge")); EXPECT_NE(ZX_OK, path.Push("corge")); EXPECT_EQ(ZX_OK, path.Remove("g")); EXPECT_NE(ZX_OK, path.Push("g")); path.Pop(); EXPECT_EQ(ZX_OK, path.Remove("foo")); EXPECT_NE(ZX_OK, path.Push("foo")); END_TEST; }
bool TestRename() { BEGIN_TEST; BEGIN_TEST; PathFixture fixture; ASSERT_TRUE(fixture.Create()); Path path; ASSERT_EQ(ZX_OK, path.Push(fixture.path("foo/ba"))); EXPECT_NE(ZX_OK, path.Rename("", "empty")); EXPECT_NE(ZX_OK, path.Rename("empty", "")); EXPECT_NE(ZX_OK, path.Rename("missing", "found")); fbl::unique_fd fd(open(fixture.path("foo/ba/r").c_str(), O_RDWR)); EXPECT_TRUE(!!fd); fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR)); EXPECT_FALSE(!!fd); EXPECT_EQ(ZX_OK, path.Rename("r", "s")); fd.reset(open(fixture.path("foo/ba/r").c_str(), O_RDWR)); EXPECT_FALSE(!!fd); fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR)); EXPECT_TRUE(!!fd); EXPECT_EQ(ZX_OK, path.Rename("s", "r")); fd.reset(open(fixture.path("foo/ba/r").c_str(), O_RDWR)); EXPECT_TRUE(!!fd); fd.reset(open(fixture.path("foo/ba/s").c_str(), O_RDWR)); EXPECT_FALSE(!!fd); EXPECT_EQ(ZX_OK, path.Rename("z", "y")); EXPECT_NE(ZX_OK, path.Push("z/qu/ux")); EXPECT_EQ(ZX_OK, path.Push("y/qu/ux")); path.Pop(); EXPECT_EQ(ZX_OK, path.Rename("y", "z")); EXPECT_NE(ZX_OK, path.Push("y/qu/ux")); EXPECT_EQ(ZX_OK, path.Push("z/qu/ux")); END_TEST; }