File: combining_tests.cpp

package info (click to toggle)
cpprest 2.10.18-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,896 kB
  • sloc: cpp: 70,952; sh: 275; makefile: 170; javascript: 147
file content (89 lines) | stat: -rw-r--r-- 2,556 bytes parent folder | download | duplicates (3)
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
/***
 * Copyright (C) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 *
 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 *
 * combining_tests.cpp
 *
 * Tests for appending/combining features of the http::uri class.
 *
 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 ****/

#include "stdafx.h"

using namespace web;
using namespace utility;

namespace tests
{
namespace functional
{
namespace uri_tests
{
SUITE(combining_tests)
{
    TEST(append_path)
    {
        utility::string_t uri_str = U("http://testname.com/path?baz");
        uri_builder ub(uri_str);
        uri combined = ub.append_path(U("/baz")).to_uri();

        VERIFY_ARE_EQUAL(uri(U("http://testname.com/path/baz?baz")), combined);
    }

    TEST(append_empty_path)
    {
        utility::string_t uri_str(U("http://fakeuri.net"));
        uri u = uri_str;
        uri_builder ub(u);
        uri combined = ub.append_path(U("")).to_uri();

        VERIFY_ARE_EQUAL(u, combined);
    }

    TEST(append_query)
    {
        utility::string_t uri_str(U("http://testname.com/path1?key1=value2"));
        uri_builder ub(uri_str);
        uri combined = ub.append_query(uri(U("http://testname2.com/path2?key2=value3")).query()).to_uri();

        VERIFY_ARE_EQUAL(U("http://testname.com/path1?key1=value2&key2=value3"), combined.to_string());
    }

    TEST(append_empty_query)
    {
        utility::string_t uri_str(U("http://fakeuri.org/?key=value"));
        uri u(uri_str);
        uri_builder ub(u);
        uri combined = ub.append_query(U("")).to_uri();

        VERIFY_ARE_EQUAL(u, combined);
    }

    TEST(append)
    {
        utility::string_t uri_str(U("http://testname.com/path1?key1=value2"));
        uri_builder ub(uri_str);
        uri combined = ub.append(U("http://testname2.com/path2?key2=value3")).to_uri();

        VERIFY_ARE_EQUAL(U("http://testname.com/path1/path2?key1=value2&key2=value3"), combined.to_string());
        VERIFY_ARE_EQUAL(U("/path1/path2?key1=value2&key2=value3"), combined.resource().to_string());
    }

    TEST(append_empty)
    {
        utility::string_t uri_str(U("http://myhost.com"));
        uri u(uri_str);
        uri_builder ub(u);
        uri combined = ub.append(U("")).to_uri();

        VERIFY_ARE_EQUAL(u, combined);
    }

} // SUITE(combining_tests)

} // namespace uri_tests
} // namespace functional
} // namespace tests