diff options
author | Tianjie Xu <xunchang@google.com> | 2019-03-20 18:43:30 +0100 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-03-20 18:43:30 +0100 |
commit | 2037c60de48b560be698f3a74588084b1de5e726 (patch) | |
tree | 9f5ad0d458a7ae8cb128e0c48caf1def481105dd /tests | |
parent | Merge "Create a FuseDataProvider base class" (diff) | |
parent | Remove the provider_vtab (diff) | |
download | android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar.gz android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar.bz2 android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar.lz android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar.xz android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.tar.zst android_bootable_recovery-2037c60de48b560be698f3a74588084b1de5e726.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/component/sideload_test.cpp | 31 |
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); } |