comparison 3rdparty/vmime/tests/parser/mailboxGroupTest.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(mailboxGroupTest)
28
29 VMIME_TEST_LIST_BEGIN
30 VMIME_TEST(testParseExtraWhitespaces)
31 VMIME_TEST(testParseNoEndDelimiter)
32 VMIME_TEST(testParseExtraChars)
33 VMIME_TEST(testEmptyGroup)
34 VMIME_TEST_LIST_END
35
36
37 void testParseExtraWhitespaces()
38 {
39 vmime::mailboxGroup mgrp;
40 mgrp.parse(" \t group : aaa <aaa@vmime.org>, bbb <bbb@vmime.org>");
41
42 VASSERT_EQ("name", "group", mgrp.getName().getWholeBuffer());
43 VASSERT_EQ("count", 2, mgrp.getMailboxCount());
44
45 VASSERT_EQ("mbox1.email", "aaa@vmime.org", mgrp.getMailboxAt(0)->getEmail());
46 VASSERT_EQ("mbox1.name", "aaa", mgrp.getMailboxAt(0)->getName());
47
48 VASSERT_EQ("mbox2.email", "bbb@vmime.org", mgrp.getMailboxAt(1)->getEmail());
49 VASSERT_EQ("mbox2.name", "bbb", mgrp.getMailboxAt(1)->getName());
50 }
51
52 void testParseNoEndDelimiter()
53 {
54 vmime::addressList addrs;
55 addrs.parse("group: aaa <aaa@vmime.org>, bbb <bbb@vmime.org>");
56
57 VASSERT_EQ("count", 1, addrs.getAddressCount());
58 VASSERT_TRUE("is group", addrs.getAddressAt(0)->isGroup());
59
60 vmime::shared_ptr <vmime::mailboxGroup> mgrp =
61 vmime::dynamicCast <vmime::mailboxGroup>(addrs.getAddressAt(0));
62
63 VASSERT_EQ("name", "group", mgrp->getName().getWholeBuffer());
64 VASSERT_EQ("count", 2, mgrp->getMailboxCount());
65
66 VASSERT_EQ("mbox1.email", "aaa@vmime.org", mgrp->getMailboxAt(0)->getEmail());
67 VASSERT_EQ("mbox1.name", "aaa", mgrp->getMailboxAt(0)->getName());
68
69 VASSERT_EQ("mbox2.email", "bbb@vmime.org", mgrp->getMailboxAt(1)->getEmail());
70 VASSERT_EQ("mbox2.name", "bbb", mgrp->getMailboxAt(1)->getName());
71 }
72
73 void testParseExtraChars()
74 {
75 vmime::mailboxGroup mgrp;
76 mgrp.parse("group: aaa <aaa@vmime.org>, bbb <bbb@vmime.org>; extra chars here...");
77
78 VASSERT_EQ("name", "group", mgrp.getName().getWholeBuffer());
79 VASSERT_EQ("count", 2, mgrp.getMailboxCount());
80
81 VASSERT_EQ("mbox1.email", "aaa@vmime.org", mgrp.getMailboxAt(0)->getEmail());
82 VASSERT_EQ("mbox1.name", "aaa", mgrp.getMailboxAt(0)->getName());
83
84 VASSERT_EQ("mbox2.email", "bbb@vmime.org", mgrp.getMailboxAt(1)->getEmail());
85 VASSERT_EQ("mbox2.name", "bbb", mgrp.getMailboxAt(1)->getName());
86 }
87
88 void testEmptyGroup()
89 {
90 vmime::mailboxGroup mgrp;
91 mgrp.parse("Undisclosed recipients:;");
92
93 VASSERT_EQ("name", "Undisclosed recipients", mgrp.getName().getWholeBuffer());
94 VASSERT_EQ("count", 0, mgrp.getMailboxCount());
95 }
96
97 VMIME_TEST_SUITE_END