File: http_client_tests.cpp

package info (click to toggle)
cpprest 2.10.19-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,916 kB
  • sloc: cpp: 71,086; sh: 275; makefile: 170; javascript: 147
file content (55 lines) | stat: -rw-r--r-- 1,904 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
/***
 * Copyright (C) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 *
 * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
 *
 * http_client_tests.cpp
 *
 * Common definitions and helper functions for http_client test cases.
 *
 * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 ****/

#include "stdafx.h"

using namespace web::http;
using namespace web::http::client;

using namespace tests::functional::http::utilities;

namespace tests
{
namespace functional
{
namespace http
{
namespace client
{
void test_connection(test_http_server* p_server, http_client* p_client, const utility::string_t& path)
{
    p_server->next_request().then([path](test_request* p_request) {
        http_asserts::assert_test_request_equals(p_request, methods::GET, path);
        VERIFY_ARE_EQUAL(0u, p_request->reply(200));
    });
    http_asserts::assert_response_equals(p_client->request(methods::GET).get(), status_codes::OK);
}

// Helper function send a simple request to test the connection.
// Take in the path to request and what path should be received in the server.
void test_connection(test_http_server* p_server,
                     http_client* p_client,
                     const utility::string_t& request_path,
                     const utility::string_t& expected_path)
{
    p_server->next_request().then([expected_path](test_request* p_request) {
        http_asserts::assert_test_request_equals(p_request, methods::GET, expected_path);
        VERIFY_ARE_EQUAL(0u, p_request->reply(200));
    });
    http_asserts::assert_response_equals(p_client->request(methods::GET, request_path).get(), status_codes::OK);
}

} // namespace client
} // namespace http
} // namespace functional
} // namespace tests