xref: /freebsd/lib/libc/tests/net/eui64_aton_test.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1*24732d67SEnji Cooper /*
2*24732d67SEnji Cooper  * Copyright 2004 The Aerospace Corporation.  All rights reserved.
3*24732d67SEnji Cooper  *
4*24732d67SEnji Cooper  * Redistribution and use in source and binary forms, with or without
5*24732d67SEnji Cooper  * modification, are permitted provided that the following conditions
6*24732d67SEnji Cooper  * are met:
7*24732d67SEnji Cooper  *
8*24732d67SEnji Cooper  * 1.  Redistributions of source code must retain the above copyright
9*24732d67SEnji Cooper  *     notice, this list of conditions, and the following disclaimer.
10*24732d67SEnji Cooper  * 2.  Redistributions in binary form must reproduce the above copyright
11*24732d67SEnji Cooper  *     notice, this list of conditions, and the following disclaimer in the
12*24732d67SEnji Cooper  *     documentation and/or other materials provided with the distribution.
13*24732d67SEnji Cooper  * 3.  The name of The Aerospace Corporation may not be used to endorse or
14*24732d67SEnji Cooper  *     promote products derived from this software.
15*24732d67SEnji Cooper  *
16*24732d67SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND
17*24732d67SEnji Cooper  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*24732d67SEnji Cooper  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*24732d67SEnji Cooper  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
20*24732d67SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*24732d67SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*24732d67SEnji Cooper  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*24732d67SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*24732d67SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*24732d67SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*24732d67SEnji Cooper  * SUCH DAMAGE.
27*24732d67SEnji Cooper  */
28*24732d67SEnji Cooper 
29*24732d67SEnji Cooper #include <sys/types.h>
30*24732d67SEnji Cooper #include <sys/eui64.h>
31*24732d67SEnji Cooper #include <locale.h>
32*24732d67SEnji Cooper #include <stdio.h>
33*24732d67SEnji Cooper #include <string.h>
34*24732d67SEnji Cooper 
35*24732d67SEnji Cooper #include <atf-c.h>
36*24732d67SEnji Cooper 
37*24732d67SEnji Cooper #include "test-eui64.h"
38*24732d67SEnji Cooper 
39*24732d67SEnji Cooper static void
test_str(const char * str,const struct eui64 * eui)40*24732d67SEnji Cooper test_str(const char *str, const struct eui64 *eui)
41*24732d67SEnji Cooper {
42*24732d67SEnji Cooper 	struct eui64 e;
43*24732d67SEnji Cooper 	char buf[EUI64_SIZ];
44*24732d67SEnji Cooper 	int rc;
45*24732d67SEnji Cooper 
46*24732d67SEnji Cooper 	ATF_REQUIRE_MSG(eui64_aton(str, &e) == 0, "eui64_aton failed");
47*24732d67SEnji Cooper 	rc = memcmp(&e, eui, sizeof(e));
48*24732d67SEnji Cooper 	if (rc != 0) {
49*24732d67SEnji Cooper 		eui64_ntoa(&e, buf, sizeof(buf));
50*24732d67SEnji Cooper 		atf_tc_fail(
51*24732d67SEnji Cooper 		    "eui64_aton(\"%s\", ..) failed; memcmp returned %d. "
52*24732d67SEnji Cooper 		    "String obtained form eui64_ntoa was: `%s`",
53*24732d67SEnji Cooper 		    str, rc, buf);
54*24732d67SEnji Cooper 	}
55*24732d67SEnji Cooper }
56*24732d67SEnji Cooper 
57*24732d67SEnji Cooper ATF_TC_WITHOUT_HEAD(id_ascii);
ATF_TC_BODY(id_ascii,tc)58*24732d67SEnji Cooper ATF_TC_BODY(id_ascii, tc)
59*24732d67SEnji Cooper {
60*24732d67SEnji Cooper 
61*24732d67SEnji Cooper 	test_str(test_eui64_id_ascii, &test_eui64_id);
62*24732d67SEnji Cooper }
63*24732d67SEnji Cooper 
64*24732d67SEnji Cooper ATF_TC_WITHOUT_HEAD(id_colon_ascii);
ATF_TC_BODY(id_colon_ascii,tc)65*24732d67SEnji Cooper ATF_TC_BODY(id_colon_ascii, tc)
66*24732d67SEnji Cooper {
67*24732d67SEnji Cooper 
68*24732d67SEnji Cooper 	test_str(test_eui64_id_colon_ascii, &test_eui64_id);
69*24732d67SEnji Cooper }
70*24732d67SEnji Cooper 
71*24732d67SEnji Cooper ATF_TC_WITHOUT_HEAD(mac_ascii);
ATF_TC_BODY(mac_ascii,tc)72*24732d67SEnji Cooper ATF_TC_BODY(mac_ascii, tc)
73*24732d67SEnji Cooper {
74*24732d67SEnji Cooper 
75*24732d67SEnji Cooper 	test_str(test_eui64_mac_ascii, &test_eui64_eui48);
76*24732d67SEnji Cooper }
77*24732d67SEnji Cooper 
78*24732d67SEnji Cooper ATF_TC_WITHOUT_HEAD(mac_colon_ascii);
ATF_TC_BODY(mac_colon_ascii,tc)79*24732d67SEnji Cooper ATF_TC_BODY(mac_colon_ascii, tc)
80*24732d67SEnji Cooper {
81*24732d67SEnji Cooper 
82*24732d67SEnji Cooper 	test_str(test_eui64_mac_colon_ascii, &test_eui64_eui48);
83*24732d67SEnji Cooper }
84*24732d67SEnji Cooper 
85*24732d67SEnji Cooper ATF_TC_WITHOUT_HEAD(hex_ascii);
ATF_TC_BODY(hex_ascii,tc)86*24732d67SEnji Cooper ATF_TC_BODY(hex_ascii, tc)
87*24732d67SEnji Cooper {
88*24732d67SEnji Cooper 
89*24732d67SEnji Cooper 	test_str(test_eui64_hex_ascii, &test_eui64_id);
90*24732d67SEnji Cooper }
91*24732d67SEnji Cooper 
ATF_TP_ADD_TCS(tp)92*24732d67SEnji Cooper ATF_TP_ADD_TCS(tp)
93*24732d67SEnji Cooper {
94*24732d67SEnji Cooper 
95*24732d67SEnji Cooper 	ATF_TP_ADD_TC(tp, id_ascii);
96*24732d67SEnji Cooper 	ATF_TP_ADD_TC(tp, id_colon_ascii);
97*24732d67SEnji Cooper 	ATF_TP_ADD_TC(tp, mac_ascii);
98*24732d67SEnji Cooper 	ATF_TP_ADD_TC(tp, mac_colon_ascii);
99*24732d67SEnji Cooper 	ATF_TP_ADD_TC(tp, hex_ascii);
100*24732d67SEnji Cooper 
101*24732d67SEnji Cooper 	return (atf_no_error());
102*24732d67SEnji Cooper }
103