summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Kientzle <kientzle@gmail.com>2010-04-10 17:02:55 -0400
committerTim Kientzle <kientzle@gmail.com>2010-04-10 17:02:55 -0400
commit055b725a714af21024387c4bd6d3a5f3e6ce9809 (patch)
treec1c23bb9732bb3ec35deb155cdfe24bb57323b82
parent0c3bfcb5e264846c8c9fe3e8ef5318134a1fd22d (diff)
downloadlibarchive-055b725a714af21024387c4bd6d3a5f3e6ce9809.tar.gz
Test cleanup:
* Use assertMakeFile() instead of fopen/fwrite/fclose * Remove -s tests from test_option_T_upper; they just duplicate tests in test_option_s SVN-Revision: 2221
-rw-r--r--tar/test/test_option_T_upper.c54
-rw-r--r--tar/test/test_option_q.c26
-rw-r--r--tar/test/test_option_r.c21
-rw-r--r--tar/test/test_strip_components.c14
-rw-r--r--tar/test/test_symlink_dir.c34
5 files changed, 31 insertions, 118 deletions
diff --git a/tar/test/test_option_T_upper.c b/tar/test/test_option_T_upper.c
index 94cd8cca..f2b65d7b 100644
--- a/tar/test/test_option_T_upper.c
+++ b/tar/test/test_option_T_upper.c
@@ -26,41 +26,33 @@
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $");
static int
-touch(const char *fn, int fail)
+tryMakeFile(const char *fn)
{
FILE *f = fopen(fn, "w");
- if (fail) {
- failure("Couldn't create file '%s', errno=%d (%s)\n",
- fn, errno, strerror(errno));
- if (!assert(f != NULL))
- return (0); /* Failure. */
- } else {
- if (f == NULL)
- return (0); /* Soft failure. */
- }
+ if (f == NULL)
+ return (0);
fclose(f);
- return (1); /* Success */
+ return (1);
}
DEFINE_TEST(test_option_T_upper)
{
FILE *f;
int r;
- struct stat st;
int gnarlyFilesSupported;
/* Create a simple dir hierarchy; bail if anything fails. */
if (!assertMakeDir("d1", 0755)) return;
if (!assertMakeDir("d1/d2", 0755)) return;
- if (!touch("f", 1)) return;
- if (!touch("d1/f1", 1)) return;
- if (!touch("d1/f2", 1)) return;
- if (!touch("d1/d2/f3", 1)) return;
- if (!touch("d1/d2/f4", 1)) return;
- if (!touch("d1/d2/f5", 1)) return;
- if (!touch("d1/d2/f6", 1)) return;
+ if (!assertMakeFile("f", 0644, "")) return;
+ if (!assertMakeFile("d1/f1", 0644, "")) return;
+ if (!assertMakeFile("d1/f2", 0644, "")) return;
+ if (!assertMakeFile("d1/d2/f3", 0644, "")) return;
+ if (!assertMakeFile("d1/d2/f4", 0644, "")) return;
+ if (!assertMakeFile("d1/d2/f5", 0644, "")) return;
+ if (!assertMakeFile("d1/d2/f6", 0644, "")) return;
/* Some platforms don't permit such things; just skip it. */
- gnarlyFilesSupported = touch("d1/d2/f\x0a", 0);
+ gnarlyFilesSupported = tryMakeFile("d1/d2/f\x0a");
/* Populate a file list */
f = fopen("filelist", "w+");
@@ -160,28 +152,8 @@ DEFINE_TEST(test_option_T_upper)
assertMakeDir("test4_out", 0755);
assertMakeDir("test4_out2", 0755);
assertMakeDir("test4/d1", 0755);
- assertEqualInt(1, touch("test4/d1/foo", 0));
+ assertMakeFile("test4/d1/foo", 0644, "");
- /* Does bsdtar support -s option ? */
- systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err",
- testprog);
- assertEqualInt(0, stat("check.err", &st));
- if (st.st_size == 0) {
- systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out",
- testprog, testprog);
- assertEmptyFile("test4_out/test4/d1/bar");
- systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out",
- testprog, testprog);
- assertEmptyFile("test4_out/test4/d2/foo");
- systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst",
- testprog, testprog);
- assertEmptyFile("test4.lst");
- systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2",
- testprog, testprog);
- assertEmptyFile("test4_out2/test4/d1/bar");
- } else {
- skipping("bsdtar does not support -s option on this platform");
- }
/* TODO: Include some use of -C directory-changing within the filelist. */
/* I'm pretty sure -C within the filelist is broken on extract. */
diff --git a/tar/test/test_option_q.c b/tar/test/test_option_q.c
index 68867b52..287e67af 100644
--- a/tar/test/test_option_q.c
+++ b/tar/test/test_option_q.c
@@ -27,7 +27,6 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:
DEFINE_TEST(test_option_q)
{
- FILE *f;
int r;
/*
@@ -40,38 +39,23 @@ DEFINE_TEST(test_option_q)
* what we use to build up the test archive.
*/
- f = fopen("foo", "w");
- assert(f != NULL);
- fprintf(f, "foo1");
- fclose(f);
+ assertMakeFile("foo", 0644, "foo1");
assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog));
- f = fopen("foo", "w");
- assert(f != NULL);
- fprintf(f, "foo2");
- fclose(f);
+ assertMakeFile("foo", 0644, "foo2");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
- f = fopen("bar", "w");
- assert(f != NULL);
- fprintf(f, "bar1");
- fclose(f);
+ assertMakeFile("bar", 0644, "bar1");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
- f = fopen("foo", "w");
- assert(f != NULL);
- fprintf(f, "foo3");
- fclose(f);
+ assertMakeFile("foo", 0644, "foo3");
assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog));
- f = fopen("bar", "w");
- assert(f != NULL);
- fprintf(f, "bar2");
- fclose(f);
+ assertMakeFile("bar", 0644, "bar2");
assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog));
diff --git a/tar/test/test_option_r.c b/tar/test/test_option_r.c
index 516a8307..2bfcacea 100644
--- a/tar/test/test_option_r.c
+++ b/tar/test/test_option_r.c
@@ -30,18 +30,12 @@ __FBSDID("$FreeBSD$");
*/
DEFINE_TEST(test_option_r)
{
- char buff[15];
char *p0, *p1;
size_t s;
- FILE *f;
int r;
/* Create a file */
- f = fopen("f1", "w");
- if (!assert(f != NULL))
- return;
- assertEqualInt(3, fwrite("abc", 1, 3, f));
- fclose(f);
+ assertMakeFile("f1", 0644, "abc");
/* Archive that one file. */
r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog);
@@ -67,11 +61,7 @@ DEFINE_TEST(test_option_r)
assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8);
/* Edit that file */
- f = fopen("f1", "w");
- if (!assert(f != NULL))
- return;
- assertEqualInt(3, fwrite("123", 1, 3, f));
- fclose(f);
+ assertMakeFile("f1", 0644, "123");
/* Update the archive. */
r = systemf("%s rf archive.tar --format=ustar f1 >step2.out 2>step2.err", testprog);
@@ -108,10 +98,5 @@ DEFINE_TEST(test_option_r)
assertEqualInt(r, 0);
/* Verify that the second one overwrote the first. */
- f = fopen("f1", "r");
- if (assert(f != NULL)) {
- assertEqualInt(3, fread(buff, 1, 3, f));
- assertEqualMem(buff, "123", 3);
- fclose(f);
- }
+ assertFileContents("123", 3, "f1");
}
diff --git a/tar/test/test_strip_components.c b/tar/test/test_strip_components.c
index c9028a4d..2db07d61 100644
--- a/tar/test/test_strip_components.c
+++ b/tar/test/test_strip_components.c
@@ -25,18 +25,6 @@
#include "test.h"
__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $");
-static int
-touch(const char *fn)
-{
- FILE *f = fopen(fn, "w");
- failure("Couldn't create file '%s', errno=%d (%s)\n",
- fn, errno, strerror(errno));
- if (!assert(f != NULL))
- return (0); /* Failure. */
- fclose(f);
- return (1); /* Success */
-}
-
DEFINE_TEST(test_strip_components)
{
assertMakeDir("d0", 0755);
@@ -44,7 +32,7 @@ DEFINE_TEST(test_strip_components)
assertMakeDir("d1", 0755);
assertMakeDir("d1/d2", 0755);
assertMakeDir("d1/d2/d3", 0755);
- assertEqualInt(1, touch("d1/d2/f1"));
+ assertMakeFile("d1/d2/f1", 0644, "");
assertMakeHardlink("l1", "d1/d2/f1");
assertMakeHardlink("d1/l2", "d1/d2/f1");
if (canSymlink()) {
diff --git a/tar/test/test_symlink_dir.c b/tar/test/test_symlink_dir.c
index aa80ba68..f6e99662 100644
--- a/tar/test/test_symlink_dir.c
+++ b/tar/test/test_symlink_dir.c
@@ -31,38 +31,22 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:
* way of a dir extraction.
*/
-static int
-mkfile(const char *name, int mode, const char *contents, size_t size)
-{
- FILE *f = fopen(name, "wb");
- size_t written;
-
- (void)mode; /* UNUSED */
- if (f == NULL)
- return (-1);
- written = fwrite(contents, 1, size, f);
- fclose(f);
- if (size != written)
- return (-1);
- return (0);
-}
-
DEFINE_TEST(test_symlink_dir)
{
assertUmask(0);
assertMakeDir("source", 0755);
- assertEqualInt(0, mkfile("source/file", 0755, "a", 1));
- assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2));
+ assertMakeFile("source/file", 0755, "a");
+ assertMakeFile("source/file2", 0755, "ab");
assertMakeDir("source/dir", 0755);
assertMakeDir("source/dir/d", 0755);
- assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3));
+ assertMakeFile("source/dir/f", 0755, "abc");
assertMakeDir("source/dir2", 0755);
assertMakeDir("source/dir2/d2", 0755);
- assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4));
+ assertMakeFile("source/dir2/f2", 0755, "abcd");
assertMakeDir("source/dir3", 0755);
assertMakeDir("source/dir3/d3", 0755);
- assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5));
+ assertMakeFile("source/dir3/f3", 0755, "abcde");
assertEqualInt(0,
systemf("%s -cf test.tar -C source dir dir2 dir3 file file2",
@@ -82,11 +66,11 @@ DEFINE_TEST(test_symlink_dir)
skipping("some symlink checks");
}
/* "dir3" is a symlink to an existing "non_dir3" */
- assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6));
+ assertMakeFile("dest1/non_dir3", 0755, "abcdef");
if (canSymlink())
assertMakeSymlink("dest1/dir3", "non_dir3");
/* "file" is a symlink to existing "real_file" */
- assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7));
+ assertMakeFile("dest1/real_file", 0755, "abcdefg");
if (canSymlink()) {
assertMakeSymlink("dest1/file", "real_file");
/* "file2" is a symlink to non-existing "real_file2" */
@@ -122,11 +106,11 @@ DEFINE_TEST(test_symlink_dir)
if (canSymlink())
assertMakeSymlink("dest2/dir2", "real_dir2");
/* "dir3" is a symlink to an existing "non_dir3" */
- assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8));
+ assertMakeFile("dest2/non_dir3", 0755, "abcdefgh");
if (canSymlink())
assertMakeSymlink("dest2/dir3", "non_dir3");
/* "file" is a symlink to existing "real_file" */
- assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9));
+ assertMakeFile("dest2/real_file", 0755, "abcdefghi");
if (canSymlink())
assertMakeSymlink("dest2/file", "real_file");
/* "file2" is a symlink to non-existing "real_file2" */