Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2014 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Alex Deymo | 10875d9 | 2014-11-10 21:52:57 -0800 | [diff] [blame] | 16 | |
| 17 | #include "update_engine/test_utils.h" |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | #include <gtest/gtest.h> |
| 22 | |
| 23 | using std::string; |
| 24 | |
| 25 | namespace chromeos_update_engine { |
| 26 | namespace test_utils { |
| 27 | |
| 28 | class TestUtilsTest : public ::testing::Test { }; |
| 29 | |
| 30 | TEST(UtilsTest, RecursiveUnlinkDirTest) { |
| 31 | string first_dir_name; |
| 32 | ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-a-XXXXXX", |
| 33 | &first_dir_name)); |
| 34 | ASSERT_EQ(0, Chmod(first_dir_name, 0755)); |
| 35 | string second_dir_name; |
| 36 | ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-b-XXXXXX", |
| 37 | &second_dir_name)); |
| 38 | ASSERT_EQ(0, Chmod(second_dir_name, 0755)); |
| 39 | |
| 40 | EXPECT_EQ(0, Symlink(string("../") + first_dir_name, |
| 41 | second_dir_name + "/link")); |
| 42 | EXPECT_EQ(0, System(string("echo hi > ") + second_dir_name + "/file")); |
| 43 | EXPECT_EQ(0, Mkdir(second_dir_name + "/dir", 0755)); |
| 44 | EXPECT_EQ(0, System(string("echo ok > ") + second_dir_name + "/dir/subfile")); |
| 45 | EXPECT_TRUE(test_utils::RecursiveUnlinkDir(second_dir_name)); |
| 46 | EXPECT_TRUE(utils::FileExists(first_dir_name.c_str())); |
| 47 | EXPECT_EQ(0, System(string("rm -rf ") + first_dir_name)); |
| 48 | EXPECT_FALSE(utils::FileExists(second_dir_name.c_str())); |
| 49 | EXPECT_TRUE(test_utils::RecursiveUnlinkDir("/something/that/doesnt/exist")); |
| 50 | } |
| 51 | |
| 52 | } // namespace test_utils |
| 53 | } // namespace chromeos_update_engine |