]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tests/testConfigParser.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / tests / testConfigParser.cc
index b17fd7a4d8927402ac1b3453c7af054c368ec115..1d8ffc82d83576469f17f76f2622b016279d6595 100644 (file)
@@ -1,11 +1,17 @@
-#define SQUID_UNIT_TEST 1
-#include "squid.h"
+/*
+ * 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 "testConfigParser.h"
-#include "SquidString.h"
-#include "Mem.h"
-#include "event.h"
+#include "squid.h"
 #include "ConfigParser.h"
+#include "event.h"
+#include "SquidString.h"
+#include "testConfigParser.h"
+#include "unitTestMain.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testConfigParser);
 
@@ -22,22 +28,15 @@ bool testConfigParser::doParseQuotedTest(const char *s, const char *expectInterp
 {
     char cfgline[2048];
     char cfgparam[2048];
-    snprintf(cfgline, 2048, "Config %s", s);
+    snprintf(cfgline, 2048, "%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;
-    }
     // Keep the initial value on cfgparam. The ConfigParser  methods will write on cfgline
-    strcpy(cfgparam, tmp+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) {
@@ -62,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("\"\\\\\"", "\\"));
 }