From: Michihiro NAKAJIMA Date: Sun, 29 Jun 2014 07:12:34 +0000 (+0900) Subject: Add a test utility function, copy_reference_file simply coping X-Git-Tag: v3.1.900a~274 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41c37ee3fc771e69e9c2e5e6b6df33b47d239a46;p=thirdparty%2Flibarchive.git Add a test utility function, copy_reference_file simply coping a sample file to the current directory of a running test. A uudecode filter test will use it for its new test. TODO: make a symbolic link file insted of copying a sample file. Historically, libarchive cannot handle uuencoded files when libarchive's test suit was made. Now libarchive can handle it directly by uudecode filter, I think, we can reduce copying sample files to the directory test program expects they are on an isolated directory for their test. --- diff --git a/cat/test/main.c b/cat/test/main.c index d96a64a28..649e00992 100644 --- a/cat/test/main.c +++ b/cat/test/main.c @@ -2203,6 +2203,29 @@ extract_reference_file(const char *name) fclose(in); } +void +copy_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + size_t rbytes; + + sprintf(buff, "%s/%s", refdir, name); + in = fopen(buff, "rb"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { + fwrite(buff, 1, rbytes, out); + } + fclose(out); + fclose(in); +} + int is_LargeInode(const char *file) { diff --git a/cat/test/test.h b/cat/test/test.h index 743321954..fa3e9c57e 100644 --- a/cat/test/test.h +++ b/cat/test/test.h @@ -305,6 +305,8 @@ char *slurpfile(size_t *, const char *fmt, ...); /* Extracts named reference file to the current directory. */ void extract_reference_file(const char *); +/* Copies named reference file to the current directory. */ +void copy_reference_file(const char *); /* Path to working directory for current test */ extern const char *testworkdir; diff --git a/cpio/test/main.c b/cpio/test/main.c index 92f216333..2b5ab0cc8 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -2203,6 +2203,29 @@ extract_reference_file(const char *name) fclose(in); } +void +copy_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + size_t rbytes; + + sprintf(buff, "%s/%s", refdir, name); + in = fopen(buff, "rb"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { + fwrite(buff, 1, rbytes, out); + } + fclose(out); + fclose(in); +} + int is_LargeInode(const char *file) { diff --git a/cpio/test/test.h b/cpio/test/test.h index 41ab019b2..d645cad86 100644 --- a/cpio/test/test.h +++ b/cpio/test/test.h @@ -303,6 +303,8 @@ char *slurpfile(size_t *, const char *fmt, ...); /* Extracts named reference file to the current directory. */ void extract_reference_file(const char *); +/* Copies named reference file to the current directory. */ +void copy_reference_file(const char *); /* Path to working directory for current test */ extern const char *testworkdir; diff --git a/libarchive/test/main.c b/libarchive/test/main.c index d21640ee5..28afb9d6e 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -2231,6 +2231,29 @@ extract_reference_file(const char *name) fclose(in); } +void +copy_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + size_t rbytes; + + sprintf(buff, "%s/%s", refdir, name); + in = fopen(buff, "rb"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { + fwrite(buff, 1, rbytes, out); + } + fclose(out); + fclose(in); +} + int is_LargeInode(const char *file) { diff --git a/libarchive/test/test.h b/libarchive/test/test.h index 105001c7c..aa1df32f1 100644 --- a/libarchive/test/test.h +++ b/libarchive/test/test.h @@ -308,6 +308,8 @@ void dumpfile(const char *filename, void *, size_t); /* Extracts named reference file to the current directory. */ void extract_reference_file(const char *); +/* Copies named reference file to the current directory. */ +void copy_reference_file(const char *); /* Extracts a list of files to the current directory. * List must be NULL terminated. diff --git a/tar/test/main.c b/tar/test/main.c index 9efdf51f9..455921ba2 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -2204,6 +2204,29 @@ extract_reference_file(const char *name) fclose(in); } +void +copy_reference_file(const char *name) +{ + char buff[1024]; + FILE *in, *out; + size_t rbytes; + + sprintf(buff, "%s/%s", refdir, name); + in = fopen(buff, "rb"); + failure("Couldn't open reference file %s", buff); + assert(in != NULL); + if (in == NULL) + return; + /* Now, decode the rest and write it. */ + /* Not a lot of error checking here; the input better be right. */ + out = fopen(name, "wb"); + while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) { + fwrite(buff, 1, rbytes, out); + } + fclose(out); + fclose(in); +} + int is_LargeInode(const char *file) { diff --git a/tar/test/test.h b/tar/test/test.h index 743321954..fa3e9c57e 100644 --- a/tar/test/test.h +++ b/tar/test/test.h @@ -305,6 +305,8 @@ char *slurpfile(size_t *, const char *fmt, ...); /* Extracts named reference file to the current directory. */ void extract_reference_file(const char *); +/* Copies named reference file to the current directory. */ +void copy_reference_file(const char *); /* Path to working directory for current test */ extern const char *testworkdir;