Skip to content

Commit d8cc5a3

Browse files
committed
tests-netsocket-socket_sigio
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 Test on HTTP connect added as test was always OK even with no connection...
1 parent bff8fc1 commit d8cc5a3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

TESTS/netsocket/socket_sigio/main.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929

3030
using namespace utest::v1;
3131

32+
#ifndef MBED_CONF_APP_HTTP_SERVER_NAME
33+
#define MBED_CONF_APP_HTTP_SERVER_NAME "os.mbed.com"
34+
#define MBED_CONF_APP_HTTP_SERVER_FILE_PATH "/media/uploads/mbed_official/hello.txt"
35+
#endif
3236

3337
namespace {
3438
// Test connection information
35-
const char *HTTP_SERVER_NAME = "os.mbed.com";
36-
const char *HTTP_SERVER_FILE_PATH = "/media/uploads/mbed_official/hello.txt";
3739
const int HTTP_SERVER_PORT = 80;
3840
#if defined(TARGET_VK_RZ_A1H)
3941
const int RECV_BUFFER_SIZE = 300;
@@ -97,12 +99,14 @@ void prep_buffer() {
9799
// We are constructing GET command like this:
98100
// GET http://developer.mbed.org/media/uploads/mbed_official/hello.txt HTTP/1.0\n\n
99101
strcpy(buffer, "GET http://");
100-
strcat(buffer, HTTP_SERVER_NAME);
101-
strcat(buffer, HTTP_SERVER_FILE_PATH);
102+
strcat(buffer, MBED_CONF_APP_HTTP_SERVER_NAME);
103+
strcat(buffer, MBED_CONF_APP_HTTP_SERVER_FILE_PATH);
102104
strcat(buffer, " HTTP/1.0\n\n");
103105
}
104106

105107
void test_socket_attach() {
108+
bool result = false;
109+
106110
// Dispatch event queue
107111
Thread eventThread;
108112
EventQueue queue(4*EVENTS_EVENT_SIZE);
@@ -111,8 +115,8 @@ void test_socket_attach() {
111115
printf("TCP client IP Address is %s\r\n", net->get_ip_address());
112116

113117
TCPSocket sock(net);
114-
printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT);
115-
if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
118+
printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT);
119+
if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
116120
printf("HTTP: OK\r\n");
117121

118122
prep_buffer();
@@ -122,10 +126,13 @@ void test_socket_attach() {
122126
sock.send(buffer, strlen(buffer));
123127
// wait for recv data
124128
recvd.wait();
129+
130+
result = true;
125131
} else {
126132
printf("HTTP: ERROR\r\n");
127133
}
128134
sock.close();
135+
TEST_ASSERT_EQUAL(true, result);
129136
}
130137

131138
void cb_fail() {
@@ -145,8 +152,8 @@ void test_socket_detach() {
145152
printf("TCP client IP Address is %s\r\n", net->get_ip_address());
146153

147154
TCPSocket sock(net);
148-
printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT);
149-
if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
155+
printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT);
156+
if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
150157
printf("HTTP: OK\r\n");
151158

152159
prep_buffer();
@@ -172,8 +179,8 @@ void test_socket_reattach() {
172179
printf("TCP client IP Address is %s\r\n", net->get_ip_address());
173180

174181
TCPSocket sock(net);
175-
printf("HTTP: Connection to %s:%d\r\n", HTTP_SERVER_NAME, HTTP_SERVER_PORT);
176-
if (sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
182+
printf("HTTP: Connection to %s:%d\r\n", MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT);
183+
if (sock.connect(MBED_CONF_APP_HTTP_SERVER_NAME, HTTP_SERVER_PORT) == 0) {
177184
printf("HTTP: OK\r\n");
178185

179186
prep_buffer();

0 commit comments

Comments
 (0)