trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [trafficserver] branch master updated: Test: Convert test_Vec.cc to Catch
Date Thu, 20 Sep 2018 21:16:58 GMT
This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new cc680ee  Test: Convert test_Vec.cc to Catch
cc680ee is described below

commit cc680ee55c0e8b453556747899cca3785e7a1dd2
Author: Xavier Chi <chitianhaoxp@gmail.com>
AuthorDate: Wed Sep 19 16:06:17 2018 -0500

    Test: Convert test_Vec.cc to Catch
---
 .gitignore                              |  1 -
 src/tscore/Makefile.am                  |  8 ++--
 src/tscore/{ => unit_tests}/test_Vec.cc | 82 +++++++++++++++------------------
 3 files changed, 39 insertions(+), 52 deletions(-)

diff --git a/.gitignore b/.gitignore
index f114acc..a1ba7ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,7 +81,6 @@ src/tscore/ParseRulesCTypeToUpper
 src/tscore/mkdfa
 src/tscore/test_atomic
 src/tscore/test_freelist
-src/tscore/test_Vec
 src/tscore/test_geometry
 src/tscore/test_Regex
 src/tscore/test_X509HostnameValidator
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index 5a47d94..10993b1 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_atomic test_freelist test_geometry test_Vec test_X509HostnameValidator
test_tscore
+check_PROGRAMS = test_atomic test_freelist test_geometry 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_Vec_SOURCES = test_Vec.cc
-test_Vec_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@
-
 test_geometry_SOURCES = test_geometry.cc
 test_geometry_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@
@LIBPCRE@
 
@@ -277,7 +274,8 @@ test_tscore_SOURCES = \
 	unit_tests/test_Regex.cc \
 	unit_tests/test_Scalar.cc \
 	unit_tests/test_scoped_resource.cc \
-	unit_tests/test_ts_file.cc
+	unit_tests/test_ts_file.cc \
+	unit_tests/test_Vec.cc
 
 CompileParseRules_SOURCES = CompileParseRules.cc
 
diff --git a/src/tscore/test_Vec.cc b/src/tscore/unit_tests/test_Vec.cc
similarity index 80%
rename from src/tscore/test_Vec.cc
rename to src/tscore/unit_tests/test_Vec.cc
index 53a6fa8..486315d 100644
--- a/src/tscore/test_Vec.cc
+++ b/src/tscore/unit_tests/test_Vec.cc
@@ -22,6 +22,8 @@
 
 /* UnionFind after Tarjan */
 
+#include "catch.hpp"
+
 #include <cstdint>
 #include <cstdio>
 #include "tscore/ink_assert.h"
@@ -202,8 +204,7 @@ UnionFind::unify(int n, int m)
   }
 }
 
-static void
-test_append()
+TEST_CASE("test append", "[Vec]")
 {
   static const char value[] = "this is a string";
   unsigned int len          = (int)sizeof(value) - 1;
@@ -211,25 +212,24 @@ test_append()
   Vec<char> str;
 
   str.append(value, 0);
-  ink_assert(str.length() == 0);
+  REQUIRE(str.length() == 0);
 
   str.append(value, len);
-  ink_assert(memcmp(&str[0], value, len) == 0);
-  ink_assert(str.length() == len);
+  REQUIRE(memcmp(&str[0], value, len) == 0);
+  REQUIRE(str.length() == len);
 
   str.clear();
-  ink_assert(str.length() == 0);
+  REQUIRE(str.length() == 0);
 
   for (unsigned i = 0; i < 1000; ++i) {
     str.append(value, len);
-    ink_assert(memcmp(&str[i * len], value, len) == 0);
+    REQUIRE(memcmp(&str[i * len], value, len) == 0);
   }
 
-  ink_assert(str.length() == 1000 * len);
+  REQUIRE(str.length() == 1000 * len);
 }
 
-static void
-test_basic()
+TEST_CASE("test basic", "[libts][Vec]")
 {
   Vec<void *> v, vv, vvv;
   int tt = 99 * 50, t = 0;
@@ -240,7 +240,7 @@ test_basic()
   for (size_t i = 0; i < 100; i++) {
     t += (int)(intptr_t)v.v[i];
   }
-  ink_assert(t == tt);
+  REQUIRE(t == tt);
 
   t = 0;
   for (size_t i = 1; i < 100; i++) {
@@ -258,7 +258,7 @@ test_basic()
       t += (int)(intptr_t)vv.v[i];
     }
   }
-  ink_assert(t == tt + 1000 * tt);
+  REQUIRE(t == tt + 1000 * tt);
 
   v.clear();
   v.reserve(1000);
