Mercurial > thymian
comparison 3rdparty/vmime/tests/parser/mailboxTest.cpp @ 0:a4671277546c tip
created the repository for the thymian project
| author | ferencd |
|---|---|
| date | Tue, 17 Aug 2021 11:19:54 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:a4671277546c |
|---|---|
| 1 // | |
| 2 // VMime library (http://www.vmime.org) | |
| 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org> | |
| 4 // | |
| 5 // This program is free software; you can redistribute it and/or | |
| 6 // modify it under the terms of the GNU General Public License as | |
| 7 // published by the Free Software Foundation; either version 3 of | |
| 8 // the License, or (at your option) any later version. | |
| 9 // | |
| 10 // This program is distributed in the hope that it will be useful, | |
| 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 // General Public License for more details. | |
| 14 // | |
| 15 // You should have received a copy of the GNU General Public License along | |
| 16 // with this program; if not, write to the Free Software Foundation, Inc., | |
| 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 18 // | |
| 19 // Linking this library statically or dynamically with other modules is making | |
| 20 // a combined work based on this library. Thus, the terms and conditions of | |
| 21 // the GNU General Public License cover the whole combination. | |
| 22 // | |
| 23 | |
| 24 #include "tests/testUtils.hpp" | |
| 25 | |
| 26 | |
| 27 VMIME_TEST_SUITE_BEGIN(mailboxTest) | |
| 28 | |
| 29 VMIME_TEST_LIST_BEGIN | |
| 30 VMIME_TEST(testParse) | |
| 31 VMIME_TEST(testEmptyEmailAddress) | |
| 32 VMIME_TEST(testSeparatorInComment) | |
| 33 VMIME_TEST_LIST_END | |
| 34 | |
| 35 | |
| 36 void testParse() | |
| 37 { | |
| 38 static const vmime::string testSuitesParse[] = | |
| 39 { | |
| 40 // Test 1 | |
| 41 "My (this is a comment)name <me(another \\)comment) @ somewhere(else).com>", | |
| 42 | |
| 43 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=My name]]], email=me@somewhere.com]]]", | |
| 44 | |
| 45 // Test 2 | |
| 46 "mailbox1 <mailbox@one>,;,,, ,, ,,;group1:mailbox1@group1, mailbox2@group2,,\"mailbox #3\" <mailbox3@group2>;, <mailbox@two>,,,,,,,,=?iso-8859-1?q?mailbox_number_3?= <mailbox@three>, =?abc?Q?mailbox?= =?def?Q?_number_4?= <mailbox@four>", | |
| 47 | |
| 48 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox1]]], email=mailbox@one],[mailbox-group: name=[text: [[word: charset=us-ascii, buffer=group1]]], list=[[mailbox: name=[text: []], email=mailbox1@group1],[mailbox: name=[text: []], email=mailbox2@group2],[mailbox: name=[text: [[word: charset=us-ascii, buffer=mailbox #3]]], email=mailbox3@group2]]],[mailbox: name=[text: []], email=mailbox@two],[mailbox: name=[text: [[word: charset=iso-8859-1, buffer=mailbox number 3]]], email=mailbox@three],[mailbox: name=[text: [[word: charset=abc, buffer=mailbox],[word: charset=def, buffer= number 4]]], email=mailbox@four]]]", | |
| 49 | |
| 50 // Test 3 | |
| 51 "John Doe <john.doe@acme.com>", | |
| 52 | |
| 53 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]", | |
| 54 | |
| 55 // Test 4 | |
| 56 "john.doe@acme.com (John Doe)", | |
| 57 | |
| 58 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]", | |
| 59 | |
| 60 // Test 5 | |
| 61 "John.Doe(ignore)@acme.com (John Doe)", | |
| 62 | |
| 63 "[address-list: [[mailbox: name=[text: []], email=John.Doe@acme.com]]]", | |
| 64 | |
| 65 // Test 6 | |
| 66 "<john.doe@acme.com>", | |
| 67 | |
| 68 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]", | |
| 69 | |
| 70 // Test 7 | |
| 71 "john.doe@acme.com", | |
| 72 | |
| 73 "[address-list: [[mailbox: name=[text: []], email=john.doe@acme.com]]]", | |
| 74 | |
| 75 // Test 8 | |
| 76 "\"John Doe\" <john.doe@acme.com>", | |
| 77 | |
| 78 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John Doe]]], email=john.doe@acme.com]]]", | |
| 79 | |
| 80 // Test 9 | |
| 81 "=?us-ascii?q?John?=<john.doe@acme.com>", | |
| 82 | |
| 83 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]", | |
| 84 | |
| 85 // Test 10 | |
| 86 "\"John\"<john.doe@acme.com>", | |
| 87 | |
| 88 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]", | |
| 89 | |
| 90 // Test 11 | |
| 91 "John<john.doe@acme.com>", | |
| 92 | |
| 93 "[address-list: [[mailbox: name=[text: [[word: charset=us-ascii, buffer=John]]], email=john.doe@acme.com]]]" | |
| 94 }; | |
| 95 | |
| 96 for (unsigned int i = 0 ; i < sizeof(testSuitesParse) / sizeof(testSuitesParse[0]) / 2 ; ++i) | |
| 97 { | |
| 98 vmime::string in = testSuitesParse[i * 2]; | |
| 99 vmime::string out = testSuitesParse[i * 2 + 1]; | |
| 100 | |
| 101 std::ostringstream oss; | |
| 102 oss << "Test " << (i + 1); | |
| 103 | |
| 104 vmime::addressList addrList; | |
| 105 addrList.parse(in); | |
| 106 | |
| 107 std::ostringstream cmp; | |
| 108 cmp << addrList; | |
| 109 | |
| 110 VASSERT_EQ(oss.str(), out, cmp.str()); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void testEmptyEmailAddress() | |
| 115 { | |
| 116 vmime::addressList addrList; | |
| 117 addrList.parse("\"Full Name\" <>"); | |
| 118 | |
| 119 VASSERT_EQ("count", 1, addrList.getAddressCount()); | |
| 120 VASSERT_EQ("!group", false, addrList.getAddressAt(0)->isGroup()); | |
| 121 | |
| 122 vmime::shared_ptr <vmime::mailbox> mbox = | |
| 123 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(0)); | |
| 124 | |
| 125 VASSERT_EQ("name", "Full Name", mbox->getName()); | |
| 126 VASSERT_EQ("email", "", mbox->getEmail()); | |
| 127 } | |
| 128 | |
| 129 void testSeparatorInComment() | |
| 130 { | |
| 131 vmime::addressList addrList; | |
| 132 addrList.parse("aaa(comment,comment)@vmime.org, bbb@vmime.org"); | |
| 133 | |
| 134 VASSERT_EQ("count", 2, addrList.getAddressCount()); | |
| 135 | |
| 136 vmime::shared_ptr <vmime::mailbox> mbox1 = | |
| 137 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(0)); | |
| 138 vmime::shared_ptr <vmime::mailbox> mbox2 = | |
| 139 vmime::dynamicCast <vmime::mailbox>(addrList.getAddressAt(1)); | |
| 140 | |
| 141 VASSERT_EQ("name1", vmime::text(), mbox1->getName()); | |
| 142 VASSERT_EQ("email1", "aaa@vmime.org", mbox1->getEmail()); | |
| 143 | |
| 144 VASSERT_EQ("name2", vmime::text(), mbox2->getName()); | |
| 145 VASSERT_EQ("email2", "bbb@vmime.org", mbox2->getEmail()); | |
| 146 } | |
| 147 | |
| 148 VMIME_TEST_SUITE_END | |
| 149 |
