diff --git a/repertory/repertory_test/src/meta_db_test.cpp b/repertory/repertory_test/src/meta_db_test.cpp index a367761f..342b68c1 100644 --- a/repertory/repertory_test/src/meta_db_test.cpp +++ b/repertory/repertory_test/src/meta_db_test.cpp @@ -355,4 +355,118 @@ TYPED_TEST(meta_db_test, get_total_item_count_decreases_after_file_is_removed) { this->meta_db->remove_api_path(test_file); EXPECT_EQ(1U, this->meta_db->get_total_item_count()); } + +TYPED_TEST(meta_db_test, can_get_total_size) { + this->meta_db->clear(); + EXPECT_EQ(0U, this->meta_db->get_total_item_count()); + + auto test_file = create_test_file(); + auto test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "2"}, + })); + + test_file = create_test_file(); + test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "1"}, + })); + + auto test_dir = create_test_file(); + EXPECT_EQ(api_error::success, + this->meta_db->set_item_meta( + test_dir, { + {META_DIRECTORY, utils::string::from_bool(true)}, + {META_SIZE, "7"}, + })); + + EXPECT_EQ(3U, this->meta_db->get_total_size()); +} + +TYPED_TEST(meta_db_test, + total_size_does_not_decrease_after_directory_is_removed) { + this->meta_db->clear(); + EXPECT_EQ(0U, this->meta_db->get_total_item_count()); + + auto test_file = create_test_file(); + auto test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "2"}, + })); + + test_file = create_test_file(); + test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "1"}, + })); + + auto test_dir = create_test_file(); + EXPECT_EQ(api_error::success, + this->meta_db->set_item_meta( + test_dir, { + {META_DIRECTORY, utils::string::from_bool(true)}, + {META_SIZE, "7"}, + })); + this->meta_db->remove_api_path(test_dir); + + EXPECT_EQ(3U, this->meta_db->get_total_size()); +} + +TYPED_TEST(meta_db_test, total_size_decreases_after_file_is_removed) { + this->meta_db->clear(); + EXPECT_EQ(0U, this->meta_db->get_total_item_count()); + + auto test_file = create_test_file(); + auto test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "2"}, + })); + + test_file = create_test_file(); + test_source = create_test_file(); + EXPECT_EQ( + api_error::success, + this->meta_db->set_item_meta( + test_file, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_SOURCE, test_source}, + {META_SIZE, "1"}, + })); + + auto test_dir = create_test_file(); + EXPECT_EQ(api_error::success, + this->meta_db->set_item_meta( + test_dir, { + {META_DIRECTORY, utils::string::from_bool(true)}, + {META_SIZE, "7"}, + })); + this->meta_db->remove_api_path(test_file); + + EXPECT_EQ(2U, this->meta_db->get_total_size()); +} } // namespace repertory