summaryrefslogtreecommitdiffstats
path: root/tests/component/updater_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-04 22:15:12 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-04 22:15:12 +0100
commit88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c (patch)
tree6ec57274514d6716c3d6f802fba49339966d825d /tests/component/updater_test.cpp
parentMerge "Cleanup the duplicates of logs rotation functions" am: e2d05c5658 am: 99adda9d67 am: 92097726ef (diff)
parentMerge "updater: Add a testcase for RenameFn()." am: d0daf7f7df am: 05a801ca8e (diff)
downloadandroid_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar.gz
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar.bz2
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar.lz
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar.xz
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.tar.zst
android_bootable_recovery-88ee9f61bf989e73a1d56eb2d2a2e6a70610e52c.zip
Diffstat (limited to 'tests/component/updater_test.cpp')
-rw-r--r--tests/component/updater_test.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 337769e6b..f922933cd 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -180,3 +180,32 @@ TEST_F(UpdaterTest, delete) {
"\", \"/doesntexist2\")");
expect("1", script3.c_str(), kNoCause);
}
+
+TEST_F(UpdaterTest, rename) {
+ // rename() expects two arguments.
+ expect(nullptr, "rename()", kArgsParsingFailure);
+ expect(nullptr, "rename(\"arg1\")", kArgsParsingFailure);
+ expect(nullptr, "rename(\"arg1\", \"arg2\", \"arg3\")", kArgsParsingFailure);
+
+ // src_name or dst_name cannot be empty.
+ expect(nullptr, "rename(\"\", \"arg2\")", kArgsParsingFailure);
+ expect(nullptr, "rename(\"arg1\", \"\")", kArgsParsingFailure);
+
+ // File doesn't exist (both of src and dst).
+ expect(nullptr, "rename(\"/doesntexist\", \"/doesntexisteither\")" , kFileRenameFailure);
+
+ // Can't create parent directory.
+ TemporaryFile temp_file1;
+ ASSERT_TRUE(android::base::WriteStringToFile("abc", temp_file1.path));
+ std::string script1("rename(\"" + std::string(temp_file1.path) + "\", \"/proc/0/file1\")");
+ expect(nullptr, script1.c_str(), kFileRenameFailure);
+
+ // Rename.
+ TemporaryFile temp_file2;
+ std::string script2("rename(\"" + std::string(temp_file1.path) + "\", \"" +
+ std::string(temp_file2.path) + "\")");
+ expect(temp_file2.path, script2.c_str(), kNoCause);
+
+ // Already renamed.
+ expect(temp_file2.path, script2.c_str(), kNoCause);
+}