Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(837)

Unified Diff: src/platform/update_engine/utils_unittest.cc

Issue 465067: Missed new files in last commit
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/update_engine/utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/update_engine/utils_unittest.cc
diff --git a/src/platform/update_engine/utils_unittest.cc b/src/platform/update_engine/utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4fee54484b12da9d56bc165d0c3305bf71714031
--- /dev/null
+++ b/src/platform/update_engine/utils_unittest.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2009 The Chromium 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 <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <vector>
+#include <gtest/gtest.h>
+#include "update_engine/utils.h"
+
+using std::vector;
+
+namespace chromeos_update_engine {
+
+class UtilsTest : public ::testing::Test { };
+
+TEST(UtilsTest, NormalizePathTest) {
+ EXPECT_EQ("", utils::NormalizePath("", false));
+ EXPECT_EQ("", utils::NormalizePath("", true));
+ EXPECT_EQ("/", utils::NormalizePath("/", false));
+ EXPECT_EQ("", utils::NormalizePath("/", true));
+ EXPECT_EQ("/", utils::NormalizePath("//", false));
+ EXPECT_EQ("", utils::NormalizePath("//", true));
+ EXPECT_EQ("foo", utils::NormalizePath("foo", false));
+ EXPECT_EQ("foo", utils::NormalizePath("foo", true));
+ EXPECT_EQ("/foo/", utils::NormalizePath("/foo//", false));
+ EXPECT_EQ("/foo", utils::NormalizePath("/foo//", true));
+ EXPECT_EQ("bar/baz/foo/adlr", utils::NormalizePath("bar/baz//foo/adlr",
+ false));
+ EXPECT_EQ("bar/baz/foo/adlr", utils::NormalizePath("bar/baz//foo/adlr",
+ true));
+ EXPECT_EQ("/bar/baz/foo/adlr/", utils::NormalizePath("/bar/baz//foo/adlr/",
+ false));
+ EXPECT_EQ("/bar/baz/foo/adlr", utils::NormalizePath("/bar/baz//foo/adlr/",
+ true));
+ EXPECT_EQ("\\\\", utils::NormalizePath("\\\\", false));
+ EXPECT_EQ("\\\\", utils::NormalizePath("\\\\", true));
+ EXPECT_EQ("\\:/;$PATH\n\\", utils::NormalizePath("\\://;$PATH\n\\", false));
+ EXPECT_EQ("\\:/;$PATH\n\\", utils::NormalizePath("\\://;$PATH\n\\", true));
+ EXPECT_EQ("/spaces s/ ok/s / / /",
+ utils::NormalizePath("/spaces s/ ok/s / / /", false));
+ EXPECT_EQ("/spaces s/ ok/s / / ",
+ utils::NormalizePath("/spaces s/ ok/s / / /", true));
+}
+
+TEST(UtilsTest, ReadFileFailure) {
+ vector<char> empty;
+ EXPECT_FALSE(utils::ReadFile("/this/doesn't/exist", &empty));
+}
+
+TEST(UtilsTest, ErrnoNumberAsStringTest) {
+ EXPECT_EQ("No such file or directory", utils::ErrnoNumberAsString(ENOENT));
+}
+
+TEST(UtilsTest, StringHasSuffixTest) {
+ EXPECT_TRUE(utils::StringHasSuffix("foo", "foo"));
+ EXPECT_TRUE(utils::StringHasSuffix("foo", "o"));
+ EXPECT_TRUE(utils::StringHasSuffix("", ""));
+ EXPECT_TRUE(utils::StringHasSuffix("abcabc", "abc"));
+ EXPECT_TRUE(utils::StringHasSuffix("adlrwashere", "ere"));
+ EXPECT_TRUE(utils::StringHasSuffix("abcdefgh", "gh"));
+ EXPECT_TRUE(utils::StringHasSuffix("abcdefgh", ""));
+ EXPECT_FALSE(utils::StringHasSuffix("foo", "afoo"));
+ EXPECT_FALSE(utils::StringHasSuffix("", "x"));
+ EXPECT_FALSE(utils::StringHasSuffix("abcdefgh", "fg"));
+ EXPECT_FALSE(utils::StringHasSuffix("abcdefgh", "ab"));
+}
+
+TEST(UtilsTest, StringHasPrefixTest) {
+ EXPECT_TRUE(utils::StringHasPrefix("foo", "foo"));
+ EXPECT_TRUE(utils::StringHasPrefix("foo", "f"));
+ EXPECT_TRUE(utils::StringHasPrefix("", ""));
+ EXPECT_TRUE(utils::StringHasPrefix("abcabc", "abc"));
+ EXPECT_TRUE(utils::StringHasPrefix("adlrwashere", "adl"));
+ EXPECT_TRUE(utils::StringHasPrefix("abcdefgh", "ab"));
+ EXPECT_TRUE(utils::StringHasPrefix("abcdefgh", ""));
+ EXPECT_FALSE(utils::StringHasPrefix("foo", "fooa"));
+ EXPECT_FALSE(utils::StringHasPrefix("", "x"));
+ EXPECT_FALSE(utils::StringHasPrefix("abcdefgh", "bc"));
+ EXPECT_FALSE(utils::StringHasPrefix("abcdefgh", "gh"));
+}
+
+TEST(UtilsTest, BootDeviceTest) {
+ // Pretty lame test...
+ EXPECT_FALSE(utils::BootDevice().empty());
+}
+
+TEST(UtilsTest, RecursiveUnlinkDirTest) {
+ EXPECT_EQ(0, mkdir("RecursiveUnlinkDirTest-a", 0755));
+ EXPECT_EQ(0, mkdir("RecursiveUnlinkDirTest-b", 0755));
+ EXPECT_EQ(0, symlink("../RecursiveUnlinkDirTest-a",
+ "RecursiveUnlinkDirTest-b/link"));
+ EXPECT_EQ(0, system("echo hi > RecursiveUnlinkDirTest-b/file"));
+ EXPECT_EQ(0, mkdir("RecursiveUnlinkDirTest-b/dir", 0755));
+ EXPECT_EQ(0, system("echo ok > RecursiveUnlinkDirTest-b/dir/subfile"));
+ EXPECT_TRUE(utils::RecursiveUnlinkDir("RecursiveUnlinkDirTest-b"));
+ EXPECT_TRUE(utils::FileExists("RecursiveUnlinkDirTest-a"));
+ EXPECT_EQ(0, system("rm -rf RecursiveUnlinkDirTest-a"));
+ EXPECT_FALSE(utils::FileExists("RecursiveUnlinkDirTest-b"));
+ EXPECT_TRUE(utils::RecursiveUnlinkDir("/something/that/doesnt/exist"));
+}
+
+TEST(UtilsTest, TempFilenameTest) {
+ const string original = "/foo.XXXXXX";
+ const string result = utils::TempFilename(original);
+ EXPECT_EQ(original.size(), result.size());
+ EXPECT_TRUE(utils::StringHasPrefix(result, "/foo."));
+ EXPECT_FALSE(utils::StringHasSuffix(result, "XXXXXX"));
+}
+
+} // namespace chromeos_update_engine
« no previous file with comments | « src/platform/update_engine/utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698