From 2d5508eb7c329c9501a55bf381a716d61555d03f Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Mon, 23 Dec 2024 09:27:17 -0600 Subject: [PATCH] Complete ring buffer and direct download support #26 --- .../src/direct_open_file_test.cpp | 23 ++++--- .../repertory_test/src/open_file_test.cpp | 6 +- .../src/ring_buffer_open_file_test.cpp | 61 +++++++++---------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/repertory/repertory_test/src/direct_open_file_test.cpp b/repertory/repertory_test/src/direct_open_file_test.cpp index e565b8eb..522f8e46 100644 --- a/repertory/repertory_test/src/direct_open_file_test.cpp +++ b/repertory/repertory_test/src/direct_open_file_test.cpp @@ -29,12 +29,22 @@ constexpr const std::size_t test_chunk_size{1024U}; } // namespace namespace repertory { -TEST(direct_open_file, read_full_file) { +class direct_open_file_test : public ::testing::Test { +public: + console_consumer con_consumer; + mock_provider provider; + +protected: + void SetUp() override { event_system::instance().start(); } + + void TearDown() override { event_system::instance().stop(); } +}; + +TEST_F(direct_open_file_test, read_full_file) { auto &source_file = test::create_random_file(test_chunk_size * 32U); auto dest_path = test::generate_test_file_name("direct_open_file"); - mock_provider provider; EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -89,12 +99,11 @@ TEST(direct_open_file, read_full_file) { } } -TEST(direct_open_file, read_full_file_in_reverse) { +TEST_F(direct_open_file_test, read_full_file_in_reverse) { auto &source_file = test::create_random_file(test_chunk_size * 32U); auto dest_path = test::generate_test_file_name("direct_open_file"); - mock_provider provider; EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -149,12 +158,11 @@ TEST(direct_open_file, read_full_file_in_reverse) { } } -TEST(direct_open_file, read_full_file_in_partial_chunks) { +TEST_F(direct_open_file_test, read_full_file_in_partial_chunks) { auto &source_file = test::create_random_file(test_chunk_size * 32U); auto dest_path = test::generate_test_file_name("test"); - mock_provider provider; EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -206,12 +214,11 @@ TEST(direct_open_file, read_full_file_in_partial_chunks) { } } -TEST(direct_open_file, read_full_file_in_partial_chunks_in_reverse) { +TEST_F(direct_open_file_test, read_full_file_in_partial_chunks_in_reverse) { auto &source_file = test::create_random_file(test_chunk_size * 32U); auto dest_path = test::generate_test_file_name("direct_open_file"); - mock_provider provider; EXPECT_CALL(provider, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; diff --git a/repertory/repertory_test/src/open_file_test.cpp b/repertory/repertory_test/src/open_file_test.cpp index 5e3eb19b..5d2d9e42 100644 --- a/repertory/repertory_test/src/open_file_test.cpp +++ b/repertory/repertory_test/src/open_file_test.cpp @@ -30,9 +30,11 @@ #include "utils/event_capture.hpp" #include "utils/path.hpp" -namespace repertory { -static constexpr const std::size_t test_chunk_size{1024U}; +namespace { +constexpr const std::size_t test_chunk_size{1024U}; +} +namespace repertory { class open_file_test : public ::testing::Test { public: console_consumer con_consumer; diff --git a/repertory/repertory_test/src/ring_buffer_open_file_test.cpp b/repertory/repertory_test/src/ring_buffer_open_file_test.cpp index 9f50b2d5..43cf49b0 100644 --- a/repertory/repertory_test/src/ring_buffer_open_file_test.cpp +++ b/repertory/repertory_test/src/ring_buffer_open_file_test.cpp @@ -37,11 +37,20 @@ std::string ring_buffer_dir = repertory::utils::path::combine( } // namespace namespace repertory { -TEST(ring_buffer_open_file, can_forward_to_last_chunk) { - auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - +class ring_buffer_open_file_test : public ::testing::Test { +public: + console_consumer con_consumer; mock_provider prov; +protected: + void SetUp() override { event_system::instance().start(); } + + void TearDown() override { event_system::instance().stop(); } +}; + +TEST_F(ring_buffer_open_file_test, can_forward_to_last_chunk) { + auto source_path = test::generate_test_file_name("ring_buffer_open_file"); + EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -67,12 +76,10 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, - can_forward_to_last_chunk_if_count_is_greater_than_remaining) { +TEST_F(ring_buffer_open_file_test, + can_forward_to_last_chunk_if_count_is_greater_than_remaining) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -98,11 +105,9 @@ TEST(ring_buffer_open_file, EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_forward_after_last_chunk) { +TEST_F(ring_buffer_open_file_test, can_forward_after_last_chunk) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -129,11 +134,9 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) { +TEST_F(ring_buffer_open_file_test, can_forward_and_rollover_after_last_chunk) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -156,11 +159,9 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_reverse_to_first_chunk) { +TEST_F(ring_buffer_open_file_test, can_reverse_to_first_chunk) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -186,12 +187,10 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, - can_reverse_to_first_chunk_if_count_is_greater_than_remaining) { +TEST_F(ring_buffer_open_file_test, + can_reverse_to_first_chunk_if_count_is_greater_than_remaining) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -217,11 +216,9 @@ TEST(ring_buffer_open_file, EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_reverse_before_first_chunk) { +TEST_F(ring_buffer_open_file_test, can_reverse_before_first_chunk) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -248,11 +245,10 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) { +TEST_F(ring_buffer_open_file_test, + can_reverse_and_rollover_before_first_chunk) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -283,11 +279,9 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, can_reverse_full_ring) { +TEST_F(ring_buffer_open_file_test, can_reverse_full_ring) { auto source_path = test::generate_test_file_name("ring_buffer_open_file"); - mock_provider prov; - EXPECT_CALL(prov, is_read_only()).WillRepeatedly(Return(false)); filesystem_item fsi; @@ -314,7 +308,7 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, read_full_file) { +TEST_F(ring_buffer_open_file_test, read_full_file) { auto &nf = test::create_random_file(test_chunk_size * 33u + 11u); auto download_source_path = nf.get_path(); @@ -379,7 +373,7 @@ TEST(ring_buffer_open_file, read_full_file) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, read_full_file_in_reverse) { +TEST_F(ring_buffer_open_file_test, read_full_file_in_reverse) { auto &nf = test::create_random_file(test_chunk_size * 32u); auto download_source_path = nf.get_path(); @@ -444,7 +438,7 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) { +TEST_F(ring_buffer_open_file_test, read_full_file_in_partial_chunks) { auto &nf = test::create_random_file(test_chunk_size * 32u); auto download_source_path = nf.get_path(); @@ -510,7 +504,8 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) { EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively()); } -TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) { +TEST_F(ring_buffer_open_file_test, + read_full_file_in_partial_chunks_in_reverse) { auto &nf = test::create_random_file(test_chunk_size * 32u); auto download_source_path = nf.get_path();