]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
adaptation_meta option
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Fri, 28 Oct 2011 20:08:24 +0000 (23:08 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Fri, 28 Oct 2011 20:08:24 +0000 (23:08 +0300)
add missing src/tests/testConfigParser[.h,.cc] files

src/tests/testConfigParser.cc [new file with mode: 0644]
src/tests/testConfigParser.h [new file with mode: 0644]

diff --git a/src/tests/testConfigParser.cc b/src/tests/testConfigParser.cc
new file mode 100644 (file)
index 0000000..9bea047
--- /dev/null
@@ -0,0 +1,85 @@
+#define SQUID_UNIT_TEST 1
+#include "config.h"
+
+#include "testConfigParser.h"
+#include "SquidString.h"
+#include "Mem.h"
+#include "event.h"
+#include "ConfigParser.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION( testConfigParser);
+
+/* let this test link sanely */
+void
+eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
+{}
+
+void testConfigParser::setUp()
+{
+}
+
+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;
+    }
+    // Keep the initial value on cfgparam. The ConfigParser  methods will write on cfgline
+    strcpy(cfgparam, tmp+1);
+
+    // Initialize parser to point to the start of quoted string
+    strtok(cfgline, w_space);
+    String unEscaped;
+    ConfigParser::ParseQuotedString(&unEscaped);
+    
+    const bool interpOk = (unEscaped.cmp(expectInterp) == 0);
+    if (!interpOk) {
+        printf("%25s: %s\n%25s: %s\n%25s: %s\n",
+               "Raw configuration", cfgparam,
+               "Expected interpretation", expectInterp,
+               "Actual interpretation", unEscaped.termedBuf());
+    }
+
+    const char *quoted = ConfigParser::QuoteString(unEscaped);
+    bool quotedOk = (strcmp(cfgparam, quoted)==0);
+    if (!quotedOk) {
+        printf("%25s: %s\n%25s: %s\n%25s: %s\n",
+               "Raw configuration", cfgparam,
+               "Parsed and quoted", quoted,
+               "parsed value was", unEscaped.termedBuf());
+    }
+
+    return quotedOk && interpOk ;
+}
+
+void testConfigParser::testParseQuoted()
+{
+    // SingleToken
+    CPPUNIT_ASSERT(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"));
+
+    // escape sequence test: \\"\"\\"
+    CPPUNIT_ASSERT(doParseQuotedTest("\"escape sequence test: \\\\\\\\\\\"\\\\\\\"\\\\\\\\\\\"\"", 
+                                     "escape sequence test: \\\\\"\\\"\\\\\""));
+    
+    // \beginning and end test"
+    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\beginning and end test\\\"\"",
+                                     "\\beginning and end test\""));
+
+    // "
+    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\"\"", "\""));
+
+    /* \ */
+    CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\\"", "\\"));
+}
+
diff --git a/src/tests/testConfigParser.h b/src/tests/testConfigParser.h
new file mode 100644 (file)
index 0000000..e36c047
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef SQUID_SRC_TEST_CONFIG_PARSER_H
+#define SQUID_SRC_TEST_CONFIG_PARSER_H
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/*
+ * test the ConfigParser framework
+ */
+
+class testConfigParser : public CPPUNIT_NS::TestFixture
+{
+    CPPUNIT_TEST_SUITE( testConfigParser );
+    CPPUNIT_TEST( testParseQuoted );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+    void setUp();
+
+protected:
+    bool doParseQuotedTest(const char *, const char *);
+    void testParseQuoted();
+};
+
+#endif