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>
diff --git a/test_utils_unittest.cc b/test_utils_unittest.cc
new file mode 100644
index 0000000..ad41814
--- /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