| 14 | } |
| 15 | |
| 16 | void execute() override |
| 17 | { |
| 18 | DEFINE_FSTR_LOCAL(FS_URL1, "http://smingtest.local?param1=1¶m2=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¶m+2=It%27s+fleece+was+very+red.¶m+3=The+" |
| 61 | "reason+for+this+was%2c+you+see¶m+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; |
nothing calls this directly
no test coverage detected