curl and pkg-config / unittest for tests
[dueringa_WikiWalker.git] / test / JsonToArticleConverterTests.cpp
blobba8abd2e404159cb3b4e05d9b9b873b352cce0a1
1 #include <UnitTest++.h>
3 #include "../src/JsonToArticleConverter.h"
4 #include "../src/WalkerException.h"
6 SUITE(JsonToArticleConverterTests)
8 TEST(JsonDataWithOneLinkedArticle)
10 std::string testdata = "{\"batchcomplete\":\"\",\"servedby\":\"mw1197\",\"query\":{\"pages\":{\"36669940\":{\"pageid\":36669940,\"ns\":0,\"title\":\"3PTT\",\"links\":[{\"ns\":0,\"title\":\"Switch\"}]}}}}";
12 ArticleCollection ac;
13 JsonToArticleConverter conv;
14 auto art = conv.convertToArticle(testdata, ac);
15 CHECK(art != nullptr);
16 CHECK(!conv.hasMoreData());
17 CHECK_EQUAL("", conv.getContinuationData());
18 CHECK_EQUAL(1, art->getNumLinks());
19 CHECK_EQUAL(2, ac.getNumArticles());
22 TEST(JsonDataWithInvalidArticle_Throws)
24 std::string testdata = "{\"batchcomplete\":\"\",\"servedby\":\"mw1208\",\"query\":{\"pages\":{\"-1\":{\"ns\":0,\"title\":\"FoObAr\",\"missing\":\"\"}}}}";
26 ArticleCollection ac;
27 JsonToArticleConverter conv;
28 CHECK_THROW(conv.convertToArticle(testdata, ac), WalkerException);
31 TEST(JsonData_MoreLinks_HasContinueData)
33 std::string testdata = "{\"continue\":{\"plcontinue\":\"34419161|0|Jharkhand\",\"continue\":\"||\"},\"servedby\":\"mw1283\",\"query\":{\"pages\":{\"34419161\":{\"pageid\":34419161,\"ns\":0,\"title\":\"Satar, Deoghar\",\"links\":[{\"ns\":0,\"title\":\"Deoghar district\"}]}}}}";
35 ArticleCollection ac;
36 JsonToArticleConverter conv;
37 auto art = conv.convertToArticle(testdata, ac);
38 CHECK(art != nullptr);
39 CHECK(conv.hasMoreData());
40 CHECK_EQUAL("34419161|0|Jharkhand", conv.getContinuationData());
41 CHECK_EQUAL(1, art->getNumLinks());
42 CHECK_EQUAL(2, ac.getNumArticles());