You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by rr...@apache.org on 2020/03/26 15:00:49 UTC

[trafficserver] branch master updated: Convert proxy/logging unit tests to use Catch.

This is an automated email from the ASF dual-hosted git repository.

rrm 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 55abbd7  Convert proxy/logging unit tests to use Catch.
55abbd7 is described below

commit 55abbd77910842979dec2f1e487f6aa2bba59103
Author: Walter Karas <wk...@verizonmedia.com>
AuthorDate: Fri Mar 20 20:16:15 2020 -0500

    Convert proxy/logging unit tests to use Catch.
---
 proxy/logging/Makefile.am                          |  24 +----
 proxy/logging/test_LogUtils.cc                     | 104 ---------------------
 .../{test_LogUtils2.cc => test_LogUtils.cc}        |  62 ++++++++++--
 proxy/logging/unit-tests/test_LogUtils.h           |   2 +-
 4 files changed, 61 insertions(+), 131 deletions(-)

diff --git a/proxy/logging/Makefile.am b/proxy/logging/Makefile.am
index 58b6b55..b825094 100644
--- a/proxy/logging/Makefile.am
+++ b/proxy/logging/Makefile.am
@@ -69,37 +69,21 @@ liblogging_a_SOURCES = \
 
 check_PROGRAMS = \
 	test_LogUtils \
-	test_LogUtils2 \
 	test_RolledLogDeleter
 
-TESTS = \
-	test_LogUtils \
-	test_LogUtils2 \
-	test_RolledLogDeleter
+TESTS = $(check_PROGRAMS)
 
 test_LogUtils_CPPFLAGS = \
 	$(AM_CPPFLAGS) \
-	-DTEST_LOG_UTILS
-
-test_LogUtils_SOURCES = \
-	test_LogUtils.cc
-
-test_LogUtils_LDADD = \
-	$(top_builddir)/src/tscore/libtscore.la \
-	$(top_builddir)/src/tscpp/util/libtscpputil.la \
-	$(top_builddir)/iocore/eventsystem/libinkevent.a
-
-test_LogUtils2_CPPFLAGS = \
-	$(AM_CPPFLAGS) \
 	-DTEST_LOG_UTILS \
 	-I$(abs_top_srcdir)/tests/include
 
-test_LogUtils2_SOURCES = \
+test_LogUtils_SOURCES = \
 	LogUtils.cc \
 	unit-tests/BufferWriterFormat.cc \
-	unit-tests/test_LogUtils2.cc
+	unit-tests/test_LogUtils.cc
 
-test_LogUtils2_LDADD = \
+test_LogUtils_LDADD = \
 	$(top_builddir)/src/tscore/libtscore.la \
 	$(top_builddir)/src/tscpp/util/libtscpputil.la \
 	$(top_builddir)/iocore/eventsystem/libinkevent.a
diff --git a/proxy/logging/test_LogUtils.cc b/proxy/logging/test_LogUtils.cc
deleted file mode 100644
index 02b8cfe..0000000
--- a/proxy/logging/test_LogUtils.cc
+++ /dev/null
@@ -1,104 +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 "tscore/TestBox.h"
-#include "LogUtils.cc"
-#include <string.h>
-
-#if 0
-// Stub
-EThread *
-this_ethread()
-{
-  return nullptr;
-}
-#endif
-
-REGRESSION_TEST(LogUtils_pure_escapify_url)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
-{
-  TestBox box(t, pstatus);
-  box = REGRESSION_TEST_PASSED;
-
-  char input[][32] = {
-    " ",
-    "%",
-    "% ",
-    "%20",
-  };
-  const char *expected[] = {
-    "%20",
-    "%25",
-    "%25%20",
-    "%2520",
-  };
-  char output[128];
-  int output_len;
-
-  int n = sizeof(input) / sizeof(input[0]);
-  for (int i = 0; i < n; ++i) {
-    LogUtils::pure_escapify_url(NULL, input[i], strlen(input[i]), &output_len, output, 128);
-    box.check(strcmp(output, expected[i]) == 0, "expected \"%s\", was \"%s\"", expected[i], output);
-  }
-}
-
-REGRESSION_TEST(LogUtils_escapify_url)(RegressionTest *t, int /* atype ATS_UNUSED */, int *pstatus)
-{
-  TestBox box(t, pstatus);
-  box = REGRESSION_TEST_PASSED;
-
-  char input[][32] = {
-    " ",
-    "%",
-    "% ",
-    "%20",
-  };
-  const char *expected[] = {
-    "%20",
-    "%25",
-    "%25%20",
-    "%20",
-  };
-  char output[128];
-  int output_len;
-
-  int n = sizeof(input) / sizeof(input[0]);
-  for (int i = 0; i < n; ++i) {
-    LogUtils::escapify_url(NULL, input[i], strlen(input[i]), &output_len, output, 128);
-    box.check(strcmp(output, expected[i]) == 0, "expected \"%s\", was \"%s\"", expected[i], output);
-  }
-}
-
-int
-main(int argc, const char **argv)
-{
-  return RegressionTest::main(argc, argv, REGRESSION_TEST_QUICK);
-}
-
-//
-// Stub
-//
-void
-RecSignalManager(int, const char *, unsigned long)
-{
-  ink_release_assert(false);
-}
diff --git a/proxy/logging/unit-tests/test_LogUtils2.cc b/proxy/logging/unit-tests/test_LogUtils.cc
similarity index 80%
rename from proxy/logging/unit-tests/test_LogUtils2.cc
rename to proxy/logging/unit-tests/test_LogUtils.cc
index d50a89b..672aaef 100644
--- a/proxy/logging/unit-tests/test_LogUtils2.cc
+++ b/proxy/logging/unit-tests/test_LogUtils.cc
@@ -21,18 +21,22 @@
   limitations under the License.
  */
 
