/ tests / lib / metalog.c
metalog.c
 1  /*-
 2   * Copyright (c) 2022 Baptiste Daroussin <bapt@FreeBSD.org>
 3   *~
 4   * Redistribution and use in source and binary forms, with or without
 5   * modification, are permitted provided that the following conditions
 6   * are met:
 7   * 1. Redistributions of source code must retain the above copyright
 8   *    notice, this list of conditions and the following disclaimer
 9   *    in this position and unchanged.
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13   *~
14   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17   * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24   */
25  
26  #include <atf-c.h>
27  #include <err.h>
28  #include <private/pkg.h>
29  #include <pkg_config.h>
30  
31  ATF_TC_WITHOUT_HEAD(basics);
32  
33  ATF_TC_BODY(basics, tc) {
34  #ifdef HAVE_FFLAGSTOSTR
35  	const char *file = "./file type=file uname=root gname=wheel mode=644 flags=uchg\n"
36  		"./dir type=dir uname=root gname=wheel mode=644 flags=uchg\n"
37  		"./link type=link uname=root gname=wheel mode=644 link=bla\n";
38  #else
39  	const char *file = "./file type=file uname=root gname=wheel mode=644 flags=\n"
40  		"./dir type=dir uname=root gname=wheel mode=644 flags=\n"
41  		"./link type=link uname=root gname=wheel mode=644 link=bla\n";
42  #endif
43  	ATF_REQUIRE_EQ(EPKG_FATAL, metalog_open("/dev/nope/nope"));
44  	ATF_REQUIRE_EQ(EPKG_FATAL, metalog_add(PKG_METALOG_FILE, "meh", "root", "wheel", 0644, 2, NULL));
45  	ATF_REQUIRE_EQ(EPKG_OK, metalog_open("out"));
46  	ATF_REQUIRE_EQ(EPKG_OK, metalog_add(PKG_METALOG_FILE, "file", "root", "wheel", 0644, 2, NULL));
47  	ATF_REQUIRE_EQ(EPKG_OK, metalog_add(PKG_METALOG_DIR, "dir", "root", "wheel", 0644, 2, NULL));
48  	ATF_REQUIRE_EQ(EPKG_OK, metalog_add(PKG_METALOG_LINK, "link", "root", "wheel", 0644, 0, "bla"));
49  	metalog_close();
50  	if (!atf_utils_compare_file("out", file)) {
51  		atf_utils_cat_file("out", ">");
52  		atf_tc_fail("Invalid file");
53  	}
54  }
55  
56  ATF_TP_ADD_TCS(tp)
57  {
58  	ATF_TP_ADD_TC(tp, basics);
59  
60  	return (atf_no_error());
61  }