Skip to content

Commit ce6b99f

Browse files
Add test for WiFiInterface::get_time
1 parent bcb0f08 commit ce6b99f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

TESTS/network/wifi/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Case cases[] = {
7272
#endif
7373
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
7474
Case("WIFI-GET-RSSI", wifi_get_rssi),
75+
Case("WIFI-GET-TIME", wifi_get_time),
7576
Case("WIFI-CONNECT-DISCONNECT-REPEAT", wifi_connect_disconnect_repeat),
7677
Case("WIFI-CONNECT-PARAMS-VALID-SECURE", wifi_connect_params_valid_secure),
7778
Case("WIFI-CONNECT-PARAMS-CHANNEL", wifi_connect_params_channel),

TESTS/network/wifi/wifi_get_time.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2017, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include "greentea-client/test_env.h"
20+
#include "unity.h"
21+
#include "utest.h"
22+
#include "wifi_tests.h"
23+
24+
using namespace utest::v1;
25+
26+
#if defined(MBED_CONF_APP_WIFI_SECURE_SSID)
27+
28+
void wifi_get_time(void)
29+
{
30+
WiFiInterface *wifi = get_interface();
31+
32+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()));
33+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->connect());
34+
35+
std::tm t = {};
36+
nsapi_error_t ret = wifi->get_time(&t);
37+
if (ret == NSAPI_ERROR_UNSUPPORTED) {
38+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
39+
TEST_SKIP_MESSAGE("This device does not support get_time or it is not enabled");
40+
}
41+
42+
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, ret);
43+
44+
TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->disconnect());
45+
}
46+
47+
#endif // defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)

TESTS/network/wifi/wifi_tests.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void wifi_set_channel(void);
4545
* When connected, it should return valid RSSI value. When unconnected it should return 0. */
4646
void wifi_get_rssi(void);
4747

48+
/** Test WiFiInterface::get_time() API. */
49+
void wifi_get_time(void);
50+
4851
/** Test WiFiInterface::connect(ssid, pass, security, channel) with NULL parameters */
4952
void wifi_connect_params_null(void);
5053

0 commit comments

Comments
 (0)