Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/test_utils.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | using std::string; |
| 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | namespace test_utils { |
| 15 | |
| 16 | class TestUtilsTest : public ::testing::Test { }; |
| 17 | |
| 18 | TEST(UtilsTest, RecursiveUnlinkDirTest) { |
| 19 | string first_dir_name; |
| 20 | ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-a-XXXXXX", |
| 21 | &first_dir_name)); |
| 22 | ASSERT_EQ(0, Chmod(first_dir_name, 0755)); |
| 23 | string second_dir_name; |
| 24 | ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-b-XXXXXX", |
| 25 | &second_dir_name)); |
| 26 | ASSERT_EQ(0, Chmod(second_dir_name, 0755)); |
| 27 | |
| 28 | EXPECT_EQ(0, Symlink(string("../") + first_dir_name, |
| 29 | second_dir_name + "/link")); |
| 30 | EXPECT_EQ(0, System(string("echo hi > ") + second_dir_name + "/file")); |
| 31 | EXPECT_EQ(0, Mkdir(second_dir_name + "/dir", 0755)); |
| 32 | EXPECT_EQ(0, System(string("echo ok > ") + second_dir_name + "/dir/subfile")); |
| 33 | EXPECT_TRUE(test_utils::RecursiveUnlinkDir(second_dir_name)); |
| 34 | EXPECT_TRUE(utils::FileExists(first_dir_name.c_str())); |
| 35 | EXPECT_EQ(0, System(string("rm -rf ") + first_dir_name)); |
| 36 | EXPECT_FALSE(utils::FileExists(second_dir_name.c_str())); |
| 37 | EXPECT_TRUE(test_utils::RecursiveUnlinkDir("/something/that/doesnt/exist")); |
| 38 | } |
| 39 | |
| 40 | } // namespace test_utils |
| 41 | } // namespace chromeos_update_engine |