summaryrefslogtreecommitdiff
path: root/tools/qa
diff options
context:
space:
mode:
authorJochen Nitschke <j.nitschke+logerrit@ok.de>2017-04-18 15:23:56 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-04-26 09:16:19 +0200
commitbef9fe6e3decc92bdcec6415b1898e4a0202cc6a (patch)
tree60283844882d4be3c2ad70081c7271123de07a93 /tools/qa
parent925ed7003b827cd4678547fb762aa002c3a10421 (diff)
extend unit test for INetMIME::scanContentType
This reverts parts of commit 631b67952909a73ba1851417bd2edbe02ad7be5a and commit abc6071b7a8af354a56c91e4caecd8afc79f55cc. some of the removed fields are usefull, m_bConverted should be checked by callers fixed 2 bugs and added test cases: * extended attributes with more than 2 sections were not parsed * extended attributes with more than 1 section were not parsed if there was an other attribute Change-Id: I61ab2af7c5151ef1bcd80cc159fa2b99559374a8 Reviewed-on: https://gerrit.libreoffice.org/36913 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'tools/qa')
-rw-r--r--tools/qa/cppunit/test_inetmime.cxx103
1 files changed, 95 insertions, 8 deletions
diff --git a/tools/qa/cppunit/test_inetmime.cxx b/tools/qa/cppunit/test_inetmime.cxx
index 1a5d16b5aba6..8b953526778c 100644
--- a/tools/qa/cppunit/test_inetmime.cxx
+++ b/tools/qa/cppunit/test_inetmime.cxx
@@ -35,11 +35,13 @@ namespace
public:
void test_decodeHeaderFieldBody();
- void test_scanContentType();
+ void test_scanContentType_basic();
+ void test_scanContentType_rfc2231();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test_decodeHeaderFieldBody);
- CPPUNIT_TEST(test_scanContentType);
+ CPPUNIT_TEST(test_scanContentType_basic);
+ CPPUNIT_TEST(test_scanContentType_rfc2231);
CPPUNIT_TEST_SUITE_END();
};
@@ -56,17 +58,61 @@ namespace
CPPUNIT_ASSERT(testDecode("=?iso-8859-1?B?QUJD?=", "ABC"));
}
- void Test::test_scanContentType()
+ void Test::test_scanContentType_basic()
{
{
OUString input
- = "TEST/subTST; parm1*0*=US-ASCII'En'5%25%20; Parm1*1*=of%2010";
+ = "TEST/subTST; parm1=Value1; Parm2=\"unpacked value; %20\"";
+ // Just scan input for valid string:
+ auto end = INetMIME::scanContentType(input.getStr(), input.getStr()+input.getLength());
+ 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.getStr(), input.getStr() + input.getLength(),
+ &type, &subType, &parameters);
+ CPPUNIT_ASSERT(end != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+ CPPUNIT_ASSERT_EQUAL(OUString("test"), type);
+ CPPUNIT_ASSERT_EQUAL(OUString("subtst"), subType);
+ CPPUNIT_ASSERT_EQUAL(
+ INetContentTypeParameterList::size_type(2), parameters.size());
+ auto i = parameters.find("parm1");
+ CPPUNIT_ASSERT(i != parameters.end());
+ CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sLanguage);
+ CPPUNIT_ASSERT_EQUAL(OUString("Value1"), i->second.m_sValue);
+ CPPUNIT_ASSERT(i->second.m_bConverted);
+ i = parameters.find("parm2");
+ CPPUNIT_ASSERT(i != parameters.end());
+ CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sLanguage);
+ CPPUNIT_ASSERT_EQUAL(OUString("unpacked value; %20"), 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
+ = "TEST/subTST; "
+ "parm1*0*=US-ASCII'En'5%25%20; "
+ "Parm1*1*=of%2010;\t"
+ "parm1*2*=%20%3d%200.5";
+ // Just scan input for valid string:
+ auto end = INetMIME::scanContentType(input.getStr(), input.getStr()+input.getLength());
+ CPPUNIT_ASSERT(end != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+ // Scan input and parse type, subType and parameters:
OUString type;
OUString subType;
INetContentTypeParameterList parameters;
- auto end = INetMIME::scanContentType(
- input.getStr(), input.getStr() + input.getLength(), &type,
- &subType, &parameters);
+ end = INetMIME::scanContentType(input.getStr(), input.getStr() + input.getLength(),
+ &type, &subType, &parameters);
CPPUNIT_ASSERT(end != nullptr);
CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
CPPUNIT_ASSERT_EQUAL(OUString("test"), type);
@@ -75,7 +121,48 @@ namespace
INetContentTypeParameterList::size_type(1), parameters.size());
auto i = parameters.find("parm1");
CPPUNIT_ASSERT(i != parameters.end());
- CPPUNIT_ASSERT_EQUAL(OUString("5% of 10"), i->second.m_sValue);
+ CPPUNIT_ASSERT_EQUAL(OString("us-ascii"), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString("en"), i->second.m_sLanguage);
+ CPPUNIT_ASSERT_EQUAL(OUString("5% of 10 = 0.5"), 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";
+ // Just scan input for valid string:
+ end = INetMIME::scanContentType(input.getStr(), input.getStr()+input.getLength());
+ CPPUNIT_ASSERT(end != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+ // Scan input and parse type, subType and parameters:
+ end = INetMIME::scanContentType(input.getStr(), input.getStr() + input.getLength(),
+ &type, &subType, &parameters);
+ CPPUNIT_ASSERT(end != nullptr);
+ CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+ CPPUNIT_ASSERT_EQUAL(OUString("test"), type);
+ CPPUNIT_ASSERT_EQUAL(OUString("subtst"), subType);
+ CPPUNIT_ASSERT_EQUAL(
+ INetContentTypeParameterList::size_type(3), parameters.size());
+ i = parameters.find("parm1");
+ CPPUNIT_ASSERT(i != parameters.end());
+ CPPUNIT_ASSERT_EQUAL(OString("us-ascii"), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString("en"), i->second.m_sLanguage);
+ CPPUNIT_ASSERT_EQUAL(OUString("value1"), i->second.m_sValue);
+ CPPUNIT_ASSERT(i->second.m_bConverted);
+ i = parameters.find("parm2");
+ CPPUNIT_ASSERT(i != parameters.end());
+ CPPUNIT_ASSERT_EQUAL(OString("windows-1250"), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString("en-gb"), i->second.m_sLanguage);
+ // Euro currency sign, windows-1250 x80 is converted to unicode u20AC:
+ CPPUNIT_ASSERT_EQUAL(OUString(u"value2 \u20AC"), i->second.m_sValue);
+ CPPUNIT_ASSERT(i->second.m_bConverted);
+ i = parameters.find("parm3");
+ CPPUNIT_ASSERT(i != parameters.end());
+ CPPUNIT_ASSERT_EQUAL(OString("unknown"), i->second.m_sCharset);
+ CPPUNIT_ASSERT_EQUAL(OString("en"), i->second.m_sLanguage);
+ // Convertion fails for unknown charsets:
+ CPPUNIT_ASSERT(!i->second.m_bConverted);
}
}