increased chunk size

Dependencies:   HTTPClient-SSL

Fork of MTS-Socket by MultiTech

Committer:
Vanger
Date:
Mon Aug 11 15:43:15 2014 +0000
Revision:
16:dbe80ac199f5
Parent:
14:7643ed024fe8
Child:
35:c85bea9cb713
Removed some unecessary wait() calls in TestTCPSocketConnection.h and TestUDPSocketConnection.h; Changed TestTCPSocketConnection.h to look for whole menu before moving on, rather than just first menu line.

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 rbuf[1024];
mfiore 8:a3b41ec82e63 20 HTTPMap* send;
mfiore 7:08b474178245 21 HTTPText* receive;
mfiore 7:08b474178245 22 };
mfiore 7:08b474178245 23
mfiore 7:08b474178245 24 TestHTTP::TestHTTP() : TestCollection("TestHTTP") {}
mfiore 7:08b474178245 25
mfiore 7:08b474178245 26 void TestHTTP::run() {
mfiore 10:42220b7df921 27 const char APN[] = "";
mfiore 10:42220b7df921 28
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 8:a3b41ec82e63 35 string url_stream = "/stream/20";
mfiore 7:08b474178245 36
mfiore 7:08b474178245 37 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
mfiore 7:08b474178245 38
mfiore 7:08b474178245 39 Test::start("Setup");
mfiore 8:a3b41ec82e63 40 io = new MTSSerialFlowControl(D8, D2, D3, D6);
mfiore 7:08b474178245 41 io->baud(115200);
mfiore 7:08b474178245 42 radio = CellularFactory::create(io);
mfiore 7:08b474178245 43 if (! radio) {
mfiore 7:08b474178245 44 Test::assertTrue(false);
mfiore 7:08b474178245 45 }
mfiore 8:a3b41ec82e63 46 radio->configureSignals(D4, D7, RESET);
mfiore 7:08b474178245 47 Transport::setTransport(radio);
mfiore 7:08b474178245 48
mfiore 7:08b474178245 49 http = new HTTPClient();
mfiore 8:a3b41ec82e63 50 send = new HTTPMap();
mfiore 7:08b474178245 51 receive = new HTTPText(rbuf);
mfiore 7:08b474178245 52
mfiore 7:08b474178245 53 for (int i = 0; i < 10; i++) {
mfiore 7:08b474178245 54 if (i >= 10) {
mfiore 7:08b474178245 55 Test::assertTrue(false);
mfiore 7:08b474178245 56 }
mfiore 12:9efe3cc3cb6c 57 if (radio->setApn(APN) == MTS_SUCCESS) {
mfiore 7:08b474178245 58 break;
mfiore 7:08b474178245 59 } else {
mfiore 7:08b474178245 60 wait(1);
mfiore 7:08b474178245 61 }
mfiore 7:08b474178245 62 }
mfiore 7:08b474178245 63 for (int i = 0; i < 3; i++) {
mfiore 7:08b474178245 64 if (i >= 3) {
mfiore 7:08b474178245 65 Test::assertTrue(false);
mfiore 7:08b474178245 66 }
mfiore 7:08b474178245 67 if (radio->connect()) {
mfiore 7:08b474178245 68 break;
mfiore 7:08b474178245 69 } else {
mfiore 7:08b474178245 70 wait(1);
mfiore 7:08b474178245 71 }
mfiore 7:08b474178245 72 }
mfiore 7:08b474178245 73
mfiore 7:08b474178245 74 for (int i = 0; i < 5; i++) {
mfiore 7:08b474178245 75 if (i >= 5) {
mfiore 7:08b474178245 76 Test::assertTrue(false);
mfiore 7:08b474178245 77 }
mfiore 7:08b474178245 78 if (radio->ping()) {
mfiore 7:08b474178245 79 break;
mfiore 7:08b474178245 80 } else {
mfiore 7:08b474178245 81 wait(1);
mfiore 7:08b474178245 82 }
mfiore 7:08b474178245 83 }
mfiore 7:08b474178245 84 Test::end();
mfiore 7:08b474178245 85
mfiore 7:08b474178245 86 url = base_url + url_get;
mfiore 7:08b474178245 87 Test::start("HTTP GET");
Vanger 16:dbe80ac199f5 88 Test::assertTrue(http->get(url.c_str(), receive, 10000) == HTTP_OK);
mfiore 7:08b474178245 89 Test::end();
mfiore 7:08b474178245 90
mfiore 7:08b474178245 91 url = base_url + url_put;
mfiore 7:08b474178245 92 Test::start("HTTP PUT");
mfiore 8:a3b41ec82e63 93 send->put("testing", "put");
Vanger 16:dbe80ac199f5 94 Test::assertTrue(http->put(url.c_str(), *send, receive, 10000) == HTTP_OK);
mfiore 7:08b474178245 95 Test::end();
mfiore 7:08b474178245 96
mfiore 7:08b474178245 97 url = base_url + url_post;
mfiore 7:08b474178245 98 Test::start("HTTP POST");
mfiore 8:a3b41ec82e63 99 send->put("testing", "put");
Vanger 16:dbe80ac199f5 100 Test::assertTrue(http->post(url.c_str(), *send, receive, 10000) == HTTP_OK);
mfiore 7:08b474178245 101 Test::end();
mfiore 7:08b474178245 102
mfiore 7:08b474178245 103 url = base_url + url_del;
mfiore 7:08b474178245 104 Test::start("HTTP DELETE");
Vanger 16:dbe80ac199f5 105 Test::assertTrue(http->del(url.c_str(), receive, 10000) == HTTP_OK);
mfiore 7:08b474178245 106 Test::end();
mfiore 7:08b474178245 107
mfiore 8:a3b41ec82e63 108 url = base_url + url_stream;
mfiore 8:a3b41ec82e63 109 char bigbuf[8 * 1024];
mfiore 8:a3b41ec82e63 110 HTTPText big(bigbuf);
mfiore 8:a3b41ec82e63 111 Test::start("HTTP big GET");
mfiore 8:a3b41ec82e63 112 Test::assertTrue(http->get(url.c_str(), &big, 5000) == HTTP_OK);
mfiore 8:a3b41ec82e63 113 Test::end();
mfiore 8:a3b41ec82e63 114
mfiore 7:08b474178245 115 radio->disconnect();
mfiore 7:08b474178245 116 }
mfiore 7:08b474178245 117
mfiore 7:08b474178245 118 #endif