forked from libcpr/cpr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructures_tests.cpp
62 lines (49 loc) · 1.75 KB
/
structures_tests.cpp
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
#include "cpr/cprtypes.h"
#include <gtest/gtest.h>
#include <string>
#include <cpr/payload.h>
#include <cpr/parameters.h>
using namespace cpr;
TEST(PayloadTests, UseStringVariableTest) {
std::string value1 = "hello";
std::string key2 = "key2";
Payload payload {{"key1", value1}, {key2, "world"}};
std::string expected = "key1=hello&key2=world";
EXPECT_EQ(payload.GetContent(CurlHolder()), expected);
}
TEST(PayloadTests, DisableEncodingTest) {
std::string key1 = "key1";
std::string key2 = "key2§$%&/";
std::string value1 = "hello.,.,";
std::string value2 = "hello";
Payload payload{{key1, value1}, {key2, value2}};
payload.encode = false;
std::string expected = key1 + '=' + value1 + '&' + key2 + '=' + value2;
EXPECT_EQ(payload.GetContent(CurlHolder()), expected);
}
TEST(ParametersTests, UseStringVariableTest) {
std::string value1 = "hello";
std::string key2 = "key2";
Parameters parameters {{"key1", value1}, {key2, "world"}};
std::string expected = "key1=hello&key2=world";
EXPECT_EQ(parameters.GetContent(CurlHolder()), expected);
}
TEST(ParametersTests, DisableEncodingTest) {
std::string key1 = "key1";
std::string key2 = "key2§$%&/";
std::string value1 = "hello.,.,";
std::string value2 = "hello";
Parameters parameters{{key1, value1}, {key2, value2}};
parameters.encode = false;
std::string expected = key1 + '=' + value1 + '&' + key2 + '=' + value2;
EXPECT_EQ(parameters.GetContent(CurlHolder()), expected);
}
TEST(UrlToAndFromString, UrlTests) {
std::string s{"https://github.com/whoshuu/cpr"};
cpr::Url url = s;
EXPECT_EQ(s, url.str());
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}