initial fork from ublox

Dependencies:   ublox-at-cellular-interface

Committer:
rlanders73
Date:
Fri Dec 14 18:20:56 2018 +0000
Revision:
17:6278a086733a
Parent:
11:3631f62bb359
updating for Geneva platform

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:0b75e22c9231 1 #include "mbed.h"
RobMeades 0:0b75e22c9231 2 #include "greentea-client/test_env.h"
RobMeades 0:0b75e22c9231 3 #include "unity.h"
RobMeades 0:0b75e22c9231 4 #include "utest.h"
RobMeades 0:0b75e22c9231 5 #include "UbloxATCellularInterfaceExt.h"
RobMeades 0:0b75e22c9231 6 #include "UDPSocket.h"
rob.meades@u-blox.com 5:9fd89567f769 7 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 8 #include "mbed_trace.h"
RobMeades 0:0b75e22c9231 9 #define TRACE_GROUP "TEST"
rob.meades@u-blox.com 5:9fd89567f769 10 #else
rob.meades@u-blox.com 5:9fd89567f769 11 #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 12 #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 13 #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 14 #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 5:9fd89567f769 15 #endif
RobMeades 0:0b75e22c9231 16
RobMeades 0:0b75e22c9231 17 using namespace utest::v1;
RobMeades 0:0b75e22c9231 18
RobMeades 0:0b75e22c9231 19 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 20 // COMPILE-TIME MACROS
RobMeades 0:0b75e22c9231 21 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 22
RobMeades 0:0b75e22c9231 23 // These macros can be overridden with an mbed_app.json file and
RobMeades 0:0b75e22c9231 24 // contents of the following form:
RobMeades 0:0b75e22c9231 25 //
RobMeades 0:0b75e22c9231 26 //{
RobMeades 0:0b75e22c9231 27 // "config": {
RobMeades 0:0b75e22c9231 28 // "apn": {
RobMeades 0:0b75e22c9231 29 // "value": "\"my_apn\""
RobMeades 0:0b75e22c9231 30 // }
RobMeades 0:0b75e22c9231 31 //}
RobMeades 0:0b75e22c9231 32
rob.meades@u-blox.com 11:3631f62bb359 33 // Whether debug trace is on
rob.meades@u-blox.com 11:3631f62bb359 34 #ifndef MBED_CONF_APP_DEBUG_ON
rob.meades@u-blox.com 11:3631f62bb359 35 # define MBED_CONF_APP_DEBUG_ON false
rob.meades@u-blox.com 11:3631f62bb359 36 #endif
rob.meades@u-blox.com 11:3631f62bb359 37
RobMeades 0:0b75e22c9231 38 // The credentials of the SIM in the board.
RobMeades 0:0b75e22c9231 39 #ifndef MBED_CONF_APP_DEFAULT_PIN
rob.meades@u-blox.com 11:3631f62bb359 40 // Note: if PIN is enabled on your SIM, you must define the PIN
rob.meades@u-blox.com 11:3631f62bb359 41 // for your SIM jere (e.g. using mbed_app.json to do so).
rob.meades@u-blox.com 11:3631f62bb359 42 # define MBED_CONF_APP_DEFAULT_PIN "0000"
RobMeades 0:0b75e22c9231 43 #endif
RobMeades 0:0b75e22c9231 44
RobMeades 0:0b75e22c9231 45 // Network credentials.
RobMeades 0:0b75e22c9231 46 #ifndef MBED_CONF_APP_APN
RobMeades 0:0b75e22c9231 47 # define MBED_CONF_APP_APN NULL
RobMeades 0:0b75e22c9231 48 #endif
RobMeades 0:0b75e22c9231 49 #ifndef MBED_CONF_APP_USERNAME
RobMeades 0:0b75e22c9231 50 # define MBED_CONF_APP_USERNAME NULL
RobMeades 0:0b75e22c9231 51 #endif
RobMeades 0:0b75e22c9231 52 #ifndef MBED_CONF_APP_PASSWORD
RobMeades 0:0b75e22c9231 53 # define MBED_CONF_APP_PASSWORD NULL
RobMeades 0:0b75e22c9231 54 #endif
RobMeades 0:0b75e22c9231 55
RobMeades 0:0b75e22c9231 56 // The time to wait for a HTTP command to complete
RobMeades 0:0b75e22c9231 57 #define HTTP_TIMEOUT 10000
RobMeades 0:0b75e22c9231 58
RobMeades 0:0b75e22c9231 59 // The HTTP echo server, as described in the
RobMeades 0:0b75e22c9231 60 // first answer here:
RobMeades 0:0b75e22c9231 61 // http://stackoverflow.com/questions/5725430/http-test-server-that-accepts-get-post-calls
RobMeades 0:0b75e22c9231 62 // !!! IMPORTANT: this test relies on that server behaving in the same way forever !!!
RobMeades 0:0b75e22c9231 63 #define HTTP_ECHO_SERVER "httpbin.org"
RobMeades 0:0b75e22c9231 64
RobMeades 0:0b75e22c9231 65 // The size of the test file
RobMeades 0:0b75e22c9231 66 #define TEST_FILE_SIZE 100
RobMeades 0:0b75e22c9231 67
RobMeades 0:0b75e22c9231 68 // The maximum number of HTTP profiles
RobMeades 0:0b75e22c9231 69 #define MAX_PROFILES 4
RobMeades 0:0b75e22c9231 70
RobMeades 0:0b75e22c9231 71 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 72 // PRIVATE VARIABLES
RobMeades 0:0b75e22c9231 73 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 74
rob.meades@u-blox.com 5:9fd89567f769 75 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 76 // Lock for debug prints
RobMeades 0:0b75e22c9231 77 static Mutex mtx;
rob.meades@u-blox.com 5:9fd89567f769 78 #endif
RobMeades 0:0b75e22c9231 79
RobMeades 0:0b75e22c9231 80 // An instance of the cellular interface
RobMeades 0:0b75e22c9231 81 static UbloxATCellularInterfaceExt *pDriver =
RobMeades 0:0b75e22c9231 82 new UbloxATCellularInterfaceExt(MDMTXD, MDMRXD,
RobMeades 0:0b75e22c9231 83 MBED_CONF_UBLOX_CELL_BAUD_RATE,
rob.meades@u-blox.com 11:3631f62bb359 84 MBED_CONF_APP_DEBUG_ON);
RobMeades 0:0b75e22c9231 85 // A few buffers for general use
RobMeades 0:0b75e22c9231 86 static char buf[1024];
RobMeades 0:0b75e22c9231 87 static char buf1[sizeof(buf)];
RobMeades 0:0b75e22c9231 88
RobMeades 0:0b75e22c9231 89 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 90 // PRIVATE FUNCTIONS
RobMeades 0:0b75e22c9231 91 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 92
rob.meades@u-blox.com 5:9fd89567f769 93 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 94 // Locks for debug prints
RobMeades 0:0b75e22c9231 95 static void lock()
RobMeades 0:0b75e22c9231 96 {
RobMeades 0:0b75e22c9231 97 mtx.lock();
RobMeades 0:0b75e22c9231 98 }
RobMeades 0:0b75e22c9231 99
RobMeades 0:0b75e22c9231 100 static void unlock()
RobMeades 0:0b75e22c9231 101 {
RobMeades 0:0b75e22c9231 102 mtx.unlock();
RobMeades 0:0b75e22c9231 103 }
rob.meades@u-blox.com 5:9fd89567f769 104 #endif
RobMeades 0:0b75e22c9231 105
RobMeades 0:0b75e22c9231 106 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 107 // TESTS
RobMeades 0:0b75e22c9231 108 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 109
RobMeades 0:0b75e22c9231 110 // Test HTTP commands
RobMeades 0:0b75e22c9231 111 void test_http_cmd() {
RobMeades 0:0b75e22c9231 112 int profile;
RobMeades 0:0b75e22c9231 113 char * pData;
RobMeades 0:0b75e22c9231 114
RobMeades 0:0b75e22c9231 115 TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
RobMeades 0:0b75e22c9231 116 MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
RobMeades 0:0b75e22c9231 117
RobMeades 0:0b75e22c9231 118 profile = pDriver->httpAllocProfile();
RobMeades 0:0b75e22c9231 119 TEST_ASSERT(profile >= 0);
RobMeades 0:0b75e22c9231 120
RobMeades 0:0b75e22c9231 121 pDriver->httpSetTimeout(profile, HTTP_TIMEOUT);
RobMeades 0:0b75e22c9231 122
RobMeades 0:0b75e22c9231 123 // Set up the server to talk to
RobMeades 0:0b75e22c9231 124 TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, HTTP_ECHO_SERVER));
RobMeades 0:0b75e22c9231 125
RobMeades 0:0b75e22c9231 126 // Check HTTP head request
RobMeades 0:0b75e22c9231 127 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 128 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_HEAD,
RobMeades 0:0b75e22c9231 129 "/headers",
RobMeades 0:0b75e22c9231 130 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 131 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 132 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 133 TEST_ASSERT(strstr(buf, "Content-Length:") != NULL);
RobMeades 0:0b75e22c9231 134
RobMeades 0:0b75e22c9231 135 // Check HTTP get request
RobMeades 0:0b75e22c9231 136 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 137 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET,
RobMeades 0:0b75e22c9231 138 "/get",
RobMeades 0:0b75e22c9231 139 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 140 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 141 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 142 TEST_ASSERT(strstr(buf, "\"http://httpbin.org/get\"") != NULL);
RobMeades 0:0b75e22c9231 143
RobMeades 0:0b75e22c9231 144 // Check HTTP delete request
RobMeades 0:0b75e22c9231 145 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 146 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_DELETE,
RobMeades 0:0b75e22c9231 147 "/delete",
RobMeades 0:0b75e22c9231 148 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 149 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 150 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 151 TEST_ASSERT(strstr(buf, "\"http://httpbin.org/delete\"") != NULL);
RobMeades 0:0b75e22c9231 152
RobMeades 0:0b75e22c9231 153 // Check HTTP put request (this will fail as the echo server doesn't support it)
RobMeades 0:0b75e22c9231 154 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 155 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_PUT,
RobMeades 0:0b75e22c9231 156 "/put",
RobMeades 0:0b75e22c9231 157 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 158 buf, sizeof (buf)) != NULL);
RobMeades 0:0b75e22c9231 159
RobMeades 0:0b75e22c9231 160 // Check HTTP post request with data
RobMeades 0:0b75e22c9231 161 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 162 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_POST_DATA,
RobMeades 0:0b75e22c9231 163 "/post",
RobMeades 0:0b75e22c9231 164 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 165 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 166 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 167 TEST_ASSERT(strstr(buf, "\"http://httpbin.org/post\"") != NULL);
RobMeades 0:0b75e22c9231 168
RobMeades 0:0b75e22c9231 169 // Check HTTP post request with a file, also checking that writing the response
RobMeades 0:0b75e22c9231 170 // to a named file works
RobMeades 0:0b75e22c9231 171 for (int x = 0; x < TEST_FILE_SIZE; x++) {
RobMeades 0:0b75e22c9231 172 buf[x] = (x % 10) + 0x30;
RobMeades 0:0b75e22c9231 173 }
RobMeades 0:0b75e22c9231 174 pDriver->delFile("post_test.txt");
RobMeades 0:0b75e22c9231 175 TEST_ASSERT(pDriver->writeFile("post_test.txt", buf, TEST_FILE_SIZE) == TEST_FILE_SIZE);
RobMeades 0:0b75e22c9231 176
RobMeades 0:0b75e22c9231 177 // This may fail if rsp.txt doesn't happen to be sitting around from a previous run
RobMeades 0:0b75e22c9231 178 // so don't check the return value
RobMeades 0:0b75e22c9231 179 pDriver->delFile("rsp.txt");
RobMeades 0:0b75e22c9231 180
RobMeades 0:0b75e22c9231 181 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 182 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_POST_FILE,
RobMeades 0:0b75e22c9231 183 "/post",
RobMeades 0:0b75e22c9231 184 "rsp.txt", "post_test.txt",
RobMeades 0:0b75e22c9231 185 UbloxATCellularInterfaceExt::HTTP_CONTENT_TEXT, NULL,
RobMeades 0:0b75e22c9231 186 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 187 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 188 // Find the data in the response and check it
RobMeades 0:0b75e22c9231 189 pData = strstr(buf, "\"data\": \"");
RobMeades 0:0b75e22c9231 190 TEST_ASSERT(pData != NULL);
RobMeades 0:0b75e22c9231 191 pData += 9;
RobMeades 0:0b75e22c9231 192 for (int x = 0; x < TEST_FILE_SIZE; x++) {
RobMeades 0:0b75e22c9231 193 TEST_ASSERT(*(pData + x) == (x % 10) + 0x30);
RobMeades 0:0b75e22c9231 194 }
RobMeades 0:0b75e22c9231 195
RobMeades 0:0b75e22c9231 196 // Also check that rsp.txt exists and is the same as buf
RobMeades 0:0b75e22c9231 197 pDriver->readFile("rsp.txt", buf1, sizeof (buf1));
RobMeades 0:0b75e22c9231 198 memcmp(buf1, buf, sizeof (buf1));
RobMeades 0:0b75e22c9231 199 TEST_ASSERT(pDriver->delFile("rsp.txt"));
RobMeades 0:0b75e22c9231 200 TEST_ASSERT(!pDriver->delFile("rsp.txt")); // Should fail
RobMeades 0:0b75e22c9231 201
RobMeades 0:0b75e22c9231 202 TEST_ASSERT(pDriver->httpFreeProfile(profile));
RobMeades 0:0b75e22c9231 203 TEST_ASSERT(pDriver->disconnect() == 0);
RobMeades 0:0b75e22c9231 204 // Wait for printfs to leave the building or the test result string gets messed up
RobMeades 0:0b75e22c9231 205 wait_ms(500);
RobMeades 0:0b75e22c9231 206 }
RobMeades 0:0b75e22c9231 207
RobMeades 0:0b75e22c9231 208 // Test HTTP with TLS
RobMeades 0:0b75e22c9231 209 void test_http_tls() {
RobMeades 0:0b75e22c9231 210 int profile;
RobMeades 0:0b75e22c9231 211 SocketAddress address;
RobMeades 0:0b75e22c9231 212
RobMeades 0:0b75e22c9231 213 TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
RobMeades 0:0b75e22c9231 214 MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
RobMeades 0:0b75e22c9231 215
RobMeades 0:0b75e22c9231 216 profile = pDriver->httpAllocProfile();
RobMeades 0:0b75e22c9231 217 TEST_ASSERT(profile >= 0);
RobMeades 0:0b75e22c9231 218
RobMeades 0:0b75e22c9231 219 pDriver->httpSetTimeout(profile, HTTP_TIMEOUT);
RobMeades 0:0b75e22c9231 220
RobMeades 0:0b75e22c9231 221 // Set up the server to talk to and TLS, using the IP address this time just for variety
RobMeades 0:0b75e22c9231 222 TEST_ASSERT(pDriver->gethostbyname("amazon.com", &address) == 0);
RobMeades 0:0b75e22c9231 223 TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_IP_ADDRESS, address.get_ip_address()));
RobMeades 0:0b75e22c9231 224 TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_SECURE, "1"));
RobMeades 0:0b75e22c9231 225
RobMeades 0:0b75e22c9231 226 // Check HTTP get request
RobMeades 0:0b75e22c9231 227 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 228 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET,
RobMeades 0:0b75e22c9231 229 "/",
RobMeades 0:0b75e22c9231 230 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 231 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 232 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 233 // This is what amazon.com returns if TLS is set
RobMeades 0:0b75e22c9231 234 TEST_ASSERT(strstr(buf, "302 MovedTemporarily") != NULL);
RobMeades 0:0b75e22c9231 235
RobMeades 0:0b75e22c9231 236 // Reset the profile and check that this now fails
RobMeades 0:0b75e22c9231 237 TEST_ASSERT(pDriver->httpResetProfile(profile));
RobMeades 0:0b75e22c9231 238 TEST_ASSERT(pDriver->httpSetPar(profile, UbloxATCellularInterfaceExt::HTTP_IP_ADDRESS, address.get_ip_address()));
RobMeades 0:0b75e22c9231 239 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 240 TEST_ASSERT(pDriver->httpCommand(profile, UbloxATCellularInterfaceExt::HTTP_GET,
RobMeades 0:0b75e22c9231 241 "/",
RobMeades 0:0b75e22c9231 242 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 243 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 244 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 245 // This is what amazon.com returns if TLS is NOT set
RobMeades 0:0b75e22c9231 246 TEST_ASSERT(strstr(buf, "301 Moved Permanently") != NULL);
RobMeades 0:0b75e22c9231 247
RobMeades 0:0b75e22c9231 248 TEST_ASSERT(pDriver->httpFreeProfile(profile));
RobMeades 0:0b75e22c9231 249 TEST_ASSERT(pDriver->disconnect() == 0);
RobMeades 0:0b75e22c9231 250 // Wait for printfs to leave the building or the test result string gets messed up
RobMeades 0:0b75e22c9231 251 wait_ms(500);
RobMeades 0:0b75e22c9231 252 }
RobMeades 0:0b75e22c9231 253
RobMeades 0:0b75e22c9231 254 // Allocate max profiles
RobMeades 0:0b75e22c9231 255 void test_alloc_profiles() {
RobMeades 0:0b75e22c9231 256 int profiles[MAX_PROFILES];
RobMeades 0:0b75e22c9231 257
RobMeades 0:0b75e22c9231 258 TEST_ASSERT(pDriver->connect(MBED_CONF_APP_DEFAULT_PIN, MBED_CONF_APP_APN,
RobMeades 0:0b75e22c9231 259 MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD) == 0);
RobMeades 0:0b75e22c9231 260
RobMeades 0:0b75e22c9231 261 // Allocate first profile and use it
RobMeades 0:0b75e22c9231 262 profiles[0] = pDriver->httpAllocProfile();
RobMeades 0:0b75e22c9231 263 TEST_ASSERT(profiles[0] >= 0);
RobMeades 0:0b75e22c9231 264 TEST_ASSERT(pDriver->httpSetPar(profiles[0], UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "developer.mbed.org"));
RobMeades 0:0b75e22c9231 265
RobMeades 0:0b75e22c9231 266 // Check HTTP get request
RobMeades 0:0b75e22c9231 267 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 268 TEST_ASSERT(pDriver->httpCommand(profiles[0], UbloxATCellularInterfaceExt::HTTP_GET,
RobMeades 0:0b75e22c9231 269 "/media/uploads/mbed_official/hello.txt",
RobMeades 0:0b75e22c9231 270 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 271 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 272 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 273 TEST_ASSERT(strstr(buf, "Hello world!") != NULL);
RobMeades 0:0b75e22c9231 274
RobMeades 0:0b75e22c9231 275 // Check that we stop being able to get profiles at the max number
RobMeades 0:0b75e22c9231 276 for (int x = 1; x < sizeof (profiles) / sizeof (profiles[0]); x++) {
RobMeades 0:0b75e22c9231 277 profiles[x] = pDriver->httpAllocProfile();
RobMeades 0:0b75e22c9231 278 TEST_ASSERT(profiles[0] >= 0);
RobMeades 0:0b75e22c9231 279 }
RobMeades 0:0b75e22c9231 280 TEST_ASSERT(pDriver->httpAllocProfile() < 0);
RobMeades 0:0b75e22c9231 281
RobMeades 0:0b75e22c9231 282 // Now use the last one and check that it doesn't affect the first one
RobMeades 0:0b75e22c9231 283 TEST_ASSERT(pDriver->httpSetPar(profiles[sizeof (profiles) / sizeof (profiles[0]) - 1],
RobMeades 0:0b75e22c9231 284 UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, HTTP_ECHO_SERVER));
RobMeades 0:0b75e22c9231 285
RobMeades 0:0b75e22c9231 286 // Check HTTP head request on last profile
RobMeades 0:0b75e22c9231 287 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 288 TEST_ASSERT(pDriver->httpCommand(profiles[sizeof (profiles) / sizeof (profiles[0]) - 1],
RobMeades 0:0b75e22c9231 289 UbloxATCellularInterfaceExt::HTTP_HEAD,
RobMeades 0:0b75e22c9231 290 "/headers",
RobMeades 0:0b75e22c9231 291 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 292 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 293 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 294 TEST_ASSERT(strstr(buf, "Content-Length:") != NULL);
RobMeades 0:0b75e22c9231 295
RobMeades 0:0b75e22c9231 296 // Check HTTP get request on first profile once more
RobMeades 0:0b75e22c9231 297 memset(buf, 0, sizeof (buf));
RobMeades 0:0b75e22c9231 298 TEST_ASSERT(pDriver->httpCommand(profiles[0], UbloxATCellularInterfaceExt::HTTP_GET,
RobMeades 0:0b75e22c9231 299 "/media/uploads/mbed_official/hello.txt",
RobMeades 0:0b75e22c9231 300 NULL, NULL, 0, NULL,
RobMeades 0:0b75e22c9231 301 buf, sizeof (buf)) == NULL);
RobMeades 0:0b75e22c9231 302 tr_debug("Received: %s", buf);
RobMeades 0:0b75e22c9231 303 TEST_ASSERT(strstr(buf, "Hello world!") != NULL);
RobMeades 0:0b75e22c9231 304
RobMeades 0:0b75e22c9231 305 // Free the profiles again
RobMeades 0:0b75e22c9231 306 for (int x = 0; x < sizeof (profiles) / sizeof (profiles[0]); x++) {
RobMeades 0:0b75e22c9231 307 TEST_ASSERT(pDriver->httpFreeProfile(profiles[x]));
RobMeades 0:0b75e22c9231 308 }
RobMeades 0:0b75e22c9231 309
RobMeades 0:0b75e22c9231 310 TEST_ASSERT(pDriver->disconnect() == 0);
RobMeades 0:0b75e22c9231 311 // Wait for printfs to leave the building or the test result string gets messed up
RobMeades 0:0b75e22c9231 312 wait_ms(500);
RobMeades 0:0b75e22c9231 313 }
RobMeades 0:0b75e22c9231 314
RobMeades 0:0b75e22c9231 315 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 316 // TEST ENVIRONMENT
RobMeades 0:0b75e22c9231 317 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 318
RobMeades 0:0b75e22c9231 319 // Setup the test environment
RobMeades 0:0b75e22c9231 320 utest::v1::status_t test_setup(const size_t number_of_cases) {
RobMeades 0:0b75e22c9231 321 // Setup Greentea with a timeout
RobMeades 0:0b75e22c9231 322 GREENTEA_SETUP(540, "default_auto");
RobMeades 0:0b75e22c9231 323 return verbose_test_setup_handler(number_of_cases);
RobMeades 0:0b75e22c9231 324 }
RobMeades 0:0b75e22c9231 325
RobMeades 0:0b75e22c9231 326 // Test cases
RobMeades 0:0b75e22c9231 327 Case cases[] = {
RobMeades 0:0b75e22c9231 328 Case("HTTP commands", test_http_cmd),
rob.meades@u-blox.com 11:3631f62bb359 329 #ifndef TARGET_UBLOX_C027
rob.meades@u-blox.com 11:3631f62bb359 330 // C027 doesn't support TLS
RobMeades 0:0b75e22c9231 331 Case("HTTP with TLS", test_http_tls),
rob.meades@u-blox.com 11:3631f62bb359 332 #endif
RobMeades 0:0b75e22c9231 333 Case("Alloc max profiles", test_alloc_profiles)
RobMeades 0:0b75e22c9231 334 };
RobMeades 0:0b75e22c9231 335
RobMeades 0:0b75e22c9231 336 Specification specification(test_setup, cases);
RobMeades 0:0b75e22c9231 337
RobMeades 0:0b75e22c9231 338 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 339 // MAIN
RobMeades 0:0b75e22c9231 340 // ----------------------------------------------------------------
RobMeades 0:0b75e22c9231 341
RobMeades 0:0b75e22c9231 342 int main() {
rob.meades@u-blox.com 5:9fd89567f769 343
rob.meades@u-blox.com 5:9fd89567f769 344 #ifdef FEATURE_COMMON_PAL
RobMeades 0:0b75e22c9231 345 mbed_trace_init();
RobMeades 0:0b75e22c9231 346
RobMeades 0:0b75e22c9231 347 mbed_trace_mutex_wait_function_set(lock);
RobMeades 0:0b75e22c9231 348 mbed_trace_mutex_release_function_set(unlock);
rob.meades@u-blox.com 5:9fd89567f769 349 #endif
RobMeades 0:0b75e22c9231 350
RobMeades 0:0b75e22c9231 351 // Run tests
RobMeades 0:0b75e22c9231 352 return !Harness::run(specification);
RobMeades 0:0b75e22c9231 353 }
RobMeades 0:0b75e22c9231 354
RobMeades 0:0b75e22c9231 355 // End Of File
RobMeades 0:0b75e22c9231 356