]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testConfigParser.cc
1 #define SQUID_UNIT_TEST 1
4 #include "testConfigParser.h"
5 #include "SquidString.h"
8 #include "ConfigParser.h"
10 CPPUNIT_TEST_SUITE_REGISTRATION( testConfigParser
);
12 /* let this test link sanely */
14 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
17 void testConfigParser::setUp()
21 bool testConfigParser::doParseQuotedTest(const char *s
, const char *expectInterp
)
25 snprintf(cfgline
, 2048, "Config %s", s
);
27 // Points to the start of quoted string
28 const char *tmp
= strchr(cfgline
, ' ');
31 fprintf(stderr
, "Invalid config line: %s\n", s
);
34 // Keep the initial value on cfgparam. The ConfigParser methods will write on cfgline
35 strcpy(cfgparam
, tmp
+1);
37 // Initialize parser to point to the start of quoted string
38 strtok(cfgline
, w_space
);
40 ConfigParser::ParseQuotedString(&unEscaped
);
42 const bool interpOk
= (unEscaped
.cmp(expectInterp
) == 0);
44 printf("%25s: %s\n%25s: %s\n%25s: %s\n",
45 "Raw configuration", cfgparam
,
46 "Expected interpretation", expectInterp
,
47 "Actual interpretation", unEscaped
.termedBuf());
50 const char *quoted
= ConfigParser::QuoteString(unEscaped
);
51 bool quotedOk
= (strcmp(cfgparam
, quoted
)==0);
53 printf("%25s: %s\n%25s: %s\n%25s: %s\n",
54 "Raw configuration", cfgparam
,
55 "Parsed and quoted", quoted
,
56 "parsed value was", unEscaped
.termedBuf());
59 return quotedOk
&& interpOk
;
62 void testConfigParser::testParseQuoted()
65 CPPUNIT_ASSERT(doParseQuotedTest("SingleToken", "SingleToken"));
67 // This is a quoted "string" by me
68 CPPUNIT_ASSERT(doParseQuotedTest("\"This is a quoted \\\"string\\\" by me\"",
69 "This is a quoted \"string\" by me"));
71 // escape sequence test: \\"\"\\"
72 CPPUNIT_ASSERT(doParseQuotedTest("\"escape sequence test: \\\\\\\\\\\"\\\\\\\"\\\\\\\\\\\"\"",
73 "escape sequence test: \\\\\"\\\"\\\\\""));
75 // \beginning and end test"
76 CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\beginning and end test\\\"\"",
77 "\\beginning and end test\""));
80 CPPUNIT_ASSERT(doParseQuotedTest("\"\\\"\"", "\""));
83 CPPUNIT_ASSERT(doParseQuotedTest("\"\\\\\"", "\\"));