aboutsummaryrefslogtreecommitdiffstats
path: root/tests/parser/wordEncoderTest.cpp
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2018-09-05 21:54:48 +0000
committerVincent Richard <[email protected]>2018-09-05 21:54:48 +0000
commitb55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769 (patch)
treeefa18d623d3bc67c41d643aae145c16aa8f1006d /tests/parser/wordEncoderTest.cpp
parentMerge pull request #198 from xguerin/master (diff)
downloadvmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.tar.gz
vmime-b55bdc9c0bb68236aa2de0a8eaec9f4c80cc2769.zip
Code style and clarity.
Diffstat (limited to 'tests/parser/wordEncoderTest.cpp')
-rw-r--r--tests/parser/wordEncoderTest.cpp131
1 files changed, 88 insertions, 43 deletions
diff --git a/tests/parser/wordEncoderTest.cpp b/tests/parser/wordEncoderTest.cpp
index c3c44a87..08d34aa4 100644
--- a/tests/parser/wordEncoderTest.cpp
+++ b/tests/parser/wordEncoderTest.cpp
@@ -1,6 +1,6 @@
//
// VMime library (http://www.vmime.org)
-// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
+// Copyright (C) 2002 Vincent Richard <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
@@ -40,88 +40,133 @@ VMIME_TEST_SUITE_BEGIN(wordEncoderTest)
VMIME_TEST_LIST_END
- void testGetNextChunk()
- {
+ void testGetNextChunk() {
+
// An integral number of characters should be encoded
vmime::wordEncoder we(
"bufferfoobarbaz",
vmime::charset("utf-8"),
- vmime::wordEncoder::ENCODING_AUTO);
+ vmime::wordEncoder::ENCODING_AUTO
+ );
VASSERT_EQ("1", "buffer", we.getNextChunk(6));
VASSERT_EQ("2", "foo", we.getNextChunk(3));
VASSERT_EQ("3", "barbaz", we.getNextChunk(10));
}
- void testGetNextChunk_integral()
- {
+ void testGetNextChunk_integral() {
+
// An integral number of characters should be encoded
vmime::wordEncoder we(
"buffer\xc3\xa0plop",
vmime::charset("utf-8"),
- vmime::wordEncoder::ENCODING_AUTO);
+ vmime::wordEncoder::ENCODING_AUTO
+ );
VASSERT_EQ("1", "buffer=C3=A0", we.getNextChunk(7));
VASSERT_EQ("2", "plop", we.getNextChunk(10));
}
- void testIsEncodingNeeded_ascii()
- {
+ void testIsEncodingNeeded_ascii() {
+
vmime::generationContext ctx(vmime::generationContext::getDefaultContext());
ctx.setInternationalizedEmailSupport(false);
- VASSERT_FALSE("ascii", vmime::wordEncoder::isEncodingNeeded
- (ctx, "ASCII-only buffer", vmime::charset("utf-8"), ""));
-
- VASSERT_TRUE("non-ascii", vmime::wordEncoder::isEncodingNeeded
- (ctx, "Buffer with some UTF-8 '\xc3\xa0'", vmime::charset("utf-8"), ""));
+ VASSERT_FALSE(
+ "ascii",
+ vmime::wordEncoder::isEncodingNeeded(
+ ctx, "ASCII-only buffer", vmime::charset("utf-8"), ""
+ )
+ );
+
+ VASSERT_TRUE(
+ "non-ascii",
+ vmime::wordEncoder::isEncodingNeeded(
+ ctx, "Buffer with some UTF-8 '\xc3\xa0'", vmime::charset("utf-8"), ""
+ )
+ );
}
- void testIsEncodingNeeded_withLanguage()
- {
- VASSERT_TRUE("ascii", vmime::wordEncoder::isEncodingNeeded
- (vmime::generationContext::getDefaultContext(), "ASCII-only buffer", vmime::charset("utf-8"), "en"));
+ void testIsEncodingNeeded_withLanguage() {
+
+ VASSERT_TRUE(
+ "ascii",
+ vmime::wordEncoder::isEncodingNeeded(
+ vmime::generationContext::getDefaultContext(),
+ "ASCII-only buffer",
+ vmime::charset("utf-8"),
+ "en"
+ )
+ );
}
- void testIsEncodingNeeded_specialChars()
- {
- VASSERT_TRUE("rfc2047", vmime::wordEncoder::isEncodingNeeded
- (vmime::generationContext::getDefaultContext(),
- "foo bar =? foo bar", vmime::charset("us-ascii"), ""));
+ void testIsEncodingNeeded_specialChars() {
+
+ VASSERT_TRUE(
+ "rfc2047",
+ vmime::wordEncoder::isEncodingNeeded(
+ vmime::generationContext::getDefaultContext(),
+ "foo bar =? foo bar",
+ vmime::charset("us-ascii"),
+ ""
+ )
+ );
+
+ VASSERT_TRUE(
+ "new line 1",
+ vmime::wordEncoder::isEncodingNeeded(
+ vmime::generationContext::getDefaultContext(),
+ "foo bar \n foo bar",
+ vmime::charset("us-ascii"),
+ ""
+ )
+ );
+
+ VASSERT_TRUE(
+ "new line 2",
+ vmime::wordEncoder::isEncodingNeeded(
+ vmime::generationContext::getDefaultContext(),
+ "foo bar \r foo bar",
+ vmime::charset("us-ascii"),
+ ""
+ )
+ );
+ }
- VASSERT_TRUE("new line 1", vmime::wordEncoder::isEncodingNeeded
- (vmime::generationContext::getDefaultContext(),
- "foo bar \n foo bar", vmime::charset("us-ascii"), ""));
+ void testGuessBestEncoding_QP() {
- VASSERT_TRUE("new line 2", vmime::wordEncoder::isEncodingNeeded
- (vmime::generationContext::getDefaultContext(),
- "foo bar \r foo bar", vmime::charset("us-ascii"), ""));
+ VASSERT_EQ(
+ "1",
+ vmime::wordEncoder::ENCODING_QP,
+ vmime::wordEncoder::guessBestEncoding("ASCII only buffer", vmime::charset("us-ascii"))
+ );
}
- void testGuessBestEncoding_QP()
- {
- VASSERT_EQ("1", vmime::wordEncoder::ENCODING_QP,
- vmime::wordEncoder::guessBestEncoding("ASCII only buffer", vmime::charset("us-ascii")));
- }
+ void testGuessBestEncoding_B64() {
- void testGuessBestEncoding_B64()
- {
// >= 40% non-ASCII => Base64...
- VASSERT_EQ("1", vmime::wordEncoder::ENCODING_B64,
- vmime::wordEncoder::guessBestEncoding("xxxxx\xc3\xa0\xc3\xa0", vmime::charset("utf-8")));
+ VASSERT_EQ(
+ "1",
+ vmime::wordEncoder::ENCODING_B64,
+ vmime::wordEncoder::guessBestEncoding("xxxxx\xc3\xa0\xc3\xa0", vmime::charset("utf-8"))
+ );
// ...else Quoted-Printable
- VASSERT_EQ("2", vmime::wordEncoder::ENCODING_QP,
- vmime::wordEncoder::guessBestEncoding("xxxxxx\xc3\xa0\xc3\xa0", vmime::charset("utf-8")));
+ VASSERT_EQ(
+ "2",
+ vmime::wordEncoder::ENCODING_QP,
+ vmime::wordEncoder::guessBestEncoding("xxxxxx\xc3\xa0\xc3\xa0", vmime::charset("utf-8"))
+ );
}
- void testEncodeQP_RFC2047()
- {
+ void testEncodeQP_RFC2047() {
+
// When Quoted-Printable is used, it should be RFC-2047 QP encoding
vmime::wordEncoder we(
"buffer\xc3\xa0 foo_bar",
vmime::charset("utf-8"),
- vmime::wordEncoder::ENCODING_AUTO);
+ vmime::wordEncoder::ENCODING_AUTO
+ );
VASSERT_EQ("1", "buffer=C3=A0_foo=5Fbar", we.getNextChunk(100));
}