ublox-at-cellular-interface-ext

Dependencies:   ublox-at-cellular-interface

Committer:
RobMeades
Date:
Mon Jun 05 12:58:04 2017 +0000
Revision:
0:0b75e22c9231
Child:
5:9fd89567f769
Initial revision.

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