summaryrefslogtreecommitdiffstats
path: root/tests/component/sideload_test.cpp
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-03-20 19:10:04 +0100
committerandroid-build-merger <android-build-merger@google.com>2019-03-20 19:10:04 +0100
commit9b177eb32d5156df43565831d8e80d958db36af5 (patch)
tree7d534e4a3f47b18eb13b11f4a386f98ae1cd289e /tests/component/sideload_test.cpp
parentMerge "Create a FuseDataProvider base class" am: eeea86f5fd am: 4aa4bf5e19 (diff)
parentMerge "Remove the provider_vtab" am: 2037c60de4 (diff)
downloadandroid_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar.gz
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar.bz2
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar.lz
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar.xz
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.tar.zst
android_bootable_recovery-9b177eb32d5156df43565831d8e80d958db36af5.zip
Diffstat (limited to 'tests/component/sideload_test.cpp')
-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);
}