1 1.1 christos /* $NetBSD: domain_name_test.c,v 1.2 2020/08/03 21:10:56 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * Copyright (C) 2019 Internet Systems Consortium, Inc. ("ISC") 5 1.1 christos * 6 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public 7 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this 8 1.1 christos * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 1.1 christos * 10 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 1.1 christos * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 1.1 christos * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 1.1 christos * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 1.1 christos * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 1.1 christos * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 1.1 christos * PERFORMANCE OF THIS SOFTWARE. 17 1.1 christos */ 18 1.1 christos 19 1.1 christos #include <config.h> 20 1.1 christos #include <atf-c.h> 21 1.1 christos #include "dhcpd.h" 22 1.1 christos 23 1.1 christos ATF_TC(pretty_print_domain_name); 24 1.1 christos 25 1.1 christos ATF_TC_HEAD(pretty_print_domain_name, tc) 26 1.1 christos { 27 1.1 christos atf_tc_set_md_var(tc, "descr", 28 1.1 christos "Verify pretty_print_option can render a domain name."); 29 1.1 christos } 30 1.1 christos 31 1.1 christos /* 32 1.1 christos * This test verifies that pretty_print_option() correctly render a 33 1.1 christos * domain name. 34 1.1 christos * 35 1.1 christos */ 36 1.1 christos ATF_TC_BODY(pretty_print_domain_name, tc) 37 1.1 christos { 38 1.1 christos struct option *option; 39 1.1 christos unsigned code; 40 1.1 christos unsigned char good_data[] = 41 1.1 christos { 0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00 }; 42 1.1 christos unsigned char short_data[] = 43 1.1 christos { 0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d }; 44 1.1 christos unsigned char long_data[] = 45 1.1 christos { 0x05, 0x62, 0x6f, 0x6f, 0x79, 0x61, 0x03, 0x63, 0x6f, 0x6d, 0x00, 46 1.1 christos 0x01, 0x02 }; 47 1.1 christos const char *output_buf; 48 1.1 christos 49 1.1 christos initialize_common_option_spaces(); 50 1.1 christos 51 1.1 christos /* We'll use v4-lost because it happens to be format d */ 52 1.1 christos code = 137; 53 1.1 christos option = NULL; 54 1.1 christos if (!option_code_hash_lookup(&option, dhcp_universe.code_hash, 55 1.1 christos &code, 0, MDL)) { 56 1.1 christos atf_tc_fail("can't find option %d", code); 57 1.1 christos } 58 1.1 christos 59 1.1 christos if (option == NULL) { 60 1.1 christos atf_tc_fail("option is NULL"); 61 1.1 christos } 62 1.1 christos 63 1.1 christos /* First we will try a good value we know should fit. */ 64 1.1 christos output_buf = pretty_print_option(option, good_data, sizeof(good_data), 0, 65 1.1 christos 0); 66 1.1 christos 67 1.1 christos /* Make sure we get what we expect */ 68 1.1 christos if (!output_buf || strcmp(output_buf, "booya.com.")) { 69 1.1 christos atf_tc_fail("pretty_print_option did not return 'booya.com.'"); 70 1.1 christos } 71 1.1 christos 72 1.1 christos fprintf(stderr, "good!\n"); 73 1.1 christos 74 1.1 christos /* Now we'll try a data value that's too short */ 75 1.1 christos output_buf = pretty_print_option(option, short_data, sizeof(short_data), 76 1.1 christos 0, 0); 77 1.1 christos 78 1.1 christos /* Make sure we safely get an error */ 79 1.1 christos if (!output_buf || strcmp(output_buf, "<error>")) { 80 1.1 christos atf_tc_fail("pretty_print_option did not return \"<error>\""); 81 1.1 christos } 82 1.1 christos 83 1.1 christos /* Now we'll try a data value that's too large */ 84 1.1 christos output_buf = pretty_print_option(option, long_data, sizeof(long_data), 0, 85 1.1 christos 0); 86 1.1 christos 87 1.1 christos /* This logs but does not return an error */ 88 1.1 christos if (!output_buf || strcmp(output_buf, "booya.com.")) { 89 1.1 christos atf_tc_fail("pretty_print_option did not return 'booya.com.' (large)"); 90 1.1 christos } 91 1.1 christos } 92 1.1 christos 93 1.1 christos 94 1.1 christos /* This macro defines main() method that will call specified 95 1.1 christos test cases. tp and simple_test_case names can be whatever you want 96 1.1 christos as long as it is a valid variable identifier. */ 97 1.1 christos ATF_TP_ADD_TCS(tp) 98 1.1 christos { 99 1.1 christos ATF_TP_ADD_TC(tp, pretty_print_domain_name); 100 1.1 christos 101 1.1 christos return (atf_no_error()); 102 1.1 christos } 103