Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
asynchronous_dns_invalid_host.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 using namespace utest::v1; 00025 00026 namespace { 00027 int result_ok; 00028 int result_no_mem; 00029 int result_dns_failure; 00030 int result_exp_timeout; 00031 } 00032 00033 void ASYNCHRONOUS_DNS_INVALID_HOST() 00034 { 00035 // Ensures that cache does not contain entries 00036 do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem, 00037 &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 exp_dns_failure = 0; 00043 int exp_ok = 0; 00044 00045 // Invalidate 1st and 3th etc. entries 00046 for (unsigned int i = 0; i < MBED_CONF_APP_DNS_SIMULT_QUERIES + 1; i++) { 00047 if ((i % 2) == 0) { 00048 // Last query fails to no memory so do not increase 00049 if (i != MBED_CONF_APP_DNS_SIMULT_QUERIES) { 00050 exp_dns_failure++; 00051 } 00052 strcat(&(dns_test_hosts_new[i][0]), "_invalid"); 00053 } else { 00054 // Last query fails to no memory so do not increase 00055 if (i != MBED_CONF_APP_DNS_SIMULT_QUERIES) { 00056 exp_ok++; 00057 } 00058 } 00059 } 00060 00061 do_asynchronous_gethostbyname(dns_test_hosts_new, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem, 00062 &result_dns_failure, &result_exp_timeout); 00063 00064 TEST_ASSERT(result_ok == exp_ok); 00065 TEST_ASSERT(result_no_mem == 1); // last query fails for no memory as expected 00066 TEST_ASSERT(result_dns_failure == exp_dns_failure || result_dns_failure == exp_dns_failure + 1); 00067 TEST_ASSERT(result_exp_timeout == 0); 00068 }
Generated on Tue Aug 9 2022 00:37:02 by
1.7.2