1 #include <UnitTest++/UnitTest++.h>
8 #include "JsonSerializer.h"
10 SUITE(JsonSerializeDeserializeTests
)
12 using namespace WikiWalker
;
13 using namespace WikiWalker::CollectionUtils
;
15 TEST(SerializeUnanalyzedArticleWithoutLinks_DeserializesInSameState
)
22 CollectionUtils::add(ac
, std::make_shared
<Article
>("Farm"));
23 atj
.serialize(ac
, ss
);
26 ArticleCollection ac2
;
27 atj
.deserialize(ac2
, ss
);
28 CHECK_EQUAL(1, ac2
.size());
29 CHECK(CollectionUtils::get(ac2
, "Farm") != nullptr);
30 CHECK(!CollectionUtils::get(ac2
, "Farm")->analyzed());
33 TEST(SerializeAnalyzedArticleWithoutLinks_DeserializesInSameState
)
40 auto a
= std::make_shared
<Article
>("Farm");
41 CollectionUtils::add(ac
, a
);
43 atj
.serialize(ac
, ss
);
46 ArticleCollection ac2
;
47 atj
.deserialize(ac2
, ss
);
48 CHECK_EQUAL(1, ac2
.size());
49 CHECK(CollectionUtils::get(ac2
, "Farm") != nullptr);
50 CHECK(CollectionUtils::get(ac2
, "Farm")->analyzed());
51 CHECK_EQUAL(0, CollectionUtils::get(ac2
, "Farm")->countLinks());
54 TEST(SerializeArticleWithOneLink_DeserializesTwoArticles
)
61 // yes, only a is inserted, since we want to emulate article-only
62 auto a
= std::make_shared
<Article
>("Farm");
63 CollectionUtils::add(ac
, a
);
65 auto linked
= std::make_shared
<Article
>("Animal");
67 atj
.serialize(ac
, ss
);
70 ArticleCollection ac2
;
71 atj
.deserialize(ac2
, ss
);
73 // Per design, linked-only articles are restored as "new" ones
74 CHECK_EQUAL(2, ac2
.size());
76 CHECK(CollectionUtils::get(ac2
, "Farm") != nullptr);
77 CHECK(CollectionUtils::get(ac2
, "Farm")->analyzed());
78 CHECK_EQUAL(1, CollectionUtils::get(ac2
, "Farm")->countLinks());
80 CHECK(CollectionUtils::get(ac2
, "Animal") != nullptr);
81 CHECK(!CollectionUtils::get(ac2
, "Animal")->analyzed());
84 TEST(SerializeArticleWithMultipleLinks_DeserializesNewArticles
)
92 // yes, only a is inserted, since we want to emulate article-only
93 auto a
= std::make_shared
<Article
>("Farm");
94 CollectionUtils::add(ac
, a
);
95 CHECK_EQUAL(1, ac
.size());
97 auto al1
= std::make_shared
<Article
>("Animal"),
98 al2
= std::make_shared
<Article
>("Pig"),
99 al3
= std::make_shared
<Article
>("Equality");
103 CHECK_EQUAL(1, ac
.size());
104 atj
.serialize(ac
, ss
);
107 ArticleCollection ac2
;
108 atj
.deserialize(ac2
, ss
);
110 // Per design, linked-only articles are restored as "new" ones
111 CHECK_EQUAL(4, ac2
.size());
113 CHECK(CollectionUtils::get(ac2
, "Farm") != nullptr);
114 CHECK(CollectionUtils::get(ac2
, "Farm")->analyzed());
115 CHECK_EQUAL(3, CollectionUtils::get(ac2
, "Farm")->countLinks());
117 for(std::string title
: {"Animal", "Pig", "Equality"}) {
118 CHECK(CollectionUtils::get(ac2
, title
) != nullptr);
119 CHECK(!CollectionUtils::get(ac2
, title
)->analyzed());
123 TEST(SerializeEmptyArticleCollection_DeserializesInSameState
)
126 std::stringstream ss
;
129 ArticleCollection ac
;
130 atj
.serialize(ac
, ss
);
133 ArticleCollection ac2
;
134 atj
.deserialize(ac2
, ss
);
135 CHECK_EQUAL(0, ac2
.size());