[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH 6/6] unit-tests: modify the existing strrstr test code to use the unit-test framework
From: Bartosz Golaszewski <bartekgola () gmail ! com>
Date: 2014-04-15 21:07:23
Message-ID: 1397603199-12864-7-git-send-email-bartekgola () gmail ! com
[Download RAW message or body]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
---
libbb/strrstr.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/libbb/strrstr.c b/libbb/strrstr.c
index d8823fc..1650fa0 100644
--- a/libbb/strrstr.c
+++ b/libbb/strrstr.c
@@ -7,13 +7,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
-#ifdef __DO_STRRSTR_TEST
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#else
#include "libbb.h"
-#endif
/*
* The strrstr() function finds the last occurrence of the substring needle
@@ -34,8 +28,11 @@ char* FAST_FUNC strrstr(const char *haystack, const char *needle)
}
}
-#ifdef __DO_STRRSTR_TEST
-int main(int argc, char **argv)
+#if ENABLE_UNIT_TEST
+
+#include "bbunit.h"
+
+BBUNIT_DEFINE_TEST(strrstr)
{
static const struct {
const char *h, *n;
@@ -59,13 +56,13 @@ int main(int argc, char **argv)
i = 0;
while (i < sizeof(test_array) / sizeof(test_array[0])) {
const char *r = strrstr(test_array[i].h, test_array[i].n);
- printf("'%s' vs. '%s': '%s' - ", test_array[i].h, test_array[i].n, r);
if (r == NULL)
r = test_array[i].h - 1;
- printf("%s\n", r == test_array[i].h + test_array[i].pos ? "PASSED" : "FAILED");
+ BBUNIT_ASSERT_EQ(r, test_array[i].h + test_array[i].pos);
i++;
}
- return 0;
+ BBUNIT_ENDTEST;
}
-#endif
+
+#endif /* ENABLE_UNIT_TEST */
--
1.8.4.5
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic