|
|
@ -21,6 +21,8 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#include "test_common.hpp"
|
|
|
|
#include "test_common.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "app_config.hpp"
|
|
|
|
|
|
|
|
#include "file_manager/cache_size_mgr.hpp"
|
|
|
|
#include "file_manager/open_file.hpp"
|
|
|
|
#include "file_manager/open_file.hpp"
|
|
|
|
#include "mocks/mock_provider.hpp"
|
|
|
|
#include "mocks/mock_provider.hpp"
|
|
|
|
#include "mocks/mock_upload_manager.hpp"
|
|
|
|
#include "mocks/mock_upload_manager.hpp"
|
|
|
@ -29,190 +31,219 @@
|
|
|
|
#include "utils/path.hpp"
|
|
|
|
#include "utils/path.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
namespace repertory {
|
|
|
|
namespace repertory {
|
|
|
|
static constexpr const std::size_t test_chunk_size = 1024u;
|
|
|
|
static constexpr const std::size_t test_chunk_size{1024U};
|
|
|
|
|
|
|
|
|
|
|
|
static void test_closeable_open_file(const open_file &o, bool directory,
|
|
|
|
class open_file_test : public ::testing::Test {
|
|
|
|
const api_error &e, std::uint64_t size,
|
|
|
|
public:
|
|
|
|
|
|
|
|
console_consumer con_consumer;
|
|
|
|
|
|
|
|
std::unique_ptr<app_config> cfg;
|
|
|
|
|
|
|
|
static std::atomic<std::size_t> inst;
|
|
|
|
|
|
|
|
mock_provider provider;
|
|
|
|
|
|
|
|
mock_upload_manager upload_mgr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
|
|
|
event_system::instance().start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto open_file_dir = repertory::utils::path::combine(
|
|
|
|
|
|
|
|
repertory::test::get_test_output_dir(),
|
|
|
|
|
|
|
|
{"open_file_test" + std::to_string(++inst)});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cfg = std::make_unique<app_config>(provider_type::sia, open_file_dir);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache_size_mgr::instance().initialize(cfg.get());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TearDown() override { event_system::instance().stop(); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::atomic<std::size_t> open_file_test::inst{0U};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void test_closeable_open_file(const open_file &file, bool directory,
|
|
|
|
|
|
|
|
const api_error &err, std::uint64_t size,
|
|
|
|
const std::string &source_path) {
|
|
|
|
const std::string &source_path) {
|
|
|
|
EXPECT_EQ(directory, o.is_directory());
|
|
|
|
EXPECT_EQ(directory, file.is_directory());
|
|
|
|
EXPECT_EQ(e, o.get_api_error());
|
|
|
|
EXPECT_EQ(err, file.get_api_error());
|
|
|
|
EXPECT_EQ(std::size_t(0u), o.get_open_file_count());
|
|
|
|
EXPECT_EQ(std::size_t(0U), file.get_open_file_count());
|
|
|
|
EXPECT_EQ(std::uint64_t(size), o.get_file_size());
|
|
|
|
EXPECT_EQ(std::uint64_t(size), file.get_file_size());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
EXPECT_TRUE(o.can_close());
|
|
|
|
EXPECT_TRUE(file.can_close());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void validate_write(open_file &o, std::size_t offset, data_buffer data,
|
|
|
|
static void validate_write(open_file &file, std::size_t offset,
|
|
|
|
std::size_t bytes_written) {
|
|
|
|
data_buffer data, std::size_t bytes_written) {
|
|
|
|
EXPECT_EQ(data.size(), bytes_written);
|
|
|
|
EXPECT_EQ(data.size(), bytes_written);
|
|
|
|
|
|
|
|
|
|
|
|
data_buffer read_data{};
|
|
|
|
data_buffer read_data{};
|
|
|
|
EXPECT_EQ(api_error::success, o.read(data.size(), offset, read_data));
|
|
|
|
EXPECT_EQ(api_error::success, file.read(data.size(), offset, read_data));
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(std::equal(data.begin(), data.end(), read_data.begin()));
|
|
|
|
EXPECT_TRUE(std::equal(data.begin(), data.end(), read_data.begin()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, properly_initializes_state_for_0_byte_file) {
|
|
|
|
TEST_F(open_file_test, properly_initializes_state_for_0_byte_file) {
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.directory = false;
|
|
|
|
fsi.directory = false;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = 0u;
|
|
|
|
fsi.size = 0U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
|
|
|
|
|
|
|
EXPECT_FALSE(o.is_modified());
|
|
|
|
|
|
|
|
EXPECT_EQ(test_chunk_size, o.get_chunk_size());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, properly_initializes_state_based_on_chunk_size) {
|
|
|
|
|
|
|
|
const auto source_path =
|
|
|
|
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
|
|
|
|
fsi.directory = false;
|
|
|
|
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
|
|
|
|
fsi.size = 8u;
|
|
|
|
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_resume)
|
|
|
|
|
|
|
|
.WillOnce(
|
|
|
|
.WillOnce(
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(1u, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
EXPECT_EQ(std::size_t(8u), o.get_read_state().size());
|
|
|
|
EXPECT_EQ(std::size_t(0U), file.get_read_state().size());
|
|
|
|
EXPECT_TRUE(o.get_read_state().none());
|
|
|
|
EXPECT_FALSE(file.is_modified());
|
|
|
|
|
|
|
|
EXPECT_EQ(test_chunk_size, file.get_chunk_size());
|
|
|
|
EXPECT_FALSE(o.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(1u), o.get_chunk_size());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
|
|
|
TEST_F(open_file_test, properly_initializes_state_based_on_chunk_size) {
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.directory = false;
|
|
|
|
fsi.directory = false;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = 0u;
|
|
|
|
fsi.size = 8U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(0u, 0U, fsi, mp, um);
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
|
|
|
.WillOnce(
|
|
|
|
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
open_file file(1U, 0U, fsi, provider, upload_mgr);
|
|
|
|
EXPECT_EQ(api_error::success, o.get_api_error());
|
|
|
|
EXPECT_EQ(std::size_t(8U), file.get_read_state().size());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_TRUE(file.get_read_state().none());
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(file.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(1U), file.get_chunk_size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
|
|
|
TEST_F(open_file_test, will_not_change_source_path_for_0_byte_file) {
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
filesystem_item fsi;
|
|
|
|
|
|
|
|
fsi.directory = false;
|
|
|
|
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
|
|
|
|
fsi.size = 0U;
|
|
|
|
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
|
|
|
|
.WillOnce(
|
|
|
|
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open_file file(0U, 0U, fsi, provider, upload_mgr);
|
|
|
|
|
|
|
|
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, file.get_api_error());
|
|
|
|
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(open_file_test, will_change_source_path_if_file_size_is_greater_than_0) {
|
|
|
|
|
|
|
|
const auto source_path =
|
|
|
|
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = test_chunk_size;
|
|
|
|
fsi.size = test_chunk_size;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_resume)
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
.WillOnce(
|
|
|
|
.WillOnce(
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
.WillOnce([&fsi](const std::string &, const std::string &,
|
|
|
|
.WillOnce([&fsi](const std::string &, const std::string &,
|
|
|
|
const std::string &source_path2) -> api_error {
|
|
|
|
const std::string &source_path2) -> api_error {
|
|
|
|
EXPECT_STRNE(fsi.source_path.c_str(), source_path2.c_str());
|
|
|
|
EXPECT_STRNE(fsi.source_path.c_str(), source_path2.c_str());
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
|
|
|
test_closeable_open_file(file, false, api_error::success, test_chunk_size,
|
|
|
|
source_path);
|
|
|
|
source_path);
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
file.close();
|
|
|
|
EXPECT_EQ(api_error::download_stopped, o.get_api_error());
|
|
|
|
EXPECT_EQ(api_error::download_stopped, file.get_api_error());
|
|
|
|
EXPECT_STRNE(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STRNE(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
EXPECT_FALSE(utils::file::file(source_path).exists());
|
|
|
|
EXPECT_FALSE(utils::file::file(source_path).exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file,
|
|
|
|
TEST_F(open_file_test,
|
|
|
|
will_not_change_source_path_if_file_size_matches_existing_source) {
|
|
|
|
will_not_change_source_path_if_file_size_matches_existing_source) {
|
|
|
|
auto &rf = test::create_random_file(test_chunk_size);
|
|
|
|
auto &rf = test::create_random_file(test_chunk_size);
|
|
|
|
const auto source_path = rf.get_path();
|
|
|
|
const auto source_path = rf.get_path();
|
|
|
|
rf.close();
|
|
|
|
rf.close();
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = test_chunk_size;
|
|
|
|
fsi.size = test_chunk_size;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
|
|
|
.WillOnce(
|
|
|
|
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
|
|
|
|
test_closeable_open_file(file, false, api_error::success, test_chunk_size,
|
|
|
|
source_path);
|
|
|
|
source_path);
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
file.close();
|
|
|
|
EXPECT_EQ(api_error::success, o.get_api_error());
|
|
|
|
EXPECT_EQ(api_error::success, file.get_api_error());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
EXPECT_TRUE(utils::file::file(source_path).exists());
|
|
|
|
EXPECT_TRUE(utils::file::file(source_path).exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, write_with_incomplete_download) {
|
|
|
|
TEST_F(open_file_test, write_with_incomplete_download) {
|
|
|
|
const auto source_path = test::generate_test_file_name("test");
|
|
|
|
const auto source_path = test::generate_test_file_name("test");
|
|
|
|
auto &nf = test::create_random_file(test_chunk_size * 2u);
|
|
|
|
auto &nf = test::create_random_file(test_chunk_size * 2u);
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = test_chunk_size * 2u;
|
|
|
|
fsi.size = test_chunk_size * 2u;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size * 2u,
|
|
|
|
test_closeable_open_file(file, false, api_error::success,
|
|
|
|
source_path);
|
|
|
|
test_chunk_size * 2u, source_path);
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
@ -220,7 +251,7 @@ TEST(open_file, write_with_incomplete_download) {
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, read_file_bytes)
|
|
|
|
EXPECT_CALL(provider, read_file_bytes)
|
|
|
|
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
|
|
|
.WillRepeatedly([&nf](const std::string & /* api_path */,
|
|
|
|
std::size_t size, std::uint64_t offset,
|
|
|
|
std::size_t size, std::uint64_t offset,
|
|
|
|
data_buffer &data,
|
|
|
|
data_buffer &data,
|
|
|
@ -229,7 +260,7 @@ TEST(open_file, write_with_incomplete_download) {
|
|
|
|
return api_error::download_stopped;
|
|
|
|
return api_error::download_stopped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (offset == 0u) {
|
|
|
|
if (offset == 0U) {
|
|
|
|
std::size_t bytes_read{};
|
|
|
|
std::size_t bytes_read{};
|
|
|
|
data.resize(size);
|
|
|
|
data.resize(size);
|
|
|
|
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
|
|
|
auto ret = nf.read(data, offset, &bytes_read) ? api_error::success
|
|
|
@ -244,11 +275,12 @@ TEST(open_file, write_with_incomplete_download) {
|
|
|
|
return api_error::download_stopped;
|
|
|
|
return api_error::download_stopped;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_CALL(upload_mgr, remove_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, store_resume)
|
|
|
|
EXPECT_CALL(upload_mgr, store_resume)
|
|
|
|
.Times(2)
|
|
|
|
.Times(2)
|
|
|
|
.WillRepeatedly([&fsi](const i_open_file &cur_file) {
|
|
|
|
.WillRepeatedly([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
@ -257,55 +289,53 @@ TEST(open_file, write_with_incomplete_download) {
|
|
|
|
|
|
|
|
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
|
|
|
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
|
|
|
validate_write(o, 0u, data, bytes_written);
|
|
|
|
validate_write(file, 0U, data, bytes_written);
|
|
|
|
|
|
|
|
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(o.can_close());
|
|
|
|
EXPECT_FALSE(file.can_close());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(o.is_modified());
|
|
|
|
EXPECT_TRUE(file.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(o.get_read_state(0u));
|
|
|
|
EXPECT_TRUE(file.get_read_state(0U));
|
|
|
|
EXPECT_FALSE(o.get_read_state(1u));
|
|
|
|
EXPECT_FALSE(file.get_read_state(1u));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
file.close();
|
|
|
|
nf.close();
|
|
|
|
nf.close();
|
|
|
|
|
|
|
|
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::download_incomplete, o.get_api_error());
|
|
|
|
EXPECT_EQ(api_error::download_incomplete, file.get_api_error());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, write_new_file) {
|
|
|
|
TEST_F(open_file_test, write_new_file) {
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = 0u;
|
|
|
|
fsi.size = 0U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
|
|
|
EXPECT_CALL(upload_mgr, store_resume)
|
|
|
|
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
|
|
|
.WillOnce([&fsi](const i_open_file &file) {
|
|
|
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
|
|
|
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
|
|
|
.WillOnce([&data](const std::string &,
|
|
|
|
.WillOnce([&data](const std::string &,
|
|
|
|
const api_meta_map &meta) -> api_error {
|
|
|
|
const api_meta_map &meta) -> api_error {
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
@ -322,62 +352,62 @@ TEST(open_file, write_new_file) {
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_CALL(upload_mgr, remove_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_CALL(upload_mgr, queue_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
|
|
|
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
|
|
|
|
|
|
|
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(o.can_close());
|
|
|
|
EXPECT_FALSE(file.can_close());
|
|
|
|
EXPECT_TRUE(o.is_modified());
|
|
|
|
EXPECT_TRUE(file.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(o.get_read_state(0u));
|
|
|
|
EXPECT_TRUE(file.get_read_state(0U));
|
|
|
|
EXPECT_EQ(std::size_t(1u), o.get_read_state().size());
|
|
|
|
EXPECT_EQ(std::size_t(1u), file.get_read_state().size());
|
|
|
|
EXPECT_EQ(data.size(), o.get_file_size());
|
|
|
|
EXPECT_EQ(data.size(), file.get_file_size());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, o.get_api_error());
|
|
|
|
EXPECT_EQ(api_error::success, file.get_api_error());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, write_new_file_multiple_chunks) {
|
|
|
|
TEST_F(open_file_test, write_new_file_multiple_chunks) {
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = 0u;
|
|
|
|
fsi.size = 0U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
|
|
|
EXPECT_CALL(upload_mgr, store_resume)
|
|
|
|
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
|
|
|
.WillOnce([&fsi](const i_open_file &file) {
|
|
|
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
|
|
|
test_closeable_open_file(file, false, api_error::success, 0U, source_path);
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
data_buffer data = {10, 9, 8};
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
|
|
|
.WillOnce([&data](const std::string &,
|
|
|
|
.WillOnce([&data](const std::string &,
|
|
|
|
const api_meta_map &meta) -> api_error {
|
|
|
|
const api_meta_map &meta) -> api_error {
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
@ -410,153 +440,159 @@ TEST(open_file, write_new_file_multiple_chunks) {
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_CALL(upload_mgr, remove_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_CALL(upload_mgr, queue_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
std::size_t bytes_written{};
|
|
|
|
EXPECT_EQ(api_error::success, o.write(0u, data, bytes_written));
|
|
|
|
EXPECT_EQ(api_error::success, file.write(0U, data, bytes_written));
|
|
|
|
EXPECT_EQ(api_error::success, o.write(test_chunk_size, data, bytes_written));
|
|
|
|
EXPECT_EQ(api_error::success,
|
|
|
|
|
|
|
|
file.write(test_chunk_size, data, bytes_written));
|
|
|
|
|
|
|
|
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
const auto test_state = [&]() {
|
|
|
|
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
|
|
|
EXPECT_STREQ(source_path.c_str(), file.get_source_path().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(o.can_close());
|
|
|
|
EXPECT_FALSE(file.can_close());
|
|
|
|
EXPECT_TRUE(o.is_modified());
|
|
|
|
EXPECT_TRUE(file.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(2u), o.get_read_state().size());
|
|
|
|
EXPECT_EQ(std::size_t(2u), file.get_read_state().size());
|
|
|
|
for (std::size_t i = 0u; i < 2u; i++) {
|
|
|
|
for (std::size_t i = 0U; i < 2u; i++) {
|
|
|
|
EXPECT_TRUE(o.get_read_state(i));
|
|
|
|
EXPECT_TRUE(file.get_read_state(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(data.size() + test_chunk_size, o.get_file_size());
|
|
|
|
EXPECT_EQ(data.size() + test_chunk_size, file.get_file_size());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
o.close();
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
|
|
|
|
test_state();
|
|
|
|
test_state();
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, o.get_api_error());
|
|
|
|
EXPECT_EQ(api_error::success, file.get_api_error());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, resize_file_to_0_bytes) {
|
|
|
|
TEST_F(open_file_test, resize_file_to_0_bytes) {
|
|
|
|
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
|
|
|
auto &r_file = test::create_random_file(test_chunk_size * 4U);
|
|
|
|
const auto source_path = rf.get_path();
|
|
|
|
const auto source_path = r_file.get_path();
|
|
|
|
rf.close();
|
|
|
|
r_file.close();
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = test_chunk_size * 4u;
|
|
|
|
fsi.size = test_chunk_size * 4U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
EXPECT_EQ(api_error::success, cache_size_mgr::instance().expand(fsi.size));
|
|
|
|
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
|
|
|
|
test_closeable_open_file(file, false, api_error::success, fsi.size,
|
|
|
|
|
|
|
|
source_path);
|
|
|
|
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
|
|
|
EXPECT_EQ(std::size_t(0u),
|
|
|
|
EXPECT_EQ(std::size_t(0U),
|
|
|
|
utils::string::to_size_t(meta.at(META_SIZE)));
|
|
|
|
utils::string::to_size_t(meta.at(META_SIZE)));
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std ::string &api_path) {
|
|
|
|
EXPECT_CALL(upload_mgr, remove_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const std ::string &api_path) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_CALL(upload_mgr, queue_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_CALL(upload_mgr, store_resume)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, o.resize(0u));
|
|
|
|
EXPECT_EQ(api_error::success, file.resize(0U));
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(0u), o.get_file_size());
|
|
|
|
EXPECT_EQ(std::size_t(0U), file.get_file_size());
|
|
|
|
EXPECT_FALSE(o.can_close());
|
|
|
|
EXPECT_FALSE(file.can_close());
|
|
|
|
EXPECT_TRUE(o.is_modified());
|
|
|
|
EXPECT_TRUE(file.is_modified());
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
|
|
|
EXPECT_EQ(std::size_t(0U), file.get_read_state().size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, resize_file_by_full_chunk) {
|
|
|
|
TEST_F(open_file_test, resize_file_by_full_chunk) {
|
|
|
|
auto &rf = test::create_random_file(test_chunk_size * 4u);
|
|
|
|
auto &r_file = test::create_random_file(test_chunk_size * 4U);
|
|
|
|
const auto source_path = rf.get_path();
|
|
|
|
const auto source_path = r_file.get_path();
|
|
|
|
rf.close();
|
|
|
|
r_file.close();
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.size = test_chunk_size * 4u;
|
|
|
|
fsi.size = test_chunk_size * 4U;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
fsi.source_path = source_path;
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, store_resume).WillOnce([&fsi](const i_open_file &o) {
|
|
|
|
EXPECT_EQ(api_error::success, cache_size_mgr::instance().expand(fsi.size));
|
|
|
|
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
|
|
|
EXPECT_CALL(upload_mgr, store_resume)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &file) {
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.api_path, file.get_api_path());
|
|
|
|
|
|
|
|
EXPECT_EQ(fsi.source_path, file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file file(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
|
|
|
test_closeable_open_file(file, false, api_error::success, fsi.size,
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
|
|
|
source_path);
|
|
|
|
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, _))
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
.WillOnce([](const std::string &, const api_meta_map &meta) -> api_error {
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_CHANGED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_MODIFIED).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_SIZE).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
|
|
|
EXPECT_NO_THROW(EXPECT_FALSE(meta.at(META_WRITTEN).empty()));
|
|
|
|
EXPECT_EQ(std::size_t(test_chunk_size * 3u),
|
|
|
|
EXPECT_EQ(std::size_t(test_chunk_size * 3U),
|
|
|
|
utils::string::to_size_t(meta.at(META_SIZE)));
|
|
|
|
utils::string::to_size_t(meta.at(META_SIZE)));
|
|
|
|
return api_error::success;
|
|
|
|
return api_error::success;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_upload).WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_CALL(upload_mgr, remove_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const std::string &api_path) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, queue_upload).WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_CALL(upload_mgr, queue_upload)
|
|
|
|
|
|
|
|
.WillOnce([&fsi](const i_open_file &cur_file) {
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.api_path, cur_file.get_api_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
EXPECT_EQ(fsi.source_path, cur_file.get_source_path());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(api_error::success, o.resize(test_chunk_size * 3u));
|
|
|
|
EXPECT_EQ(api_error::success, file.resize(test_chunk_size * 3U));
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(std::size_t(test_chunk_size * 3u), o.get_file_size());
|
|
|
|
EXPECT_EQ(std::size_t(test_chunk_size * 3U), file.get_file_size());
|
|
|
|
EXPECT_FALSE(o.can_close());
|
|
|
|
EXPECT_FALSE(file.can_close());
|
|
|
|
EXPECT_TRUE(o.is_modified());
|
|
|
|
EXPECT_TRUE(file.is_modified());
|
|
|
|
EXPECT_EQ(std::size_t(3u), o.get_read_state().size());
|
|
|
|
EXPECT_EQ(std::size_t(3U), file.get_read_state().size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, can_add_handle) {
|
|
|
|
TEST_F(open_file_test, can_add_handle) {
|
|
|
|
event_system::instance().start();
|
|
|
|
event_system::instance().start();
|
|
|
|
console_consumer c;
|
|
|
|
console_consumer c;
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
@ -582,9 +618,9 @@ TEST(open_file, can_add_handle) {
|
|
|
|
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
|
|
|
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
EXPECT_CALL(um, remove_resume)
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
.WillOnce(
|
|
|
|
.WillOnce(
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
@ -594,7 +630,7 @@ TEST(open_file, can_add_handle) {
|
|
|
|
event_capture capture(
|
|
|
|
event_capture capture(
|
|
|
|
{"filesystem_item_opened", "filesystem_item_handle_opened"});
|
|
|
|
{"filesystem_item_opened", "filesystem_item_handle_opened"});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
o.add(1u, {});
|
|
|
|
o.add(1u, {});
|
|
|
|
EXPECT_EQ(nullptr, o.get_open_data(1u).directory_buffer);
|
|
|
|
EXPECT_EQ(nullptr, o.get_open_data(1u).directory_buffer);
|
|
|
@ -608,17 +644,14 @@ TEST(open_file, can_add_handle) {
|
|
|
|
event_system::instance().stop();
|
|
|
|
event_system::instance().stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, can_remove_handle) {
|
|
|
|
TEST_F(open_file_test, can_remove_handle) {
|
|
|
|
event_system::instance().start();
|
|
|
|
event_system::instance().start();
|
|
|
|
console_consumer c;
|
|
|
|
console_consumer c;
|
|
|
|
|
|
|
|
|
|
|
|
const auto source_path =
|
|
|
|
const auto source_path =
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
test::generate_test_file_name("file_manager_open_file_test");
|
|
|
|
|
|
|
|
|
|
|
|
mock_provider mp;
|
|
|
|
EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
mock_upload_manager um;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filesystem_item fsi;
|
|
|
|
filesystem_item fsi;
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
|
fsi.api_path = "/test.txt";
|
|
|
@ -644,13 +677,13 @@ TEST(open_file, can_remove_handle) {
|
|
|
|
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
|
|
|
EXPECT_STREQ("1", ee.get_handle().get<std::string>().c_str());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(um, remove_resume)
|
|
|
|
EXPECT_CALL(upload_mgr, remove_resume)
|
|
|
|
.WillOnce(
|
|
|
|
.WillOnce(
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
[&fsi](const std::string &api_path, const std::string &source_path2) {
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.api_path, api_path);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
EXPECT_EQ(fsi.source_path, source_path2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
EXPECT_CALL(mp, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
EXPECT_CALL(provider, set_item_meta(fsi.api_path, META_SOURCE, _))
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
.WillOnce(Return(api_error::success));
|
|
|
|
|
|
|
|
|
|
|
|
event_capture capture({
|
|
|
|
event_capture capture({
|
|
|
@ -660,7 +693,7 @@ TEST(open_file, can_remove_handle) {
|
|
|
|
"filesystem_item_closed",
|
|
|
|
"filesystem_item_closed",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
|
|
|
open_file o(test_chunk_size, 0U, fsi, provider, upload_mgr);
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#if defined(_WIN32)
|
|
|
|
o.add(1u, {});
|
|
|
|
o.add(1u, {});
|
|
|
|
#else
|
|
|
|
#else
|
|
|
@ -673,12 +706,13 @@ TEST(open_file, can_remove_handle) {
|
|
|
|
event_system::instance().stop();
|
|
|
|
event_system::instance().stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file,
|
|
|
|
TEST_F(open_file_test,
|
|
|
|
can_read_locally_after_write_with_file_size_greater_than_existing_size) {}
|
|
|
|
can_read_locally_after_write_with_file_size_greater_than_existing_size) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, test_valid_download_chunks) {}
|
|
|
|
TEST_F(open_file_test, test_valid_download_chunks) {}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, test_full_download_with_partial_chunk) {}
|
|
|
|
TEST_F(open_file_test, test_full_download_with_partial_chunk) {}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(open_file, source_is_read_after_full_download) {}
|
|
|
|
TEST_F(open_file_test, source_is_read_after_full_download) {}
|
|
|
|
} // namespace repertory
|
|
|
|
} // namespace repertory
|
|
|
|