-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_wapopp.cpp
133 lines (127 loc) · 4.71 KB
/
test_wapopp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <sstream>
#include <catch2/catch_test_macros.hpp>
#include <nlohmann/json.hpp>
#include "wapopp/wapopp.hpp"
using namespace wapopp;
TEST_CASE("Read record", "[unit]")
{
auto r =
R"({"id": "b2e89334-33f9-11e1-825f-dabc29fd7071",)"
R"("article_url": "https://www.washingtonpost.com/truncated.html",)"
R"("title": "Danny Coale, Jarrett Boykin are a perfect 1-2 punch for Virginia Tech",)"
R"("author": null,)"
R"("published_date": 1325376562000,)"
R"("contents": [)"
R"({)"
R"( "content":"Colleges",)"
R"( "mime":"text/plain",)"
R"( "type":"kicker")"
R"(},)"
R"({)"
R"( "content":"Danny Coale, Jarrett Boykin are a perfect 1-2 punch for Virginia Tech",)"
R"( "mime":"text/plain",)"
R"( "type":"title")"
R"(},)"
R"({)"
R"( "fullcaption":"Virginia Tech wide receiver Danny Coale",)"
R"( "imageURL":"https://img.washingtonpost.com/somepic.jpg",)"
R"( "mime":"image/jpeg",)"
R"( "imageHeight":2260,)"
R"( "imageWidth":2775,)"
R"( "type":"image",)"
R"( "blurb":"Virginia Tech Blurb")"
R"(},)"
R"({)"
R"( "content":"By Mark Giannotto",)"
R"( "mime":"text/plain",)"
R"( "type":"byline")"
R"(},)"
R"({)"
R"( "content":1325376562000,)"
R"( "mime":"text/plain",)"
R"( "type":"date")"
R"(},)"
R"({)"
R"( "content":"<span class=\"dateline\">NEW ORLEANS</span>.",)"
R"( "subtype":"paragraph",)"
R"( "type":"sanitized_html",)"
R"( "mime":"text/html")"
R"(},)"
R"({)"
R"( "corrupted":"content",)"
R"( "subtype":"paragraph",)"
R"( "type":"sanitized_html",)"
R"( "mime":"text/html")"
R"(},)"
R"({)"
R"( "type":"unknown")"
R"(},)"
R"({)"
R"( "role":"Reporter",)"
R"( "type":"author_info",)"
R"( "name":"Mark Giannotto",)"
R"( "bio":"Mark Giannotto's bio")"
R"(})"
R"(],)"
R"("type": "article",)"
R"("source": "The Washington Post")"
"}";
std::istringstream is(r);
auto result = Record::read(is);
REQUIRE(std::get_if<Record>(&result) != nullptr);
auto record = *std::get_if<Record>(&result);
auto j = nlohmann::json::parse(r);
REQUIRE(record.id == j["id"]);
REQUIRE(record.url == j["article_url"]);
REQUIRE(record.title == j["title"]);
REQUIRE(record.author == "");
REQUIRE(record.published == j["published_date"]);
REQUIRE(record.type == j["type"]);
REQUIRE(record.source == j["source"]);
{
REQUIRE(std::get_if<Kicker>(&record.contents[0]) != nullptr);
auto kicker = *std::get_if<Kicker>(&record.contents[0]);
REQUIRE(kicker.content == "Colleges");
REQUIRE(kicker.mime == "text/plain");
}
{
REQUIRE(std::get_if<Title>(&record.contents[1]) != nullptr);
auto title = *std::get_if<Title>(&record.contents[1]);
REQUIRE(title.content ==
"Danny Coale, Jarrett Boykin are a perfect 1-2 punch for Virginia Tech");
REQUIRE(title.mime == "text/plain");
}
{
REQUIRE(std::get_if<Image>(&record.contents[2]) != nullptr);
auto image = *std::get_if<Image>(&record.contents[2]);
REQUIRE(image.caption == "Virginia Tech wide receiver Danny Coale");
REQUIRE(image.url == "https://img.washingtonpost.com/somepic.jpg");
REQUIRE(image.height == 2260);
REQUIRE(image.width == 2775);
REQUIRE(image.blurb == "Virginia Tech Blurb");
}
{
REQUIRE(std::get_if<Byline>(&record.contents[3]) != nullptr);
auto byline = *std::get_if<Byline>(&record.contents[3]);
REQUIRE(byline.content == "By Mark Giannotto");
REQUIRE(byline.mime == "text/plain");
}
{
REQUIRE(std::get_if<Date>(&record.contents[4]) != nullptr);
auto date = *std::get_if<Date>(&record.contents[4]);
REQUIRE(date.timestamp == 1325376562000);
}
{
REQUIRE(std::get_if<Text>(&record.contents[5]) != nullptr);
auto text = *std::get_if<Text>(&record.contents[5]);
REQUIRE(text.content == "<span class=\"dateline\">NEW ORLEANS</span>.");
REQUIRE(text.mime == "text/html");
}
{
REQUIRE(std::get_if<AuthorInfo>(&record.contents[6]) != nullptr);
auto author_info = *std::get_if<AuthorInfo>(&record.contents[6]);
REQUIRE(author_info.role == "Reporter");
REQUIRE(author_info.name == "Mark Giannotto");
REQUIRE(author_info.bio == "Mark Giannotto's bio");
}
}