TEST(IndexerTest, testPurgeByUserSingleItem) { Indexer i; const string username = "******"; const uint64_t postId = 666; const TTopics topics = {"check", "source", "html"}; EXPECT_TRUE(i.index(topics, username, postId)); EXPECT_TRUE(i.hasPostTopics(postId)); EXPECT_TRUE(i.hasTopicItem("check")); EXPECT_TRUE(i.hasTopicItem("source")); EXPECT_TRUE(i.hasTopicItem("html")); EXPECT_FALSE(i.purgeByUser("kim")); EXPECT_TRUE(i.purgeByUser(username)); EXPECT_FALSE(i.hasPostTopics(postId)); EXPECT_FALSE(i.hasTopicItem("check")); EXPECT_FALSE(i.hasTopicItem("source")); EXPECT_FALSE(i.hasTopicItem("html")); }
TEST(IndexerTest, testGetPostTopic) { Indexer i; const string username = "******"; const uint64_t postId = 666; { const TTopics topics = {"secret", "still", "there"}; EXPECT_TRUE(i.index(topics, username, postId)); EXPECT_FALSE(i.hasPostTopics(0)); EXPECT_TRUE(i.hasPostTopics(postId)); auto set = i.getPostTopics(postId); EXPECT_EQ(3, set.size()); auto it = set.begin(); EXPECT_EQ("there", *it); EXPECT_EQ("still", *++it); EXPECT_EQ("secret", *++it); } { EXPECT_TRUE(i.index({"check_html"}, username, postId)); auto set = i.getPostTopics(postId); EXPECT_EQ(4, set.size()); auto it = set.begin(); EXPECT_EQ("check_html", *it); } }
TEST(IndexerTest, testPurgeByUser) { Indexer i; const string username1 = "val"; const uint64_t postId1 = 666; const string username2 = "kim"; const uint64_t postId2 = 777; EXPECT_TRUE(i.index(TTopics({"href", "cv", "date"}), username1, postId1)); EXPECT_TRUE(i.index(TTopics({"cv"}), username1, postId1 + 1)); EXPECT_TRUE(i.hasPostTopics(postId1)); EXPECT_TRUE(i.hasPostTopics(postId1 + 1)); EXPECT_FALSE(i.hasPostTopics(postId2)); EXPECT_TRUE(i.hasTopicItem("href")); EXPECT_TRUE(i.hasTopicItem("cv")); EXPECT_TRUE(i.hasTopicItem("date")); EXPECT_EQ(2, i.getTopicItem("cv").postsCount); EXPECT_TRUE(i.index(TTopics({"href", "cv"}), username2, postId2)); EXPECT_TRUE(i.index(TTopics({"cv"}), username2, postId2 + 1)); EXPECT_TRUE(i.hasPostTopics(postId2)); EXPECT_TRUE(i.hasPostTopics(postId2 + 1)); EXPECT_EQ(4, i.getTopicItem("cv").postsCount); EXPECT_EQ(2, i.getTopicItem("href").postsCount); EXPECT_TRUE(i.purgeByUser(username1)); EXPECT_FALSE(i.hasPostTopics(postId1)); EXPECT_FALSE(i.hasPostTopics(postId1 + 1)); EXPECT_TRUE(i.hasPostTopics(postId2)); EXPECT_TRUE(i.hasPostTopics(postId2 + 1)); EXPECT_EQ(2, i.getTopicItem("cv").postsCount); EXPECT_EQ(1, i.getTopicItem("href").postsCount); EXPECT_FALSE(i.hasTopicItem("date")); EXPECT_TRUE(i.purgeByUser(username2)); EXPECT_FALSE(i.hasPostTopics(postId2)); EXPECT_FALSE(i.hasPostTopics(postId2 + 1)); EXPECT_FALSE(i.hasTopicItem("cv")); EXPECT_FALSE(i.hasTopicItem("href")); }