From f6bd64159f0a027a4fc2947804cdcac44d80a27e Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 17 Dec 2024 14:07:14 -0600 Subject: [PATCH] file db unit tests and fixes --- repertory/repertory_test/src/file_db_test.cpp | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/repertory/repertory_test/src/file_db_test.cpp b/repertory/repertory_test/src/file_db_test.cpp index b5f05502..8f57cb2d 100644 --- a/repertory/repertory_test/src/file_db_test.cpp +++ b/repertory/repertory_test/src/file_db_test.cpp @@ -103,7 +103,7 @@ TYPED_TEST(file_db_test, can_get_directory_api_path) { } TYPED_TEST(file_db_test, - directory_not_found_is_returned_for_non_existing_directory) { + directory_not_found_is_returned_for_non_existing_directory_source) { this->file_db->clear(); std::string api_path; @@ -128,7 +128,8 @@ TYPED_TEST(file_db_test, can_get_file_api_path) { EXPECT_STREQ("/file", api_path.c_str()); } -TYPED_TEST(file_db_test, file_not_found_is_returned_for_non_existing_file) { +TYPED_TEST(file_db_test, + file_not_found_is_returned_for_non_existing_file_source) { this->file_db->clear(); std::string api_path; @@ -137,5 +138,53 @@ TYPED_TEST(file_db_test, file_not_found_is_returned_for_non_existing_file) { EXPECT_TRUE(api_path.empty()); } +TYPED_TEST(file_db_test, can_get_directory_source_path) { + this->file_db->clear(); + + EXPECT_EQ(api_error::success, this->file_db->add_directory("/", "c:\\test")); + + std::string source_path; + EXPECT_EQ(api_error::success, + this->file_db->get_directory_source_path("/", source_path)); + EXPECT_STREQ("c:\\test", source_path.c_str()); +} + +TYPED_TEST( + file_db_test, + directory_not_found_is_returned_for_non_existing_directory_api_path) { + this->file_db->clear(); + + std::string source_path; + EXPECT_EQ(api_error::directory_not_found, + this->file_db->get_directory_api_path("/", source_path)); + EXPECT_TRUE(source_path.empty()); +} + +TYPED_TEST(file_db_test, can_get_file_source_path) { + this->file_db->clear(); + + EXPECT_EQ(api_error::success, this->file_db->add_or_update_file({ + "/file", + 0U, + {}, + "c:\\test\\file.txt", + })); + + std::string source_path; + EXPECT_EQ(api_error::success, + this->file_db->get_file_source_path("/file", source_path)); + EXPECT_STREQ("c:\\test\\file.txt", source_path.c_str()); +} + +TYPED_TEST(file_db_test, + file_not_found_is_returned_for_non_existing_file_source) { + this->file_db->clear(); + + std::string source_path; + EXPECT_EQ(api_error::item_not_found, + this->file_db->get_file_source_path("/file.txt", source_path)); + EXPECT_TRUE(source_path.empty()); +} + // test can update file source, iv, size } // namespace repertory