summaryrefslogtreecommitdiff
path: root/libtmdb/testModels.cpp
blob: 2b61644dfaded4ed49994cc2e3ad5c23982dbabc (plain)
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
134
#define BOOST_TEST_MODULE Deserialize
#include <boost/test/unit_test.hpp>

#include <tmdb-models.h>
#include <slicer/slicer.h>
#include <slicer/json/serializer.h>
#include <definedDirs.h>

namespace std {
	std::ostream &
	operator<<(std::ostream & o, const Ice::optional<TMDb::Date> & d)
	{
		if (d) {
			o << *d;
		}
		return o;
	}
	std::ostream &
	operator<<(std::ostream & o, const TMDb::Date & d)
	{
		o << d.Year << '-' << d.Month << '-' << d.Day;
		return o;
	}
};

BOOST_AUTO_TEST_CASE( deserialize_searchmulti_json_breakingbad )
{
	auto results = Slicer::DeserializeAny<Slicer::JsonFileDeserializer, TMDb::SearchMultiResultsPtr>((rootDir / "samples" / "searchMulti_breakingBad.json").string());
	BOOST_REQUIRE_EQUAL(1, results->Page);
	BOOST_REQUIRE_EQUAL(1, results->TotalPages);
	BOOST_REQUIRE_EQUAL(3, results->TotalResults);

	BOOST_REQUIRE_EQUAL("::TMDb::SearchMatchTv", results->Results[0]->ice_id());
	auto tv = std::dynamic_pointer_cast<TMDb::SearchMatchTv>(results->Results[0]);
	BOOST_REQUIRE_EQUAL("Breaking Bad", tv->Name);
	BOOST_REQUIRE_EQUAL("/1yeVJox3rjo2jBKrrihIMj7uoS9.jpg", tv->PosterPath);
	BOOST_REQUIRE_EQUAL(1396, tv->Id);

	BOOST_REQUIRE_EQUAL("::TMDb::SearchMatchMovie", results->Results[1]->ice_id());
	auto movie = std::dynamic_pointer_cast<TMDb::SearchMatchMovie>(results->Results[1]);
	BOOST_REQUIRE_EQUAL("No Half Measures: Creating the Final Season of Breaking Bad", movie->Title);
	BOOST_REQUIRE_EQUAL("/8OixSR45U5dbqv8F0tlspmTbXxN.jpg", movie->PosterPath);
	BOOST_REQUIRE_EQUAL(239459, movie->Id);
}

BOOST_AUTO_TEST_CASE( deserialize_searchmulti_json_bradpitt )
{
	auto results = Slicer::DeserializeAny<Slicer::JsonFileDeserializer, TMDb::SearchMultiResultsPtr>((rootDir / "samples" / "searchMulti_bradPitt.json").string());
	BOOST_REQUIRE_EQUAL(1, results->Page);
	BOOST_REQUIRE_EQUAL(1, results->TotalPages);
	BOOST_REQUIRE_EQUAL(1, results->TotalResults);

	BOOST_REQUIRE_EQUAL("::TMDb::SearchMatchPerson", results->Results[0]->ice_id());
	auto person = std::dynamic_pointer_cast<TMDb::SearchMatchPerson>(results->Results[0]);
	BOOST_REQUIRE_EQUAL("Brad Pitt", person->Name);
	BOOST_REQUIRE_EQUAL(287, person->Id);
}

BOOST_AUTO_TEST_CASE( deserialize_movie_json )
{
	auto movie = Slicer::DeserializeAny<Slicer::JsonFileDeserializer, TMDb::MoviePtr>((rootDir / "samples" / "movie_550.json").string());
	BOOST_REQUIRE_EQUAL(550, movie->Id);
	BOOST_REQUIRE_EQUAL(false, movie->Adult);
	BOOST_REQUIRE_EQUAL("/87hTDiay2N2qWyX4Ds7ybXi9h8I.jpg", movie->BackdropPath);
	BOOST_REQUIRE_EQUAL(1, movie->Genres.size());
	BOOST_REQUIRE_EQUAL(18, movie->Genres.front().Id);
	BOOST_REQUIRE_EQUAL("Drama", movie->Genres.front().Name);
	BOOST_REQUIRE_EQUAL(63000000, movie->Budget);
	BOOST_REQUIRE_EQUAL("http://www.foxmovies.com/movies/fight-club", movie->HomePage);
	BOOST_REQUIRE_EQUAL("tt0137523", movie->ImdbId);
	BOOST_REQUIRE_EQUAL("Fight Club", movie->OriginalTitle);
	BOOST_REQUIRE_CLOSE(8.202502, movie->Popularity, 0.1);
	BOOST_REQUIRE_EQUAL("/adw6Lq9FiC9zjYEpOqfq03ituwp.jpg", movie->PosterPath);
	BOOST_REQUIRE_EQUAL(295, movie->Overview.length());
	BOOST_REQUIRE_EQUAL(6, movie->ProductionCompanies.size());
	BOOST_REQUIRE_EQUAL(508, movie->ProductionCompanies.front().Id);
	BOOST_REQUIRE_EQUAL("Regency Enterprises", movie->ProductionCompanies.front().Name);
	BOOST_REQUIRE_EQUAL(2, movie->ProductionCountries.size());
	BOOST_REQUIRE_EQUAL("DE", movie->ProductionCountries.front().Id);
	BOOST_REQUIRE_EQUAL("Germany", movie->ProductionCountries.front().Name);
	BOOST_REQUIRE_EQUAL(TMDb::Date({1999, 10, 15}), movie->ReleaseDate);
	BOOST_REQUIRE_EQUAL(1, movie->SpokenLanguages.size());
	BOOST_REQUIRE_EQUAL("en", movie->SpokenLanguages.front().Id);
	BOOST_REQUIRE_EQUAL("English", movie->SpokenLanguages.front().Name);
	BOOST_REQUIRE_EQUAL(100853753, movie->Revenue);
	BOOST_REQUIRE_EQUAL(139, movie->Runtime);
	BOOST_REQUIRE_EQUAL("Released", movie->Status);
	BOOST_REQUIRE_EQUAL("How much can you know about yourself if you've never been in a fight?", movie->Tagline);
	BOOST_REQUIRE_EQUAL("Fight Club", movie->Title);
	BOOST_REQUIRE_CLOSE(8.2, movie->VoteAverage, 0.01);
	BOOST_REQUIRE_EQUAL(7715, movie->VoteCount);
}

