From 161208a1fd47a6508368e9234c164f059e41b070 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 5 Dec 2024 07:00:16 -0600 Subject: [PATCH] meta db unit tests and fixes --- repertory/repertory_test/src/meta_db_test.cpp | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/repertory/repertory_test/src/meta_db_test.cpp b/repertory/repertory_test/src/meta_db_test.cpp index a7f9b75e..bf779075 100644 --- a/repertory/repertory_test/src/meta_db_test.cpp +++ b/repertory/repertory_test/src/meta_db_test.cpp @@ -169,4 +169,84 @@ TYPED_TEST(meta_db_test, can_get_full_item_meta_for_file) { EXPECT_EQ(2ULL, utils::string::to_uint64(meta[META_SIZE])); EXPECT_STREQ(source_path.c_str(), meta[META_SOURCE].c_str()); } + +TYPED_TEST(meta_db_test, can_get_individual_item_meta_for_directory) { + auto api_path = create_test_file(); + auto source_path = create_test_file(); + EXPECT_EQ(api_error::success, + this->meta_db->set_item_meta( + api_path, { + {META_DIRECTORY, utils::string::from_bool(true)}, + {META_PINNED, utils::string::from_bool(true)}, + {META_SIZE, std::to_string(2ULL)}, + {META_SOURCE, source_path}, + })); + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_DIRECTORY, value)); + EXPECT_TRUE(utils::string::to_bool(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_PINNED, value)); + EXPECT_FALSE(utils::string::to_bool(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_SIZE, value)); + EXPECT_EQ(0ULL, utils::string::to_uint64(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_SOURCE, value)); + EXPECT_TRUE(value.empty()); + } +} + +TYPED_TEST(meta_db_test, can_get_individual_item_meta_for_file) { + auto api_path = create_test_file(); + auto source_path = create_test_file(); + EXPECT_EQ(api_error::success, + this->meta_db->set_item_meta( + api_path, { + {META_DIRECTORY, utils::string::from_bool(false)}, + {META_PINNED, utils::string::from_bool(true)}, + {META_SIZE, std::to_string(2ULL)}, + {META_SOURCE, source_path}, + })); + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_DIRECTORY, value)); + EXPECT_FALSE(utils::string::to_bool(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_PINNED, value)); + EXPECT_TRUE(utils::string::to_bool(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_SIZE, value)); + EXPECT_EQ(2ULL, utils::string::to_uint64(value)); + } + + { + std::string value; + EXPECT_EQ(api_error::success, + this->meta_db->get_item_meta(api_path, META_SOURCE, value)); + EXPECT_STREQ(source_path.c_str(), value.c_str()); + } +} } // namespace repertory