Added and moved tests for RFC-2231.
This commit is contained in:
parent
bff027cfa0
commit
be8daf3f8e
@ -32,7 +32,9 @@ VMIME_TEST_SUITE_BEGIN
|
|||||||
|
|
||||||
VMIME_TEST_LIST_BEGIN
|
VMIME_TEST_LIST_BEGIN
|
||||||
VMIME_TEST(testParse)
|
VMIME_TEST(testParse)
|
||||||
|
VMIME_TEST(testParseRFC2231)
|
||||||
VMIME_TEST(testGenerate)
|
VMIME_TEST(testGenerate)
|
||||||
|
VMIME_TEST(testGenerateRFC2231)
|
||||||
VMIME_TEST(testNonStandardEncodedParam)
|
VMIME_TEST(testNonStandardEncodedParam)
|
||||||
VMIME_TEST_LIST_END
|
VMIME_TEST_LIST_END
|
||||||
|
|
||||||
@ -134,57 +136,60 @@ VMIME_TEST_SUITE_BEGIN
|
|||||||
VASSERT_EQ("7.1", 1, p7.getParameterCount());
|
VASSERT_EQ("7.1", 1, p7.getParameterCount());
|
||||||
VASSERT_EQ("7.2", "param1", PARAM_NAME(p7, 0));
|
VASSERT_EQ("7.2", "param1", PARAM_NAME(p7, 0));
|
||||||
VASSERT_EQ("7.3", "this is a slash: \"\\\"", PARAM_VALUE(p7, 0));
|
VASSERT_EQ("7.3", "this is a slash: \"\\\"", PARAM_VALUE(p7, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void testParseRFC2231()
|
||||||
|
{
|
||||||
// Extended parameter with charset specified in more than one
|
// Extended parameter with charset specified in more than one
|
||||||
// section (this is forbidden by RFC, but is should not fail)
|
// section (this is forbidden by RFC, but is should not fail)
|
||||||
parameterizedHeaderField p8;
|
parameterizedHeaderField p1;
|
||||||
p8.parse("X; param1*0*=charset1'language1'value1;\r\n"
|
p1.parse("X; param1*0*=charset1'language1'value1;\r\n"
|
||||||
" param1*1*=charset2'language2'value2;");
|
" param1*1*=charset2'language2'value2;");
|
||||||
|
|
||||||
VASSERT_EQ("8.1", 1, p8.getParameterCount());
|
VASSERT_EQ("1.1", 1, p1.getParameterCount());
|
||||||
VASSERT_EQ("8.2", "param1", PARAM_NAME(p8, 0));
|
VASSERT_EQ("1.2", "param1", PARAM_NAME(p1, 0));
|
||||||
VASSERT_EQ("8.3", "charset1", PARAM_CHARSET(p8, 0));
|
VASSERT_EQ("1.3", "charset1", PARAM_CHARSET(p1, 0));
|
||||||
VASSERT_EQ("8.4", "value1charset2'language2'value2", PARAM_BUFFER(p8, 0));
|
VASSERT_EQ("1.4", "value1charset2'language2'value2", PARAM_BUFFER(p1, 0));
|
||||||
|
|
||||||
// Charset not specified in the first section (that is not encoded),
|
// Charset not specified in the first section (that is not encoded),
|
||||||
// but specified in the second one (legal)
|
// but specified in the second one (legal)
|
||||||
parameterizedHeaderField p9;
|
parameterizedHeaderField p2;
|
||||||
p9.parse("X; param1*0=value1;\r\n"
|
p2.parse("X; param1*0=value1;\r\n"
|
||||||
" param1*1*=charset'language'value2;");
|
" param1*1*=charset'language'value2;");
|
||||||
|
|
||||||
VASSERT_EQ("9.1", 1, p9.getParameterCount());
|
VASSERT_EQ("2.1", 1, p2.getParameterCount());
|
||||||
VASSERT_EQ("9.2", "param1", PARAM_NAME(p9, 0));
|
VASSERT_EQ("2.2", "param1", PARAM_NAME(p2, 0));
|
||||||
VASSERT_EQ("9.3", "charset", PARAM_CHARSET(p9, 0));
|
VASSERT_EQ("2.3", "charset", PARAM_CHARSET(p2, 0));
|
||||||
VASSERT_EQ("9.4", "value1value2", PARAM_BUFFER(p9, 0));
|
VASSERT_EQ("2.4", "value1value2", PARAM_BUFFER(p2, 0));
|
||||||
|
|
||||||
// Characters prefixed with '%' in a simple (not extended) section
|
// Characters prefixed with '%' in a simple (not extended) section
|
||||||
// should not be decoded
|
// should not be decoded
|
||||||
parameterizedHeaderField p10;
|
parameterizedHeaderField p3;
|
||||||
p10.parse("X; param1=val%20ue1");
|
p3.parse("X; param1=val%20ue1");
|
||||||
|
|
||||||
VASSERT_EQ("10.1", 1, p10.getParameterCount());
|
VASSERT_EQ("3.1", 1, p3.getParameterCount());
|
||||||
VASSERT_EQ("10.2", "param1", PARAM_NAME(p10, 0));
|
VASSERT_EQ("3.2", "param1", PARAM_NAME(p3, 0));
|
||||||
VASSERT_EQ("10.3", "val%20ue1", PARAM_VALUE(p10, 0));
|
VASSERT_EQ("3.3", "val%20ue1", PARAM_VALUE(p3, 0));
|
||||||
|
|
||||||
// Multiple sections + charset specified and encoding
|
// Multiple sections + charset specified and encoding
|
||||||
parameterizedHeaderField p11;
|
parameterizedHeaderField p4;
|
||||||
p11.parse("X; param1*0*=charset'language'value1a%20;"
|
p4.parse("X; param1*0*=charset'language'value1a%20;"
|
||||||
" param1*1*=value1b%20;"
|
" param1*1*=value1b%20;"
|
||||||
" param1*2=value1c");
|
" param1*2=value1c");
|
||||||
|
|
||||||
VASSERT_EQ("11.1", 1, p11.getParameterCount());
|
VASSERT_EQ("4.1", 1, p4.getParameterCount());
|
||||||
VASSERT_EQ("11.2", "param1", PARAM_NAME(p11, 0));
|
VASSERT_EQ("4.2", "param1", PARAM_NAME(p4, 0));
|
||||||
VASSERT_EQ("11.3", "charset", PARAM_CHARSET(p11, 0));
|
VASSERT_EQ("4.3", "charset", PARAM_CHARSET(p4, 0));
|
||||||
VASSERT_EQ("11.4", "value1a value1b value1c", PARAM_BUFFER(p11, 0));
|
VASSERT_EQ("4.4", "value1a value1b value1c", PARAM_BUFFER(p4, 0));
|
||||||
|
|
||||||
// No charset specified: defaults to US-ASCII
|
// No charset specified: defaults to US-ASCII
|
||||||
parameterizedHeaderField p12;
|
parameterizedHeaderField p5;
|
||||||
p12.parse("X; param1*='language'value1");
|
p5.parse("X; param1*='language'value1");
|
||||||
|
|
||||||
VASSERT_EQ("12.1", 1, p12.getParameterCount());
|
VASSERT_EQ("5.1", 1, p5.getParameterCount());
|
||||||
VASSERT_EQ("12.2", "param1", PARAM_NAME(p12, 0));
|
VASSERT_EQ("5.2", "param1", PARAM_NAME(p5, 0));
|
||||||
VASSERT_EQ("12.3", "us-ascii", PARAM_CHARSET(p12, 0));
|
VASSERT_EQ("5.3", "us-ascii", PARAM_CHARSET(p5, 0));
|
||||||
VASSERT_EQ("12.4", "value1", PARAM_BUFFER(p12, 0));
|
VASSERT_EQ("5.4", "value1", PARAM_BUFFER(p5, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testGenerate()
|
void testGenerate()
|
||||||
@ -206,21 +211,24 @@ VMIME_TEST_SUITE_BEGIN
|
|||||||
p2b.appendParameter(vmime::create <vmime::parameter>("param1", "va\\lue\"1"));
|
p2b.appendParameter(vmime::create <vmime::parameter>("param1", "va\\lue\"1"));
|
||||||
|
|
||||||
VASSERT_EQ("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate());
|
VASSERT_EQ("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate());
|
||||||
|
}
|
||||||
|
|
||||||
|
void testGenerateRFC2231()
|
||||||
|
{
|
||||||
// Extended parameter with charset specifier
|
// Extended parameter with charset specifier
|
||||||
parameterizedHeaderField p3;
|
parameterizedHeaderField p1;
|
||||||
p3.appendParameter(vmime::create <vmime::parameter>("param1",
|
p1.appendParameter(vmime::create <vmime::parameter>("param1",
|
||||||
vmime::word("value 1\xe9", vmime::charset("charset"))));
|
vmime::word("value 1\xe9", vmime::charset("charset"))));
|
||||||
|
|
||||||
VASSERT_EQ("3", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p3.generate());
|
VASSERT_EQ("1", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p1.generate());
|
||||||
|
|
||||||
// Value that spans on multiple lines
|
// Value that spans on multiple lines
|
||||||
parameterizedHeaderField p4;
|
parameterizedHeaderField p2;
|
||||||
p4.appendParameter(vmime::create <vmime::parameter>("param1",
|
p2.appendParameter(vmime::create <vmime::parameter>("param1",
|
||||||
vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
vmime::charset("charset"))));
|
vmime::charset("charset"))));
|
||||||
|
|
||||||
VASSERT_EQ("4", "F: X; \r\n "
|
VASSERT_EQ("2", "F: X; \r\n "
|
||||||
"param1=abcdefghijklm;\r\n "
|
"param1=abcdefghijklm;\r\n "
|
||||||
"param1*0*=charset''abc;\r\n "
|
"param1*0*=charset''abc;\r\n "
|
||||||
"param1*1*=defghijkl;\r\n "
|
"param1*1*=defghijkl;\r\n "
|
||||||
@ -228,7 +236,23 @@ VMIME_TEST_SUITE_BEGIN
|
|||||||
"param1*3*=vwxyzABCD;\r\n "
|
"param1*3*=vwxyzABCD;\r\n "
|
||||||
"param1*4*=EFGHIJKLM;\r\n "
|
"param1*4*=EFGHIJKLM;\r\n "
|
||||||
"param1*5*=NOPQRSTUV;\r\n "
|
"param1*5*=NOPQRSTUV;\r\n "
|
||||||
"param1*6*=WXYZ", p4.generate(25)); // max line length = 25
|
"param1*6*=WXYZ", p2.generate(25)); // max line length = 25
|
||||||
|
|
||||||
|
// Non-ASCII parameter value
|
||||||
|
parameterizedHeaderField p3;
|
||||||
|
p3.appendParameter(vmime::create <vmime::parameter>("param1",
|
||||||
|
vmime::word("δσσσσσσσσσσσσσσσσσσσσδσδα δσαδσδσαδσαδασδασ δσαδασδσα δσαδασδσα δασδασδασ δασαχφδδσα 2008.doc",
|
||||||
|
vmime::charset("utf-8"))));
|
||||||
|
|
||||||
|
VASSERT_EQ("3", "F: X; \r\n "
|
||||||
|
"param1=\" 2008.doc\";param1*0*=utf-8''%CE%B4%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83;\r\n "
|
||||||
|
"param1*1*=%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83%CF%83;\r\n "
|
||||||
|
"param1*2*=%CE%B4%CF%83%CE%B4%CE%B1%20%CE%B4%CF%83%CE%B1%CE%B4%CF%83%CE%B4%CF;\r\n "
|
||||||
|
"param1*3*=%83%CE%B1%CE%B4%CF%83%CE%B1%CE%B4%CE%B1%CF%83%CE%B4%CE%B1%CF%83%20;\r\n "
|
||||||
|
"param1*4*=%CE%B4%CF%83%CE%B1%CE%B4%CE%B1%CF%83%CE%B4%CF%83%CE%B1%20%CE%B4%CF;\r\n "
|
||||||
|
"param1*5*=%83%CE%B1%CE%B4%CE%B1%CF%83%CE%B4%CF%83%CE%B1%20%CE%B4%CE%B1%CF%83;\r\n "
|
||||||
|
"param1*6*=%CE%B4%CE%B1%CF%83%CE%B4%CE%B1%CF%83%20%CE%B4%CE%B1%CF%83%CE%B1%CF;\r\n "
|
||||||
|
"param1*7*=%87%CF%86%CE%B4%CE%B4%CF%83%CE%B1%202008.doc", p3.generate(80));
|
||||||
}
|
}
|
||||||
|
|
||||||
void testNonStandardEncodedParam()
|
void testNonStandardEncodedParam()
|
||||||
|
Loading…
Reference in New Issue
Block a user