/** * Connect with credentials included in the connect request */ void test_connect_credentials() { driver.disconnect(); TEST_ASSERT(do_connect(&driver) == 0); use_connection(&driver); drop_connection(&driver); }
/** * Test with credentials preset */ void test_connect_preset_credentials() { driver.disconnect(); driver.set_sim_pin(MBED_CONF_APP_DEFAULT_PIN); driver.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD); int num_retries = 0; nsapi_error_t err = NSAPI_ERROR_OK; while (!driver.is_connected()) { err = driver.connect(); if (err == NSAPI_ERROR_OK || num_retries > MBED_CONF_APP_MAX_RETRIES) { break; } } TEST_ASSERT(err == 0); use_connection(&driver); drop_connection(&driver); }
/** * Test TCP data exchange via the asynchronous sigio() mechanism */ void test_tcp_echo_async() { TCPSocket sock; SocketAddress host_address; bool callback_triggered = false; int x; int size; driver.disconnect(); TEST_ASSERT(do_connect(&driver) == 0); TEST_ASSERT( driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); host_address.set_port(MBED_CONF_APP_ECHO_TCP_PORT); tr_debug("TCP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), host_address.get_port()); TEST_ASSERT(sock.open(&driver) == 0) // Set up the async callback and set the timeout to zero sock.sigio(callback(async_cb, &callback_triggered)); sock.set_timeout(0); TEST_ASSERT(sock.connect(host_address) == 0); // Test min, max, and some random sizes in-between do_tcp_echo_async(&sock, 1, &callback_triggered); do_tcp_echo_async(&sock, MBED_CONF_APP_TCP_MAX_PACKET_SIZE, &callback_triggered); sock.close(); drop_connection(&driver); tr_debug("TCP packets of size up to %d byte(s) echoed asynchronously and successfully.", MBED_CONF_APP_TCP_MAX_PACKET_SIZE); }
/** * Test UDP data exchange */ void test_udp_echo() { UDPSocket sock; SocketAddress host_address; int x; int size; driver.disconnect(); TEST_ASSERT(do_connect(&driver) == 0); TEST_ASSERT(driver.gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0); host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT); tr_debug("UDP: Server %s address: %s on port %d.", MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(), host_address.get_port()); TEST_ASSERT(sock.open(&driver) == 0) sock.set_timeout(10000); // Test min, max, and some random sizes in-between do_udp_echo(&sock, &host_address, 1); do_udp_echo(&sock, &host_address, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); for (x = 0; x < 10; x++) { size = (rand() % MBED_CONF_APP_UDP_MAX_PACKET_SIZE) + 1; size = fix(size, MBED_CONF_APP_UDP_MAX_PACKET_SIZE + 1); do_udp_echo(&sock, &host_address, size); } sock.close(); drop_connection(&driver); tr_debug("%d UDP packets of size up to %d byte(s) echoed successfully.", x, MBED_CONF_APP_UDP_MAX_PACKET_SIZE); }
/** * Drop a connection and check that it has dropped */ static void drop_connection(OnboardCellularInterface *driver) { TEST_ASSERT(driver->disconnect() == 0); TEST_ASSERT(!driver->is_connected()); }