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 fe6e874  Make TextView.h available to C++ plugins.
fe6e874 is described below

commit fe6e87403f45591138647c1bc0514fe6fe5b50be
Author: Walt Karas <[email protected]>
AuthorDate: Mon Mar 26 22:58:08 2018 +0000

    Make TextView.h available to C++ plugins.
---
 lib/ts/Makefile.am                 |  2 +-
 plugins/test_cppapi/test_cppapi.cc | 63 +++++++++++++++++++++++++++++++-------
 2 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 57e9036..a2555e2 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -20,7 +20,7 @@ include $(top_srcdir)/build/tidy.mk
 
 library_includedir=$(includedir)/ts
 
-library_include_HEADERS = apidefs.h string_view.h
+library_include_HEADERS = apidefs.h string_view.h TextView.h
 
 noinst_PROGRAMS = mkdfa CompileParseRules
 check_PROGRAMS = test_tsutil test_arena test_atomic test_freelist 
test_geometry test_List test_Map test_Vec test_X509HostnameValidator test_tslib
diff --git a/plugins/test_cppapi/test_cppapi.cc 
b/plugins/test_cppapi/test_cppapi.cc
index a2c782f..5de22c9 100644
--- a/plugins/test_cppapi/test_cppapi.cc
+++ b/plugins/test_cppapi/test_cppapi.cc
@@ -16,20 +16,59 @@
  * limitations under the License.
  */
 
-#include "ts/ts.h"
+#include <sstream>
+#include <vector>
 
-// Placeholder test.
+#include <ts/ts.h>
+
+#include <ts/TextView.h>
+
+// TSReleaseAssert() doesn't seem to produce any logging output for a debug 
build, so do both kinds of assert.
 //
-namespace Test1
-{
-void
-x()
+#define ASS(EXPR)          \
+  {                        \
+    TSAssert(EXPR);        \
+    TSReleaseAssert(EXPR); \
+  }
+
+std::vector<void (*)()> testList;
+
+struct ATest {
+  ATest(void (*testFuncPtr)()) { testList.push_back(testFuncPtr); }
+};
+
+// Put a test function, whose name is the actual parameter for TEST_FUNC, into 
testList, the list of test functions.
+//
+#define TEST(TEST_FUNC) ATest t(TEST_FUNC);
+
+#define TNS_(LN) TestNamespaceName##LN
+
+// Generate a unique name for a separate namespace for each test.
+//
+#define TNS namespace TNS_(__LINE__)
+
+// TextView test. This is not testing the actual TextView code, just that it 
works to call functions in TextView.cc in the core
+// from a plugin.
+//
+TNS
 {
-  TSReleaseAssert(true);
-}
+  void f()
+  {
+    ts::TextView tv("abcdefg");
+
+    std::ostringstream oss;
 
-} // end namespace Test1;
+    oss << tv;
 
+    ASS(ts::memcmp(ts::TextView(oss.str()), tv) == 0)
+  }
+
+  TEST(f)
+
+} // end TNS namespace
+
+// Run all the tests.
+//
 void
 TSPluginInit(int, const char **)
 {
@@ -39,7 +78,9 @@ TSPluginInit(int, const char **)
   info.vendor_name   = "Apache Software Foundation";
   info.support_email = "[email protected]";
 
-  TSReleaseAssert(TSPluginRegister(&info) == TS_SUCCESS);
+  ASS(TSPluginRegister(&info) == TS_SUCCESS)
 
-  Test1::x();
+  for (auto fp : testList) {
+    fp();
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to