You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2018/09/19 21:49:43 UTC

[trafficserver] branch master updated: Test: Convert test_Map.cc to Catch

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 edf9c6b  Test: Convert test_Map.cc to Catch
edf9c6b is described below

commit edf9c6bdd8188b2c4ffbbea7a939567171feb022
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Wed Sep 19 15:40:54 2018 -0500

    Test: Convert test_Map.cc to Catch
---
 .gitignore                              |   1 -
 src/tscore/Makefile.am                  |   6 +-
 src/tscore/{ => unit_tests}/test_Map.cc | 148 ++++++++++++++++----------------
 3 files changed, 74 insertions(+), 81 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0b846b3..ef6a007 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,7 +83,6 @@ src/tscore/test_List
 src/tscore/test_arena
 src/tscore/test_atomic
 src/tscore/test_freelist
-src/tscore/test_Map
 src/tscore/test_Vec
 src/tscore/test_geometry
 src/tscore/test_Regex
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index 6b42cf5..8e82d16 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_List test_Map test_Vec test_X509HostnameValidator test_tscore
+check_PROGRAMS = test_arena test_atomic test_freelist test_geometry test_List test_Vec test_X509HostnameValidator test_tscore
 
 TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt
 
@@ -238,9 +238,6 @@ test_arena_SOURCES = test_arena.cc
 test_arena_LDADD = libtscore.la $(top_builddir)/src/tscpp/util/libtscpputil.la @LIBTCL@ @LIBPCRE@
 
 test_List_SOURCES = test_List.cc
-test_Map_SOURCES = test_Map.cc
-test_Map_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@
 
@@ -269,6 +266,7 @@ test_tscore_SOURCES = \
 	unit_tests/test_IntrusivePtr.cc \
 	unit_tests/test_IpMap.cc \
 	unit_tests/test_layout.cc \
+	unit_tests/test_Map.cc \
 	unit_tests/test_MemSpan.cc \
 	unit_tests/test_MemArena.cc \
 	unit_tests/test_MT_hashtable.cc \
diff --git a/src/tscore/test_Map.cc b/src/tscore/unit_tests/test_Map.cc
similarity index 81%
rename from src/tscore/test_Map.cc
rename to src/tscore/unit_tests/test_Map.cc
index bc2b4ff..08fa4da 100644
--- a/src/tscore/test_Map.cc
+++ b/src/tscore/unit_tests/test_Map.cc
@@ -20,6 +20,9 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 */
+
+#include "catch.hpp"
+
 #include <cstdint>
 #include "tscore/Map.h"
 #include <list>
@@ -63,67 +66,6 @@ Item::Hash::equal(Key lhs, Key rhs)
 
 using Table = TSHashTable<Item::Hash>;
 
-void
-test_TSHashTable()
-{
-  static uint32_t const N = 270;
-  Table t;
-  Item *item = nullptr;
-  Table::Location loc;
-  std::list<Item *> to_delete;
-
-  for (uint32_t i = 1; i <= N; ++i) {
-    item = new Item(i);
-    t.insert(item);
-    to_delete.push_back(item);
-  }
-
-  for (uint32_t i = 1; i <= N; ++i) {
-    Table::Location l = t.find(i);
-    ink_assert(l.isValid());
-    ink_assert(i == l->_value);
-  }
-
-  ink_assert(!(t.find(N * 2).isValid()));
-
-  loc = t.find(N / 2 | 1);
-  if (loc) {
-    t.remove(loc);
-  } else {
-    ink_assert(!"Did not find expected value");
-  }
-
-  if (!loc) {
-    ; // compiler check.
-  }
-
-  ink_assert(!(t.find(N / 2 | 1).isValid()));
-
-  for (uint32_t i = 1; i <= N; i += 2) {
-    t.remove(i);
-  }
-
-  for (uint32_t i = 1; i <= N; ++i) {
-    Table::Location l = t.find(i);
-    if (1 & i) {
-      ink_assert(!l.isValid());
-    } else {
-      ink_assert(l.isValid());
-    }
-  }
-
-  int n = 0;
-  for (Table::iterator spot = t.begin(), limit = t.end(); spot != limit; ++spot) {
-    ++n;
-    ink_assert((spot->_value & 1) == 0);
-  }
-  ink_assert(n == N / 2);
-
-  for (auto it : to_delete) {
-    delete it;
-  }
-}
-
 class testHashMap
 {
 private:
@@ -143,8 +85,7 @@ public:
   }
 };
 
