]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testConfigParser.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "ConfigParser.h"
12 #include "SquidString.h"
13 #include "testConfigParser.h"
14 #include "unitTestMain.h"
16 CPPUNIT_TEST_SUITE_REGISTRATION( testConfigParser
);
18 /* let this test link sanely */
20 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
23 void testConfigParser::setUp()
27 bool testConfigParser::doParseQuotedTest(const char *s
, const char *expectInterp
)
31 snprintf(cfgline
, 2048, "%s", s
);
33 // Keep the initial value on cfgparam. The ConfigParser methods will write on cfgline
34 strncpy(cfgparam
, cfgline
, sizeof(cfgparam
)-1);
35 cfgparam
[sizeof(cfgparam
)-1] = '\0';
37 // Initialize parser to point to the start of quoted string
38 ConfigParser::SetCfgLine(cfgline
);
39 String unEscaped
= ConfigParser::NextToken();
41 const bool interpOk
= (unEscaped
.cmp(expectInterp
) == 0);
43 printf("%25s: %s\n%25s: %s\n%25s: %s\n",
44 "Raw configuration", cfgparam
,
45 "Expected interpretation", expectInterp
,
46 "Actual interpretation", unEscaped
.termedBuf());
49 const char *quoted
= ConfigParser::QuoteString(unEscaped
);
50 bool quotedOk
= (strcmp(cfgparam
, quoted
)==0);
52 printf("%25s: %s\n%25s: %s\n%25s: %s\n",
53 "Raw configuration", cfgparam
,
54 "Parsed and quoted", quoted
,
55 "parsed value was", unEscaped
.termedBuf());
58 return quotedOk
&& interpOk
;
61 void testConfigParser::testParseQuoted()
64 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("SingleToken", "SingleToken"));
66 // This is a quoted "string" by me
67 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"This is a quoted \\\"string\\\" by me\"",
68 "This is a quoted \"string\" by me"));
70 // escape sequence test: \\"\"\\"
71 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"escape sequence test: \\\\\\\\\\\"\\\\\\\"\\\\\\\\\\\"\"",
72 "escape sequence test: \\\\\"\\\"\\\\\""));
74 // \beginning and end test"
75 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\\beginning and end test\\\"\"",
76 "\\beginning and end test\""));
79 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\"\"", "\""));
82 CPPUNIT_ASSERT_EQUAL(true, doParseQuotedTest("\"\\\\\"", "\\"));