ublox-at-cellular-interface-ext

Dependencies:   ublox-at-cellular-interface

Committer:
rob.meades@u-blox.com
Date:
Tue Jun 13 00:12:01 2017 +0100
Revision:
5:9fd89567f769
Parent:
0:0b75e22c9231
Child:
11:3631f62bb359
Updated to use u-blox cellular libraries outside mbed but NOT yet fully working on C027.  Please hold off from using this library on C027 for now until a commit comes along stating that it is tested and working on C027.

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