Path: blob/main/lib/libc/tests/net/eui64_aton_test.c
39534 views
/*1* Copyright 2004 The Aerospace Corporation. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6*7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions, and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. The name of The Aerospace Corporation may not be used to endorse or13* promote products derived from this software.14*15* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/types.h>29#include <sys/eui64.h>30#include <locale.h>31#include <stdio.h>32#include <string.h>3334#include <atf-c.h>3536#include "test-eui64.h"3738static void39test_str(const char *str, const struct eui64 *eui)40{41struct eui64 e;42char buf[EUI64_SIZ];43int rc;4445ATF_REQUIRE_MSG(eui64_aton(str, &e) == 0, "eui64_aton failed");46rc = memcmp(&e, eui, sizeof(e));47if (rc != 0) {48eui64_ntoa(&e, buf, sizeof(buf));49atf_tc_fail(50"eui64_aton(\"%s\", ..) failed; memcmp returned %d. "51"String obtained form eui64_ntoa was: `%s`",52str, rc, buf);53}54}5556ATF_TC_WITHOUT_HEAD(id_ascii);57ATF_TC_BODY(id_ascii, tc)58{5960test_str(test_eui64_id_ascii, &test_eui64_id);61}6263ATF_TC_WITHOUT_HEAD(id_colon_ascii);64ATF_TC_BODY(id_colon_ascii, tc)65{6667test_str(test_eui64_id_colon_ascii, &test_eui64_id);68}6970ATF_TC_WITHOUT_HEAD(mac_ascii);71ATF_TC_BODY(mac_ascii, tc)72{7374test_str(test_eui64_mac_ascii, &test_eui64_eui48);75}7677ATF_TC_WITHOUT_HEAD(mac_colon_ascii);78ATF_TC_BODY(mac_colon_ascii, tc)79{8081test_str(test_eui64_mac_colon_ascii, &test_eui64_eui48);82}8384ATF_TC_WITHOUT_HEAD(hex_ascii);85ATF_TC_BODY(hex_ascii, tc)86{8788test_str(test_eui64_hex_ascii, &test_eui64_id);89}9091ATF_TP_ADD_TCS(tp)92{9394ATF_TP_ADD_TC(tp, id_ascii);95ATF_TP_ADD_TC(tp, id_colon_ascii);96ATF_TP_ADD_TC(tp, mac_ascii);97ATF_TP_ADD_TC(tp, mac_colon_ascii);98ATF_TP_ADD_TC(tp, hex_ascii);99100return (atf_no_error());101}102103104