1 /*
2  * libdpkg - Debian packaging suite library routines
3  * t-ar.c - test ar implementation
4  *
5  * Copyright © 2010 Guillem Jover <guillem@debian.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include <config.h>
22 #include <compat.h>
23 
24 #include <string.h>
25 
26 #include <dpkg/test.h>
27 #include <dpkg/ar.h>
28 
29 static void
test_ar_normalize_name(void)30 test_ar_normalize_name(void)
31 {
32 	struct dpkg_ar_hdr arh;
33 
34 	memccpy(arh.ar_name, "member-name/    ", '\0', sizeof(arh.ar_name));
35 	dpkg_ar_normalize_name(&arh);
36 	test_str(arh.ar_name, ==, "member-name");
37 
38 	memccpy(arh.ar_name, "member-name     ", '\0', sizeof(arh.ar_name));
39 	dpkg_ar_normalize_name(&arh);
40 	test_str(arh.ar_name, ==, "member-name");
41 }
42 
43 static void
test_ar_member_is_illegal(void)44 test_ar_member_is_illegal(void)
45 {
46 	struct dpkg_ar_hdr arh;
47 
48 	memset(&arh, ' ', sizeof(arh));
49 	test_pass(dpkg_ar_member_is_illegal(&arh));
50 
51 	memcpy(arh.ar_fmag, DPKG_AR_FMAG, sizeof(arh.ar_fmag));
52 	test_fail(dpkg_ar_member_is_illegal(&arh));
53 }
54 
TEST_ENTRY(test)55 TEST_ENTRY(test)
56 {
57 	test_plan(4);
58 
59 	test_ar_normalize_name();
60 	test_ar_member_is_illegal();
61 }
62