BOOST_AUTO_TEST_CASE( deserialize_tvseries_json )
{
	auto tvSeries = Slicer::DeserializeAny<Slicer::JsonFileDeserializer, TMDb::TvSeriesPtr>((rootDir / "samples" / "tv_1396.json").string());
	BOOST_REQUIRE_EQUAL("/eSzpy96DwBujGFj0xMbXBcGcfxX.jpg", tvSeries->BackdropPath);
	BOOST_REQUIRE_EQUAL(1, tvSeries->CreatedBy.size());
	BOOST_REQUIRE_EQUAL(66633, tvSeries->CreatedBy.front().Id);
	BOOST_REQUIRE_EQUAL("Vince Gilligan", tvSeries->CreatedBy.front().Name);
	BOOST_REQUIRE_EQUAL("/rLSUjr725ez1cK7SKVxC9udO03Y.jpg", tvSeries->CreatedBy.front().ProfilePath);
	BOOST_REQUIRE_EQUAL(2, tvSeries->EpisodeRunTimes.size());
	BOOST_REQUIRE_EQUAL(45, tvSeries->EpisodeRunTimes.front());
	BOOST_REQUIRE_EQUAL(TMDb::Date({2008, 1, 19}), tvSeries->FirstAirDate);
	BOOST_REQUIRE_EQUAL(1, tvSeries->Genres.size());
	BOOST_REQUIRE_EQUAL(18, tvSeries->Genres.front().Id);
	BOOST_REQUIRE_EQUAL("Drama", tvSeries->Genres.front().Name);
	BOOST_REQUIRE_EQUAL("http://www.amc.com/shows/breaking-bad", tvSeries->HomePage);
	BOOST_REQUIRE_EQUAL(1396, tvSeries->Id);
	BOOST_REQUIRE_EQUAL(false, tvSeries->InProduction);
	BOOST_REQUIRE_EQUAL(5, tvSeries->Languages.size());
	BOOST_REQUIRE_EQUAL("en", tvSeries->Languages.front());
	BOOST_REQUIRE_EQUAL(TMDb::Date({2013, 9, 29}), tvSeries->LastAirDate);
	BOOST_REQUIRE_EQUAL("Breaking Bad", tvSeries->Name);
	BOOST_REQUIRE_EQUAL(1, tvSeries->Networks.size());
	BOOST_REQUIRE_EQUAL(174, tvSeries->Networks.front().Id);
	BOOST_REQUIRE_EQUAL("AMC", tvSeries->Networks.front().Name);
	BOOST_REQUIRE_EQUAL(62, tvSeries->NumberOfEpisodes);
	BOOST_REQUIRE_EQUAL(5, tvSeries->NumberOfSeasons);
	BOOST_REQUIRE_EQUAL(1, tvSeries->OriginCountries.size());
	BOOST_REQUIRE_EQUAL("US", tvSeries->OriginCountries.front());
	BOOST_REQUIRE_EQUAL(651, tvSeries->Overview.length());
	BOOST_REQUIRE_CLOSE(18.21, tvSeries->Popularity, 0.01);
	BOOST_REQUIRE_EQUAL("/1yeVJox3rjo2jBKrrihIMj7uoS9.jpg", tvSeries->PosterPath);
	BOOST_REQUIRE_EQUAL(6, tvSeries->Seasons.size());
	BOOST_REQUIRE_EQUAL(TMDb::Date({2012, 7, 15}), tvSeries->Seasons.back().AirDate);
	BOOST_REQUIRE_EQUAL(3578, tvSeries->Seasons.back().Id);
	BOOST_REQUIRE_EQUAL("/r3z70vunihrAkjILQKWHX0G2xzO.jpg", tvSeries->Seasons.back().PosterPath);
	BOOST_REQUIRE_EQUAL(5, tvSeries->Seasons.back().SeasonNumber);
	BOOST_REQUIRE_EQUAL("Ended", tvSeries->Status);
	BOOST_REQUIRE_CLOSE(8.2, tvSeries->VoteAverage, 0.01);
	BOOST_REQUIRE_EQUAL(1536, tvSeries->VoteCount);
}