takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers synchronous_dns_invalid.cpp Source File

synchronous_dns_invalid.cpp

00001 /*
00002  * Copyright (c) 2018, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "mbed.h"
00019 #include "greentea-client/test_env.h"
00020 #include "unity.h"
00021 #include "utest.h"
00022 #include "dns_tests.h"
00023 
00024 
00025 using namespace utest::v1;
00026 
00027 namespace {
00028 int result_ok;
00029 int result_no_mem;
00030 int result_dns_failure;
00031 int result_exp_timeout;
00032 }
00033 
00034 void SYNCHRONOUS_DNS_INVALID()
00035 {
00036     //Ensure that there are no addressess in cache
00037     do_gethostbyname(dns_test_hosts_second, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
00038 
00039     char dns_test_hosts_new[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN];
00040     memcpy(dns_test_hosts_new, dns_test_hosts, sizeof(dns_test_hosts_new));
00041 
00042     int expected_failures = 0;
00043     int expected_successes = 0;
00044 
00045     for (int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
00046         if ((i % 2) == 0) {
00047             expected_failures++;
00048             strcat(&(dns_test_hosts_new[i][0]), "_invalid");
00049         } else {
00050             expected_successes++;
00051         }
00052     }
00053 
00054     do_gethostbyname(dns_test_hosts_new, MBED_CONF_APP_DNS_TEST_HOSTS_NUM, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
00055 
00056     TEST_ASSERT(result_ok == expected_successes);
00057     TEST_ASSERT(result_no_mem == 0);
00058     TEST_ASSERT(result_dns_failure == expected_failures);
00059     TEST_ASSERT(result_exp_timeout == 0);
00060 }