summaryrefslogtreecommitdiff
path: root/libtmdb/testFormatUrls.cpp
blob: 49ce017e2198db64c80b8937ee0e18a395c102ba (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
#define BOOST_TEST_MODULE FormatUrls
#include <boost/test/unit_test.hpp>

#define private public
#define protected public

#include "tmdb-proxy.h"

const std::string MockBase = "http://private-5513-themoviedb.apiary-mock.com/3";
const std::string ApiKey = "48b32823d2b60c5c1085af36daed03fa";

BOOST_AUTO_TEST_CASE( initialize_simple_proxy )
{
	TMDb::Proxy test(MockBase, ApiKey);
}

BOOST_AUTO_TEST_CASE( format_url_simple )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl<int>("/something/%d", 23, { });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something/23?api_key=48b32823d2b60c5c1085af36daed03fa", url);
}

BOOST_AUTO_TEST_CASE( format_url_query )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl<int>("/something/%d", 23, { { "page", 5  } });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something/23?api_key=48b32823d2b60c5c1085af36daed03fa&page=5", url);
}

BOOST_AUTO_TEST_CASE( format_url_multiple )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl("/something", { { "page", 5}, {"query", "string" } });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something?api_key=48b32823d2b60c5c1085af36daed03fa&page=5&query=string", url);
}

BOOST_AUTO_TEST_CASE( format_url_escaped )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl("/something", { { "query", "sample string" } });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something?api_key=48b32823d2b60c5c1085af36daed03fa&query=sample%20string", url);
}

BOOST_AUTO_TEST_CASE( format_url_optionalvalue )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl("/something", { { "query", IceUtil::Optional<Ice::Int>(10) } });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something?api_key=48b32823d2b60c5c1085af36daed03fa&query=10", url);
}

BOOST_AUTO_TEST_CASE( format_url_optionalnovalue )
{
	TMDb::Proxy test(MockBase, ApiKey);
	auto url = test.GetUrl("/something", { { "query", IceUtil::Optional<Ice::Int>() } });
	BOOST_REQUIRE_EQUAL("http://private-5513-themoviedb.apiary-mock.com/3/something?api_key=48b32823d2b60c5c1085af36daed03fa", url);
}