forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestFormData.cpp
More file actions
67 lines (59 loc) · 1.35 KB
/
TestFormData.cpp
File metadata and controls
67 lines (59 loc) · 1.35 KB
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
#include <StdInc.h>
#include <catch_amalgamated.hpp>
#include <FormData.h>
#include "TestUtils.h"
TEST_CASE("Form data decode")
{
std::string data;
constexpr size_t valueCount = 100;
std::map<std::string, std::string> generatedData {};
for (size_t i = 0; i < valueCount; i++)
{
std::string key = fx::TestUtils::asciiRandom(20);
std::string value = fx::TestUtils::asciiRandom(20);
if (i == valueCount - 1)
{
data += key + "=" + value;
}
else
{
data += key + "=" + value + "&";
}
generatedData[key] = value;
}
std::map<std::string, std::string> decodedData = net::DecodeFormData(data);
REQUIRE(generatedData == decodedData);
}
TEST_CASE("Form data url decode")
{
WHEN ("%20 is given in")
{
std::string value = "%20";
std::string out;
REQUIRE(net::UrlDecode(value, out) == true);
THEN("it is replaced by a space")
{
REQUIRE(out == " ");
}
}
WHEN ("+ is given in")
{
std::string value = "+";
std::string out;
REQUIRE(net::UrlDecode(value, out) == true);
THEN("it is replaced by a space")
{
REQUIRE(out == " ");
}
}
WHEN ("+ is given in and replace + is false")
{
std::string value = "+";
std::string out;
REQUIRE(net::UrlDecode(value, out, false) == true);
THEN("it is not replaced by a space")
{
REQUIRE(out == "+");
}
}
}