msg[0] = '\0';
return (value);
}
- failures ++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (value);
fprintf(stderr, "%s:%d: Assertion failed\n", file, line);
msg[0] = '\0';
return (1);
}
- failures ++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Ints not equal\n",
msg[0] = '\0';
return (1);
}
- failures ++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Strings not equal\n",
msg[0] = '\0';
return (1);
}
- failures ++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: Unicode strings not equal\n",
msg[0] = '\0';
return (1);
}
- failures ++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (0);
fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n",
if (st.st_size == 0)
return (1);
- failures ++;
+ ++failures;
if (!verbose && previous_failures(test_filename, test_line, 1))
return (0);
fprintf(stderr, "%s:%d: Could not stat: %s\n",
test_filename, test_line, f1);
report_failure(NULL);
- failures++;
+ ++failures;
return (0);
}
if (st.st_size != 0)
return (1);
- failures ++;
+ ++failures;
if (!verbose && previous_failures(test_filename, test_line, 1))
return (0);
}
fclose(f1);
fclose(f2);
- failures ++;
+ ++failures;
if (!verbose && previous_failures(test_filename, test_line, 1))
return (0);
fprintf(stderr, "%s:%d: Files are not identical\n",
char f[1024];
va_list ap;
+ count_assertion(test_filename, test_line);
va_start(ap, fpattern);
vsprintf(f, fpattern, ap);
va_end(ap);
if (!access(f, F_OK))
return (1);
#endif
+ ++failures;
if (!previous_failures(test_filename, test_line, 1)) {
fprintf(stderr, "%s:%d: File doesn't exist\n",
test_filename, test_line);
char f[1024];
va_list ap;
+ count_assertion(test_filename, test_line);
va_start(ap, fpattern);
vsprintf(f, fpattern, ap);
va_end(ap);
if (access(f, F_OK))
return (1);
#endif
+ ++failures;
if (!previous_failures(test_filename, test_line, 1)) {
fprintf(stderr, "%s:%d: File exists and shouldn't\n",
test_filename, test_line);
FILE *f;
int n;
+ count_assertion(test_filename, test_line);
va_start(ap, fpattern);
vsprintf(fn, fpattern, ap);
va_end(ap);
f = fopen(fn, "rb");
if (f == NULL) {
- failures ++;
+ ++failures;
if (!previous_failures(test_filename, test_line, 1)) {
fprintf(stderr, "%s:%d: File doesn't exist: %s\n",
test_filename, test_line, fn);
free(contents);
return (1);
}
- failures ++;
+ ++failures;
if (!previous_failures(test_filename, test_line, 1)) {
fprintf(stderr, "%s:%d: File contents don't match\n",
test_filename, test_line);
FILE *f;
int n, s;
+ count_assertion(test_filename, test_line);
f = fopen(fn, "r");
s = strlen(buff);
contents = malloc(s * 2 + 128);
free(contents);
return (1);
}
- failures ++;
+ ++failures;
if (!previous_failures(test_filename, test_line, 1)) {
fprintf(stderr, "%s:%d: File contents don't match\n",
test_filename, test_line);
struct stat st1, st2;
int r;
+ count_assertion(file, line);
r = lstat(path1, &st1);
if (r != 0) {
+ ++failures;
if (!previous_failures(file, line, 1))
fprintf(stderr, "%s:%d: File ``%s'' should exist\n",
file, line, path1);
}
r = lstat(path2, &st2);
if (r != 0) {
+ ++failures;
if (!previous_failures(file, line, 1))
fprintf(stderr, "%s:%d: File ``%s'' should exist\n",
file, line, path2);
return (0);
}
if (st1.st_ino != st2.st_ino || st1.st_dev != st2.st_dev) {
+ ++failures;
if (!previous_failures(file, line, 1)) {
fprintf(stderr,
"%s:%d: Files ``%s'' and ``%s'' are not hardlinked\n",
}
int
-test_assert_file_nlinks(const char *file, int line, const char *pathname, int nlinks)
+test_assert_file_nlinks(const char *file, int line,
+ const char *pathname, int nlinks)
{
struct stat st;
int r;
+ count_assertion(file, line);
r = lstat(pathname, &st);
if (r == 0 && st.st_nlink == nlinks)
return (1);
+ ++failures;
if (!previous_failures(file, line, 1)) {
fprintf(stderr, "%s:%d: File ``%s'' has %d links, expected %d\n",
file, line, pathname, st.st_nlink, nlinks);
}
int
-test_assert_file_size(const char *file, int line, const char *pathname, long size)
+test_assert_file_size(const char *file, int line,
+ const char *pathname, long size)
{
struct stat st;
int r;
+ count_assertion(file, line);
r = lstat(pathname, &st);
if (r == 0 && st.st_size == size)
return (1);
+ ++failures;
if (!previous_failures(file, line, 1)) {
fprintf(stderr, "%s:%d: File ``%s'' has size %ld, expected %ld\n",
- file, line, pathname, st.st_size, size);
+ file, line, pathname, (long)st.st_size, (long)size);
report_failure(NULL);
}
return (0);
struct stat st;
int r;
+ count_assertion(file, line);
r = lstat(pathname, &st);
- if (r == 0 && S_ISDIR(st.st_mode))
- return (1);
- if (!previous_failures(test_filename, test_line, 1)) {
- fprintf(stderr, "%s:%d: Dir ``%s'' doesn't exist\n",
- test_filename, test_line, pathname);
- report_failure(NULL);
+ if (r != 0 || !S_ISDIR(st.st_mode)) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: Dir ``%s'' doesn't exist\n",
+ file, line, pathname);
+ report_failure(NULL);
+ }
+ return (0);
}
- return (0);
+ if (mode < 0)
+ return (1);
+ if (mode != (st.st_mode & 07777)) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: Dir ``%s'' has wrong mode\n",
+ file, line, pathname);
+ fprintf(stderr, " Expected: 0%3o\n", mode);
+ fprintf(stderr, " Found: 0%3o\n", st.st_mode & 07777);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ return (1);
+}
+
+int
+test_assert_is_link(const char *file, int line,
+ const char *pathname, const char *contents)
+{
+ char buff[300];
+ struct stat st;
+ ssize_t linklen;
+ int r;
+
+ count_assertion(file, line);
+ r = lstat(pathname, &st);
+ if (r != 0) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: Symlink ``%s'' doesn't exist\n",
+ file, line, pathname);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ if (!S_ISLNK(st.st_mode)) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: ``%s'' should be a symlink\n",
+ file, line, pathname);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ if (contents == NULL)
+ return (1);
+ linklen = readlink(pathname, buff, sizeof(buff));
+ if (linklen < 0) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: symlink ``%s'' can't be read\n",
+ file, line, pathname);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ buff[linklen] = '\0';
+ if (strcmp(buff, contents) != 0) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: Wrong symlink ``%s''\n",
+ file, line, pathname);
+ fprintf(stderr, " Expected: %s\n", contents);
+ fprintf(stderr, " Found: %s\n", buff);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ return (1);
}
int
struct stat st;
int r;
+ count_assertion(file, line);
r = lstat(pathname, &st);
- if (r == 0 && S_ISREG(st.st_mode))
- return (1);
- if (!previous_failures(test_filename, test_line, 1)) {
- fprintf(stderr, "%s:%d: File ``%s'' doesn't exist\n",
- test_filename, test_line, pathname);
- report_failure(NULL);
+ if (r != 0 || !S_ISREG(st.st_mode)) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: File ``%s'' doesn't exist\n",
+ file, line, pathname);
+ report_failure(NULL);
+ }
+ return (0);
}
- return (0);
+ if (mode < 0)
+ return (1);
+ if (mode != (st.st_mode & 07777)) {
+ ++failures;
+ if (!previous_failures(file, line, 1)) {
+ fprintf(stderr, "%s:%d: Dir ``%s'' has wrong mode\n",
+ file, line, pathname);
+ fprintf(stderr, " Expected: 0%3o\n", mode);
+ fprintf(stderr, " Found: 0%3o\n", st.st_mode & 07777);
+ report_failure(NULL);
+ }
+ return (0);
+ }
+ return (1);
}
int
msg[0] = '\0';
return (1);
}
- failures++;
+ ++failures;
if (!verbose && previous_failures(file, line, 1))
return (0);
fprintf(stderr, "%s:%d: Could not create directory\n",
{
int succeeded;
+ count_assertion(file, line);
#if defined(_WIN32) && !defined(__CYGWIN__)
succeeded = CreateHardLink(newpath, linkto, NULL);
#else
msg[0] = '\0';
return (1);
}
- failures++;
+ ++failures;
if (verbose || !previous_failures(file, line, 1)) {
fprintf(stderr, "%s:%d: Could not create new hardlink\n",
file, line);
{
int succeeded;
+ count_assertion(file, line);
#if defined(_WIN32) && !defined(__CYGWIN__)
int targetIsDir = 0; /* TODO: Fix this. */
succeeded = CreateSymbolicLink(newpath, linkto, targetIsDir);
msg[0] = '\0';
return (1);
}
- failures++;
+ ++failures;
if (verbose || !previous_failures(file, line, 1)) {
fprintf(stderr, "%s:%d: Could not create new symlink\n",
file, line);
int
test_assert_umask(const char *file, int line, int mask)
{
+ count_assertion(file, line);
+ (void)file; /* UNUSED */
+ (void)line; /* UNUSED */
umask(mask);
return (1);
}
#define assertFileHardlinks(path1, path2) \
test_assert_file_hardlinks(__FILE__, __LINE__, path1, path2)
#define assertFileNLinks(pathname, nlinks) \
- test_assert_file_size(__FILE__, __LINE__, pathname, nlinks)
+ test_assert_file_nlinks(__FILE__, __LINE__, pathname, nlinks)
#define assertFileSize(pathname, size) \
test_assert_file_size(__FILE__, __LINE__, pathname, size)
#define assertTextFileContents \
test_setup(__FILE__, __LINE__);test_assert_text_file_contents
#define assertIsDir(pathname, mode) \
test_assert_is_dir(__FILE__, __LINE__, pathname, mode)
+#define assertIsLink(pathname, contents) \
+ test_assert_is_link(__FILE__, __LINE__, pathname, contents)
#define assertIsReg(pathname, mode) \
test_assert_is_reg(__FILE__, __LINE__, pathname, mode)
/* Create a directory, report error if it fails. */
int test_assert_file_nlinks(const char *, int, const char *, int);
int test_assert_file_size(const char *, int, const char *, long);
int test_assert_is_dir(const char *, int, const char *, int);
+int test_assert_is_link(const char *, int, const char *, const char *);
int test_assert_is_reg(const char *, int, const char *, int);
int test_assert_make_dir(const char *, int, const char *, int);
int test_assert_make_hardlink(const char *, int, const char *newpath, const char *);