fixes
This commit is contained in:
parent
d34ccc424d
commit
c0b0c5d397
@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
#include "file_manager/file_manager.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"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
@ -31,9 +31,8 @@
|
|||||||
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 file_manager::open_file &o,
|
static void test_closeable_open_file(const open_file &o, bool directory,
|
||||||
bool directory, const api_error &e,
|
const api_error &e, std::uint64_t size,
|
||||||
std::uint64_t size,
|
|
||||||
const std::string &source_path) {
|
const std::string &source_path) {
|
||||||
EXPECT_EQ(directory, o.is_directory());
|
EXPECT_EQ(directory, o.is_directory());
|
||||||
EXPECT_EQ(e, o.get_api_error());
|
EXPECT_EQ(e, o.get_api_error());
|
||||||
@ -43,8 +42,8 @@ static void test_closeable_open_file(const file_manager::open_file &o,
|
|||||||
EXPECT_TRUE(o.can_close());
|
EXPECT_TRUE(o.can_close());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validate_write(file_manager::open_file &o, std::size_t offset,
|
static void validate_write(open_file &o, std::size_t offset, data_buffer data,
|
||||||
data_buffer data, std::size_t bytes_written) {
|
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{};
|
||||||
@ -68,7 +67,7 @@ TEST(open_file, properly_initializes_state_for_0_byte_file) {
|
|||||||
fsi.size = 0u;
|
fsi.size = 0u;
|
||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
EXPECT_EQ(std::size_t(0u), o.get_read_state().size());
|
||||||
EXPECT_FALSE(o.is_modified());
|
EXPECT_FALSE(o.is_modified());
|
||||||
EXPECT_EQ(test_chunk_size, o.get_chunk_size());
|
EXPECT_EQ(test_chunk_size, o.get_chunk_size());
|
||||||
@ -96,7 +95,7 @@ TEST(open_file, properly_initializes_state_based_on_chunk_size) {
|
|||||||
EXPECT_EQ(fsi.source_path, source_path2);
|
EXPECT_EQ(fsi.source_path, source_path2);
|
||||||
});
|
});
|
||||||
|
|
||||||
file_manager::open_file o(1u, 0U, fsi, mp, um);
|
open_file o(1u, 0U, fsi, mp, um);
|
||||||
EXPECT_EQ(std::size_t(8u), o.get_read_state().size());
|
EXPECT_EQ(std::size_t(8u), o.get_read_state().size());
|
||||||
EXPECT_TRUE(o.get_read_state().none());
|
EXPECT_TRUE(o.get_read_state().none());
|
||||||
|
|
||||||
@ -122,7 +121,7 @@ TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
|||||||
fsi.size = 0u;
|
fsi.size = 0u;
|
||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
file_manager::open_file o(0u, 0U, fsi, mp, um);
|
open_file o(0u, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||||
|
|
||||||
o.close();
|
o.close();
|
||||||
@ -159,7 +158,7 @@ TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
|||||||
return api_error::success;
|
return api_error::success;
|
||||||
});
|
});
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
||||||
source_path);
|
source_path);
|
||||||
|
|
||||||
@ -185,7 +184,7 @@ TEST(open_file,
|
|||||||
fsi.size = test_chunk_size;
|
fsi.size = test_chunk_size;
|
||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size,
|
||||||
source_path);
|
source_path);
|
||||||
|
|
||||||
@ -209,7 +208,7 @@ TEST(open_file, write_with_incomplete_download) {
|
|||||||
fsi.size = test_chunk_size * 2u;
|
fsi.size = test_chunk_size * 2u;
|
||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, test_chunk_size * 2u,
|
test_closeable_open_file(o, false, api_error::success, test_chunk_size * 2u,
|
||||||
source_path);
|
source_path);
|
||||||
|
|
||||||
@ -302,7 +301,7 @@ TEST(open_file, write_new_file) {
|
|||||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||||
});
|
});
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||||
data_buffer data = {10, 9, 8};
|
data_buffer data = {10, 9, 8};
|
||||||
|
|
||||||
@ -374,7 +373,7 @@ TEST(open_file, write_new_file_multiple_chunks) {
|
|||||||
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
EXPECT_EQ(fsi.api_path, o.get_api_path());
|
||||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||||
});
|
});
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
test_closeable_open_file(o, false, api_error::success, 0u, source_path);
|
||||||
data_buffer data = {10, 9, 8};
|
data_buffer data = {10, 9, 8};
|
||||||
|
|
||||||
@ -463,7 +462,7 @@ TEST(open_file, resize_file_to_0_bytes) {
|
|||||||
fsi.size = test_chunk_size * 4u;
|
fsi.size = test_chunk_size * 4u;
|
||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
||||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
EXPECT_CALL(mp, 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 {
|
||||||
@ -518,7 +517,7 @@ TEST(open_file, resize_file_by_full_chunk) {
|
|||||||
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
EXPECT_EQ(fsi.source_path, o.get_source_path());
|
||||||
});
|
});
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
test_closeable_open_file(o, false, api_error::success, fsi.size, source_path);
|
||||||
EXPECT_CALL(mp, set_item_meta(fsi.api_path, _))
|
EXPECT_CALL(mp, 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 {
|
||||||
@ -595,7 +594,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"});
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
#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);
|
||||||
@ -661,7 +660,7 @@ TEST(open_file, can_remove_handle) {
|
|||||||
"filesystem_item_closed",
|
"filesystem_item_closed",
|
||||||
});
|
});
|
||||||
|
|
||||||
file_manager::open_file o(test_chunk_size, 0U, fsi, mp, um);
|
open_file o(test_chunk_size, 0U, fsi, mp, um);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
o.add(1u, {});
|
o.add(1u, {});
|
||||||
#else
|
#else
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
#include "file_manager/file_manager.hpp"
|
#include "file_manager/ring_buffer_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"
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
@ -48,8 +48,8 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(0u, 3u);
|
rb.set(0u, 3u);
|
||||||
rb.forward(4u);
|
rb.forward(4u);
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ TEST(ring_buffer_open_file,
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(0u, 3u);
|
rb.set(0u, 3u);
|
||||||
rb.forward(100u);
|
rb.forward(100u);
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(0u, 3u);
|
rb.set(0u, 3u);
|
||||||
rb.forward(5u);
|
rb.forward(5u);
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(16u, 20u);
|
rb.set(16u, 20u);
|
||||||
rb.forward(8u);
|
rb.forward(8u);
|
||||||
|
|
||||||
@ -171,8 +171,8 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(0u, 3u);
|
rb.set(0u, 3u);
|
||||||
rb.reverse(3u);
|
rb.reverse(3u);
|
||||||
|
|
||||||
@ -203,8 +203,8 @@ TEST(ring_buffer_open_file,
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(0u, 3u);
|
rb.set(0u, 3u);
|
||||||
rb.reverse(13u);
|
rb.reverse(13u);
|
||||||
|
|
||||||
@ -234,8 +234,8 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(1u, 3u);
|
rb.set(1u, 3u);
|
||||||
rb.reverse(3u);
|
rb.reverse(3u);
|
||||||
|
|
||||||
@ -266,8 +266,8 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(16u, 20u);
|
rb.set(16u, 20u);
|
||||||
rb.reverse(8u);
|
rb.reverse(8u);
|
||||||
|
|
||||||
@ -302,8 +302,8 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
|||||||
fsi.source_path = source_path;
|
fsi.source_path = source_path;
|
||||||
|
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
rb.set(8u, 15u);
|
rb.set(8u, 15u);
|
||||||
rb.reverse(16u);
|
rb.reverse(16u);
|
||||||
|
|
||||||
@ -349,8 +349,8 @@ TEST(ring_buffer_open_file, read_full_file) {
|
|||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
|
|
||||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||||
auto &nf2 = *ptr;
|
auto &nf2 = *ptr;
|
||||||
@ -414,8 +414,8 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
|||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
|
|
||||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||||
auto &nf2 = *ptr;
|
auto &nf2 = *ptr;
|
||||||
@ -479,8 +479,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
|||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
|
|
||||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||||
auto &nf2 = *ptr;
|
auto &nf2 = *ptr;
|
||||||
@ -545,8 +545,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
|||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
{
|
{
|
||||||
file_manager::ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size,
|
ring_buffer_open_file rb(ring_buffer_dir, test_chunk_size, 30U, fsi, mp,
|
||||||
30U, fsi, mp, 8u);
|
8u);
|
||||||
|
|
||||||
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
auto ptr = utils::file::file::open_or_create_file(dest_path);
|
||||||
auto &nf2 = *ptr;
|
auto &nf2 = *ptr;
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "test_common.hpp"
|
#include "test_common.hpp"
|
||||||
|
|
||||||
#include "file_manager/file_manager.hpp"
|
#include "file_manager/upload.hpp"
|
||||||
#include "mocks/mock_provider.hpp"
|
#include "mocks/mock_provider.hpp"
|
||||||
#include "utils/event_capture.hpp"
|
#include "utils/event_capture.hpp"
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ TEST(upload, can_upload_a_valid_file) {
|
|||||||
EXPECT_FALSE(stop_requested);
|
EXPECT_FALSE(stop_requested);
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
});
|
});
|
||||||
file_manager::upload upload(fsi, mock_prov);
|
upload upload(fsi, mock_prov);
|
||||||
|
|
||||||
event_capture evt_cap({"file_upload_completed"});
|
event_capture evt_cap({"file_upload_completed"});
|
||||||
evt_cap.wait_for_empty();
|
evt_cap.wait_for_empty();
|
||||||
@ -120,7 +120,7 @@ TEST(upload, can_cancel_upload) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
unique_mutex_lock lock(mtx);
|
unique_mutex_lock lock(mtx);
|
||||||
file_manager::upload upload(fsi, mock_provider);
|
upload upload(fsi, mock_provider);
|
||||||
notify.wait(lock);
|
notify.wait(lock);
|
||||||
|
|
||||||
upload.cancel();
|
upload.cancel();
|
||||||
@ -173,7 +173,9 @@ TEST(upload, can_stop_upload) {
|
|||||||
|
|
||||||
event_capture evt_cap({"file_upload_completed"});
|
event_capture evt_cap({"file_upload_completed"});
|
||||||
|
|
||||||
{ file_manager::upload upload(fsi, mock_provider); }
|
{
|
||||||
|
upload upload(fsi, mock_provider);
|
||||||
|
}
|
||||||
|
|
||||||
evt_cap.wait_for_empty();
|
evt_cap.wait_for_empty();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user