reverted HTTPCLient debug back to defaulted off
Fork of MTS-Socket by
TestHTTP.h
00001 #ifndef TESTHTTP_H 00002 #define TESTHTTP_H 00003 00004 #include "mtsas.h" 00005 #include <string> 00006 00007 using namespace mts; 00008 00009 class TestHTTP : public TestCollection 00010 { 00011 public: 00012 TestHTTP(); 00013 virtual void run(); 00014 00015 private: 00016 MTSSerialFlowControl* io; 00017 Cellular* radio; 00018 HTTPClient* http; 00019 char rbuf[1024]; 00020 HTTPMap* send; 00021 HTTPText* receive; 00022 }; 00023 00024 TestHTTP::TestHTTP() : TestCollection("TestHTTP") {} 00025 00026 void TestHTTP::run() { 00027 00028 string url; 00029 string base_url = "http://httpbin.org:80"; 00030 string url_get = "/get"; 00031 string url_put = "/put"; 00032 string url_post = "/post"; 00033 string url_del = "/delete"; 00034 string url_stream = "/stream/20"; 00035 00036 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); 00037 00038 Test::start("Setup"); 00039 io = new MTSSerialFlowControl(D8, D2, D3, D6); 00040 io->baud(115200); 00041 radio = CellularFactory::create(io); 00042 if (! radio) { 00043 Test::assertTrue(false); 00044 } 00045 radio->configureSignals(D4, D7, RESET); 00046 Transport::setTransport(radio); 00047 00048 http = new HTTPClient(); 00049 send = new HTTPMap(); 00050 receive = new HTTPText(rbuf); 00051 00052 for (int i = 0; i < 10; i++) { 00053 if (i >= 10) { 00054 Test::assertTrue(false); 00055 } 00056 if (radio->setApn(APN) == MTS_SUCCESS) { 00057 break; 00058 } else { 00059 wait(1); 00060 } 00061 } 00062 for (int i = 0; i < 3; i++) { 00063 if (i >= 3) { 00064 Test::assertTrue(false); 00065 } 00066 if (radio->connect()) { 00067 break; 00068 } else { 00069 wait(1); 00070 } 00071 } 00072 00073 for (int i = 0; i < 5; i++) { 00074 if (i >= 5) { 00075 Test::assertTrue(false); 00076 } 00077 if (radio->ping()) { 00078 break; 00079 } else { 00080 wait(1); 00081 } 00082 } 00083 Test::end(); 00084 00085 url = base_url + url_get; 00086 Test::start("HTTP GET"); 00087 Test::assertTrue(http->get(url.c_str(), receive, 10000) == HTTP_OK); 00088 Test::end(); 00089 00090 url = base_url + url_put; 00091 Test::start("HTTP PUT"); 00092 send->put("testing", "put"); 00093 Test::assertTrue(http->put(url.c_str(), *send, receive, 10000) == HTTP_OK); 00094 Test::end(); 00095 00096 url = base_url + url_post; 00097 Test::start("HTTP POST"); 00098 send->put("testing", "put"); 00099 Test::assertTrue(http->post(url.c_str(), *send, receive, 10000) == HTTP_OK); 00100 Test::end(); 00101 00102 url = base_url + url_del; 00103 Test::start("HTTP DELETE"); 00104 Test::assertTrue(http->del(url.c_str(), receive, 10000) == HTTP_OK); 00105 Test::end(); 00106 00107 url = base_url + url_stream; 00108 char bigbuf[8 * 1024]; 00109 HTTPText big(bigbuf); 00110 Test::start("HTTP big GET"); 00111 Test::assertTrue(http->get(url.c_str(), &big, 5000) == HTTP_OK); 00112 Test::end(); 00113 00114 radio->disconnect(); 00115 } 00116 00117 #endif
Generated on Wed Jul 13 2022 10:29:47 by 1.7.2