mirror of
https://github.com/troglobit/libite.git
synced 2026-10-21 11:19:38 +00:00
test: slight refactor to add diff -q A B check to fcopyfile()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
97cb2cb87c
commit
e44aaa4fd5
1 file changed
+27
-12
+27
-12
@@ -2,6 +2,9 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
#define ERR(fmt, args...) { printf(fmt, ##args); rc = 1; }
|
||||||
|
#define ERRX(fmt, args...) { printf(fmt, ##args); rc = 1; }
|
||||||
|
|
||||||
static int sz()
|
static int sz()
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@@ -34,34 +37,47 @@ int main(void)
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
FILE *src, *dst;
|
FILE *src, *dst;
|
||||||
int i = 0;
|
int rc, i;
|
||||||
|
|
||||||
printf("=>Start testing fcopyfile()\n");
|
printf("=>Start testing fcopyfile()\n");
|
||||||
while (files[i]) {
|
for (i = 0; files[i]; i += 3) {
|
||||||
printf("fcopyfile(%s, %s)\t", files[i], files[i + 1]);
|
printf("fcopyfile(%s, %s)\t", files[i], files[i + 1]);
|
||||||
src = fopen(files[i], "r");
|
src = fopen(files[i], "r");
|
||||||
dst = fopen(files[i + 1], "w");
|
dst = fopen(files[i + 1], "w");
|
||||||
if (fcopyfile(src, dst)) {
|
|
||||||
if (!fisdir(files[i + 1]))
|
rc = fcopyfile(src, dst);
|
||||||
err(1, "Failed fcopyfile(%s, %s)", files[i], files[i + 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (src)
|
if (src)
|
||||||
fclose(src);
|
fclose(src);
|
||||||
if (dst)
|
if (dst)
|
||||||
fclose(dst);
|
fclose(dst);
|
||||||
|
|
||||||
if (fexist(files[i + 2]))
|
if (rc) {
|
||||||
printf("OK => %s", files[i + 2]);
|
if (!fisdir(files[i + 1]))
|
||||||
|
err(1, "Failed fcopyfile(%s, %s)", files[i], files[i + 1]);
|
||||||
|
|
||||||
|
/* Expected to fail, user tried to copy to fp=NULL due to dir */
|
||||||
|
printf("OK\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fexist(files[i + 2])) {
|
||||||
|
if (systemf("diff -q %s %s", files[i], files[i + 2])) {
|
||||||
|
ERRX("src and dst differ");
|
||||||
|
} else
|
||||||
|
printf("OK => %s", files[i + 2]);
|
||||||
|
} else
|
||||||
|
ERR("cannot find %s", files[i + 2]);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
erase(files[i + 2]);
|
erase(files[i + 2]);
|
||||||
i += 3;
|
|
||||||
|
if (rc)
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n=>Start testing copyfile()\n");
|
printf("\n=>Start testing copyfile()\n");
|
||||||
i = 0;
|
for (i = 0; files[i]; i += 3) {
|
||||||
while (files[i]) {
|
|
||||||
printf("copyfile(%s, %s)\t", files[i], files[i + 1]);
|
printf("copyfile(%s, %s)\t", files[i], files[i + 1]);
|
||||||
if (!copyfile(files[i], files[i + 1], 0, 0))
|
if (!copyfile(files[i], files[i + 1], 0, 0))
|
||||||
err(1, "Failed copyfile(%s, %s)", files[i], files[i + 1]);
|
err(1, "Failed copyfile(%s, %s)", files[i], files[i + 1]);
|
||||||
@@ -71,7 +87,6 @@ int main(void)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
erase(files[i + 2]);
|
erase(files[i + 2]);
|
||||||
i += 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sz();
|
return sz();
|
||||||
|
|||||||
Reference in new issue
Block a user