etc/protocols - sync with NetBSD-8
[minix.git] / tests / sys / netatalk / t_print.c
blob2e506c635bc189d37c102f2a40d909d1035521bc
1 /* $NetBSD: t_print.c,v 1.1 2014/12/02 19:48:21 christos Exp $ */
3 /*-
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_print.c,v 1.1 2014/12/02 19:48:21 christos Exp $");
34 #include "netatalk/at_print.c"
36 #include <atf-c.h>
38 static const struct {
39 struct at_addr ia;
40 const char *str;
41 int len;
42 } tst[] = {
44 { 0, 0 },
45 "0.0",
49 { htons(3), 255 },
50 "3.255",
56 ATF_TC(at_print);
57 ATF_TC_HEAD(at_print, tc)
60 atf_tc_set_md_var(tc, "descr", "printing of struct at_addr");
63 ATF_TC_BODY(at_print, tc)
65 char buf[ATALK_ADDRSTRLEN];
66 int r;
67 size_t l = sizeof(buf);
69 for (size_t i = 0; i < __arraycount(tst); i++) {
70 r = at_print(buf, l, &tst[i].ia);
71 ATF_REQUIRE_STREQ(buf, tst[i].str);
72 ATF_REQUIRE_EQ(r, tst[i].len);
75 l = 4;
76 for (size_t i = 0; i < __arraycount(tst); i++) {
77 r = at_print(buf, l, &tst[i].ia);
78 ATF_CHECK(strncmp(buf, tst[i].str, l - 1) == 0);
79 if (r > (int)l)
80 ATF_REQUIRE_EQ(buf[l - 1], '\0');
81 ATF_REQUIRE_EQ(r, tst[i].len);
85 ATF_TC(sat_print);
86 ATF_TC_HEAD(sat_print, tc)
89 atf_tc_set_md_var(tc, "descr", "printing of sockaddr_at");
92 ATF_TC_BODY(sat_print, tc)
94 char buf[1024];
95 char res[1024];
96 int r, e;
97 size_t l = sizeof(buf);
98 struct sockaddr_at sat;
100 memset(&sat, 0, sizeof(sat));
101 for (size_t i = 0; i < __arraycount(tst); i++) {
102 sat.sat_addr = tst[i].ia;
103 sat.sat_port = (uint8_t)i;
104 r = sat_print(buf, l, &sat);
105 if (i == 0)
106 e = snprintf(res, sizeof(res), "%s", tst[i].str);
107 else
108 e = snprintf(res, sizeof(res), "%s:%zu", tst[i].str, i);
110 ATF_REQUIRE_STREQ(buf, res);
111 ATF_REQUIRE_EQ(r, e);
114 l = 8;
115 for (size_t i = 0; i < __arraycount(tst); i++) {
116 sat.sat_addr = tst[i].ia;
117 sat.sat_port = (uint8_t)i;
118 r = sat_print(buf, l, &sat);
119 if (i == 0)
120 e = snprintf(res, l, "%s", tst[i].str);
121 else
122 e = snprintf(res, l, "%s:%zu", tst[i].str, i);
124 ATF_REQUIRE_STREQ(buf, res);
125 ATF_REQUIRE_EQ(r, e);
129 ATF_TP_ADD_TCS(tp)
132 ATF_TP_ADD_TC(tp, at_print);
133 ATF_TP_ADD_TC(tp, sat_print);
134 return atf_no_error();