void Test::test_scanContentType_basic()
{
OUString input
= u"TEST/subTST; parm1=Value1; Parm2=\"unpacked value; %20\""_ustr; // Just scan input for valid string: auto end = INetMIME::scanContentType(input);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end)); // Scan input and parse type, subType and parameters:
OUString type;
OUString subType;
INetContentTypeParameterList parameters;
end = INetMIME::scanContentType(input,
&type, &subType, ¶meters);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
CPPUNIT_ASSERT_EQUAL(u"test"_ustr, type);
CPPUNIT_ASSERT_EQUAL(u"subtst"_ustr, subType);
CPPUNIT_ASSERT_EQUAL(
INetContentTypeParameterList::size_type(2), parameters.size()); auto i = parameters.find("parm1"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sLanguage);
CPPUNIT_ASSERT_EQUAL(u"Value1"_ustr, i->second.m_sValue);
CPPUNIT_ASSERT(i->second.m_bConverted);
i = parameters.find("parm2"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sLanguage);
CPPUNIT_ASSERT_EQUAL(u"unpacked value; %20"_ustr, i->second.m_sValue);
CPPUNIT_ASSERT(i->second.m_bConverted);
}
void Test::test_scanContentType_rfc2231()
{ // Test extended parameter with value split in 3 sections:
OUString input
= u"TEST/subTST; " "parm1*0*=US-ASCII'En'5%25%20; " "Parm1*1*=of%2010;\t" "parm1*2*=%20%3d%200.5"_ustr; // Just scan input for valid string: auto end = INetMIME::scanContentType(input);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end)); // Scan input and parse type, subType and parameters:
OUString type;
OUString subType;
INetContentTypeParameterList parameters;
end = INetMIME::scanContentType(input,
&type, &subType, ¶meters);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
CPPUNIT_ASSERT_EQUAL(u"test"_ustr, type);
CPPUNIT_ASSERT_EQUAL(u"subtst"_ustr, subType);
CPPUNIT_ASSERT_EQUAL(
INetContentTypeParameterList::size_type(1), parameters.size()); auto i = parameters.find("parm1"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL("us-ascii"_ostr, i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL("en"_ostr, i->second.m_sLanguage);
CPPUNIT_ASSERT_EQUAL(u"5% of 10 = 0.5"_ustr, i->second.m_sValue);
CPPUNIT_ASSERT(i->second.m_bConverted);
// Test extended parameters with different value charsets:
input = "TEST/subTST;" "parm1*0*=us-ascii'en'value;PARM1*1*=1;" "parm2*0*=WINDOWS-1250'en-GB'value2%20%80;" "parm3*0*=UNKNOWN'EN'value3;" "parm1*1*=2"; // this parameter is a duplicate, // the scan should end before this parameter // Just scan input for valid string:
end = INetMIME::scanContentType(input);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(u";parm1*1*=2"_ustr, OUString(end)); // the invalid end of input // Scan input and parse type, subType and parameters:
end = INetMIME::scanContentType(input,
&type, &subType, ¶meters);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(u";parm1*1*=2"_ustr, OUString(end)); // the invalid end of input
CPPUNIT_ASSERT_EQUAL(u"test"_ustr, type);
CPPUNIT_ASSERT_EQUAL(u"subtst"_ustr, subType);
CPPUNIT_ASSERT_EQUAL(
INetContentTypeParameterList::size_type(3), parameters.size());
i = parameters.find("parm1"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL("us-ascii"_ostr, i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL("en"_ostr, i->second.m_sLanguage);
CPPUNIT_ASSERT_EQUAL(u"value1"_ustr, i->second.m_sValue);
CPPUNIT_ASSERT(i->second.m_bConverted);
i = parameters.find("parm2"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL("windows-1250"_ostr, i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL("en-gb"_ostr, i->second.m_sLanguage); // Euro currency sign, windows-1250 x80 is converted to unicode u20AC:
CPPUNIT_ASSERT_EQUAL(u"value2 \u20AC"_ustr, i->second.m_sValue);
CPPUNIT_ASSERT(i->second.m_bConverted);
i = parameters.find("parm3"_ostr);
CPPUNIT_ASSERT(i != parameters.end());
CPPUNIT_ASSERT_EQUAL("unknown"_ostr, i->second.m_sCharset);
CPPUNIT_ASSERT_EQUAL("en"_ostr, i->second.m_sLanguage); // Conversion fails for unknown charsets:
CPPUNIT_ASSERT(!i->second.m_bConverted);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.