aboutsummaryrefslogtreecommitdiff
path: root/libbb/strrstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/strrstr.c')
-rw-r--r--libbb/strrstr.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/libbb/strrstr.c b/libbb/strrstr.c
index d8823fc51..93d970a1b 100644
--- a/libbb/strrstr.c
+++ b/libbb/strrstr.c
@@ -7,13 +7,7 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9 9
10#ifdef __DO_STRRSTR_TEST
11#include <stdlib.h>
12#include <string.h>
13#include <stdio.h>
14#else
15#include "libbb.h" 10#include "libbb.h"
16#endif
17 11
18/* 12/*
19 * The strrstr() function finds the last occurrence of the substring needle 13 * The strrstr() function finds the last occurrence of the substring needle
@@ -34,8 +28,9 @@ char* FAST_FUNC strrstr(const char *haystack, const char *needle)
34 } 28 }
35} 29}
36 30
37#ifdef __DO_STRRSTR_TEST 31#if ENABLE_UNIT_TEST
38int main(int argc, char **argv) 32
33BBUNIT_DEFINE_TEST(strrstr)
39{ 34{
40 static const struct { 35 static const struct {
41 const char *h, *n; 36 const char *h, *n;
@@ -59,13 +54,13 @@ int main(int argc, char **argv)
59 i = 0; 54 i = 0;
60 while (i < sizeof(test_array) / sizeof(test_array[0])) { 55 while (i < sizeof(test_array) / sizeof(test_array[0])) {
61 const char *r = strrstr(test_array[i].h, test_array[i].n); 56 const char *r = strrstr(test_array[i].h, test_array[i].n);
62 printf("'%s' vs. '%s': '%s' - ", test_array[i].h, test_array[i].n, r);
63 if (r == NULL) 57 if (r == NULL)
64 r = test_array[i].h - 1; 58 r = test_array[i].h - 1;
65 printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED"); 59 BBUNIT_ASSERT_EQ(r, test_array[i].h + test_array[i].pos);
66 i++; 60 i++;
67 } 61 }
68 62
69 return 0; 63 BBUNIT_ENDTEST;
70} 64}
71#endif 65
66#endif /* ENABLE_UNIT_TEST */