git-svn: trunk@4289
Török Edvin authored on 2008/10/23 02:27:44... | ... |
@@ -1,3 +1,10 @@ |
1 |
+Wed Oct 22 20:52:37 EEST 2008 (edwin) |
|
2 |
+------------------------------------- |
|
3 |
+ * unit_tests/check_clamav.c, unit_tests/check_disasm.c, |
|
4 |
+ unit_tests/check_jsnorm.c, unit_tests/check_matchers.c, |
|
5 |
+ unit_tests/check_regex.c, unit_tests/check_uniq.c, |
|
6 |
+ unit_tests/checks.h: support building with older versions of check |
|
7 |
+ |
|
1 | 8 |
Wed Oct 22 17:45:11 EEST 2008 (edwin) |
2 | 9 |
------------------------------------- |
3 | 10 |
* configure, m4/acinclude.m4: fix typo in previous commit |
... | ... |
@@ -326,7 +326,7 @@ int open_testfile(const char *name) |
326 | 326 |
sprintf(str, "%s/%s", srcdir, name); |
327 | 327 |
|
328 | 328 |
fd = open(str, O_RDONLY); |
329 |
- fail_unless(fd >= 0, "open() failed: %s", str); |
|
329 |
+ fail_unless_fmt(fd >= 0, "open() failed: %s", str); |
|
330 | 330 |
free(str); |
331 | 331 |
return fd; |
332 | 332 |
} |
... | ... |
@@ -337,9 +337,9 @@ void diff_file_mem(int fd, const char *ref, size_t len) |
337 | 337 |
size_t p, reflen = len; |
338 | 338 |
char *buf = cli_malloc(len); |
339 | 339 |
|
340 |
- fail_unless(!!buf, "unable to malloc buffer: %d", len); |
|
340 |
+ fail_unless_fmt(!!buf, "unable to malloc buffer: %d", len); |
|
341 | 341 |
p = read(fd, buf, len); |
342 |
- fail_unless(p == len, "file is smaller: %lu, expected: %lu", p, len); |
|
342 |
+ fail_unless_fmt(p == len, "file is smaller: %lu, expected: %lu", p, len); |
|
343 | 343 |
p = 0; |
344 | 344 |
while(len > 0) { |
345 | 345 |
c1 = ref[p]; |
... | ... |
@@ -350,10 +350,10 @@ void diff_file_mem(int fd, const char *ref, size_t len) |
350 | 350 |
len--; |
351 | 351 |
} |
352 | 352 |
if (len > 0) |
353 |
- fail_unless(c1 == c2, "file contents mismatch at byte: %lu, was: %c, expected: %c", p, c2, c1); |
|
353 |
+ fail_unless_fmt(c1 == c2, "file contents mismatch at byte: %lu, was: %c, expected: %c", p, c2, c1); |
|
354 | 354 |
free(buf); |
355 | 355 |
p = lseek(fd, 0, SEEK_END); |
356 |
- fail_unless(p == reflen, "trailing garbage, file size: %ld, expected: %ld", p, reflen); |
|
356 |
+ fail_unless_fmt(p == reflen, "trailing garbage, file size: %ld, expected: %ld", p, reflen); |
|
357 | 357 |
close(fd); |
358 | 358 |
} |
359 | 359 |
|
... | ... |
@@ -362,14 +362,14 @@ void diff_files(int fd, int ref_fd) |
362 | 362 |
char *ref; |
363 | 363 |
ssize_t nread; |
364 | 364 |
off_t siz = lseek(ref_fd, 0, SEEK_END); |
365 |
- fail_unless(siz != -1, "lseek failed"); |
|
365 |
+ fail_unless_fmt(siz != -1, "lseek failed"); |
|
366 | 366 |
|
367 | 367 |
ref = cli_malloc(siz); |
368 |
- fail_unless(!!ref, "unable to malloc buffer: %d", siz); |
|
368 |
+ fail_unless_fmt(!!ref, "unable to malloc buffer: %d", siz); |
|
369 | 369 |
|
370 |
- fail_unless(lseek(ref_fd, 0, SEEK_SET) == 0,"lseek failed"); |
|
370 |
+ fail_unless_fmt(lseek(ref_fd, 0, SEEK_SET) == 0,"lseek failed"); |
|
371 | 371 |
nread = read(ref_fd, ref, siz); |
372 |
- fail_unless(nread == siz, "short read, expected: %ld, was: %ld", siz, nread); |
|
372 |
+ fail_unless_fmt(nread == siz, "short read, expected: %ld, was: %ld", siz, nread); |
|
373 | 373 |
close(ref_fd); |
374 | 374 |
diff_file_mem(fd, ref, siz); |
375 | 375 |
free(ref); |
... | ... |
@@ -126,10 +126,10 @@ START_TEST (test_disasm_basic) { |
126 | 126 |
fail_unless(fstat(ref, &st)!=-1, "fstat failed"); |
127 | 127 |
disasmbuf(buf, sizeof(buf), fd); |
128 | 128 |
size = lseek(fd, 0, SEEK_CUR); |
129 |
- fail_unless(size==st.st_size, "disasm size mismatch(value %u, expected: %u)", size, st.st_size); |
|
129 |
+ fail_unless_fmt(size==st.st_size, "disasm size mismatch(value %u, expected: %u)", size, st.st_size); |
|
130 | 130 |
lseek(fd, 0, SEEK_SET); |
131 | 131 |
d=malloc(size*2); |
132 |
- fail_unless(d!=NULL, "disasm malloc(%u) failed", size); |
|
132 |
+ fail_unless_fmt(d!=NULL, "disasm malloc(%u) failed", size); |
|
133 | 133 |
fail_unless(read(ref, d, size)==size, "disasm reference read failed"); |
134 | 134 |
fail_unless(read(fd, d+size, size)==size, "disasm read failed"); |
135 | 135 |
close(fd); |
... | ... |
@@ -252,7 +252,7 @@ static void tokenizer_test(const char *in, const char *expected, int split) |
252 | 252 |
fd = open(filename, O_RDONLY); |
253 | 253 |
if(fd < 0) { |
254 | 254 |
jstest_teardown(); |
255 |
- fail("failed to open output file: %s", filename); |
|
255 |
+ fail_fmt("failed to open output file: %s", filename); |
|
256 | 256 |
} |
257 | 257 |
|
258 | 258 |
diff_file_mem(fd, expected, len); |
... | ... |
@@ -77,8 +77,8 @@ START_TEST (test_ac_scanbuff) { |
77 | 77 |
|
78 | 78 |
for(i = 0; ac_testdata[i].data; i++) { |
79 | 79 |
ret = cli_ac_scanbuff(ac_testdata[i].data, strlen(ac_testdata[i].data), &virname, NULL, NULL, root, &mdata, 0, 0, -1, NULL, AC_SCAN_VIR, NULL); |
80 |
- fail_unless(ret == CL_VIRUS, "cli_ac_scanbuff() failed for %s", ac_testdata[i].virname); |
|
81 |
- fail_unless(!strncmp(virname, ac_testdata[i].virname, strlen(ac_testdata[i].virname)), "Dataset %u matched with %s", i, virname); |
|
80 |
+ fail_unless_fmt(ret == CL_VIRUS, "cli_ac_scanbuff() failed for %s", ac_testdata[i].virname); |
|
81 |
+ fail_unless_fmt(!strncmp(virname, ac_testdata[i].virname, strlen(ac_testdata[i].virname)), "Dataset %u matched with %s", i, virname); |
|
82 | 82 |
} |
83 | 83 |
|
84 | 84 |
cli_ac_freedata(&mdata); |
... | ... |
@@ -52,7 +52,7 @@ static int cb_expect_single(void *cbdata, const char *suffix, size_t len, const |
52 | 52 |
{ |
53 | 53 |
const char *expected = cbdata; |
54 | 54 |
cb_called++; |
55 |
- fail_unless(suffix && strcmp(suffix, expected) == 0, |
|
55 |
+ fail_unless_fmt(suffix && strcmp(suffix, expected) == 0, |
|
56 | 56 |
"suffix mismatch, was: %s, expected: %s\n", suffix, expected); |
57 | 57 |
return 0; |
58 | 58 |
} |
... | ... |
@@ -107,11 +107,11 @@ static int cb_expect_multi(void *cbdata, const char *suffix, size_t len, const s |
107 | 107 |
const char **exp = cbdata; |
108 | 108 |
fail_unless(!!exp, "expected data"); |
109 | 109 |
exp++; |
110 |
- fail_unless(!!*exp, "expected no suffix, got: %s\n",suffix); |
|
111 |
- fail_unless(!!exp[cb_called], "expected less suffixes, but already got: %d\n", cb_called); |
|
112 |
- fail_unless(strcmp(exp[cb_called], suffix) == 0, |
|
110 |
+ fail_unless_fmt(!!*exp, "expected no suffix, got: %s\n",suffix); |
|
111 |
+ fail_unless_fmt(!!exp[cb_called], "expected less suffixes, but already got: %d\n", cb_called); |
|
112 |
+ fail_unless_fmt(strcmp(exp[cb_called], suffix) == 0, |
|
113 | 113 |
"suffix mismatch, was: %s, expected: %s\n",suffix, exp[cb_called]); |
114 |
- fail_unless(strlen(suffix) == len, "incorrect suffix len, expected: %d, got: %d\n", strlen(suffix), len); |
|
114 |
+ fail_unless_fmt(strlen(suffix) == len, "incorrect suffix len, expected: %d, got: %d\n", strlen(suffix), len); |
|
115 | 115 |
cb_called++; |
116 | 116 |
return 0; |
117 | 117 |
} |
... | ... |
@@ -134,7 +134,7 @@ START_TEST (test_suffix) |
134 | 134 |
free(preg); |
135 | 135 |
p++; |
136 | 136 |
while(*p++) n++; |
137 |
- fail_unless(cb_called == n, |
|
137 |
+ fail_unless_fmt(cb_called == n, |
|
138 | 138 |
"suffix number mismatch, expected: %d, was: %d\n", n, cb_called); |
139 | 139 |
} |
140 | 140 |
END_TEST |
... | ... |
@@ -374,30 +374,30 @@ static void do_phishing_test(const struct rtest *rtest) |
374 | 374 |
fail_unless(rc == CL_CLEAN,"phishingScan"); |
375 | 375 |
switch(rtest->result) { |
376 | 376 |
case 0: |
377 |
- fail_unless(ctx.found_possibly_unwanted, |
|
377 |
+ fail_unless_fmt(ctx.found_possibly_unwanted, |
|
378 | 378 |
"this should be phishing, realURL: %s, displayURL: %s", |
379 | 379 |
rtest->realurl, rtest->displayurl); |
380 | 380 |
break; |
381 | 381 |
case 1: |
382 |
- fail_unless(!ctx.found_possibly_unwanted, |
|
382 |
+ fail_unless_fmt(!ctx.found_possibly_unwanted, |
|
383 | 383 |
"this should be whitelisted, realURL: %s, displayURL: %s", |
384 | 384 |
rtest->realurl, rtest->displayurl); |
385 | 385 |
break; |
386 | 386 |
case 2: |
387 |
- fail_unless(!ctx.found_possibly_unwanted, |
|
387 |
+ fail_unless_fmt(!ctx.found_possibly_unwanted, |
|
388 | 388 |
"this should be clean, realURL: %s, displayURL: %s", |
389 | 389 |
rtest->realurl, rtest->displayurl); |
390 | 390 |
break; |
391 | 391 |
case 3: |
392 | 392 |
if(!loaded_2) |
393 |
- fail_unless(!ctx.found_possibly_unwanted, |
|
393 |
+ fail_unless_fmt(!ctx.found_possibly_unwanted, |
|
394 | 394 |
"this should be clean, realURL: %s, displayURL: %s", |
395 | 395 |
rtest->realurl, rtest->displayurl); |
396 | 396 |
else { |
397 |
- fail_unless(ctx.found_possibly_unwanted, |
|
397 |
+ fail_unless_fmt(ctx.found_possibly_unwanted, |
|
398 | 398 |
"this should be blacklisted, realURL: %s, displayURL: %s", |
399 | 399 |
rtest->realurl, rtest->displayurl); |
400 |
- fail_unless(!strstr((const char*)ctx.virname,"Blacklisted"), |
|
400 |
+ fail_unless_fmt(!strstr((const char*)ctx.virname,"Blacklisted"), |
|
401 | 401 |
"should be blacklisted, but is: %s\n", ctx.virname); |
402 | 402 |
} |
403 | 403 |
break; |
... | ... |
@@ -59,12 +59,12 @@ START_TEST (test_uniq_known) { |
59 | 59 |
|
60 | 60 |
for(i=0; tests[i].expected; i++) { |
61 | 61 |
u = uniq_add(U, tests[i].key, tests[i].key_len, &hash); |
62 |
- fail_unless(u==0 && strcmp(hash, tests[i].expected)==0, "uniq_add(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
|
62 |
+ fail_unless_fmt(u==0 && strcmp(hash, tests[i].expected)==0, "uniq_add(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
|
63 | 63 |
} |
64 | 64 |
|
65 | 65 |
for(i=0; tests[i].expected; i++) { |
66 | 66 |
u = uniq_get(U, tests[i].key, tests[i].key_len, &hash); |
67 |
- fail_unless(u==1 && strcmp(hash, tests[i].expected)==0, "uniq_get(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
|
67 |
+ fail_unless_fmt(u==1 && strcmp(hash, tests[i].expected)==0, "uniq_get(%s) = %u - expected %s, got %s", tests[i].key, u, tests[i].expected, hash); |
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
uniq_free(U); |
... | ... |
@@ -86,7 +86,7 @@ START_TEST (test_uniq_colls) { |
86 | 86 |
|
87 | 87 |
for (i=0; i<4; i++) { |
88 | 88 |
u = uniq_add(U, tests[i], strlen(tests[i]), NULL); |
89 |
- fail_unless(u+i==4, "uniq_get(%s) = %u - expected %u", tests[i], u, 4-i); |
|
89 |
+ fail_unless_fmt(u+i==4, "uniq_get(%s) = %u - expected %u", tests[i], u, 4-i); |
|
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
uniq_free(U); |
... | ... |
@@ -4,6 +4,15 @@ |
4 | 4 |
#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 3)) |
5 | 5 |
#define CHECK_HAVE_LOOPS |
6 | 6 |
#endif |
7 |
+ |
|
8 |
+#if CHECK_MAJOR_VERSION > 0 || ( CHECK_MINOR_VERSION > 9 || ( CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION > 0)) |
|
9 |
+#define fail_unless_fmt fail_unless |
|
10 |
+#define fail_fmt fail |
|
11 |
+#else |
|
12 |
+#define fail_unless_fmt(cond, msg, ...) fail_unless(cond, msg) |
|
13 |
+#define fail_fmt(msg, ...) fail(msg) |
|
14 |
+#endif |
|
15 |
+ |
|
7 | 16 |
Suite *test_jsnorm_suite(void); |
8 | 17 |
Suite *test_str_suite(void); |
9 | 18 |
Suite *test_regex_suite(void); |