-int
-main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
+TEST_CASE("test Map", "[libts][Map]")
 {
   typedef Map<cchar *, cchar *> SSMap;
   typedef MapElem<cchar *, cchar *> SSMapElem;
@@ -177,30 +118,85 @@ main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
   sh.put(ho, 2);
   sh.put(hum, 3);
   sh.put(hhi, 4);
-  ink_assert(sh.get(hi) == 4);
-  ink_assert(sh.get(ho) == 2);
-  ink_assert(sh.get(hum) == 3);
+  REQUIRE(sh.get(hi) == 4);
+  REQUIRE(sh.get(ho) == 2);
+  REQUIRE(sh.get(hum) == 3);
   sh.put("aa", 5);
   sh.put("ab", 6);
   sh.put("ac", 7);
   sh.put("ad", 8);
   sh.put("ae", 9);
   sh.put("af", 10);
-  ink_assert(sh.get(hi) == 4);
-  ink_assert(sh.get(ho) == 2);
-  ink_assert(sh.get(hum) == 3);
-  ink_assert(sh.get("af") == 10);
-  ink_assert(sh.get("ac") == 7);
+  REQUIRE(sh.get(hi) == 4);
+  REQUIRE(sh.get(ho) == 2);
+  REQUIRE(sh.get(hum) == 3);
+  REQUIRE(sh.get("af") == 10);
+  REQUIRE(sh.get("ac") == 7);
 
   HashMap<cchar *, StringHashFns, int> sh2(-99); // return -99 if key not found
   sh2.put("aa", 15);
   sh2.put("ab", 16);
   testsh.put("aa", 15);
   testsh.put("ab", 16);
-  ink_assert(sh2.get("aa") == 15);
-  ink_assert(sh2.get("ac") == -99);
-  ink_assert(testsh.get("aa") == 15);
-  test_TSHashTable();
+  REQUIRE(sh2.get("aa") == 15);
+  REQUIRE(sh2.get("ac") == -99);
+  REQUIRE(testsh.get("aa") == 15);
+
+  // test_TSHashTable
+  static uint32_t const N = 270;
+  Table t;
+  Item *item = nullptr;
+  Table::Location loc;
+  std::list<Item *> to_delete;
+
+  for (uint32_t i = 1; i <= N; ++i) {
+    item = new Item(i);
+    t.insert(item);
+    to_delete.push_back(item);
+  }
+
+  for (uint32_t i = 1; i <= N; ++i) {
+    Table::Location l = t.find(i);
+    REQUIRE(l.isValid());
+    REQUIRE(i == l->_value);
+  }
+
+  REQUIRE(!(t.find(N * 2).isValid()));
+
+  loc = t.find(N / 2 | 1);
+  if (loc) {
+    t.remove(loc);
+  } else {
+    REQUIRE(!"Did not find expected value");
+  }
 
-  printf("test_Map PASSED\n");
+  if (!loc) {
+    ; // compiler check.
+  }
+
+  REQUIRE(!(t.find(N / 2 | 1).isValid()));
+
+  for (uint32_t i = 1; i <= N; i += 2) {
+    t.remove(i);
+  }
+
+  for (uint32_t i = 1; i <= N; ++i) {
+    Table::Location l = t.find(i);
+    if (1 & i) {
+      REQUIRE(!l.isValid());
+    } else {
+      REQUIRE(l.isValid());
+    }
+  }
+
+  int n = 0;
+  for (Table::iterator spot = t.begin(), limit = t.end(); spot != limit; ++spot) {
+    ++n;
+    REQUIRE((spot->_value & 1) == 0);
+  }
+  REQUIRE(n == N / 2);
+
+  for (auto it : to_delete) {
+    delete it;
+  }
 }