diff options
author | Tao Bao <tbao@google.com> | 2018-07-13 01:07:31 +0200 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-07-13 01:07:31 +0200 |
commit | 90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45 (patch) | |
tree | 8745ee7e013df3e0cf9fb8373d0bc66cf7453906 /tests/unit | |
parent | Merge "applypatch: Switch freecache.cpp to libbase logging." (diff) | |
parent | applypatch: Fix the return type of FreeSpaceForFile(). (diff) | |
download | android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar.gz android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar.bz2 android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar.lz android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar.xz android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.tar.zst android_bootable_recovery-90c9e4f55c5a2fcb24cd921356bc25ad6ea9fc45.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/unit/applypatch_test.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/tests/unit/applypatch_test.cpp b/tests/unit/applypatch_test.cpp index 5cc03bc7b..4b757feab 100644 --- a/tests/unit/applypatch_test.cpp +++ b/tests/unit/applypatch_test.cpp @@ -16,6 +16,7 @@ #include <dirent.h> #include <fcntl.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> @@ -29,6 +30,7 @@ #include <vector> #include <android-base/file.h> +#include <android-base/logging.h> #include <android-base/stringprintf.h> #include <android-base/test_utils.h> #include <android-base/unique_fd.h> @@ -176,7 +178,7 @@ class FreeCacheTest : public ::testing::Test { // A mock method to calculate the free space. It assumes the partition has a total size of 40960 // bytes and all files are 4096 bytes in size. - size_t MockFreeSpaceChecker(const std::string& dirname) { + int64_t MockFreeSpaceChecker(const std::string& dirname) { std::vector<std::string> files = FindFilesInDir(dirname); return PARTITION_SIZE - 4096 * files.size(); } @@ -191,7 +193,7 @@ TEST_F(FreeCacheTest, FreeCacheSmoke) { ASSERT_EQ(files, FindFilesInDir(mock_cache.path)); ASSERT_EQ(4096 * 7, MockFreeSpaceChecker(mock_cache.path)); - ASSERT_TRUE(RemoveFilesInDirectory(4096 * 9, mock_cache.path, [&](const std::string& dir) { + ASSERT_TRUE(RemoveFilesInDirectory(4096 * 9, mock_cache.path, [this](const std::string& dir) { return this->MockFreeSpaceChecker(dir); })); @@ -199,6 +201,16 @@ TEST_F(FreeCacheTest, FreeCacheSmoke) { ASSERT_EQ(4096 * 9, MockFreeSpaceChecker(mock_cache.path)); } +TEST_F(FreeCacheTest, FreeCacheFreeSpaceCheckerError) { + std::vector<std::string> files{ "file1", "file2", "file3" }; + AddFilesToDir(mock_cache.path, files); + ASSERT_EQ(files, FindFilesInDir(mock_cache.path)); + ASSERT_EQ(4096 * 7, MockFreeSpaceChecker(mock_cache.path)); + + ASSERT_FALSE( + RemoveFilesInDirectory(4096 * 9, mock_cache.path, [](const std::string&) { return -1; })); +} + TEST_F(FreeCacheTest, FreeCacheOpenFile) { std::vector<std::string> files = { "file1", "file2" }; AddFilesToDir(mock_cache.path, files); @@ -209,7 +221,7 @@ TEST_F(FreeCacheTest, FreeCacheOpenFile) { android::base::unique_fd fd(open(file1_path.c_str(), O_RDONLY)); // file1 can't be deleted as it's opened by us. - ASSERT_FALSE(RemoveFilesInDirectory(4096 * 10, mock_cache.path, [&](const std::string& dir) { + ASSERT_FALSE(RemoveFilesInDirectory(4096 * 10, mock_cache.path, [this](const std::string& dir) { return this->MockFreeSpaceChecker(dir); })); @@ -222,7 +234,7 @@ TEST_F(FreeCacheTest, FreeCacheLogsSmoke) { AddFilesToDir(mock_log_dir.path, log_files); ASSERT_EQ(4096 * 5, MockFreeSpaceChecker(mock_log_dir.path)); - ASSERT_TRUE(RemoveFilesInDirectory(4096 * 8, mock_log_dir.path, [&](const std::string& dir) { + ASSERT_TRUE(RemoveFilesInDirectory(4096 * 8, mock_log_dir.path, [this](const std::string& dir) { return this->MockFreeSpaceChecker(dir); })); @@ -238,7 +250,7 @@ TEST_F(FreeCacheTest, FreeCacheLogsStringComparison) { AddFilesToDir(mock_log_dir.path, log_files); ASSERT_EQ(4096 * 6, MockFreeSpaceChecker(mock_log_dir.path)); - ASSERT_TRUE(RemoveFilesInDirectory(4096 * 9, mock_log_dir.path, [&](const std::string& dir) { + ASSERT_TRUE(RemoveFilesInDirectory(4096 * 9, mock_log_dir.path, [this](const std::string& dir) { return this->MockFreeSpaceChecker(dir); })); @@ -255,7 +267,7 @@ TEST_F(FreeCacheTest, FreeCacheLogsOtherFiles) { AddFilesToDir(mock_log_dir.path, log_files); ASSERT_EQ(4096 * 5, MockFreeSpaceChecker(mock_log_dir.path)); - ASSERT_FALSE(RemoveFilesInDirectory(4096 * 8, mock_log_dir.path, [&](const std::string& dir) { + ASSERT_FALSE(RemoveFilesInDirectory(4096 * 8, mock_log_dir.path, [this](const std::string& dir) { return this->MockFreeSpaceChecker(dir); })); |