mirror of
https://github.com/troglobit/libite.git
synced 2026-11-13 17:01:18 +00:00
Add unit test for fexist()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
267465f3d2
commit
92d81280a9
5 files changed
+25
-32
No files matched your search
@@ -44,36 +44,8 @@ int fexist(char *file)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNITTEST
|
|
||||||
#include "lite.h"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
struct { char *file; int exist; } arr[] = {
|
|
||||||
{ "/etc/passwd", 1 },
|
|
||||||
{ "/etc/kalle", 0 },
|
|
||||||
{ "/sbin/init", 1 },
|
|
||||||
{ "/dev/null", 1 },
|
|
||||||
{ NULL, 0 },
|
|
||||||
};
|
|
||||||
FILE *src, *dst;
|
|
||||||
|
|
||||||
for (i = 0; i < NELEMS(arr); i++) {
|
|
||||||
if (fexist(arr[i].file) != arr[i].exist)
|
|
||||||
err(1, "Failed fexist(%s)", arr[i].file ?: "NULL");
|
|
||||||
else
|
|
||||||
printf("File %-11s %-14s => OK!\n", arr[i].file ?: "NULL",
|
|
||||||
arr[i].exist ? "does exist" : "does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* UNITTEST */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* compile-command: "make V=1 -f fexist.mk"
|
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* c-file-style: "linux"
|
* c-file-style: "linux"
|
||||||
* End:
|
* End:
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
*.log
|
*.log
|
||||||
*.trs
|
*.trs
|
||||||
|
fexist
|
||||||
fisdir
|
fisdir
|
||||||
fsendfile
|
fsendfile
|
||||||
lfile
|
lfile
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ EXTRA_DIST = check.h
|
|||||||
CLEANFILES = *~ *.trs *.log
|
CLEANFILES = *~ *.trs *.log
|
||||||
|
|
||||||
TESTS =
|
TESTS =
|
||||||
|
TESTS += fexist
|
||||||
TESTS += fisdir
|
TESTS += fisdir
|
||||||
TESTS += fsendfile
|
TESTS += fsendfile
|
||||||
TESTS += lfile
|
TESTS += lfile
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include "check.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
struct { char *file; int exist; } arr[] = {
|
||||||
|
{ "/etc/passwd", 1 },
|
||||||
|
{ "/etc/kalle", 0 },
|
||||||
|
{ "/sbin/init", 1 },
|
||||||
|
{ "/dev/null", 1 },
|
||||||
|
{ NULL, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i = 0; i < NELEMS(arr); i++) {
|
||||||
|
if (fexist(arr[i].file) != arr[i].exist)
|
||||||
|
err(1, "Failed fexist(%s)", arr[i].file ?: "NULL");
|
||||||
|
else
|
||||||
|
printf("File %-11s %-14s => OK!\n", arr[i].file ?: "NULL",
|
||||||
|
arr[i].exist ? "does exist" : "does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user