forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_http_server.ino
125 lines (116 loc) · 3.58 KB
/
test_http_server.ino
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <BSTest.h>
#include <test_config.h>
#include <pgmspace.h>
BS_ENV_DECLARE();
static ESP8266WebServer server(80);
static uint32_t siteHits = 0;
static String siteData = "";
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.persistent(false);
WiFi.begin(STA_SSID, STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
MDNS.begin("etd");
server.onNotFound([](){ server.send(404); });
server.begin();
BS_RUN(Serial);
}
TEST_CASE("HTTP GET Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/get", HTTP_GET, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
REQUIRE(siteHits > 0 && siteData.equals("var1 = val with spaces\nva=r+ = so&me%"));
}
}
TEST_CASE("HTTP POST Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/post", HTTP_POST, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
REQUIRE(siteHits > 0 && siteData.equals("var2 = val with spaces"));
}
}
TEST_CASE("HTTP GET+POST Parameters", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/get_and_post", HTTP_POST, [](){
siteData = "";
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
});
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
REQUIRE(siteHits > 0 && siteData.equals("var3 = val with spaces\nva&r+ = so=me%"));
}
}
TEST_CASE("HTTP Upload", "[HTTPServer]")
{
{
siteHits = 0;
server.on("/upload", HTTP_POST, [](){
for (uint8_t i=0; i<server.args(); i++){
if(i > 0)
siteData += "\n";
siteData += server.argName(i) + " = " + server.arg(i);
}
siteHits++;
server.send(200, "text/plain", siteData);
}, [](){
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
siteData = upload.filename;
} else if(upload.status == UPLOAD_FILE_END){
siteData.concat(":");
siteData.concat(String(upload.totalSize));
siteData.concat("\n");
}
});
uint32_t startTime = millis();
while(siteHits == 0 && (millis() - startTime) < 10000)
server.handleClient();
REQUIRE(siteHits > 0 && siteData.equals("test.txt:16\nvar4 = val with spaces"));
}
}
void loop()
{
}