Pass title by const reference
[dueringa_WikiWalker.git] / test / CurlUrlCreatorTests.cpp
blob01c790c0d467629fed6562f7c138b95f040cc977
1 #include <algorithm>
3 #include <UnitTest++/UnitTest++.h>
5 #include "CurlUrlCreator.h"
7 SUITE(CurlUrlCreatorTests)
9 using namespace WikiWalker;
11 TEST(InitInstanceWithoutAddingParamsReturnsBaseUrl)
13 CurlUrlCreator cucu("http://example.com/get");
14 CHECK_EQUAL("http://example.com/get", cucu.buildUrl());
17 TEST(AddOneParameterPair)
19 CurlUrlCreator cucu("http://example.com/get");
20 cucu.addParameter("foo", "bar");
22 auto url = cucu.buildUrl();
23 CHECK(url.find("http://example.com/get?") == 0);
24 CHECK_EQUAL("http://example.com/get?foo=bar", url);
27 TEST(AddTwoParametersSeparateCalls)
29 CurlUrlCreator cucu("http://example.com/get");
30 cucu.addParameter("foo", "bar");
31 cucu.addParameter("baz", "nul");
32 auto url = cucu.buildUrl();
33 // or swapped
34 std::string expected = "http://example.com/get?foo=bar&baz=nul";
35 CHECK_EQUAL(expected.length(), url.length());
36 CHECK(url.find("http://example.com/get?") == 0);
37 CHECK(url.find("foo=bar") != std::string::npos);
38 CHECK(url.find("baz=nul") != std::string::npos);
40 CHECK_EQUAL(1, std::count(url.begin(), url.end(), '&'));
43 TEST(AddTwoParametersChaining)
45 CurlUrlCreator cucu("http://example.com/get");
46 cucu.addParameter("foo", "bar").addParameter("baz", "nul");
47 auto url = cucu.buildUrl();
48 // or swapped
49 std::string expected = "http://example.com/get?foo=bar&baz=nul";
50 CHECK_EQUAL(expected.length(), url.length());
51 CHECK(url.find("http://example.com/get?") == 0);
52 CHECK(url.find("foo=bar") != std::string::npos);
53 CHECK(url.find("baz=nul") != std::string::npos);
54 CHECK_EQUAL(1, std::count(url.begin(), url.end(), '&'));
57 TEST(AddParametersAgainOverwrites)
59 CurlUrlCreator cucu("http://example.com/get");
60 cucu.addParameter("foo", "bar");
61 cucu.addParameter("baz", "nul");
62 cucu.addParameter("zig", "zag");
63 cucu.addParameter("baz", "kling");
64 // or swapped
65 std::string expected = "http://example.com/get?foo=bar&baz=kling&zig=zag";
66 auto url = cucu.buildUrl();
67 CHECK_EQUAL(expected.length(), url.length());
68 CHECK(url.find("http://example.com/get?") == 0);
69 CHECK(url.find("foo=bar") != std::string::npos);
70 CHECK(url.find("baz=kling") != std::string::npos);
71 CHECK(url.find("zig=zag") != std::string::npos);
72 CHECK_EQUAL(2, std::count(url.begin(), url.end(), '&'));
75 TEST(Reset_MustReturnBaseUrl)
77 CurlUrlCreator cucu("http://example.com/get");
78 cucu.addParameter("foo", "bar");
80 auto url = cucu.buildUrl();
81 CHECK(url.find("http://example.com/get") == 0);
82 CHECK("http://example.com/get" != url);
84 cucu.reset();
85 url = cucu.buildUrl();
86 CHECK(url.find("http://example.com/get") == 0);
87 CHECK_EQUAL("http://example.com/get", url);