You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2018/10/10 23:07:53 UTC
[trafficserver] branch 8.0.x updated: Test: Convert test_Map.cc to
Catch
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/8.0.x by this push:
new 9e20c68 Test: Convert test_Map.cc to Catch
9e20c68 is described below
commit 9e20c688e5d8210f3e7d50ffbee08bdfb2290089
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Wed Sep 19 15:40:54 2018 -0500
Test: Convert test_Map.cc to Catch
(cherry picked from commit edf9c6bdd8188b2c4ffbbea7a939567171feb022)
Conflicts:
.gitignore
src/tscore/Makefile.am
---
.gitignore | 1 -
src/tscore/Makefile.am | 6 +-
src/tscore/{ => unit_tests}/test_Map.cc | 148 ++++++++++++++++----------------
3 files changed, 73 insertions(+), 82 deletions(-)
diff --git a/.gitignore b/.gitignore
index 6fe5ae8..51188d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -80,7 +80,6 @@ src/tscore/ParseRulesCTypeToUpper
src/tscore/mkdfa
src/tscore/test_atomic
src/tscore/test_freelist
-src/tscore/test_Map
src/tscore/test_geometry
src/tscore/test_Regex
src/tscore/test_PriorityQueue
diff --git a/src/tscore/Makefile.am b/src/tscore/Makefile.am
index ea6704a..92bb5e7 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_libtscore test_atomic test_freelist test_geometry test_Map test_X509HostnameValidator test_tscore
+check_PROGRAMS = test_libtscore test_atomic test_freelist test_geometry test_X509HostnameValidator test_tscore
TESTS_ENVIRONMENT = LSAN_OPTIONS=suppressions=suppression.txt
@@ -229,9 +229,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_Map_SOURCES = test_Map.cc
-test_Map_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@
@@ -261,7 +258,6 @@ test_tscore_SOURCES = \
unit_tests/test_IntrusivePtr.cc \
unit_tests/test_IpMap.cc \
unit_tests/test_layout.cc \
- unit_tests/test_List.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;
+ }
}