summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorxunchang <xunchang@google.com>2019-03-22 17:33:49 +0100
committerxunchang <xunchang@google.com>2019-03-26 19:47:27 +0100
commit625c588c0f1a77bf632f56aa1cf92bb746f6f02a (patch)
tree303b8ebc0cdc324d4f8ecdd49249b2c2171c1f7b /tests
parentMerge "Move librecovery_ui to a sub-directory" (diff)
downloadandroid_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar.gz
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar.bz2
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar.lz
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar.xz
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.tar.zst
android_bootable_recovery-625c588c0f1a77bf632f56aa1cf92bb746f6f02a.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/sysutil_test.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/unit/sysutil_test.cpp b/tests/unit/sysutil_test.cpp
index 77625dbe9..3466e8eec 100644
--- a/tests/unit/sysutil_test.cpp
+++ b/tests/unit/sysutil_test.cpp
@@ -17,8 +17,10 @@
#include <string>
#include <android-base/file.h>
+#include <android-base/strings.h>
#include <gtest/gtest.h>
+#include "otautil/rangeset.h"
#include "otautil/sysutil.h"
TEST(SysUtilTest, InvalidArgs) {
@@ -28,6 +30,65 @@ TEST(SysUtilTest, InvalidArgs) {
ASSERT_FALSE(mapping.MapFile(""));
}
+TEST(SysUtilTest, ParseBlockMapFile_smoke) {
+ std::vector<std::string> content = {
+ "/dev/abc", "49652 4096", "3", "1000 1008", "2100 2102", "30 33",
+ };
+
+ TemporaryFile temp_file;
+ ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path));
+
+ auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path);
+ ASSERT_EQ("/dev/abc", block_map_data.path());
+ ASSERT_EQ(49652, block_map_data.file_size());
+ ASSERT_EQ(4096, block_map_data.block_size());
+ ASSERT_EQ(RangeSet(std::vector<Range>{
+ { 1000, 1008 },
+ { 2100, 2102 },
+ { 30, 33 },
+ }),
+ block_map_data.block_ranges());
+}
+
+TEST(SysUtilTest, ParseBlockMapFile_invalid_line_count) {
+ std::vector<std::string> content = {
+ "/dev/abc", "49652 4096", "2", "1000 1008", "2100 2102", "30 33",
+ };
+
+ TemporaryFile temp_file;
+ ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path));
+
+ auto block_map_data1 = BlockMapData::ParseBlockMapFile(temp_file.path);
+ ASSERT_FALSE(block_map_data1);
+}
+
+TEST(SysUtilTest, ParseBlockMapFile_invalid_size) {
+ std::vector<std::string> content = {
+ "/dev/abc",
+ "42949672950 4294967295",
+ "1",
+ "0 9",
+ };
+
+ TemporaryFile temp_file;
+ ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path));
+
+ auto block_map_data = BlockMapData::ParseBlockMapFile(temp_file.path);
+ ASSERT_EQ("/dev/abc", block_map_data.path());
+ ASSERT_EQ(42949672950, block_map_data.file_size());
+ ASSERT_EQ(4294967295, block_map_data.block_size());
+
+ content[1] = "42949672950 4294967296";
+ ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path));
+ auto large_block_size = BlockMapData::ParseBlockMapFile(temp_file.path);
+ ASSERT_FALSE(large_block_size);
+
+ content[1] = "4294967296 1";
+ ASSERT_TRUE(android::base::WriteStringToFile(android::base::Join(content, '\n'), temp_file.path));
+ auto too_many_blocks = BlockMapData::ParseBlockMapFile(temp_file.path);
+ ASSERT_FALSE(too_many_blocks);
+}
+
TEST(SysUtilTest, MapFileRegularFile) {
TemporaryFile temp_file1;
std::string content = "abc";