11 #include <cppunit/TestAssert.h>
13 #define private public
14 #define protected public
29 static bool setup_done =
false;
54 #ifdef SQUID_DEBUG_TESTS
75 Replace(raw,
SBuf(
"\r"),
SBuf(
"\\r"));
76 Replace(raw,
SBuf(
"\n"),
SBuf(
"\\n"));
84 #ifdef SQUID_DEBUG_TESTS
85 std::cerr <<
"TEST @" << line <<
", in=" << Pretty(input) <<
"\n";
90 const bool parsed = output.
parse(input);
92 #ifdef SQUID_DEBUG_TESTS
93 if (expect.
parsed != parsed)
94 std::cerr <<
"\tparse-FAILED: " << expect.
parsed <<
"!=" << parsed <<
"\n";
96 std::cerr <<
"\tmethod-FAILED: " << expect.
method <<
"!=" << output.
method_ <<
"\n";
100 std::cerr <<
"\tsuffixSz-FAILED: " << expect.
suffixSz <<
"!=" << output.
buf_.
length() <<
"\n";
104 CPPUNIT_ASSERT_EQUAL(expect.
parsed, parsed);
110 CPPUNIT_ASSERT_EQUAL(0, output.
uri_.
cmp(expect.
uri));
166 input.
append(
"GET /\r\n", 7);
184 input.
append(
"POST /\r\n", 8);
190 .suffixSz = input.
length(),
202 input.
append(
"GET / HTTP/1.0\r\n", 16);
220 input.
append(
"GET / HTTP/1.1\r\n", 16);
238 input.
append(
"GET / HTTP/1.2\r\n", 16);
258 input.
append(
"GET / HTTP/2.0\r\n", 16);
273 input.
append(
"GET / HTTP/9.9\r\n", 16);
291 input.
append(
"GET / HTTP/10.12\r\n", 18);
297 .suffixSz = input.
length(),
309 input.
append(
"GET / FOO/1.0\r\n", 15);
315 .suffixSz = input.
length(),
327 input.
append(
"GET / HTTP/\r\n", 13);
333 .suffixSz = input.
length(),
345 input.
append(
"GET / HTTP/.1\r\n", 15);
351 .suffixSz = input.
length(),
363 input.
append(
"GET / HTTP/11\r\n", 15);
369 .suffixSz = input.
length(),
381 input.
append(
"GET / HTTP/-999999.1\r\n", 22);
387 .suffixSz = input.
length(),
399 input.
append(
"GET / HTTP/1.\r\n", 15);
405 .suffixSz = input.
length(),
417 input.
append(
"GET / HTTP/1.-999999\r\n", 22);
423 .suffixSz = input.
length(),
445 input.
append(
"GET / HTTP/1.1\r\n", 21);
467 .suffixSz = input.
length(),
473 testResults(__LINE__, input, output, expectStrict);
479 input.
append(
"GET /fo o/ HTTP/1.1\r\n", 21);
500 .suffixSz = input.
length(),
506 testResults(__LINE__, input, output, expectStrict);
512 input.
append(
"GET / HTTP/1.1\r\nboo!", 20);
542 input.
append(
"GET / HTTP/1.1\n", 15);
563 .suffixSz = input.
length(),
569 testResults(__LINE__, input, output, expectStrict);
577 input.
append(
"GET / HTTP/1.1\n\n", 16);
598 .suffixSz = input.
length(),
604 testResults(__LINE__, input, output, expectStrict);
611 input.
append(
"GET / HTTP/1.1 \r\n", 17);
617 .suffixSz = input.
length(),
639 input.
append(
". / HTTP/1.1\r\n", 14);
657 input.
append(
"!#$%&'*+-.^_`|~ / HTTP/1.1\r\n", 28);
675 input.
append(
"OPTIONS * HTTP/1.1\r\n", 20);
693 input.
append(
"HELLOWORLD / HTTP/1.1\r\n", 23);
717 .suffixSz = input.
length(),
734 .suffixSz = input.
length(),
746 input.
append(
" GET / HTTP/1.1\r\n", 17);
752 .suffixSz = input.
length(),
764 input.
append(
"\r\n\r\n\nGET / HTTP/1.1\r\n", 21);
785 .suffixSz = input.
length(),
791 testResults(__LINE__, input, output, expectStrict);
797 input.
append(
"\tGET / HTTP/1.1\r\n", 17);
803 .suffixSz = input.
length(),
816 input.
append(
"GET\r / HTTP/1.1\r\n", 17);
837 .suffixSz = input.
length(),
843 testResults(__LINE__, input, output, expectStrict);
850 input.
append(
"GET\r\t\x0B\x0C / HTTP/1.1\r\n", 20);
871 .suffixSz = input.
length(),
877 testResults(__LINE__, input, output, expectStrict);
894 input.
append(
"/ HTTP/1.0\n", 11);
900 .suffixSz = input.
length(),
912 input.
append(
" / HTTP/1.0\n", 12);
918 .suffixSz = input.
length(),
924 testResults(__LINE__, input, output, expectStrict);
930 input.
append(
"GET\x16 / HTTP/1.1\r\n", 17);
936 .suffixSz = input.
length(),
948 input.
append(
"GET\0 / HTTP/1.1\r\n", 17);
954 .suffixSz = input.
length(),
967 input.
append(
"GET HTTP/1.1\r\n", 15);
974 .suffixSz = input.
length(),
988 .suffixSz = input.
length(),
994 testResults(__LINE__, input, output, expectStrict);
1001 input.
append(
"GET HTTP/1.1\r\n", 14);
1007 .suffixSz = input.
length(),
1019 input.
append(
"\xB\xC\xE\xF\n", 5);
1025 .suffixSz = input.
length(),
1037 input.
append(
"\t \t \t\n", 6);
1043 .suffixSz = input.
length(),
1055 input.
append(
"\r \t \n", 6);
1061 .suffixSz = input.
length(),
1080 data.
append(
"\n\n\n\n\n\n\n\n\n\n\n\n", 12);
1083 data.
append(
"http://example.com/ ", 20);
1084 data.
append(
"HTTP/1.1\r\n", 10);
1086 data.
append(
"Host: example.com\r\n\r\n", 21);
1129 if (pos == garbageEnd)
1133 if (pos >= garbageEnd)
1138 if (pos == reqLineEnd) {
1143 expect.
uri =
"http://example.com/";
1149 if (pos == mimeEnd) {