diff --git a/.gitignore b/.gitignore index d5b03d40713..f114acc78c1 100644 --- a/.gitignore +++ b/.gitignore @@ -79,7 +79,6 @@ src/tscore/ParseRulesCType src/tscore/ParseRulesCTypeToLower src/tscore/ParseRulesCTypeToUpper src/tscore/mkdfa -src/tscore/test_arena src/tscore/test_atomic src/tscore/test_freelist src/tscore/test_Vec diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am index aa1724f0ee4..5a47d94978c 100644 --- a/src/tscore/Makefile.am +++ b/src/tscore/Makefile.am @@ -19,7 +19,7 @@ include $(top_srcdir)/build/tidy.mk noinst_PROGRAMS = mkdfa CompileParseRules -check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore +check_PROGRAMS = test_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator test_tscore TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt @@ -237,9 +237,6 @@ test_atomic_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la test_freelist_SOURCES = test_freelist.cc test_freelist_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@ -test_arena_SOURCES = test_arena.cc -test_arena_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@ - test_Vec_SOURCES = test_Vec.cc test_Vec_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@ @@ -258,6 +255,7 @@ test_tscore_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la test_tscore_SOURCES = \ unit_tests/unit_test_main.cc \ unit_tests/test_AcidPtr.cc \ + unit_tests/test_arena.cc \ unit_tests/test_ArgParser.cc \ unit_tests/test_BufferWriter.cc \ unit_tests/test_BufferWriterFormat.cc \ diff --git a/src/tscore/test_arena.cc b/src/tscore/unit_tests/test_arena.cc similarity index 77% rename from src/tscore/test_arena.cc rename to src/tscore/unit_tests/test_arena.cc index 17e7c6dfbbc..ec3f28cac20 100644 --- a/src/tscore/test_arena.cc +++ b/src/tscore/unit_tests/test_arena.cc @@ -23,7 +23,7 @@ /**************************************************************************** - ArenaTest.cc + test_arena.cc Description: @@ -33,6 +33,8 @@ ****************************************************************************/ +#include "catch.hpp" + #include "tscore/Arena.h" #include @@ -47,29 +49,11 @@ fill_test_data(char *ptr, int size, int seed) } } -int -check_test_data(char *ptr, int size, int seed) -{ - int fail = 0; - char a = 'a' + (seed % 52); - - for (int i = 0; i < size; i++) { - if (ptr[i] != a) { - fail++; - } - a = (a + 1) % 52; - } - - return fail; -} - -int -test_block_boundries() +TEST_CASE("test arena", "[libts][arena]") { const int sizes_to_test = 12; const int regions_to_test = 1024 * 2; char **test_regions = new char *[regions_to_test]; - int failures = 0; Arena *a = new Arena(); for (int i = 0; i < sizes_to_test; i++) { @@ -89,14 +73,12 @@ test_block_boundries() // Now check to make sure the data is correct for (j = 0; j < regions_to_test; j++) { - int f = check_test_data(test_regions[j], test_size, j); - - if (f != 0) { - fprintf(stderr, "block_boundries test failed. size %d region %d\n", test_size, j); - failures++; + char a = 'a' + (j % 52); + for (int k = 0; k < test_size; k++) { + REQUIRE(test_regions[j][k] == a); + a = (a + 1) % 52; } } - // Now free the regions for (j = 0; j < regions_to_test; j++) { a->free(test_regions[j], test_size); @@ -107,19 +89,4 @@ test_block_boundries() delete[] test_regions; delete a; - return failures; -} - -int -main() -{ - int failures = 0; - - failures += test_block_boundries(); - - if (failures) { - return 1; - } else { - return 0; - } }