1 /* $NetBSD: t_print.c,v 1.1 2014/12/02 19:48:21 christos Exp $ */
4 * Copyright (c) 2014 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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"
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
];
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
);
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);
80 ATF_REQUIRE_EQ(buf
[l
- 1], '\0');
81 ATF_REQUIRE_EQ(r
, tst
[i
].len
);
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
)
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
);
106 e
= snprintf(res
, sizeof(res
), "%s", tst
[i
].str
);
108 e
= snprintf(res
, sizeof(res
), "%s:%zu", tst
[i
].str
, i
);
110 ATF_REQUIRE_STREQ(buf
, res
);
111 ATF_REQUIRE_EQ(r
, e
);
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
);
120 e
= snprintf(res
, l
, "%s", tst
[i
].str
);
122 e
= snprintf(res
, l
, "%s:%zu", tst
[i
].str
, i
);
124 ATF_REQUIRE_STREQ(buf
, res
);
125 ATF_REQUIRE_EQ(r
, e
);
132 ATF_TP_ADD_TC(tp
, at_print
);
133 ATF_TP_ADD_TC(tp
, sat_print
);
134 return atf_no_error();