-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathasynchronous_dns_non_async_and_async.cpp
56 lines (46 loc) · 1.91 KB
/
asynchronous_dns_non_async_and_async.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2018, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"
#include "dns_tests.h"
using namespace utest::v1;
void ASYNCHRONOUS_DNS_NON_ASYNC_AND_ASYNC()
{
rtos::Semaphore semaphore;
dns_application_data data;
data.semaphore = &semaphore;
// Initiate
nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts_second[0],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data));
TEST_ASSERT(err >= 0);
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
SocketAddress addr;
int err = get_interface()->gethostbyname(dns_test_hosts[i], &addr);
greentea_serial->printf("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts[i], addr.get_ip_address());
TEST_ASSERT_EQUAL(0, err);
TEST_ASSERT((bool)addr);
TEST_ASSERT(strlen(addr.get_ip_address()) > 1);
}
semaphore.wait(100);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);
greentea_serial->printf("DNS: query \"%s\" => \"%s\"\n",
dns_test_hosts_second[0], data.addr.get_ip_address());
TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1);
}