TEST(IndexerTest, testSizes) { Indexer i; EXPECT_TRUE(i.index({"Y",}, "val", 1)); EXPECT_EQ(1, i.getTopicItemsSize()); EXPECT_EQ(1, i.getPostTopicsSize()); EXPECT_EQ(1, i.getUserTopicsSize()); EXPECT_TRUE(i.index({"m"}, "val", 1)); EXPECT_EQ(2, i.getTopicItemsSize()); EXPECT_EQ(1, i.getPostTopicsSize()); EXPECT_EQ(1, i.getUserTopicsSize()); EXPECT_TRUE(i.index({"d"}, "val", 2)); EXPECT_EQ(3, i.getTopicItemsSize()); EXPECT_EQ(2, i.getPostTopicsSize()); EXPECT_EQ(1, i.getUserTopicsSize()); EXPECT_TRUE(i.index({"find"}, "kim", 3)); EXPECT_EQ(4, i.getTopicItemsSize()); EXPECT_EQ(3, i.getPostTopicsSize()); EXPECT_EQ(2, i.getUserTopicsSize()); EXPECT_TRUE(i.index({"Y"}, "kim", 3)); EXPECT_EQ(4, i.getTopicItemsSize()); EXPECT_EQ(3, i.getPostTopicsSize()); EXPECT_EQ(2, i.getUserTopicsSize()); EXPECT_TRUE(i.purgeByUser("val")); EXPECT_EQ(2, i.getTopicItemsSize()); EXPECT_EQ(1, i.getPostTopicsSize()); EXPECT_EQ(1, i.getUserTopicsSize()); EXPECT_TRUE(i.purgeByUser("kim")); EXPECT_EQ(0, i.getTopicItemsSize()); EXPECT_EQ(0, i.getPostTopicsSize()); EXPECT_EQ(0, i.getUserTopicsSize()); EXPECT_TRUE(i.index({"find", "admin", "page"}, "kim", 4)); EXPECT_EQ(3, i.getTopicItemsSize()); EXPECT_EQ(1, i.getPostTopicsSize()); EXPECT_EQ(1, i.getUserTopicsSize()); }
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")); }
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")); }