diff options
Diffstat (limited to 'tests/utility/encoder')
| -rw-r--r-- | tests/utility/encoder/b64EncoderTest.cpp | 55 | ||||
| -rw-r--r-- | tests/utility/encoder/encoderFactoryTest.cpp | 10 | ||||
| -rw-r--r-- | tests/utility/encoder/encoderTestUtils.hpp | 31 | ||||
| -rw-r--r-- | tests/utility/encoder/qpEncoderTest.cpp | 115 |
4 files changed, 132 insertions, 79 deletions
diff --git a/tests/utility/encoder/b64EncoderTest.cpp b/tests/utility/encoder/b64EncoderTest.cpp index fa6fd766..36fa61ac 100644 --- a/tests/utility/encoder/b64EncoderTest.cpp +++ b/tests/utility/encoder/b64EncoderTest.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 @@ -33,10 +33,10 @@ VMIME_TEST_SUITE_BEGIN(b64EncoderTest) VMIME_TEST_LIST_END - void testBase64() - { - static const vmime::string testSuites[] = - { + void testBase64() { + + static const vmime::string testSuites[] = { + // Test 1 "", @@ -96,8 +96,8 @@ VMIME_TEST_SUITE_BEGIN(b64EncoderTest) }; - for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i) - { + for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i) { + const vmime::string decoded = testSuites[i * 2]; const vmime::string encoded = testSuites[i * 2 + 1]; @@ -111,25 +111,36 @@ VMIME_TEST_SUITE_BEGIN(b64EncoderTest) VASSERT_EQ(oss.str() + "decoding", decoded, decode("base64", encoded)); // Multiple and successive encoding/decoding - VASSERT_EQ(oss.str() + "multiple1", decoded, + VASSERT_EQ( + oss.str() + "multiple1", + decoded, decode("base64", - encode("base64", decoded))); + encode("base64", decoded)) + ); - VASSERT_EQ(oss.str() + "multiple2", decoded, + VASSERT_EQ( + oss.str() + "multiple2", + decoded, decode("base64", decode("base64", encode("base64", - encode("base64", decoded))))); + encode("base64", decoded)))) + ); - VASSERT_EQ(oss.str() + "multiple3", decoded, + VASSERT_EQ( + oss.str() + "multiple3", + decoded, decode("base64", decode("base64", decode("base64", encode("base64", encode("base64", - encode("base64", decoded))))))); + encode("base64", decoded)))))) + ); - VASSERT_EQ(oss.str() + "multiple4", decoded, + VASSERT_EQ( + oss.str() + "multiple4", + decoded, decode("base64", decode("base64", decode("base64", @@ -137,17 +148,21 @@ VMIME_TEST_SUITE_BEGIN(b64EncoderTest) encode("base64", encode("base64", encode("base64", - encode("base64", decoded))))))))); + encode("base64", decoded)))))))) + ); - VASSERT(oss.str() + "encoded size", + VASSERT( + oss.str() + "encoded size", getEncoder("base64")->getEncodedSize(decoded.length()) - >= encode("base64", decoded).length()); + >= encode("base64", decoded).length() + ); - VASSERT(oss.str() + "decoded size", + VASSERT( + oss.str() + "decoded size", getEncoder("base64")->getDecodedSize(encoded.length()) - >= decode("base64", encoded).length()); + >= decode("base64", encoded).length() + ); } } VMIME_TEST_SUITE_END - diff --git a/tests/utility/encoder/encoderFactoryTest.cpp b/tests/utility/encoder/encoderFactoryTest.cpp index ce50dc6a..916706c9 100644 --- a/tests/utility/encoder/encoderFactoryTest.cpp +++ b/tests/utility/encoder/encoderFactoryTest.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 @@ -35,8 +35,8 @@ VMIME_TEST_SUITE_BEGIN(encoderFactoryTest) VMIME_TEST_LIST_END - void testNoDefaultEncoder() - { + void testNoDefaultEncoder() { + vmime::shared_ptr <vmime::utility::encoder::encoderFactory> ef = vmime::utility::encoder::encoderFactory::getInstance(); @@ -47,8 +47,8 @@ VMIME_TEST_SUITE_BEGIN(encoderFactoryTest) ); } - void testDefaultEncoder() - { + void testDefaultEncoder() { + vmime::shared_ptr <vmime::utility::encoder::encoderFactory> ef = vmime::utility::encoder::encoderFactory::getInstance(); diff --git a/tests/utility/encoder/encoderTestUtils.hpp b/tests/utility/encoder/encoderTestUtils.hpp index d74c4709..cc1141c7 100644 --- a/tests/utility/encoder/encoderTestUtils.hpp +++ b/tests/utility/encoder/encoderTestUtils.hpp @@ -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 @@ -23,25 +23,32 @@ // Helper function to obtain an encoder given its name -static vmime::shared_ptr <vmime::utility::encoder::encoder> getEncoder(const vmime::string& name, - int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet()) -{ +static vmime::shared_ptr <vmime::utility::encoder::encoder> getEncoder( + const vmime::string& name, + int maxLineLength = 0, + const vmime::propertySet props = vmime::propertySet() +) { + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = vmime::utility::encoder::encoderFactory::getInstance()->create(name); enc->getProperties() = props; - if (maxLineLength != 0) + if (maxLineLength != 0) { enc->getProperties()["maxlinelength"] = maxLineLength; + } return enc; } // Encoding helper function -static const vmime::string encode(const vmime::string& name, const vmime::string& in, - int maxLineLength = 0, const vmime::propertySet props = vmime::propertySet()) -{ +static const vmime::string encode( + const vmime::string& name, const vmime::string& in, + int maxLineLength = 0, + const vmime::propertySet props = vmime::propertySet() +) { + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength, props); vmime::utility::inputStreamStringAdapter vin(in); @@ -56,8 +63,12 @@ static const vmime::string encode(const vmime::string& name, const vmime::string // Decoding helper function -static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0) -{ +static const vmime::string decode( + const vmime::string& name, + const vmime::string& in, + int maxLineLength = 0 +) { + vmime::shared_ptr <vmime::utility::encoder::encoder> enc = getEncoder(name, maxLineLength); vmime::utility::inputStreamStringAdapter vin(in); diff --git a/tests/utility/encoder/qpEncoderTest.cpp b/tests/utility/encoder/qpEncoderTest.cpp index e7d1bcd2..e4769475 100644 --- a/tests/utility/encoder/qpEncoderTest.cpp +++ b/tests/utility/encoder/qpEncoderTest.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 @@ -38,10 +38,10 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) VMIME_TEST_LIST_END - void testQuotedPrintable() - { - static const vmime::string testSuites[] = - { + void testQuotedPrintable() { + + static const vmime::string testSuites[] = { + // Test 1 "", @@ -94,8 +94,8 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) }; - for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i) - { + for (unsigned int i = 0 ; i < sizeof(testSuites) / sizeof(testSuites[0]) / 2 ; ++i) { + const vmime::string decoded = testSuites[i * 2]; const vmime::string encoded = testSuites[i * 2 + 1]; @@ -109,25 +109,36 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) VASSERT_EQ(oss.str() + "decoding", decoded, decode("quoted-printable", encoded, 74)); // Multiple and successive encoding/decoding - VASSERT_EQ(oss.str() + "multiple1", decoded, + VASSERT_EQ( + oss.str() + "multiple1", + decoded, decode("quoted-printable", - encode("quoted-printable", decoded))); + encode("quoted-printable", decoded)) + ); - VASSERT_EQ(oss.str() + "multiple2", decoded, + VASSERT_EQ( + oss.str() + "multiple2", + decoded, decode("quoted-printable", decode("quoted-printable", encode("quoted-printable", - encode("quoted-printable", decoded))))); + encode("quoted-printable", decoded)))) + ); - VASSERT_EQ(oss.str() + "multiple3", decoded, + VASSERT_EQ( + oss.str() + "multiple3", + decoded, decode("quoted-printable", decode("quoted-printable", decode("quoted-printable", encode("quoted-printable", encode("quoted-printable", - encode("quoted-printable", decoded))))))); + encode("quoted-printable", decoded)))))) + ); - VASSERT_EQ(oss.str() + "multiple4", decoded, + VASSERT_EQ( + oss.str() + "multiple4", + decoded, decode("quoted-printable", decode("quoted-printable", decode("quoted-printable", @@ -135,38 +146,50 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) encode("quoted-printable", encode("quoted-printable", encode("quoted-printable", - encode("quoted-printable", decoded))))))))); + encode("quoted-printable", decoded)))))))) + ); - VASSERT(oss.str() + "encoded size", + VASSERT( + oss.str() + "encoded size", getEncoder("quoted-printable")->getEncodedSize(decoded.length()) - >= encode("quoted-printable", decoded).length()); + >= encode("quoted-printable", decoded).length() + ); - VASSERT(oss.str() + "decoded size", + VASSERT( + oss.str() + "decoded size", getEncoder("quoted-printable")->getDecodedSize(encoded.length()) - >= decode("quoted-printable", encoded).length()); + >= decode("quoted-printable", encoded).length() + ); } } /** Tests Soft Line Breaks (RFC-2047/6.7(5). */ - void testQuotedPrintable_SoftLineBreaks() - { - VASSERT_EQ("1", "Now's the time=\r\n" - " for all folk =\r\n" - "to come to the=\r\n" - " aid of their =\r\n" - "country.", - encode("quoted-printable", "Now's the time for all folk " - "to come to the aid of their country.", 15)); + void testQuotedPrintable_SoftLineBreaks() { + + VASSERT_EQ( + "1", + "Now's the time=\r\n" + " for all folk =\r\n" + "to come to the=\r\n" + " aid of their =\r\n" + "country.", + encode( + "quoted-printable", + "Now's the time for all folk " + "to come to the aid of their country.", + 15 + ) + ); } - void testQuotedPrintable_HardLineBreakEncode() - { + void testQuotedPrintable_HardLineBreakEncode() { + const std::string data = "If you believe that truth=beauty," " then surely mathematics\r\nis the most" " beautiful branch of philosophy."; - const std::string expected = + const std::string expected = "If you believe that truth=3Dbeauty=\r\n" ", then surely mathematics\r\n" "is the most beautiful branch of ph=\r\n" @@ -178,14 +201,14 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) VASSERT_EQ("1", expected, encode("quoted-printable", data, 35, encProps)); } - void testQuotedPrintable_HardLineBreakDecode() - { + void testQuotedPrintable_HardLineBreakDecode() { + const std::string expected = "If you believe that truth=beauty," " then surely mathematics\r\nis the most" " beautiful branch of philosophy."; - const std::string data = + const std::string data = "If you believe that truth=3Dbeauty=\r\n" ", then surely mathematics\r\n" "is the most beautiful branch of ph=\r\n" @@ -197,23 +220,29 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) /** In text mode, ensure line breaks in QP-encoded text are represented * by a CRLF sequence, as per RFC-2047/6.7(4). */ - void testQuotedPrintable_CRLF() - { + void testQuotedPrintable_CRLF() { + vmime::propertySet encProps; // in "text" mode encProps["text"] = true; - VASSERT_EQ("text", "line1\r\nline2", - encode("quoted-printable", "line1\r\nline2", 80, encProps)); + VASSERT_EQ( + "text", + "line1\r\nline2", + encode("quoted-printable", "line1\r\nline2", 80, encProps) + ); // in "binary" mode encProps["text"] = false; - VASSERT_EQ("binary", "line1=0D=0Aline2", - encode("quoted-printable", "line1\r\nline2", 80, encProps)); + VASSERT_EQ( + "binary", + "line1=0D=0Aline2", + encode("quoted-printable", "line1\r\nline2", 80, encProps) + ); } - void testQuotedPrintable_RFC2047() - { + void testQuotedPrintable_RFC2047() { + /* * The RFC (http://tools.ietf.org/html/rfc2047#section-5) says: * @@ -243,6 +272,4 @@ VMIME_TEST_SUITE_BEGIN(qpEncoderTest) VASSERT_EQ("especials.12", "=22", encode("quoted-printable", "\"", 10, encProps)); } - // TODO: UUEncode - VMIME_TEST_SUITE_END |
