summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorxunchang <xunchang@google.com>2019-03-16 00:04:32 +0100
committerxunchang <xunchang@google.com>2019-03-19 21:03:59 +0100
commit5e6832a24d39f15261be0cad19708274db57a126 (patch)
tree0e556c1f464c230f410028b8abf6378f0b45c92e /tests
parentCreate a FuseDataProvider base class (diff)
downloadandroid_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar.gz
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar.bz2
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar.lz
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar.xz
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.tar.zst
android_bootable_recovery-5e6832a24d39f15261be0cad19708274db57a126.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/component/sideload_test.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/tests/component/sideload_test.cpp b/tests/component/sideload_test.cpp
index 8d290dbcd..f5981acbd 100644
--- a/tests/component/sideload_test.cpp
+++ b/tests/component/sideload_test.cpp
@@ -16,13 +16,16 @@
#include <unistd.h>
+#include <memory>
#include <string>
#include <vector>
#include <android-base/file.h>
#include <android-base/strings.h>
+#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
+#include "fuse_provider.h"
#include "fuse_sideload.h"
TEST(SideloadTest, fuse_device) {
@@ -30,14 +33,17 @@ TEST(SideloadTest, fuse_device) {
}
TEST(SideloadTest, run_fuse_sideload_wrong_parameters) {
- provider_vtab vtab;
- vtab.close = [](void) {};
+ auto provider_small_block =
+ std::make_unique<FuseFileDataProvider>(android::base::unique_fd(), 4096, 4095);
+ ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_small_block)));
- ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, 4095));
- ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, (1 << 22) + 1));
+ auto provider_large_block =
+ std::make_unique<FuseFileDataProvider>(android::base::unique_fd(), 4096, (1 << 22) + 1);
+ ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_large_block)));
- // Too many blocks.
- ASSERT_EQ(-1, run_fuse_sideload(vtab, ((1 << 18) + 1) * 4096, 4096));
+ auto provider_too_many_blocks = std::make_unique<FuseFileDataProvider>(
+ android::base::unique_fd(), ((1 << 18) + 1) * 4096, 4096);
+ ASSERT_EQ(-1, run_fuse_sideload(std::move(provider_too_many_blocks)));
}
TEST(SideloadTest, run_fuse_sideload) {
@@ -50,18 +56,15 @@ TEST(SideloadTest, run_fuse_sideload) {
const std::string content = android::base::Join(blocks, "");
ASSERT_EQ(16384U, content.size());
- provider_vtab vtab;
- vtab.close = [](void) {};
- vtab.read_block = [&blocks](uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
- if (block >= 4) return false;
- blocks[block].copy(reinterpret_cast<char*>(buffer), fetch_size);
- return true;
- };
+ TemporaryFile temp_file;
+ ASSERT_TRUE(android::base::WriteStringToFile(content, temp_file.path));
+ auto provider = std::make_unique<FuseFileDataProvider>(temp_file.path, 4096);
+ ASSERT_TRUE(provider->Valid());
TemporaryDir mount_point;
pid_t pid = fork();
if (pid == 0) {
- ASSERT_EQ(0, run_fuse_sideload(vtab, 16384, 4096, mount_point.path));
+ ASSERT_EQ(0, run_fuse_sideload(std::move(provider), mount_point.path));
_exit(EXIT_SUCCESS);
}