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 31e4d28 Testing: Convert test_History.cc to Catch.
31e4d28 is described below
commit 31e4d28546bf8c0de15bd42d76780d08d84bacec
Author: Alan M. Carroll <[email protected]>
AuthorDate: Fri Jul 13 20:10:10 2018 -0500
Testing: Convert test_History.cc to Catch.
---
CMakeLists.txt | 2 +-
lib/ts/History.h | 1 +
lib/ts/Makefile.am | 2 +-
lib/ts/test_History.cc | 111 ------------------------------------
lib/ts/unit-tests/test_History.cc | 117 ++++++++++++++++++++++++++++++++++++++
5 files changed, 120 insertions(+), 113 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3f6b47..1c15297 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1132,7 +1132,6 @@ add_library(libtsutil SHARED
lib/ts/test_atomic.cc
lib/ts/test_freelist.cc
lib/ts/test_geometry.cc
- lib/ts/test_History.cc
lib/ts/test_List.cc
lib/ts/test_Map.cc
lib/ts/test_PriorityQueue.cc
@@ -1159,6 +1158,7 @@ add_executable(test_tslib
lib/ts/unit-tests/unit_test_main.cc
lib/ts/unit-tests/test_BufferWriter.cc
lib/ts/unit-tests/test_BufferWriterFormat.cc
+ lib/ts/unit-tests/test_History.cc
lib/ts/unit-tests/test_ink_inet.cc
lib/ts/unit-tests/test_IntrusiveDList.cc
lib/ts/unit-tests/test_IntrusivePtr.cc
diff --git a/lib/ts/History.h b/lib/ts/History.h
index ff7125a..c8cfc16 100644
--- a/lib/ts/History.h
+++ b/lib/ts/History.h
@@ -24,6 +24,7 @@
#pragma once
#include "ts/SourceLocation.h"
+#include "ts/ink_memory.h"
#define NO_REENTRANT 99999
#define NO_EVENT NO_REENTRANT
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index dd30801..3f30afd 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -253,7 +253,6 @@ test_X509HostnameValidator_LDADD = libtsutil.la @LIBTCL@
@LIBPCRE@ @OPENSSL_LIBS
test_tsutil_LDADD = libtsutil.la @LIBTCL@ @LIBPCRE@
test_tsutil_SOURCES = \
- test_History.cc \
test_PriorityQueue.cc \
test_Ptr.cc \
tests.cc
@@ -269,6 +268,7 @@ test_tslib_SOURCES = \
unit-tests/test_BufferWriter.cc \
unit-tests/test_BufferWriterFormat.cc \
unit-tests/test_PostScript.cc \
+ unit-tests/test_History.cc \
unit-tests/test_ink_inet.cc \
unit-tests/test_IntrusiveDList.cc \
unit-tests/test_IntrusivePtr.cc \
diff --git a/lib/ts/test_History.cc b/lib/ts/test_History.cc
deleted file mode 100644
index 9585680..0000000
--- a/lib/ts/test_History.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-/** @file
- *
- * A brief file description
- *
- * @section license License
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ts/History.h"
-#include "ts/TestBox.h"
-
-#define REMEMBER(e, r) \
- { \
- history.push_back(MakeSourceLocation(), e, r); \
- }
-
-#define SM_REMEMBER(sm, e, r) \
- { \
- sm->history.push_back(MakeSourceLocation(), e, r); \
- }
-
-template <unsigned Count> class SM
-{
-public:
- History<Count> history;
-};
-
-REGRESSION_TEST(History_test)(RegressionTest *t, int /* atype ATS_UNUSED */,
int *pstatus)
-{
- char buf[128];
-
- TestBox tb(t, pstatus);
- *pstatus = REGRESSION_TEST_PASSED;
-
- History<HISTORY_DEFAULT_SIZE> history;
- REMEMBER(1, 1);
- REMEMBER(2, 2);
- REMEMBER(3, NO_REENTRANT);
-
- tb.check(history[0].event == 1 && history[0].reentrancy == 1, "Checking that
event is 1 and reentrancy is 1");
- tb.check(history[1].event == 2 && history[1].reentrancy == 2, "Checking that
event is 2 and reentrancy is 2");
- tb.check(history[2].event == 3 && history[2].reentrancy ==
(short)NO_REENTRANT,
- "Checking that event is 3 and reentrancy is NO_REENTRANT");
-
- tb.check(strncmp(history[0].location.str(buf, 128), "test_History.cc:51
(RegressionTest_History_test)",
- strlen("test_History.cc:51 (RegressionTest_History_test)"))
== 0,
- "Checking history string");
- tb.check(strncmp(history[1].location.str(buf, 128), "test_History.cc:52
(RegressionTest_History_test)",
- strlen("test_History.cc:52 (RegressionTest_History_test)"))
== 0,
- "Checking history string");
-
- SM<HISTORY_DEFAULT_SIZE> *sm = new SM<HISTORY_DEFAULT_SIZE>;
- SM_REMEMBER(sm, 1, 1);
- SM_REMEMBER(sm, 2, 2);
- SM_REMEMBER(sm, 3, NO_REENTRANT);
-
- tb.check(strncmp(sm->history[0].location.str(buf, 128), "test_History.cc:68
(RegressionTest_History_test)",
- strlen("test_History.cc:68 (RegressionTest_History_test)"))
== 0,
- "Checking SM's history string");
- tb.check(strncmp(sm->history[1].location.str(buf, 128), "test_History.cc:69
(RegressionTest_History_test)",
- strlen("test_History.cc:69 (RegressionTest_History_test)"))
== 0,
- "Checking SM's history string");
-
- tb.check(sm->history[0].event == 1 && sm->history[0].reentrancy == 1,
"Checking that SM's event is 1 and reentrancy is 1");
- tb.check(sm->history[1].event == 2 && sm->history[1].reentrancy == 2,
"Checking that SM's event is 2 and reentrancy is 2");
- tb.check(sm->history[2].event == 3 && sm->history[2].reentrancy ==
(short)NO_REENTRANT,
- "Checking that SM's event is 3 and reentrancy is NO_REENTRANT");
-
- SM<2> *sm2 = new SM<2>;
-
- tb.check(sm2->history.size() == 0, "Checking that history size is 0");
- tb.check(sm2->history.overflowed() == false, "Checking that history
overflowed 1");
- SM_REMEMBER(sm2, 1, 1);
- tb.check(sm2->history.size() == 1, "Checking that history size is 1");
- tb.check(sm2->history.overflowed() == false, "Checking that history
overflowed 2");
- SM_REMEMBER(sm2, 2, 2);
- tb.check(sm2->history.size() == 2, "Checking that history size is 2");
- tb.check(sm2->history.overflowed() == true, "Checking that history
overflowed 3");
- SM_REMEMBER(sm2, 3, NO_REENTRANT);
- tb.check(sm2->history.size() == 2, "Checking that history size is 2");
- tb.check(sm2->history.overflowed() == true, "Checking that history
overflowed 4");
-
- tb.check(strncmp(sm2->history[0].location.str(buf, 128), "test_History.cc:94
(RegressionTest_History_test)",
- strlen("test_History.cc:88 (RegressionTest_History_test)"))
== 0,
- "Checking history string");
-
- tb.check(strncmp(sm2->history[1].location.str(buf, 128), "test_History.cc:91
(RegressionTest_History_test)",
- strlen("test_History.cc:91 (RegressionTest_History_test)"))
== 0,
- "Checking history string");
-
- sm2->history.clear();
- tb.check(sm2->history.size() == 0, "Checking that history pos is 0 after
clear");
-
- delete sm;
- delete sm2;
-}
diff --git a/lib/ts/unit-tests/test_History.cc
b/lib/ts/unit-tests/test_History.cc
new file mode 100644
index 0000000..e402ea8
--- /dev/null
+++ b/lib/ts/unit-tests/test_History.cc
@@ -0,0 +1,117 @@
+/** @file
+ *
+ * A brief file description
+ *
+ * @section license License
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string_view>
+
+#include "ts/History.h"
+#include "catch.hpp"
+
+using std::string_view;
+
+#define REMEMBER(e, r) history.push_back(MakeSourceLocation(), e, r)
+#define SM_REMEMBER(sm, e, r) sm->history.push_back(MakeSourceLocation(), e, r)
+
+// State Machine mock
+template <unsigned Count> class SM
+{
+public:
+ History<Count> history;
+};
+
+TEST_CASE("History", "[libts][History]")
+{
+ char buf[128];
+
+ History<HISTORY_DEFAULT_SIZE> history;
+
+ REMEMBER(1, 1);
+ REMEMBER(2, 2);
+ REMEMBER(3, NO_REENTRANT);
+
+ REQUIRE(history[0].event == 1);
+ REQUIRE(history[0].reentrancy == 1);
+
+ REQUIRE(history[1].event == 2);
+ REQUIRE(history[1].reentrancy == 2);
+
+ REQUIRE(history[2].event == 3);
+ REQUIRE(history[2].reentrancy == static_cast<short>(NO_REENTRANT));
+
+ history[0].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:47
(____C_A_T_C_H____T_E_S_T____0)");
+
+ history[1].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:48
(____C_A_T_C_H____T_E_S_T____0)");
+
+ SM<HISTORY_DEFAULT_SIZE> *sm = new SM<HISTORY_DEFAULT_SIZE>;
+ SM_REMEMBER(sm, 1, 1);
+ SM_REMEMBER(sm, 2, 2);
+ SM_REMEMBER(sm, 3, NO_REENTRANT);
+
+ sm->history[0].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:67
(____C_A_T_C_H____T_E_S_T____0)");
+
+ sm->history[1].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:68
(____C_A_T_C_H____T_E_S_T____0)");
+
+ REQUIRE(sm->history[0].event == 1);
+ REQUIRE(sm->history[0].reentrancy == 1);
+
+ REQUIRE(sm->history[1].event == 2);
+ REQUIRE(sm->history[1].reentrancy == 2);
+
+ REQUIRE(sm->history[2].event == 3);
+ REQUIRE(sm->history[2].reentrancy == static_cast<short>(NO_REENTRANT));
+
+ SM<2> *sm2 = new SM<2>;
+
+ REQUIRE(sm2->history.size() == 0);
+ REQUIRE(sm2->history.overflowed() == false);
+
+ SM_REMEMBER(sm2, 1, 1);
+
+ REQUIRE(sm2->history.size() == 1);
+ REQUIRE(sm2->history.overflowed() == false);
+
+ SM_REMEMBER(sm2, 2, 2);
+
+ REQUIRE(sm2->history.size() == 2);
+ REQUIRE(sm2->history.overflowed() == true);
+
+ SM_REMEMBER(sm2, 3, NO_REENTRANT);
+
+ REQUIRE(sm2->history.size() == 2);
+ REQUIRE(sm2->history.overflowed() == true);
+
+ sm2->history[0].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:101
(____C_A_T_C_H____T_E_S_T____0)");
+
+ sm2->history[1].location.str(buf, sizeof(buf));
+ REQUIRE(string_view{buf} == "test_History.cc:96
(____C_A_T_C_H____T_E_S_T____0)");
+
+ sm2->history.clear();
+ REQUIRE(sm2->history.size() == 0);
+
+ delete sm;
+ delete sm2;
+}