+#include <string_view>
+#include <cstring>
+#include <cstdlib>
+#include <iostream>
+#include <cstdio>
+
 #include <tscore/ink_assert.h>
 #include <tscore/ink_align.h>
 
 #include <LogUtils.h>
 
-#include "test_LogUtils.h"
+#include "unit-tests/test_LogUtils.h"
 
 #define CATCH_CONFIG_MAIN
 #include "catch.hpp"
 
-#include <cstring>
-
 using namespace LogUtils;
 
 namespace
@@ -115,9 +119,6 @@ TEST_CASE("LogUtilsHttp", "[LUHP]")
   test(nullptr, 0, "", 1);
 }
 
-#include <cstdlib>
-#include <iostream>
-
 void
 _ink_assert(const char *a, const char *f, int line)
 {
@@ -129,6 +130,7 @@ _ink_assert(const char *a, const char *f, int line)
 void
 RecSignalManager(int, char const *, std::size_t)
 {
+  ink_release_assert(false);
 }
 
 TEST_CASE("get_unrolled_filename parses possible log files as expected", "[get_unrolled_filename]")
@@ -153,3 +155,51 @@ TEST_CASE("get_unrolled_filename parses possible log files as expected", "[get_u
   constexpr ts::TextView no_dot = "logging_yaml";
   REQUIRE(get_unrolled_filename(no_dot) == no_dot);
 }
+
+TEST_CASE("LogUtils pure escapify url", "[pure_esc_url]")
+{
+  char input[][32] = {
+    " ",
+    "%",
+    "% ",
+    "%20",
+  };
+  const char *expected[] = {
+    "%20",
+    "%25",
+    "%25%20",
+    "%2520",
+  };
+  char output[128];
+  int output_len;
+
+  int n = sizeof(input) / sizeof(input[0]);
+  for (int i = 0; i < n; ++i) {
+    LogUtils::pure_escapify_url(NULL, input[i], std::strlen(input[i]), &output_len, output, 128);
+    CHECK(std::string_view(output) == expected[i]);
+  }
+}
+
+TEST_CASE("LogUtils escapify url", "[esc_url]")
+{
+  char input[][32] = {
+    " ",
+    "%",
+    "% ",
+    "%20",
+  };
+  const char *expected[] = {
+    "%20",
+    "%25",
+    "%25%20",
+    "%20",
+  };
+  char output[128];
+  int output_len;
+
+  int n = sizeof(input) / sizeof(input[0]);
+  for (int i = 0; i < n; ++i) {
+    LogUtils::escapify_url(NULL, input[i], std::strlen(input[i]), &output_len, output, 128);
+    CHECK(std::string_view(output) == expected[i]);
+  }
+}
diff --git a/proxy/logging/unit-tests/test_LogUtils.h b/proxy/logging/unit-tests/test_LogUtils.h
index c5b4da9..dc204a5 100644
--- a/proxy/logging/unit-tests/test_LogUtils.h
+++ b/proxy/logging/unit-tests/test_LogUtils.h
@@ -1,6 +1,6 @@
 /** @file
 
-  Header file for shared declarations/definitions for test_LogUtils2.cc and LogUtils.h for unit testing.
+  Header file for shared declarations/definitions for test_LogUtils.cc and LogUtils.h for unit testing.
 
   @section license License