summaryrefslogtreecommitdiff
path: root/test_utils_unittest.cc
diff options
context:
space:
mode:
authorAlex Deymo <deymo@chromium.org>2014-11-10 21:52:57 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-12 19:56:39 +0000
commit10875d90cf67f883ba7c9ed13bc8d706aa8c6fbc (patch)
tree97effd2a6cce73cbb6f131df93284d4fb5efc345 /test_utils_unittest.cc
parent192393ba515e917d06248b6459b20b6547ef496d (diff)
update_engine: Move test-only utils to test_utils.{h,cc}.
utils.{h,cc} contains a collections of basic or small functions used in different parts of the codebase. The test_utils.{h,cc} instead contains functions only required during testing split out to a separated file to be reused in different tests. This CL moves without changes some functions defined in utils.h that were only used during unittests. Two other basic functions were replaced by the same function already present in base/ (StringHasSuffix and StringHasPrefix). The functions in test_utils.h now have their own namespace chromeos_update_engine::test_utils so is clear they come from the test_utils file, in the same way the ones from utils are in their own namespace. Some othe minor linter fixes included here. BUG=chromium:351429 TEST=Unittest still pass. Change-Id: I73ab72a14158cb21c8e1f404cbc728423bc8f34f Reviewed-on: https://chromium-review.googlesource.com/229021 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'test_utils_unittest.cc')
-rw-r--r--test_utils_unittest.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/test_utils_unittest.cc b/test_utils_unittest.cc
new file mode 100644
index 00000000..ad41814d
--- /dev/null
+++ b/test_utils_unittest.cc
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "update_engine/test_utils.h"
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+using std::string;
+
+namespace chromeos_update_engine {
+namespace test_utils {
+
+class TestUtilsTest : public ::testing::Test { };
+
+TEST(UtilsTest, RecursiveUnlinkDirTest) {
+ string first_dir_name;
+ ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-a-XXXXXX",
+ &first_dir_name));
+ ASSERT_EQ(0, Chmod(first_dir_name, 0755));
+ string second_dir_name;
+ ASSERT_TRUE(utils::MakeTempDirectory("RecursiveUnlinkDirTest-b-XXXXXX",
+ &second_dir_name));
+ ASSERT_EQ(0, Chmod(second_dir_name, 0755));
+
+ EXPECT_EQ(0, Symlink(string("../") + first_dir_name,
+ second_dir_name + "/link"));
+ EXPECT_EQ(0, System(string("echo hi > ") + second_dir_name + "/file"));
+ EXPECT_EQ(0, Mkdir(second_dir_name + "/dir", 0755));
+ EXPECT_EQ(0, System(string("echo ok > ") + second_dir_name + "/dir/subfile"));
+ EXPECT_TRUE(test_utils::RecursiveUnlinkDir(second_dir_name));
+ EXPECT_TRUE(utils::FileExists(first_dir_name.c_str()));
+ EXPECT_EQ(0, System(string("rm -rf ") + first_dir_name));
+ EXPECT_FALSE(utils::FileExists(second_dir_name.c_str()));
+ EXPECT_TRUE(test_utils::RecursiveUnlinkDir("/something/that/doesnt/exist"));
+}
+
+} // namespace test_utils
+} // namespace chromeos_update_engine