tests-netsocket-tcp_hello_world

HTTP_SERVER_NAME and HTTP_SERVER_FILE_PATH are replaced by
  MBED_CONF_APP_HTTP_SERVER_NAME and MBED_CONF_APP_HTTP_SERVER_FILE_PATH
  to allow user to make local tests
pull/5576/head
jeromecoutant 2017-11-24 11:09:37 +01:00
parent df27bca67d
commit bff8fc1534
1 changed files with 8 additions and 6 deletions

View File

@ -29,11 +29,13 @@
using namespace utest::v1; using namespace utest::v1;
#ifndef MBED_CONF_APP_HTTP_SERVER_NAME
#define MBED_CONF_APP_HTTP_SERVER_NAME "os.mbed.com"
#define MBED_CONF_APP_HTTP_SERVER_FILE_PATH "/media/uploads/mbed_official/hello.txt"
#endif
namespace { namespace {
// Test connection information // Test connection information
const char *HTTP_SERVER_NAME = "os.mbed.com";
const char *HTTP_SERVER_FILE_PATH = "/media/uploads/mbed_official/hello.txt";
const int HTTP_SERVER_PORT = 80; const int HTTP_SERVER_PORT = 80;
#if defined(TARGET_VK_RZ_A1H) #if defined(TARGET_VK_RZ_A1H)
const int RECV_BUFFER_SIZE = 300; const int RECV_BUFFER_SIZE = 300;
@ -60,15 +62,15 @@ void test_tcp_hello_world() {
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());
TCPSocket sock(net); TCPSocket sock(net);
printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT); printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT);
if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) { if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
printf("HTTP: OK\r\n"); printf("HTTP: OK\r\n");
// We are constructing GET command like this: // We are constructing GET command like this:
// GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n // GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n
strcpy(buffer, "GET http://"); strcpy(buffer, "GET http://");
strcat(buffer, HTTP_SERVER_NAME); strcat(buffer, MBED_CONF_APP_HTTP_SERVER_NAME);
strcat(buffer, HTTP_SERVER_FILE_PATH); strcat(buffer, MBED_CONF_APP_HTTP_SERVER_FILE_PATH);
strcat(buffer, " HTTP/1.0\n\n"); strcat(buffer, " HTTP/1.0\n\n");
// Send GET command // Send GET command
sock.send(buffer, strlen(buffer)); sock.send(buffer, strlen(buffer));