summaryrefslogtreecommitdiffstats
path: root/tests/component/updater_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-11-09 20:20:45 +0100
committerandroid-build-merger <android-build-merger@google.com>2016-11-09 20:20:45 +0100
commit7da0c7e4394c9ab131a24bf9a7cfa571fdc89908 (patch)
treee36d032bec67b60a1d6c08eb49be9459819eb99b /tests/component/updater_test.cpp
parentMerge "otautil: Clean up obsolete includes." am: b80d136dca (diff)
parentMerge "updater: Add more testcase for symlink()." (diff)
downloadandroid_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar.gz
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar.bz2
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar.lz
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar.xz
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.tar.zst
android_bootable_recovery-7da0c7e4394c9ab131a24bf9a7cfa571fdc89908.zip
Diffstat (limited to 'tests/component/updater_test.cpp')
-rw-r--r--tests/component/updater_test.cpp45
1 files changed, 39 insertions, 6 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index acc2b4040..973c19de3 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -14,6 +14,10 @@
* limitations under the License.
*/
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
#include <string>
#include <android-base/file.h>
@@ -212,10 +216,15 @@ TEST_F(UpdaterTest, rename) {
// Parents create successfully.
TemporaryFile temp_file3;
TemporaryDir td;
- std::string temp_dir = std::string(td.path) + "/aaa/bbb/a.txt";
- std::string script3("rename(\"" + std::string(temp_file3.path) + "\", \"" +
- temp_dir + "\")");
- expect(temp_dir.c_str(), script3.c_str(), kNoCause);
+ std::string temp_dir(td.path);
+ std::string dst_file = temp_dir + "/aaa/bbb/a.txt";
+ std::string script3("rename(\"" + std::string(temp_file3.path) + "\", \"" + dst_file + "\")");
+ expect(dst_file.c_str(), script3.c_str(), kNoCause);
+
+ // Clean up the temp files under td.
+ ASSERT_EQ(0, unlink(dst_file.c_str()));
+ ASSERT_EQ(0, rmdir((temp_dir + "/aaa/bbb").c_str()));
+ ASSERT_EQ(0, rmdir((temp_dir + "/aaa").c_str()));
}
TEST_F(UpdaterTest, symlink) {
@@ -227,7 +236,31 @@ TEST_F(UpdaterTest, symlink) {
std::string script1("symlink(\"" + std::string(temp_file1.path) + "\", \"\")");
expect(nullptr, script1.c_str(), kSymlinkFailure);
- // symlink failed to remove old src.
- std::string script2("symlink(\"" + std::string(temp_file1.path) + "\", \"/proc\")");
+ std::string script2("symlink(\"" + std::string(temp_file1.path) + "\", \"src1\", \"\")");
expect(nullptr, script2.c_str(), kSymlinkFailure);
+
+ // symlink failed to remove old src.
+ std::string script3("symlink(\"" + std::string(temp_file1.path) + "\", \"/proc\")");
+ expect(nullptr, script3.c_str(), kSymlinkFailure);
+
+ // symlink can create symlinks.
+ TemporaryFile temp_file;
+ std::string content = "magicvalue";
+ ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path));
+
+ TemporaryDir td;
+ std::string src1 = std::string(td.path) + "/symlink1";
+ std::string src2 = std::string(td.path) + "/symlink2";
+ std::string script4("symlink(\"" + std::string(temp_file.path) + "\", \"" +
+ src1 + "\", \"" + src2 + "\")");
+ expect("t", script4.c_str(), kNoCause);
+
+ // Verify the created symlinks.
+ struct stat sb;
+ ASSERT_TRUE(lstat(src1.c_str(), &sb) == 0 && S_ISLNK(sb.st_mode));
+ ASSERT_TRUE(lstat(src2.c_str(), &sb) == 0 && S_ISLNK(sb.st_mode));
+
+ // Clean up the leftovers.
+ ASSERT_EQ(0, unlink(src1.c_str()));
+ ASSERT_EQ(0, unlink(src2.c_str()));
}