comparison 3rdparty/vmime/tests/parser/dispositionTest.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(dispositionTest)
28
29 VMIME_TEST_LIST_BEGIN
30 VMIME_TEST(testParse)
31 VMIME_TEST(testGenerate)
32 VMIME_TEST(testModifiers)
33 VMIME_TEST_LIST_END
34
35
36 void testParse()
37 {
38 // disposition-mode ";" disposition-type
39 // [ "/" disposition-modifier *( "," disposition-modifier ) ]
40 //
41 // disposition-mode = action-mode "/" sending-mode
42
43 vmime::disposition disp1;
44 disp1.parse("mode");
45
46 VASSERT_EQ("1.1", "mode", disp1.getActionMode());
47 VASSERT_EQ("1.2", "", disp1.getSendingMode());
48 VASSERT_EQ("1.3", "", disp1.getType());
49 VASSERT_EQ("1.4", 0, static_cast <int>(disp1.getModifierList().size()));
50
51 vmime::disposition disp2;
52 disp2.parse("amode/smode");
53
54 VASSERT_EQ("2.1", "amode", disp2.getActionMode());
55 VASSERT_EQ("2.2", "smode", disp2.getSendingMode());
56 VASSERT_EQ("2.3", "", disp2.getType());
57 VASSERT_EQ("2.4", 0, static_cast <int>(disp2.getModifierList().size()));
58
59 vmime::disposition disp3;
60 disp3.parse("amode/smode;type");
61
62 VASSERT_EQ("3.1", "amode", disp3.getActionMode());
63 VASSERT_EQ("3.2", "smode", disp3.getSendingMode());
64 VASSERT_EQ("3.3", "type", disp3.getType());
65 VASSERT_EQ("3.4", 0, static_cast <int>(disp3.getModifierList().size()));
66
67 vmime::disposition disp4;
68 disp4.parse("amode/smode;type/modif");
69
70 VASSERT_EQ("4.1", "amode", disp4.getActionMode());
71 VASSERT_EQ("4.2", "smode", disp4.getSendingMode());
72 VASSERT_EQ("4.3", "type", disp4.getType());
73 VASSERT_EQ("4.4", 1, static_cast <int>(disp4.getModifierList().size()));
74 VASSERT_EQ("4.5", "modif", disp4.getModifierList()[0]);
75
76 vmime::disposition disp5;
77 disp5.parse("amode/smode;type/modif1,modif2");
78
79 VASSERT_EQ("5.1", "amode", disp5.getActionMode());
80 VASSERT_EQ("5.2", "smode", disp5.getSendingMode());
81 VASSERT_EQ("5.3", "type", disp5.getType());
82 VASSERT_EQ("5.4", 2, static_cast <int>(disp5.getModifierList().size()));
83 VASSERT_EQ("5.5", "modif1", disp5.getModifierList()[0]);
84 VASSERT_EQ("5.6", "modif2", disp5.getModifierList()[1]);
85 }
86
87 void testGenerate()
88 {
89 vmime::disposition disp;
90
91 VASSERT_EQ("1", "automatic-action/MDN-sent-automatically;displayed", disp.generate());
92
93 disp.setActionMode("amode");
94
95 VASSERT_EQ("2", "amode/MDN-sent-automatically;displayed", disp.generate());
96
97 disp.setActionMode("amode");
98 disp.setSendingMode("smode");
99
100 VASSERT_EQ("3", "amode/smode;displayed", disp.generate());
101
102 disp.setType("type");
103
104 VASSERT_EQ("4", "amode/smode;type", disp.generate());
105
106 disp.addModifier("modif1");
107
108 VASSERT_EQ("5", "amode/smode;type/modif1", disp.generate());
109
110 disp.addModifier("modif2");
111
112 VASSERT_EQ("6", "amode/smode;type/modif1,modif2", disp.generate());
113 }
114
115 void testModifiers()
116 {
117 vmime::disposition disp1;
118
119 VASSERT_EQ("1", false, disp1.hasModifier("foo"));
120 VASSERT_EQ("2", 0, static_cast <int>(disp1.getModifierList().size()));
121
122 disp1.addModifier("bar");
123
124 VASSERT_EQ("3", false, disp1.hasModifier("foo"));
125 VASSERT_EQ("4", true, disp1.hasModifier("bar"));
126 VASSERT_EQ("5", 1, static_cast <int>(disp1.getModifierList().size()));
127
128 disp1.addModifier("plop");
129
130 VASSERT_EQ("6", false, disp1.hasModifier("foo"));
131 VASSERT_EQ("7", true, disp1.hasModifier("bar"));
132 VASSERT_EQ("8", true, disp1.hasModifier("plop"));
133 VASSERT_EQ("9", 2, static_cast <int>(disp1.getModifierList().size()));
134
135 disp1.removeModifier("bar");
136
137 VASSERT_EQ("10", false, disp1.hasModifier("foo"));
138 VASSERT_EQ("11", false, disp1.hasModifier("bar"));
139 VASSERT_EQ("12", true, disp1.hasModifier("plop"));
140 VASSERT_EQ("13", 1, static_cast <int>(disp1.getModifierList().size()));
141
142 disp1.removeModifier("PlOp");
143
144 VASSERT_EQ("14", false, disp1.hasModifier("foo"));
145 VASSERT_EQ("15", false, disp1.hasModifier("bar"));
146 VASSERT_EQ("16", false, disp1.hasModifier("plop"));
147 VASSERT_EQ("17", 0, static_cast <int>(disp1.getModifierList().size()));
148 }
149
150 VMIME_TEST_SUITE_END
151