void HTTPPostRequestBodyParserTest::ReadMultiPartPost() { StartTrace(HTTPPostRequestBodyParserTest.ReadMultiPartPost); std::iostream *is = coast::system::OpenStream("MultiPartBody.txt", 0); t_assertm(is != 0, "expected 'MultiPartBody.txt' to be there"); if ( is ) { MIMEHeader mh; t_assertm(mh.ParseHeaders(*is, 4096, 4096), "expected global header parsing to succeed"); assertEqual(586L, mh.GetParsedHeaderLength()); HTTPPostRequestBodyParser sm(mh); t_assert(sm.Parse(*is)); Anything expected; Anything result = sm.GetContent(); delete is; t_assert(!GetConfig().IsNull()); assertAnyEqual(GetConfig()["MultiPartResult"], result); } // This sequence takes advantage of the String::SubString // feature to return the whole remainder of the string starting // from the first occurrence the substring-pattern has been found. // This relieves us from the need to create an expected result file // which we would use to verify the results. is = coast::system::OpenStream("MultiPartBody.txt", 0); if ( is ) { MIMEHeader mh; t_assertm(mh.ParseHeaders(*is, 4096, 4096), "expected global header parsing to succeed"); assertEqual(586L, mh.GetParsedHeaderLength()); HTTPPostRequestBodyParser sm(mh); t_assert(sm.Parse(*is)); String unparsedContent = sm.GetUnparsedContent(); delete is; is = coast::system::OpenStream("MultiPartBody.txt", 0); if (is) { char c; String tmp; while ((!!(*is).get(c))) { tmp.Append(c); } String final; final = tmp.SubString(unparsedContent); assertEqual(final, unparsedContent); delete is; } }