Merge pull request #5604 from betzw/betzw_tests_netsocket_wb

TESTS/NETSOCKET: Refinement of `netsocket` tests
pull/6028/merge
Martin Kojtal 2018-02-08 15:25:45 +00:00 committed by GitHub
commit 04f0f2b1aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 9 deletions

View File

@ -67,16 +67,17 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
void get_data(TCPSocket* sock){ void get_data(TCPSocket* sock){
bool result = false; bool result = false;
// Server will respond with HTTP GET's success code // Server will respond with HTTP GET's success code
const int ret = sock->recv(buffer, sizeof(buffer) - 1); int len = 0;
if(ret <= 0) int ret;
return; while((ret = sock->recv(buffer+len, sizeof(buffer) - 1 - len)) > 0) {
len += ret;
buffer[ret] = '\0'; }
buffer[len] = '\0';
// Find 200 OK HTTP status in reply // Find 200 OK HTTP status in reply
bool found_200_ok = find_substring(buffer, buffer + ret, HTTP_OK_STR, HTTP_OK_STR + strlen(HTTP_OK_STR)); bool found_200_ok = find_substring(buffer, buffer + len, HTTP_OK_STR, HTTP_OK_STR + strlen(HTTP_OK_STR));
// Find "Hello World!" string in reply // Find "Hello World!" string in reply
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR)); bool found_hello = find_substring(buffer, buffer + len, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
TEST_ASSERT_TRUE(found_200_ok); TEST_ASSERT_TRUE(found_200_ok);
TEST_ASSERT_TRUE(found_hello); TEST_ASSERT_TRUE(found_hello);
@ -85,7 +86,7 @@ void get_data(TCPSocket* sock){
TEST_ASSERT_EQUAL(result, true); TEST_ASSERT_EQUAL(result, true);
printf("HTTP: Received %d chars from server\r\n", ret); printf("HTTP: Received %d chars from server\r\n", len);
printf("HTTP: Received 200 OK status ... %s\r\n", found_200_ok ? "[OK]" : "[FAIL]"); printf("HTTP: Received 200 OK status ... %s\r\n", found_200_ok ? "[OK]" : "[FAIL]");
printf("HTTP: Received '%s' status ... %s\r\n", HTTP_HELLO_STR, found_hello ? "[OK]" : "[FAIL]"); printf("HTTP: Received '%s' status ... %s\r\n", HTTP_HELLO_STR, found_hello ? "[OK]" : "[FAIL]");
printf("HTTP: Received message:\r\n"); printf("HTTP: Received message:\r\n");
@ -109,7 +110,7 @@ void test_socket_attach() {
// Dispatch event queue // Dispatch event queue
Thread eventThread; Thread eventThread;
EventQueue queue(4*EVENTS_EVENT_SIZE); EventQueue queue(10*EVENTS_EVENT_SIZE);
eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
printf("TCP client IP Address is %s\r\n", net->get_ip_address()); printf("TCP client IP Address is %s\r\n", net->get_ip_address());