increased chunk size

Dependencies:   HTTPClient-SSL

Fork of MTS-Socket by MultiTech

Committer:
mfiore
Date:
Tue Jun 03 14:49:26 2014 +0000
Revision:
7:08b474178245
Child:
8:a3b41ec82e63
add HTTPClient; add tests for HTTPClient and TCPSocketConnection - still need work

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 7:08b474178245 1 #ifndef TESTHTTP_H
mfiore 7:08b474178245 2 #define TESTHTTP_H
mfiore 7:08b474178245 3
mfiore 7:08b474178245 4 #include "mtsas.h"
mfiore 7:08b474178245 5 #include <string>
mfiore 7:08b474178245 6
mfiore 7:08b474178245 7 using namespace mts;
mfiore 7:08b474178245 8
mfiore 7:08b474178245 9 class TestHTTP : public TestCollection
mfiore 7:08b474178245 10 {
mfiore 7:08b474178245 11 public:
mfiore 7:08b474178245 12 TestHTTP();
mfiore 7:08b474178245 13 virtual void run();
mfiore 7:08b474178245 14
mfiore 7:08b474178245 15 private:
mfiore 7:08b474178245 16 MTSSerialFlowControl* io;
mfiore 7:08b474178245 17 Cellular* radio;
mfiore 7:08b474178245 18 HTTPClient* http;
mfiore 7:08b474178245 19 char sbuf[1024];
mfiore 7:08b474178245 20 char rbuf[1024];
mfiore 7:08b474178245 21 HTTPText* send;
mfiore 7:08b474178245 22 HTTPText* receive;
mfiore 7:08b474178245 23 };
mfiore 7:08b474178245 24
mfiore 7:08b474178245 25 TestHTTP::TestHTTP() : TestCollection("TestHTTP") {}
mfiore 7:08b474178245 26
mfiore 7:08b474178245 27 void TestHTTP::run() {
mfiore 7:08b474178245 28 string data;
mfiore 7:08b474178245 29 string url;
mfiore 7:08b474178245 30 string base_url = "http://httpbin.org:80";
mfiore 7:08b474178245 31 string url_get = "/get";
mfiore 7:08b474178245 32 string url_put = "/put";
mfiore 7:08b474178245 33 string url_post = "/post";
mfiore 7:08b474178245 34 string url_del = "/delete";
mfiore 7:08b474178245 35
mfiore 7:08b474178245 36 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
mfiore 7:08b474178245 37
mfiore 7:08b474178245 38 Test::start("Setup");
mfiore 7:08b474178245 39 io = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
mfiore 7:08b474178245 40 io->baud(115200);
mfiore 7:08b474178245 41 radio = CellularFactory::create(io);
mfiore 7:08b474178245 42 if (! radio) {
mfiore 7:08b474178245 43 Test::assertTrue(false);
mfiore 7:08b474178245 44 }
mfiore 7:08b474178245 45 radio->configureSignals(PTA4, PTC9, PTA20);
mfiore 7:08b474178245 46 Transport::setTransport(radio);
mfiore 7:08b474178245 47
mfiore 7:08b474178245 48 http = new HTTPClient();
mfiore 7:08b474178245 49 send = new HTTPText(sbuf);
mfiore 7:08b474178245 50 receive = new HTTPText(rbuf);
mfiore 7:08b474178245 51
mfiore 7:08b474178245 52 for (int i = 0; i < 10; i++) {
mfiore 7:08b474178245 53 if (i >= 10) {
mfiore 7:08b474178245 54 Test::assertTrue(false);
mfiore 7:08b474178245 55 }
mfiore 7:08b474178245 56 if (radio->setApn("wap.cingular") == SUCCESS) {
mfiore 7:08b474178245 57 break;
mfiore 7:08b474178245 58 } else {
mfiore 7:08b474178245 59 wait(1);
mfiore 7:08b474178245 60 }
mfiore 7:08b474178245 61 }
mfiore 7:08b474178245 62 for (int i = 0; i < 3; i++) {
mfiore 7:08b474178245 63 if (i >= 3) {
mfiore 7:08b474178245 64 Test::assertTrue(false);
mfiore 7:08b474178245 65 }
mfiore 7:08b474178245 66 if (radio->connect()) {
mfiore 7:08b474178245 67 break;
mfiore 7:08b474178245 68 } else {
mfiore 7:08b474178245 69 wait(1);
mfiore 7:08b474178245 70 }
mfiore 7:08b474178245 71 }
mfiore 7:08b474178245 72
mfiore 7:08b474178245 73 for (int i = 0; i < 5; i++) {
mfiore 7:08b474178245 74 if (i >= 5) {
mfiore 7:08b474178245 75 Test::assertTrue(false);
mfiore 7:08b474178245 76 }
mfiore 7:08b474178245 77 if (radio->ping()) {
mfiore 7:08b474178245 78 break;
mfiore 7:08b474178245 79 } else {
mfiore 7:08b474178245 80 wait(1);
mfiore 7:08b474178245 81 }
mfiore 7:08b474178245 82 }
mfiore 7:08b474178245 83 Test::end();
mfiore 7:08b474178245 84
mfiore 7:08b474178245 85 url = base_url + url_get;
mfiore 7:08b474178245 86 Test::start("HTTP GET");
mfiore 7:08b474178245 87 logInfo("testing GET");
mfiore 7:08b474178245 88 Test::assertTrue(http->get(url.c_str(), receive, 5000) == HTTP_OK);
mfiore 7:08b474178245 89 logInfo("done testing GET");
mfiore 7:08b474178245 90 Test::end();
mfiore 7:08b474178245 91
mfiore 7:08b474178245 92 url = base_url + url_put;
mfiore 7:08b474178245 93 data = "testing HTTP PUT method";
mfiore 7:08b474178245 94 Test::start("HTTP PUT");
mfiore 7:08b474178245 95 logInfo("testing PUT");
mfiore 7:08b474178245 96 strncpy(sbuf, data.c_str(), sizeof(sbuf));
mfiore 7:08b474178245 97 Test::assertTrue(http->put(url.c_str(), *send, receive, 5000) == HTTP_OK);
mfiore 7:08b474178245 98 Test::assertTrue(string(rbuf).find(data) != string::npos);
mfiore 7:08b474178245 99 logInfo("done testing PUT");
mfiore 7:08b474178245 100 Test::end();
mfiore 7:08b474178245 101
mfiore 7:08b474178245 102 url = base_url + url_post;
mfiore 7:08b474178245 103 data = "testing HTTP POST method";
mfiore 7:08b474178245 104 Test::start("HTTP POST");
mfiore 7:08b474178245 105 logInfo("testing POST");
mfiore 7:08b474178245 106 strncpy(sbuf, data.c_str(), sizeof(sbuf));
mfiore 7:08b474178245 107 Test::assertTrue(http->post(url.c_str(), *send, receive, 5000) == HTTP_OK);
mfiore 7:08b474178245 108 Test::assertTrue(string(rbuf).find(data) != string::npos);
mfiore 7:08b474178245 109 logInfo("done testing POST");
mfiore 7:08b474178245 110 Test::end();
mfiore 7:08b474178245 111
mfiore 7:08b474178245 112 url = base_url + url_del;
mfiore 7:08b474178245 113 data = "testing HTTP DELETE method";
mfiore 7:08b474178245 114 Test::start("HTTP DELETE");
mfiore 7:08b474178245 115 logInfo("testing DELETE");
mfiore 7:08b474178245 116 Test::assertTrue(http->del(url.c_str(), receive, 5000) == HTTP_OK);
mfiore 7:08b474178245 117 logInfo("done testing DELETE");
mfiore 7:08b474178245 118 Test::end();
mfiore 7:08b474178245 119
mfiore 7:08b474178245 120 radio->disconnect();
mfiore 7:08b474178245 121 }
mfiore 7:08b474178245 122
mfiore 7:08b474178245 123 #endif