comparison 3rdparty/vmime/tests/utility/pathTest.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 #include "vmime/utility/path.hpp"
27
28
29 VMIME_TEST_SUITE_BEGIN(utilityPathTest)
30
31 VMIME_TEST_LIST_BEGIN
32 VMIME_TEST(testConstruct1)
33 VMIME_TEST(testConstruct2)
34 VMIME_TEST(testConstruct3)
35 VMIME_TEST(testConstruct4)
36
37 VMIME_TEST(testAppendComponent)
38
39 VMIME_TEST(testOperatorDiv1)
40 VMIME_TEST(testOperatorDiv2)
41
42 VMIME_TEST(testOperatorDivEqual1)
43 VMIME_TEST(testOperatorDivEqual2)
44
45 VMIME_TEST(testGetParent)
46
47 VMIME_TEST(testComparison)
48
49 VMIME_TEST(testGetLastComponent)
50
51 VMIME_TEST(testIsDirectParentOf)
52 VMIME_TEST(testIsParentOf)
53 VMIME_TEST(testIsParentOf_EquivalentCharset)
54
55 VMIME_TEST(testRenameParent)
56
57 VMIME_TEST(testFromString)
58 VMIME_TEST(testFromString_IgnoreLeadingOrTrailingSep)
59 VMIME_TEST(testToString)
60 VMIME_TEST_LIST_END
61
62
63 typedef vmime::utility::path path;
64 typedef vmime::utility::path::component comp;
65
66
67 void testConstruct1()
68 {
69 VASSERT_EQ("1", true, path().isEmpty());
70 VASSERT_EQ("2", 0, path().getSize());
71 }
72
73 void testConstruct2()
74 {
75 path p(comp("foo"));
76
77 VASSERT_EQ("1", false, p.isEmpty());
78 VASSERT_EQ("2", 1, p.getSize());
79 VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer());
80 }
81
82 void testAppendComponent()
83 {
84 path p;
85
86 VASSERT_EQ("1", 0, p.getSize());
87
88 comp c("foo");
89 p.appendComponent(c);
90
91 VASSERT_EQ("2", 1, p.getSize());
92 VASSERT_EQ("3", c.getBuffer(), p.getComponentAt(0).getBuffer());
93 }
94
95 void testConstruct3()
96 {
97 path p1;
98 p1.appendComponent(comp("foo"));
99 p1.appendComponent(comp("bar"));
100
101 path p2(p1);
102
103 VASSERT_EQ("1", 2, p2.getSize());
104 VASSERT_EQ("2", "foo", p2.getComponentAt(0).getBuffer());
105 VASSERT_EQ("3", "bar", p2.getComponentAt(1).getBuffer());
106 }
107
108 void testConstruct4()
109 {
110 // Same as path::path(const component&)
111 path p("foo");
112
113 VASSERT_EQ("1", false, p.isEmpty());
114 VASSERT_EQ("2", 1, p.getSize());
115 VASSERT_EQ("3", "foo", p.getComponentAt(0).getBuffer());
116 }
117
118 void testOperatorDiv1()
119 {
120 path p1;
121 p1.appendComponent(comp("foo"));
122 p1.appendComponent(comp("bar"));
123
124 path p2;
125 p2.appendComponent(comp("baz"));
126
127 path p3 = p1 / p2;
128
129 VASSERT_EQ("1", 3, p3.getSize());
130 VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer());
131 VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer());
132 VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer());
133 }
134
135 void testOperatorDiv2()
136 {
137 path p1;
138 p1.appendComponent(comp("foo"));
139 p1.appendComponent(comp("bar"));
140
141 comp c("baz");
142
143 path p2 = p1 / c;
144
145 VASSERT_EQ("1", 3, p2.getSize());
146 VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer());
147 VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer());
148 VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer());
149 }
150
151 void testOperatorDivEqual1()
152 {
153 path p1;
154 p1.appendComponent(comp("foo"));
155 p1.appendComponent(comp("bar"));
156
157 path p2;
158 p2.appendComponent(comp("baz"));
159
160 path p3(p1);
161 p3 /= p2;
162
163 VASSERT_EQ("1", 3, p3.getSize());
164 VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p3.getComponentAt(0).getBuffer());
165 VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p3.getComponentAt(1).getBuffer());
166 VASSERT_EQ("4", p2.getComponentAt(0).getBuffer(), p3.getComponentAt(2).getBuffer());
167 }
168
169 void testOperatorDivEqual2()
170 {
171 path p1;
172 p1.appendComponent(comp("foo"));
173 p1.appendComponent(comp("bar"));
174
175 comp c("baz");
176
177 path p2(p1);
178 p2 /= c;
179
180 VASSERT_EQ("1", 3, p2.getSize());
181 VASSERT_EQ("2", p1.getComponentAt(0).getBuffer(), p2.getComponentAt(0).getBuffer());
182 VASSERT_EQ("3", p1.getComponentAt(1).getBuffer(), p2.getComponentAt(1).getBuffer());
183 VASSERT_EQ("4", c.getBuffer(), p2.getComponentAt(2).getBuffer());
184 }
185
186 void testGetParent()
187 {
188 path p1;
189 path p1p = p1.getParent();
190
191 VASSERT_EQ("1", true, p1p.isEmpty());
192
193 path p2;
194 p2.appendComponent(comp("foo"));
195 p2.appendComponent(comp("bar"));
196
197 path p2p = p2.getParent();
198
199 VASSERT_EQ("2", 1, p2p.getSize());
200 VASSERT_EQ("3", p2.getComponentAt(0).getBuffer(), p2p.getComponentAt(0).getBuffer());
201 }
202
203 void testComparison()
204 {
205 path p1;
206 p1.appendComponent(comp("foo"));
207 p1.appendComponent(comp("bar"));
208
209 path p2;
210 p2.appendComponent(comp("foo"));
211 p2.appendComponent(comp("bar"));
212
213 path p3;
214 p3.appendComponent(comp("foo"));
215 p3.appendComponent(comp("bar"));
216 p3.appendComponent(comp("baz"));
217
218 VASSERT_EQ("1", true, p1 == p2);
219 VASSERT_EQ("2", false, p1 == p3);
220
221 VASSERT_EQ("3", false, p1 != p2);
222 VASSERT_EQ("4", true, p1 != p3);
223
224 VASSERT_EQ("5", true, p3.getParent() == p1);
225 }
226
227 void testGetLastComponent()
228 {
229 path p1;
230 p1.appendComponent(comp("foo"));
231 p1.appendComponent(comp("bar"));
232 p1.appendComponent(comp("baz"));
233
234 VASSERT_EQ("1", "baz", p1.getLastComponent().getBuffer());
235 VASSERT_EQ("2", "bar", p1.getParent().getLastComponent().getBuffer());
236 VASSERT_EQ("3", "foo", p1.getParent().getParent().getLastComponent().getBuffer());
237 }
238
239 void testIsDirectParentOf()
240 {
241 path p1;
242 p1.appendComponent(comp("foo"));
243
244 path p2;
245 p2.appendComponent(comp("foo"));
246 p2.appendComponent(comp("bar"));
247
248 path p3;
249 p3.appendComponent(comp("foo"));
250 p3.appendComponent(comp("bar"));
251 p3.appendComponent(comp("baz"));
252
253 VASSERT_EQ("1", true, p1.isDirectParentOf(p2));
254 VASSERT_EQ("2", true, p2.isDirectParentOf(p3));
255 VASSERT_EQ("3", false, p1.isDirectParentOf(p3));
256 VASSERT_EQ("4", false, p2.isDirectParentOf(p1));
257 }
258
259 void testIsParentOf()
260 {
261 path p1;
262 p1.appendComponent(comp("foo"));
263
264 path p2;
265 p2.appendComponent(comp("foo"));
266 p2.appendComponent(comp("bar"));
267
268 path p3;
269 p3.appendComponent(comp("foo"));
270 p3.appendComponent(comp("bar"));
271 p3.appendComponent(comp("baz"));
272
273 VASSERT_EQ("1", true, p1.isParentOf(p2));
274 VASSERT_EQ("2", true, p2.isParentOf(p3));
275 VASSERT_EQ("3", true, p1.isParentOf(p3));
276 VASSERT_EQ("4", false, p2.isParentOf(p1));
277 }
278
279 void testIsParentOf_EquivalentCharset()
280 {
281 path p1;
282 p1.appendComponent(comp("foo", "us-ascii"));
283
284 path p2;
285 p2.appendComponent(comp("foo", "utf-8"));
286 p2.appendComponent(comp("bar"));
287 p2.appendComponent(comp("baz"));
288
289 VASSERT_EQ("1", true, p1.isParentOf(p2));
290 }
291
292 void testRenameParent()
293 {
294 path p1;
295 p1.appendComponent(comp("a"));
296 p1.appendComponent(comp("b"));
297 p1.appendComponent(comp("c"));
298 p1.appendComponent(comp("d"));
299
300 path p2;
301 p2.appendComponent(comp("a"));
302 p2.appendComponent(comp("b"));
303
304 path p3;
305 p3.appendComponent(comp("x"));
306 p3.appendComponent(comp("y"));
307 p3.appendComponent(comp("z"));
308
309 path p(p1);
310 p.renameParent(p2, p3);
311
312 VASSERT_EQ("1", 5, p.getSize());
313 VASSERT_EQ("2", "x", p.getComponentAt(0).getBuffer());
314 VASSERT_EQ("3", "y", p.getComponentAt(1).getBuffer());
315 VASSERT_EQ("4", "z", p.getComponentAt(2).getBuffer());
316 VASSERT_EQ("5", "c", p.getComponentAt(3).getBuffer());
317 VASSERT_EQ("6", "d", p.getComponentAt(4).getBuffer());
318 }
319
320 void testFromString()
321 {
322 path p = path::fromString("ab/cde/f", "/", vmime::charset("my-charset"));
323
324 VASSERT_EQ("count", 3, p.getSize());
325 VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer());
326 VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName());
327 VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer());
328 VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName());
329 VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer());
330 VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName());
331 }
332
333 void testFromString_IgnoreLeadingOrTrailingSep()
334 {
335 path p = path::fromString("//ab/cde/f////", "/", vmime::charset("my-charset"));
336
337 VASSERT_EQ("count", 3, p.getSize());
338 VASSERT_EQ("buffer1", "ab", p.getComponentAt(0).getBuffer());
339 VASSERT_EQ("charset1", "my-charset", p.getComponentAt(0).getCharset().getName());
340 VASSERT_EQ("buffer2", "cde", p.getComponentAt(1).getBuffer());
341 VASSERT_EQ("charset2", "my-charset", p.getComponentAt(1).getCharset().getName());
342 VASSERT_EQ("buffer3", "f", p.getComponentAt(2).getBuffer());
343 VASSERT_EQ("charset3", "my-charset", p.getComponentAt(2).getCharset().getName());
344 }
345
346 void testToString()
347 {
348 path p;
349 p.appendComponent(comp("ab"));
350 p.appendComponent(comp("cde"));
351 p.appendComponent(comp("f"));
352
353 VASSERT_EQ("string", "ab/cde/f", p.toString("/", vmime::charset("us-ascii")));
354 }
355
356 VMIME_TEST_SUITE_END
357