diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/net/imap/IMAPParserTest.cpp | 37 | ||||
-rw-r--r-- | tests/testUtils.cpp | 6 | ||||
-rw-r--r-- | tests/testUtils.hpp | 2 | ||||
-rw-r--r-- | tests/utility/pathTest.cpp | 40 |
4 files changed, 85 insertions, 0 deletions
diff --git a/tests/net/imap/IMAPParserTest.cpp b/tests/net/imap/IMAPParserTest.cpp index 30e8f574..e598a548 100644 --- a/tests/net/imap/IMAPParserTest.cpp +++ b/tests/net/imap/IMAPParserTest.cpp @@ -31,6 +31,7 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VMIME_TEST_LIST_BEGIN VMIME_TEST(testExtraSpaceInCapaResponse) + VMIME_TEST(testContinueReqWithoutSpace) VMIME_TEST_LIST_END @@ -64,4 +65,40 @@ VMIME_TEST_SUITE_BEGIN(IMAPParserTest) VASSERT_THROW("strict mode", parser->readResponse(/* literalHandler */ NULL), vmime::exceptions::invalid_response); } + // For Apple iCloud/Exchange IMAP server + void testContinueReqWithoutSpace() + { + // continue_req ::= "+" SPACE (resp_text / base64) + // + // Some servers do not send SPACE when response text is empty. + // IMAP parser should allow this in non-strict mode. + // + // Eg: + // + // C: a002 AUTHENTICATE xxx[CR][LF] + // S: +[CR][LF] + + vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>(); + vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>(); + + vmime::shared_ptr <vmime::net::imap::IMAPTag> tag = + vmime::make_shared <vmime::net::imap::IMAPTag>(); + + socket->localSend("+\r\n"); + + vmime::shared_ptr <vmime::net::imap::IMAPParser> parser = + vmime::make_shared <vmime::net::imap::IMAPParser> + (tag, vmime::dynamicCast <vmime::net::socket>(socket), toh); + + parser->setStrict(false); + VASSERT_NO_THROW("non-strict mode", parser->readResponse()); + + ++(*tag); + + socket->localSend("+\r\n"); + + parser->setStrict(true); + VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response); + } + VMIME_TEST_SUITE_END diff --git a/tests/testUtils.cpp b/tests/testUtils.cpp index 437b476b..ee642bea 100644 --- a/tests/testUtils.cpp +++ b/tests/testUtils.cpp @@ -79,6 +79,12 @@ const vmime::string testSocket::getPeerAddress() const } +vmime::shared_ptr <vmime::net::timeoutHandler> testSocket::getTimeoutHandler() +{ + return vmime::null; +} + + void testSocket::receive(vmime::string& buffer) { buffer = m_inBuffer; diff --git a/tests/testUtils.hpp b/tests/testUtils.hpp index f0ecf454..9e72158a 100644 --- a/tests/testUtils.hpp +++ b/tests/testUtils.hpp @@ -263,6 +263,8 @@ public: const vmime::string getPeerName() const; const vmime::string getPeerAddress() const; + vmime::shared_ptr <vmime::net::timeoutHandler> getTimeoutHandler(); + /** Send data to client. * * @param buffer data to send diff --git a/tests/utility/pathTest.cpp b/tests/utility/pathTest.cpp index d0c1c091..ef1b773d 100644 --- a/tests/utility/pathTest.cpp +++ b/tests/utility/pathTest.cpp @@ -53,6 +53,10 @@ VMIME_TEST_SUITE_BEGIN(utilityPathTest) VMIME_TEST(testIsParentOf_EquivalentCharset) VMIME_TEST(testRenameParent) + + VMIME_TEST(testFromString) + VMIME_TEST(testFromString_IgnoreLeadingOrTrailingSep) + VMIME_TEST(testToString) VMIME_TEST_LIST_END @@ -313,5 +317,41 @@ VMIME_TEST_SUITE_BEGIN(utilityPathTest) VASSERT_EQ("6", "d", p.getComponentAt(4).getBuffer()); } + void testFromString() + { + path p = path::fromString("ab/cde/f", "/", vmime::charset("my-charset")); + + VASSERT_EQ("count", 3, p.getSize()); + VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer()); + VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName()); + VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer()); + VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName()); + VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer()); + VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName()); + } + + void testFromString_IgnoreLeadingOrTrailingSep() + { + path p = path::fromString("//ab/cde/f////", "/", vmime::charset("my-charset")); + + VASSERT_EQ("count", 3, p.getSize()); + VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer()); + VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName()); + VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer()); + VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName()); + VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer()); + VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName()); + } + + void testToString() + { + path p; + p.appendComponent(comp("ab")); + p.appendComponent(comp("cde")); + p.appendComponent(comp("f")); + + VASSERT_EQ("string", "ab/cde/f", p.toString("/", vmime::charset("us-ascii"))); + } + VMIME_TEST_SUITE_END |