reverted HTTPCLient debug back to defaulted off
Fork of MTS-Socket by
Diff: Test/TestTCPSocketConnection.h
- Revision:
- 8:a3b41ec82e63
- Parent:
- 7:08b474178245
- Child:
- 9:b2e3862705fc
--- a/Test/TestTCPSocketConnection.h Tue Jun 03 14:49:26 2014 +0000 +++ b/Test/TestTCPSocketConnection.h Mon Jun 16 14:05:19 2014 +0000 @@ -11,26 +11,26 @@ public: TestTCPSocketConnection(); virtual void run(); - + private: - bool runIteration(const string name); + bool runIteration(); MTSSerialFlowControl* io; Cellular* radio; TCPSocketConnection* sock; }; -const char PATTERN_LINE1[] = "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|"; -const char PATTERN[] = "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\" - "abcdefghiiklmnopqrstuvwzyzABCDEFGHIiKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*"; +const char PATTERN_LINE1[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|"; +const char PATTERN[] = "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}|\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}/\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}-\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}\\\r\n" + "abcdefghijklmnopqrstuvwzyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()[]{}*\r\n"; -const char MENU_LINE1[] = "1 send ascii pattern until keypress"; +const char MENU_LINE1[] = "send ascii pattern until keypress"; const char MENU[] = "1 send ascii pattern until keypress" "2 send ascii pattern (numbered)" "3 send pattern and close socket" @@ -45,19 +45,19 @@ TestTCPSocketConnection::TestTCPSocketConnection() : TestCollection("TestTCPSocketConnection") {} -void TestTCPSocketConnection::run() { +void TestTCPSocketConnection::run() +{ MTSLog::setLogLevel(MTSLog::TRACE_LEVEL); - Test::start("Setup"); - io = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); + io = new MTSSerialFlowControl(D8, D2, D3, D6); io->baud(115200); radio = CellularFactory::create(io); if (! radio) { Test::assertTrue(false); } - radio->configureSignals(PTA4, PTC9, PTA20); + radio->configureSignals(D4, D7, RESET); Transport::setTransport(radio); - + for (int i = 0; i < 10; i++) { if (i >= 10) { Test::assertTrue(false); @@ -78,7 +78,7 @@ wait(1); } } - + for (int i = 0; i < 5; i++) { if (i >= 5) { Test::assertTrue(false); @@ -89,23 +89,26 @@ wait(1); } } - + sock = new TCPSocketConnection(); - sock->set_blocking(false); + sock->set_blocking(false, 2); Test::end(); - - for (int i = 0; i < 5; i++) { - Test::assertTrue(runIteration("Iteration " + i)); + + for (int i = 0; i < 10; i++) { + Test::start("Test TCP"); + Test::assertTrue(runIteration()); + Test::end(); } } -bool TestTCPSocketConnection::runIteration(const string iteration) { +bool TestTCPSocketConnection::runIteration() +{ Timer tmr; int bytesRead = 0; const int readSize = 1024; char buffer[readSize] = {0}; string result; - + for (int i = 0; i < 5; i++) { if (i >= 5) { return false; @@ -116,90 +119,85 @@ wait(1); } } + + logInfo("Receiving Menu"); + tmr.reset(); + tmr.start(); + do { + bytesRead = sock->receive(buffer, readSize); + if (bytesRead > 0) { + result.append(buffer, bytesRead); + } + logInfo("Total Bytes Read: %d", result.size()); + } while(tmr.read() <= 5); + wait(5); + + logInfo("Received: [%d] [%s]", result.size(), result.c_str()); + + size_t pos = result.find(MENU_LINE1); + if(pos != string::npos) { + logInfo("Found Menu 1st Line"); + } else { + logError("Failed To Find Menu 1st Line"); + sock->close(); + return false; + } + + result.clear(); + + logInfo("Writing To Socket: 2"); + if(sock->send("2\r\n", 3) == 3) { + logInfo("Successfully Wrote '2'"); + } else { + logError("Failed To Write '2'"); + sock->close(); + return false; + } + logInfo("Expecting 'how many ? >:'"); + tmr.reset(); + tmr.start(); + do { + bytesRead = sock->receive(buffer, readSize); + if (bytesRead > 0) { + result.append(buffer, bytesRead); + } + logInfo("Total Bytes Read: %d", result.size()); + } while(tmr.read() <= 3); + + logInfo("Received: [%d] [%s]", result.size(), result.c_str()); + + if(result.find("how many") != std::string::npos) { + logInfo("Successfully Found 'how many'"); + logInfo("Writing To Socket: 2"); + if(sock->send("2\r\n", 3) == 3) { + logInfo("Successfully wrote '2'"); + } else { + logError("Failed to write '2'"); + sock->close(); + return false; + } + } else { + logError("didn't receive 'how many'"); + sock->close(); + return false; + } + + result.clear(); + logInfo("Receiving Data"); tmr.reset(); tmr.start(); do { bytesRead = sock->receive(buffer, readSize); - if (bytesRead > 0) { result.append(buffer, bytesRead); - } else if (bytesRead <= 0) { - break; } - logInfo("Total Bytes Read: %d", result.size()); - } while(tmr.read() <= 15 && result.size() < readSize); - - size_t pos = result.find(MENU_LINE1); - if(pos != string::npos) { - int patternSize = sizeof(MENU) - 1; - const char* ptr = &result.data()[pos]; - bool match = true; - for(int i = 0; i < patternSize; i++) { - if(MENU[i] != ptr[i]) { - logError("1st Pattern Doesn't Match At [%d]", i); - logError("Pattern [%02X] Buffer [%02X]", MENU[i], ptr[i]); - match = false; - break; - } - } - if(match) { - logError("Found Menu"); - } - } - - result.clear(); - - logInfo("Writing To Socket: 2"); - if(sock->send("2\r\n", 3) == 3) { - logInfo("Successfully Wrote '2'"); - } else { - logError("Failed To Write '2'"); - return false; - } - logInfo("Expecting 'how many ? >:"); - bytesRead = sock->receive(buffer, readSize); - if(bytesRead > 0) { - result.append(buffer, bytesRead); - logInfo("Received: [%d] [%s]", bytesRead, result.c_str()); - if(result.find("how many") != std::string::npos) { - logInfo("Successfully Found 'how many'"); - logInfo("Writing To Socket: 2"); - if(sock->send("2\r\n", 3) == 3) { - logInfo("Successfully wrote '2'"); - } else { - logError("Failed to write '2'"); - return false; - } - } else { - logInfo("Missing second option to menu item 2"); - } - } else { - logError("Error reading from socket"); - return false; - } - - result.clear(); - - logInfo("Receiving Data"); - tmr.reset(); - tmr.start(); - do { - bytesRead = sock->receive(buffer, readSize); - - if (bytesRead > 0) { - result.append(buffer, bytesRead); - } else if (bytesRead <= 0) { - break; - } - - logInfo("Total Bytes Read: %d", result.size()); - } while(tmr.read() <= 15 && result.size() < readSize); - + } while(tmr.read() <= 8); + logInfo("Received Data: [%d] [%s]", result.size(), result.c_str()); - + pos = result.find(PATTERN_LINE1); if(pos != string::npos) { int patternSize = sizeof(PATTERN) - 1; @@ -210,13 +208,17 @@ logError("1st Pattern Doesn't Match At [%d]", i); logError("Pattern [%02X] Buffer [%02X]", PATTERN[i], ptr[i]); match = false; - break; + break; } } if(match) { - logError("Found 1st Pattern"); + logInfo("Found 1st Pattern"); + } else { + logError("Failed To Find 1st Pattern"); + sock->close(); + return false; } - + pos = result.find(PATTERN_LINE1, pos + patternSize); if(pos != std::string::npos) { ptr = &result.data()[pos]; @@ -226,19 +228,25 @@ logError("2nd Pattern Doesn't Match At [%d]", i); logError("Pattern [%02X] Buffer [%02X]", PATTERN[i], ptr[i]); match = false; - break; + break; } } if(match) { - logError("Found 2nd Pattern"); + logInfo("Found 2nd Pattern"); + } else { + logError("Failed To Find 2nd Pattern"); + sock->close(); + return false; } } + } else { + logError("Failed To Find Pattern 1st Line"); + sock->close(); + return false; } - + result.clear(); - sock->close(); - return true; }