@@ -269,42 +269,42 @@ test_basic()
   for (size_t i = 0; i < 1000; i++) {
     t += (int)(intptr_t)v.v[i];
   }
-  ink_assert(t == 999 * 500);
+  REQUIRE(t == 999 * 500);
   printf("%zu %zu\n", v.n, v.i);
 
   Intervals in;
   in.insert(1);
-  ink_assert(in.n == 2);
+  REQUIRE(in.n == 2);
   in.insert(2);
-  ink_assert(in.n == 2);
+  REQUIRE(in.n == 2);
   in.insert(6);
-  ink_assert(in.n == 4);
+  REQUIRE(in.n == 4);
   in.insert(7);
-  ink_assert(in.n == 4);
+  REQUIRE(in.n == 4);
   in.insert(9);
-  ink_assert(in.n == 6);
+  REQUIRE(in.n == 6);
   in.insert(4);
-  ink_assert(in.n == 8);
+  REQUIRE(in.n == 8);
   in.insert(5);
-  ink_assert(in.n == 6);
+  REQUIRE(in.n == 6);
   in.insert(3);
-  ink_assert(in.n == 4);
+  REQUIRE(in.n == 4);
   in.insert(8);
-  ink_assert(in.n == 2);
+  REQUIRE(in.n == 2);
 
   UnionFind uf;
   uf.size(4);
   uf.unify(0, 1);
   uf.unify(2, 3);
-  ink_assert(uf.find(2) == uf.find(3));
-  ink_assert(uf.find(0) == uf.find(1));
-  ink_assert(uf.find(0) != uf.find(3));
-  ink_assert(uf.find(1) != uf.find(3));
-  ink_assert(uf.find(1) != uf.find(2));
-  ink_assert(uf.find(0) != uf.find(2));
+  REQUIRE(uf.find(2) == uf.find(3));
+  REQUIRE(uf.find(0) == uf.find(1));
+  REQUIRE(uf.find(0) != uf.find(3));
+  REQUIRE(uf.find(1) != uf.find(3));
+  REQUIRE(uf.find(1) != uf.find(2));
+  REQUIRE(uf.find(0) != uf.find(2));
   uf.unify(1, 2);
-  ink_assert(uf.find(0) == uf.find(3));
-  ink_assert(uf.find(1) == uf.find(3));
+  REQUIRE(uf.find(0) == uf.find(3));
+  REQUIRE(uf.find(1) == uf.find(3));
 }
 
 static bool
@@ -313,8 +313,7 @@ compare(void *a, void *b)
   return a < b;
 }
 
-static void
-test_sort()
+TEST_CASE("test sort", "[libts][Vec]")
 {
   Vec<void *> v;
   for (long i = 1; i <= 1000; ++i) {
@@ -322,7 +321,7 @@ test_sort()
   }
   v.qsort(&compare);
   for (int i = 0; i < 1000; ++i) {
-    ink_assert(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
+    REQUIRE(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
   }
 
   v.clear();
@@ -332,7 +331,7 @@ test_sort()
   v.qsort(&compare);
 
   for (long i = 0; i < 1000000; ++i) {
-    ink_assert(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
+    REQUIRE(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
   }
 
   v.clear();
@@ -343,7 +342,7 @@ test_sort()
   v.qsort(&compare);
 
   for (long i = 0; i < 1000000; ++i) {
-    ink_assert(reinterpret_cast<void *>(static_cast<intptr_t>((i / 2) + 1)) ==
v[i]);
+    REQUIRE(reinterpret_cast<void *>(static_cast<intptr_t>((i / 2) + 1)) == v[i]);
   }
 
   // Very long array, already sorted. This is what broke before.
@@ -353,7 +352,7 @@ test_sort()
   }
   v.qsort(&compare);
   for (long i = 0; i < 10000000; ++i) {
-    ink_assert(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
+    REQUIRE(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
   }
 
   // very long, reverse sorted.
@@ -363,15 +362,6 @@ test_sort()
   }
   v.qsort(&compare);
   for (long i = 0; i < 10000000; ++i) {
-    ink_assert(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
+    REQUIRE(reinterpret_cast<void *>(static_cast<intptr_t>(i + 1)) == v[i]);
   }
 }
-
-int
-main(int /* argc ATS_UNUSED */, char ** /* argv ATS_UNUSED */)
-{
-  test_append();
-  test_basic();
-  test_sort();
-  printf("test_Vec PASSED\n");
-}


Mime
View raw message