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

Unified Diff: utils_unittest.cc

Issue 5265001: AU: Add unit tests for utils IsSymlink and SetProcessPriority. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 10 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils_unittest.cc
diff --git a/utils_unittest.cc b/utils_unittest.cc
index 4f1730596c52ca0f12239d1b15697aebb377b552..d8bc866a286f264ce8cf8b727cc70016f40f4fd3 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -129,6 +129,20 @@ TEST(UtilsTest, RecursiveUnlinkDirTest) {
EXPECT_TRUE(utils::RecursiveUnlinkDir("/something/that/doesnt/exist"));
}
+TEST(UtilsTest, IsSymlinkTest) {
+ string temp_dir;
+ EXPECT_TRUE(utils::MakeTempDirectory("/tmp/symlink-test.XXXXXX", &temp_dir));
+ string temp_file = temp_dir + "temp-file";
+ EXPECT_TRUE(utils::WriteFile(temp_file.c_str(), "", 0));
+ string temp_symlink = temp_dir + "temp-symlink";
+ EXPECT_EQ(0, symlink(temp_file.c_str(), temp_symlink.c_str()));
+ EXPECT_FALSE(utils::IsSymlink(temp_dir.c_str()));
+ EXPECT_FALSE(utils::IsSymlink(temp_file.c_str()));
+ EXPECT_TRUE(utils::IsSymlink(temp_symlink.c_str()));
+ EXPECT_FALSE(utils::IsSymlink("/non/existent/path"));
+ EXPECT_TRUE(utils::RecursiveUnlinkDir(temp_dir));
+}
+
TEST(UtilsTest, TempFilenameTest) {
const string original = "/foo.XXXXXX";
const string result = utils::TempFilename(original);
@@ -164,6 +178,22 @@ TEST(UtilsTest, PartitionNumberTest) {
EXPECT_EQ("3", utils::PartitionNumber("/dev/mmc0p3"));
}
+
+TEST(UtilsTest, RunAsRootSetProcessPriorityTest) {
+ // getpriority may return -1 on error so the getpriority logic needs to be
+ // enhanced if any of the pre-defined priority constants are changed to -1.
+ ASSERT_NE(-1, utils::kProcessPriorityLow);
+ ASSERT_NE(-1, utils::kProcessPriorityNormal);
+ ASSERT_NE(-1, utils::kProcessPriorityHigh);
+ EXPECT_EQ(utils::kProcessPriorityNormal, getpriority(PRIO_PROCESS, 0));
+ EXPECT_TRUE(utils::SetProcessPriority(utils::kProcessPriorityHigh));
+ EXPECT_EQ(utils::kProcessPriorityHigh, getpriority(PRIO_PROCESS, 0));
+ EXPECT_TRUE(utils::SetProcessPriority(utils::kProcessPriorityLow));
+ EXPECT_EQ(utils::kProcessPriorityLow, getpriority(PRIO_PROCESS, 0));
+ EXPECT_TRUE(utils::SetProcessPriority(utils::kProcessPriorityNormal));
+ EXPECT_EQ(utils::kProcessPriorityNormal, getpriority(PRIO_PROCESS, 0));
+}
+
TEST(UtilsTest, ComparePrioritiesTest) {
EXPECT_LT(utils::ComparePriorities(utils::kProcessPriorityLow,
utils::kProcessPriorityNormal), 0);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698