]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testConfigParser.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testConfigParser.cc
index 2ac31e67d1ffc2178b587b6511c887ed509b1a09..1d8ffc82d83576469f17f76f2622b016279d6595 100644 (file)
@@ -1,10 +1,17 @@
-#define SQUID_UNIT_TEST 1
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
-#include "testConfigParser.h"
-#include "SquidString.h"
-#include "Mem.h"
-#include "event.h"
 #include "ConfigParser.h"
+#include "event.h"
+#include "SquidString.h"
+#include "testConfigParser.h"
+#include "unitTestMain.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testConfigParser);
 
@@ -21,24 +28,15 @@ bool testConfigParser::doParseQuotedTest(const char *s, const char *expectInterp
 {
     char cfgline[2048];
     char cfgparam[2048];
-    snprintf(cfgline, 2048, "Config %s", s);
-
-    // Points to the start of quoted string
-    const char *tmp = strchr(cfgline, ' ');
-
-    if (tmp == NULL) {
-        fprintf(stderr, "Invalid config line: %s\n", s);
-        return false;
-    }
+    snprintf(cfgline, 2048, "%s", s);
 
     // Keep the initial value on cfgparam. The ConfigParser  methods will write on cfgline
-    strncpy(cfgparam, tmp+1, sizeof(cfgparam)-1);
+    strncpy(cfgparam, cfgline, sizeof(cfgparam)-1);
     cfgparam[sizeof(cfgparam)-1] = '\0';
 
     // Initialize parser to point to the start of quoted string
-    strtok(cfgline, w_space);
-    String unEscaped;
-    ConfigParser::ParseQuotedString(&unEscaped);
+    ConfigParser::SetCfgLine(cfgline);
+    String unEscaped = ConfigParser::NextToken();
 
     const bool interpOk = (unEscaped.cmp(expectInterp) == 0);
     if (!interpOk) {
@@ -63,24 +61,24 @@ bool testConfigParser::doParseQuotedTest(const char *s, const char *expectInterp
 void testConfigParser::testParseQuoted()
 {
     // SingleToken
-    CPPUNIT_ASSERT(doParseQuotedTest("SingleToken", "SingleToken"));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("SingleToken", "SingleToken"));
 
     // This is a quoted "string" by me
-    CPPUNIT_ASSERT(doParseQuotedTest("\"This is a quoted \\\"string\\\" by me\"",
-                                     "This is a quoted \"string\" by me"));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"This is a quoted \\\"string\\\" by me\"",
+                         "This is a quoted \"string\" by me"));
 
     // escape sequence test: \\"\"\\"
-    CPPUNIT_ASSERT(doParseQuotedTest("\"escape sequence test: \\\\\\\\\\\"\\\\\\\"\\\\\\\\\\\"\"",
-                                     "escape sequence test: \\\\\"\\\"\\\\\""));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"escape sequence test: \\\\\\\\\\\"\\\\\\\"\\\\\\\\\\\"\"",
+                         "escape sequence test: \\\\\"\\\"\\\\\""));
 
     // \beginning and end test"
-    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\beginning and end test\\\"\"",
-                                     "\\beginning and end test\""));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\\beginning and end test\\\"\"",
+                         "\\beginning and end test\""));
 
     // "
-    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\"\"", "\""));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\"\"", "\""));
 
     /* \ */
-    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\\"", "\\"));
+    CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\\\"", "\\"));
 }