MCPcopy Create free account
hub / github.com/SmingHub/Sming / execute

Method execute

tests/HostTests/modules/Network/Url.cpp:16–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 }
15
16 void execute() override
17 {
18 DEFINE_FSTR_LOCAL(FS_URL1, "http://smingtest.local?param1=1&param2=2#whacky%20races");
19 DEFINE_FSTR_LOCAL(FS_URL2, "http://smingtest.local/iocontrol.js?cid=fa373784");
20 DEFINE_FSTR_LOCAL(FS_URL3, "/iocontrol.js?cid=81e66a3a");
21
22 TEST_CASE("formUrlParser test")
23 {
24 auto testUrl = [this](const FlashString& urlText, const char* param) {
25 Serial << _F("URL \"") << urlText << '"' << endl;
26 Url url(urlText);
27 String query = url.Query;
28 const char* p = query.c_str();
29 ++p; // Skip the '?'
30 HttpRequest request;
31 formUrlParser(request, nullptr, PARSE_DATASTART);
32 while(*p != '\0') {
33 formUrlParser(request, p, 1);
34 ++p;
35 }
36 formUrlParser(request, nullptr, PARSE_DATAEND);
37 printParams(request.postParams);
38 String cid = request.getPostParameter("cid");
39 Serial << _F("cid = ") << cid << endl;
40 REQUIRE(cid == param);
41 };
42
43 testUrl(FS_URL1, "");
44 testUrl(FS_URL2, "fa373784");
45 testUrl(FS_URL3, "81e66a3a");
46 }
47
48 HttpRequest request;
49
50 TEST_CASE("HttpRequest getQueryParameter()")
51 {
52 request.uri = FS_URL2;
53 Serial << _F("URL = \"") << request.uri << '"' << endl;
54 Serial << _F("cid = ") << request.getQueryParameter("cid") << endl;
55 }
56
57 TEST_CASE("HttpRequest postParams test");
58 {
59 DEFINE_FSTR_LOCAL(FS_serializedParams,
60 "param+1=Mary+had+a+little+lamb%2c&param+2=It%27s+fleece+was+very+red.&param+3=The+"
61 "reason+for+this+was%2c+you+see&param+4=It+had+a+pickaxe+through+its+head.");
62 HttpParams params;
63 params["param 1"] = F("Mary had a little lamb,");
64 params["param 2"] = F("It's fleece was very red.");
65 params["param 3"] = F("The reason for this was, you see");
66 params["param 4"] = F("It had a pickaxe through its head.");
67 UrlencodedOutputStream stream(params);
68 char buffer[256];
69 unsigned n = 0;
70 while(!stream.isFinished()) {
71 unsigned count = stream.readMemoryBlock(&buffer[n], 11);
72 stream.seek(count);
73 n += count;

Callers

nothing calls this directly

Calls 15

formUrlParserFunction · 0.85
getQueryParameterMethod · 0.80
FFunction · 0.50
StringClass · 0.50
c_strMethod · 0.45
isFinishedMethod · 0.45
readMemoryBlockMethod · 0.45
seekMethod · 0.45
setMultipleMethod · 0.45
toStringMethod · 0.45
printMethod · 0.45
seekFromMethod · 0.45

Tested by

no test coverage detected