mirror of
https://github.com/troglobit/libite.git
synced 2026-12-04 21:48:22 +00:00
Add unit test for fsendfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
6fdffeb355
commit
69291d3e74
5 files changed
+33
-38
No files matched your search
-34
@@ -77,42 +77,8 @@ ssize_t fsendfile(FILE *src, FILE *dst, size_t len)
|
|||||||
return (num == -1) ? -1 : (ssize_t)tot;
|
return (num == -1) ? -1 : (ssize_t)tot;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNITTEST
|
|
||||||
#include <err.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
char *files[] = {
|
|
||||||
"/etc/passwd", "/tmp/tok",
|
|
||||||
"/etc/passwd", "/tmp/passwd",
|
|
||||||
"/etc/passwd", "/tmp/passwd",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
FILE *src, *dst;
|
|
||||||
|
|
||||||
while (files[i]) {
|
|
||||||
src = fopen(files[i], "r");
|
|
||||||
dst = fopen(files[i + 1], "w");
|
|
||||||
printf("fsendfile(%s, %s, 512)\t", files[i], files[i + 1]);
|
|
||||||
if (-1 == fsendfile(src, dst, 512))
|
|
||||||
err(1, "Failed fsendfile(%s, %s)", files[i], files[i + 1]);
|
|
||||||
|
|
||||||
if (!access(files[i + 1], F_OK))
|
|
||||||
printf("OK => %s\n", files[i + 1]);
|
|
||||||
|
|
||||||
remove(files[i + 1]);
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* UNITTEST */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* compile-command: "make V=1 -f fsendfile.mk"
|
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* c-file-style: "linux"
|
* c-file-style: "linux"
|
||||||
* End:
|
* End:
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
OBJS =
|
|
||||||
TARGET = fsendfile.test clean
|
|
||||||
|
|
||||||
include rules.mk
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
*.log
|
*.log
|
||||||
*.trs
|
*.trs
|
||||||
|
fsendfile
|
||||||
lfile
|
lfile
|
||||||
makepath
|
makepath
|
||||||
pidfile
|
pidfile
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ EXTRA_DIST = check.h
|
|||||||
CLEANFILES = *~ *.trs *.log
|
CLEANFILES = *~ *.trs *.log
|
||||||
|
|
||||||
TESTS =
|
TESTS =
|
||||||
|
TESTS += fsendfile
|
||||||
TESTS += lfile
|
TESTS += lfile
|
||||||
TESTS += makepath
|
TESTS += makepath
|
||||||
TESTS += pidfile
|
TESTS += pidfile
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include <err.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
char *files[] = {
|
||||||
|
"/etc/passwd", "/tmp/tok",
|
||||||
|
"/etc/passwd", "/tmp/passwd",
|
||||||
|
"/etc/passwd", "/tmp/passwd",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
FILE *src, *dst;
|
||||||
|
|
||||||
|
while (files[i]) {
|
||||||
|
src = fopen(files[i], "r");
|
||||||
|
dst = fopen(files[i + 1], "w");
|
||||||
|
printf("fsendfile(%s, %s, 512)\t", files[i], files[i + 1]);
|
||||||
|
if (-1 == fsendfile(src, dst, 512))
|
||||||
|
err(1, "Failed fsendfile(%s, %s)", files[i], files[i + 1]);
|
||||||
|
|
||||||
|
if (!access(files[i + 1], F_OK))
|
||||||
|
printf("OK => %s\n", files[i + 1]);
|
||||||
|
|
||||||
|
remove(files[i + 1]);
|
||||||
|
i += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user