1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include <testshl/simpleheader.hxx>
25 #include <odiapi/props/Properties.hxx>
26 #include "FileLoggerImpl.hxx"
27 #include "ExternalViewLogger.hxx"
28 #include <osl/file.hxx>
29 #include <osl/thread.hxx>
30 #include <exception>
31 #include <stdio.h>
32
33 using namespace odiapi::props;
34 using namespace writerfilter;
35 using namespace std;
36 using namespace util;
37 using namespace osl;
38 using namespace rtl;
39
40 /** Helper function, get a temporary file name
41 */
getTempFileName(const OUString & fileName)42 OString getTempFileName(const OUString& fileName)
43 {
44 OUString ousTmpUrl;
45 FileBase::getTempDirURL(ousTmpUrl);
46 if (!ousTmpUrl.endsWithIgnoreAsciiCaseAsciiL("/", 1))
47 ousTmpUrl += OUString::createFromAscii("/");
48 ousTmpUrl += fileName;
49
50 OUString sysTmpPath;
51 FileBase::getSystemPathFromFileURL(ousTmpUrl, sysTmpPath);
52
53 return OUStringToOString(sysTmpPath, osl_getThreadTextEncoding());
54 }
55
56 class TestProperty : public CppUnit::TestFixture
57 {
58 public:
testCreateIntProperty()59 void testCreateIntProperty()
60 {
61 Property::Pointer_t intProp = createIntegerProperty(NS_fo::LN_font_weight, 35);
62 CPPUNIT_ASSERT_MESSAGE("Wrong property id", intProp->getId() == NS_fo::LN_font_weight);
63 CPPUNIT_ASSERT_MESSAGE("Wrong int value", intProp->getIntValue() == 35);
64 CPPUNIT_ASSERT_MESSAGE("Wrong string value", intProp->getStringValue() == "35");
65 }
66
testCreateStringProperty()67 void testCreateStringProperty()
68 {
69 Property::Pointer_t strProp = createStringProperty(NS_style::LN_font_face, "Times New Roman");
70 CPPUNIT_ASSERT_MESSAGE("Wrong property id", strProp->getId() == NS_style::LN_font_face);
71 CPPUNIT_ASSERT_MESSAGE("Wrong string value", strProp->getStringValue() == "Times New Roman");
72 try
73 {
74 strProp->getIntValue();
75 }
76 catch(const logic_error& ex)
77 {
78 return;
79 }
80 CPPUNIT_ASSERT_MESSAGE("Operation getIntValue should not be supported by StringProperty", false);
81 }
82
testCreateCompositeProperty()83 void testCreateCompositeProperty()
84 {
85 PropertyPool::Pointer_t pool = createPropertyPool();
86
87 PropertyBag_Pointer_t pb = createPropertyBag();
88 pb->insert(createStringProperty(NS_style::LN_font_face, "Times"));
89 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
90 Property::Pointer_t cp1 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb));
91
92 CPPUNIT_ASSERT_MESSAGE("Failed to get NS_style::LN_font_face", cp1->findChild(NS_style::LN_font_face)->getStringValue() == "Times");
93 CPPUNIT_ASSERT_MESSAGE("Failed to get NS_fo::LN_font_weight", cp1->findChild(NS_fo::LN_font_weight)->getIntValue() == 12);
94 }
95
testCompareSimpleProperties()96 void testCompareSimpleProperties()
97 {
98 Property::Pointer_t pb1 = createStringProperty(NS_style::LN_font_face, "Times New Roman");
99 Property::Pointer_t pb2 = createStringProperty(NS_style::LN_font_face, "Times New Roman");
100 CPPUNIT_ASSERT_MESSAGE("pb1 == pb2", pb1 == pb2);
101
102 Property::Pointer_t fw = createIntegerProperty(NS_fo::LN_font_weight, 12);
103 Property::Pointer_t ff = createStringProperty(NS_style::LN_font_face, "Times");
104
105 CPPUNIT_ASSERT_MESSAGE("fw == fw failed", fw == fw);
106 CPPUNIT_ASSERT_MESSAGE("fw > ff failed", ff < fw);
107 CPPUNIT_ASSERT_MESSAGE("ff == ff failed", ff == ff);
108 CPPUNIT_ASSERT_MESSAGE("!(ff < fw) failed", !(fw < ff));
109 }
110
testCompareCompositeProperties()111 void testCompareCompositeProperties()
112 {
113 PropertyPool::Pointer_t pool = createPropertyPool();
114
115 PropertyBag_Pointer_t pb1 = createPropertyBag();
116 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
117 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
118 Property::Pointer_t cp1 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1));
119
120 PropertyBag_Pointer_t ps2 = createPropertyBag();
121 ps2->insert(createStringProperty(NS_style::LN_font_face, "Times"));
122 ps2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
123 Property::Pointer_t cp2 = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(ps2));
124
125 CPPUNIT_ASSERT_MESSAGE("cp1 == cp2 failed", cp1 == cp2);
126 }
127
testPropertyBagAsStructure()128 void testPropertyBagAsStructure()
129 {
130 PropertyBag_Pointer_t propSeq = createPropertyBag();
131 Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12);
132
133 propSeq->insert(fontWeight12);
134 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq->size() == 1);
135 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 12);
136 }
137
testNoDuplicatesInPropertyBagStructures()138 void testNoDuplicatesInPropertyBagStructures()
139 {
140 PropertyBag_Pointer_t propSeq = createPropertyBag();
141 Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12);
142 propSeq->insert(fontWeight12);
143
144 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq->size() == 1);
145 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 12", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 12);
146
147 Property::Pointer_t fontWeight14 = createIntegerProperty(NS_fo::LN_font_weight, 14);
148 propSeq->insert(fontWeight14);
149
150 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq->size() == 1);
151 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 14", propSeq->find(NS_fo::LN_font_weight)->getIntValue() == 14);
152 }
153
testPropertyBagAsArray()154 void testPropertyBagAsArray()
155 {
156 PropertyBag_Pointer_t pb = createPropertyBag();
157 Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12);
158
159 pb->insert(0, fontWeight12);
160
161 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", pb->size() == 1);
162 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", pb->get(0)->getIntValue() == 12);
163 CPPUNIT_ASSERT_MESSAGE("Wrong property id", pb->get(0)->getId() == NS_fo::LN_font_weight);
164
165 Iterator<Property::Pointer_t>::Pointer_t iter = pb->createIterator();
166 for (iter->first(); !iter->isDone(); iter->next())
167 {
168 CPPUNIT_ASSERT_MESSAGE("Test property bag as array failed", iter->getCurrent()->getId() == NS_fo::LN_font_weight);
169 }
170 }
171
testCopyPropertyBag()172 void testCopyPropertyBag()
173 {
174 PropertyBag_Pointer_t propBag = createPropertyBag();
175 Property::Pointer_t fontWeight12 = createIntegerProperty(NS_fo::LN_font_weight, 12);
176
177 propBag->insert(0, fontWeight12);
178
179 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propBag->size() == 1);
180 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propBag->get(0)->getIntValue() == 12);
181 CPPUNIT_ASSERT_MESSAGE("Wrong property id", propBag->get(0)->getId() == NS_fo::LN_font_weight);
182
183 PropertyBag_Pointer_t propBagCopy = propBag->copy();
184
185 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed, distinct instances expected", propBag.get() != propBagCopy.get());
186
187 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->size() == 1);
188 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->get(0)->getIntValue() == 12);
189 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy->get(0)->getId() == NS_fo::LN_font_weight);
190 }
191
testClearPropertyBag()192 void testClearPropertyBag()
193 {
194 PropertyBag_Pointer_t pb = createPropertyBag();
195 pb->insert(createStringProperty(NS_style::LN_font_face, "Times"));
196 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
197
198 CPPUNIT_ASSERT_MESSAGE("Insert into property bag failed", pb->size() == 2);
199
200 pb->clear();
201
202 CPPUNIT_ASSERT_MESSAGE("Clearing property bag failed", pb->size() == 0);
203 }
204
testSortPropertyBag()205 void testSortPropertyBag()
206 {
207 QName_t sortedOrder [] = { NS_style::LN_font_face, NS_fo::LN_font_weight };
208
209 PropertyBag_Pointer_t pb = createPropertyBag();
210 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
211 pb->insert(createStringProperty(NS_style::LN_font_face, "Times"));
212
213 pb->sort();
214
215 Iterator<Property::Pointer_t>::Pointer_t iter = pb->createIterator();
216 int i = 0;
217 for (iter->first(); !iter->isDone(); iter->next(), i++)
218 {
219 CPPUNIT_ASSERT_MESSAGE("Sorting property bag failed", sortedOrder[i] == iter->getCurrent()->getId());
220 }
221 }
222
testDuplicateValuesInArray()223 void testDuplicateValuesInArray()
224 {
225 PropertyBag_Pointer_t propSeq = createPropertyBag();
226
227 Property::Pointer_t fontWeight1 = createIntegerProperty(NS_fo::LN_font_weight, 12);
228 propSeq->insert(0, fontWeight1);
229
230 Property::Pointer_t fontWeight2 = createIntegerProperty(NS_fo::LN_font_weight, 12);
231 propSeq->insert(1, fontWeight2);
232
233 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq->size() == 2);
234 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence",
235 propSeq->get(0)->getId() == propSeq->get(1)->getId() &&
236 propSeq->get(0)->getIntValue() == propSeq->get(1)->getIntValue());
237 }
238
testPropertyPool()239 void testPropertyPool()
240 {
241 PropertyPool::Pointer_t pool = createPropertyPool();
242
243 PropertyBag_Pointer_t pb1 = createPropertyBag();
244 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
245 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
246 PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1);
247
248 PropertyBag_Pointer_t ps2 = createPropertyBag();
249 ps2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
250 ps2->insert(createStringProperty(NS_style::LN_font_face, "Times"));
251 PropertyPoolHandle_Pointer_t ph2 = pool->insert(ps2);
252
253 CPPUNIT_ASSERT_MESSAGE("ph1 == ph2 failed", ph1 == ph2);
254
255 PropertyBag_Pointer_t ps3 = createPropertyBag();
256 ps3->insert(createIntegerProperty(NS_fo::LN_font_weight, 14));
257 ps3->insert(createStringProperty(NS_style::LN_font_face, "Times"));
258
259 PropertyPoolHandle_Pointer_t ph3 = pool->insert(ps3);
260
261 CPPUNIT_ASSERT_MESSAGE("ph2 != ph3 failed", ph2 != ph3);
262
263 PropertyBag_Pointer_t ps4 = createPropertyBag();
264 ps4->insert(0, createIntegerProperty(NS_fo::LN_font_weight, 12));
265 ps4->insert(1, createIntegerProperty(NS_fo::LN_font_weight, 12));
266 ps4->insert(2, createIntegerProperty(NS_fo::LN_font_weight, 12));
267 ps4->insert(3, createIntegerProperty(NS_fo::LN_font_weight, 12));
268
269 pool->insert(ps4);
270
271 OString tmpFileName = getTempFileName(OUString::createFromAscii("testPropertyPool_int.dot"));
272 printf("Pool dump: %s\n", tmpFileName.getStr());
273 FileLoggerImpl fl(tmpFileName.getStr());
274 pool->dump(&fl);
275
276 OString tmpFileName2 = getTempFileName(OUString::createFromAscii("testPropertyPool_ext.dot"));
277 printf("Pool dump: %s\n", tmpFileName2.getStr());
278 ExternalViewLoggerImpl evl(tmpFileName2.getStr());
279 pool->dump(&evl);
280 }
281
testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail()282 void testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail()
283 {
284 PropertyPool::Pointer_t pool = createPropertyPool();
285
286 PropertyBag_Pointer_t pb1 = createPropertyBag();
287 pb1->insert(createIntegerProperty(NS_style::LN_tab_stop, 100));
288 pb1->insert(createStringProperty(NS_style::LN_type, "left"));
289 Property::Pointer_t tab100 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1));
290
291 pb1->clear();
292 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
293 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman"));
294 Property::Pointer_t charProps1 = createCompositeProperty(NS_style::LN_char, pool->insert(pb1));
295
296 pb1->clear();
297 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
298 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman"));
299 Property::Pointer_t charProps2 = createCompositeProperty(NS_style::LN_char, pool->insert(pb1));
300
301 CPPUNIT_ASSERT_MESSAGE("CharProps1 == CharProps2 failed", charProps1 == charProps2);
302 }
303
testComplexParagraphProperty()304 void testComplexParagraphProperty()
305 {
306 PropertyPool::Pointer_t pool = createPropertyPool();
307 PropertyBag_Pointer_t pb1 = createPropertyBag();
308
309 pb1->insert(createIntegerProperty(NS_style::LN_position, 100));
310 pb1->insert(createStringProperty(NS_style::LN_type, "left"));
311 Property::Pointer_t tab100 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1));
312
313 pb1->clear();
314
315 pb1->insert(createIntegerProperty(NS_style::LN_position, 200));
316 pb1->insert(createStringProperty(NS_style::LN_type, "center"));
317 Property::Pointer_t tab200 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1));
318
319 CPPUNIT_ASSERT_MESSAGE("tab100 != tab200 failed", tab100 != tab200);
320
321 pb1->clear();
322 pb1->insert(100, tab100);
323 pb1->insert(200, tab200);
324 Property::Pointer_t tabs = createCompositeProperty(NS_style::LN_tab_stops, pool->insert(pb1));
325
326 pb1->clear();
327 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
328 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman"));
329 Property::Pointer_t charProps = createCompositeProperty(NS_style::LN_char, pool->insert(pb1));
330
331 pb1->clear();
332 pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20));
333 pb1->insert(tabs);
334 pb1->insert(charProps);
335 Property::Pointer_t paraProps = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1));
336
337 pb1->clear();
338 pb1->insert(createIntegerProperty(NS_style::LN_position, 100));
339 pb1->insert(createStringProperty(NS_style::LN_type, "left"));
340 Property::Pointer_t tab300 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1));
341
342 pb1->clear();
343 pb1->insert(createIntegerProperty(NS_style::LN_position, 200));
344 pb1->insert(createStringProperty(NS_style::LN_type, "center"));
345 Property::Pointer_t tab400 = createCompositeProperty(NS_style::LN_tab_stop, pool->insert(pb1));
346
347 CPPUNIT_ASSERT_MESSAGE("tab300 != tab400 failed", tab300 != tab400);
348
349 pb1->clear();
350 pb1->insert(100, tab300);
351 pb1->insert(200, tab400);
352 Property::Pointer_t tabulators = createCompositeProperty(NS_style::LN_tab_stops, pool->insert(pb1));
353
354 CPPUNIT_ASSERT_MESSAGE("tabs == tabulators failed", tabs == tabulators);
355
356 pb1->clear();
357 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
358 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times New Roman"));
359 Property::Pointer_t characterProps = createCompositeProperty(NS_style::LN_char, pool->insert(pb1));
360
361 CPPUNIT_ASSERT_MESSAGE("Comparison of character properties failed", charProps == characterProps);
362
363 pb1->clear();
364 pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20));
365 pb1->insert(tabulators);
366 pb1->insert(characterProps);
367 Property::Pointer_t paragraphProps = createCompositeProperty(NS_style::LN_paragraph_properties, pool->insert(pb1));
368
369 CPPUNIT_ASSERT_MESSAGE("paraProps == failed failed", paraProps == paragraphProps);
370
371 OString tmpFileName = getTempFileName(OUString::createFromAscii("testComplexParaProps_int.dot"));
372 printf("Pool dump: %s\n", tmpFileName.getStr());
373 FileLoggerImpl fl(tmpFileName.getStr());
374 pool->dump(&fl);
375
376 OString tmpFileName2 = getTempFileName(OUString::createFromAscii("testComplexParaProps_ext.dot"));
377 printf("Pool dump: %s\n", tmpFileName2.getStr());
378 ExternalViewLoggerImpl evl(tmpFileName2.getStr());
379 pool->dump(&evl);
380 }
381
testInsertEmptyPropertyBag()382 void testInsertEmptyPropertyBag()
383 {
384 PropertyPool::Pointer_t pool = createPropertyPool();
385 PropertyBag_Pointer_t pb = createPropertyBag();
386 PropertyPoolHandle_Pointer_t ph = pool->insert(pb);
387
388 CPPUNIT_ASSERT_MESSAGE("Inserting empty property bag failed", ph->getPropertyBag()->size() == 0);
389 }
390
testDumpPropertyPool()391 void testDumpPropertyPool()
392 {
393 PropertyPool::Pointer_t pool = createPropertyPool();
394 PropertyBag_Pointer_t pb1 = createPropertyBag();
395 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
396 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
397 PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1);
398
399 Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator();
400
401 int i = 0;
402 for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */;
403
404 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1);
405
406 /* Insert an equal PropertyBag again, as PropertyBags in the
407 pool are unique there must be still just one PropertyBag in the pool
408 */
409 PropertyBag_Pointer_t pb2 = createPropertyBag();
410 pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
411 pb2->insert(createStringProperty(NS_style::LN_font_face, "Times"));
412 PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2);
413
414 iter = pool->createIterator();
415
416 i = 0;
417 for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */;
418
419 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1);
420
421 { // scope
422
423 /* Insert a different PropertyBag into the pool now there must be
424 two PropertyBags in the pool */
425 PropertyBag_Pointer_t pb3 = createPropertyBag();
426 pb3->insert(createIntegerProperty(NS_style::LN_position, 12));
427 pb3->insert(createStringProperty(NS_style::LN_type, "left"));
428 PropertyPoolHandle_Pointer_t ph3 = pool->insert(pb3);
429
430 iter = pool->createIterator();
431
432 i = 0;
433 for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */;
434
435 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 2);
436
437 } // end scope
438
439 /* as pb3 is only valid in the above scope the property pool must
440 now contain just one property bag
441 */
442 iter = pool->createIterator();
443
444 i = 0;
445 for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/;
446
447 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 1);
448 }
449
testInsertPropertySubsets()450 void testInsertPropertySubsets()
451 {
452 PropertyPool::Pointer_t pool = createPropertyPool();
453
454 PropertyBag_Pointer_t pb1 = createPropertyBag();
455 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
456 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
457 PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1);
458
459 /* Insert an equal PropertyBag again, as PropertyBags in the
460 pool are unique there must be still just one PropertyBag in the pool
461 */
462 pb1->clear();
463 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
464 PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb1);
465
466 CPPUNIT_ASSERT_MESSAGE("ph1 != ph2 failed", ph1 != ph2);
467
468 Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator();
469
470 int i = 0;
471 for (iter->first(); !iter->isDone(); iter->next(), i++) /* nothing to do */;
472
473 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 2);
474 }
475
testDumpEmptyPropertyPool()476 void testDumpEmptyPropertyPool()
477 {
478 PropertyPool::Pointer_t pool = createPropertyPool();
479 Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator();
480
481 int i = 0;
482 for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/;
483
484 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i == 0);
485 }
486
testPropertyPoolGarbageCollection()487 void testPropertyPoolGarbageCollection()
488 {
489 PropertyPool::Pointer_t pool = createPropertyPool();
490
491 PropertyBag_Pointer_t pb1 = createPropertyBag();
492 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
493 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
494 pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20));
495 PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1);
496
497 {
498 PropertyBag_Pointer_t pb2 = createPropertyBag();
499 pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
500 pb2->insert(createStringProperty(NS_style::LN_font_face, "Roman"));
501 PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2);
502
503 OString tmpFileName = getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_1.dot"));
504 printf("Pool dump: %s\n", tmpFileName.getStr());
505 FileLoggerImpl fl(tmpFileName.getStr());
506 pool->dump(&fl);
507
508 }
509
510 OString tmpFileName = getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_2.dot"));
511 printf("Pool dump: %s\n", tmpFileName.getStr());
512 FileLoggerImpl fl(tmpFileName.getStr());
513 pool->dump(&fl);
514
515 pool->garbageCollection();
516
517 OString tmpFileName2 = getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_after.dot"));
518 printf("Pool dump: %s\n", tmpFileName2.getStr());
519 FileLoggerImpl fl2(tmpFileName2.getStr());
520 pool->dump(&fl2);
521
522 }
523
testDumpPropertyPoolAfterGarbageCollection()524 void testDumpPropertyPoolAfterGarbageCollection()
525 {
526 PropertyPool::Pointer_t pool = createPropertyPool();
527
528 PropertyBag_Pointer_t pb1 = createPropertyBag();
529 pb1->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
530 pb1->insert(createStringProperty(NS_style::LN_font_face, "Times"));
531 pb1->insert(createIntegerProperty(NS_fo::LN_line_height, 20));
532 PropertyPoolHandle_Pointer_t ph1 = pool->insert(pb1);
533
534 {
535 PropertyBag_Pointer_t pb2 = createPropertyBag();
536 pb2->insert(createIntegerProperty(NS_fo::LN_font_weight, 12));
537 pb2->insert(createStringProperty(NS_style::LN_font_face, "Roman"));
538 PropertyPoolHandle_Pointer_t ph2 = pool->insert(pb2);
539
540 Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator();
541
542 int i = 0;
543 for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/;
544
545 CPPUNIT_ASSERT_MESSAGE("Expectation '2 PropertyBags in PropertyPool' failed", i == 2);
546 }
547
548 pool->garbageCollection();
549
550 Iterator<PropertyBag_Pointer_t>::Pointer_t iter = pool->createIterator();
551
552 int i = 0;
553 for (iter->first(); !iter->isDone(); iter->next(), i++) /*nothing to do*/;
554
555 CPPUNIT_ASSERT_MESSAGE("Expectation '1 PropertyBag in PropertyPool' failed", i == 1);
556 }
557
558 // 'cm', 'mm', 'inch', 'pt', 'px', 'pc'
testCreateTwipsProperty()559 void testCreateTwipsProperty()
560 {
561 Property::Pointer_t tp1 = createTwipsProperty(NS_style::LN_position, "1cm");
562 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp1->getIntValue() == 567);
563 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp1->getStringValue() == "1.000 cm");
564
565 Property::Pointer_t tp2 = createTwipsProperty(NS_style::LN_position, "1 cm");
566 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp2->getIntValue() == 567);
567 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp2->getStringValue() == "1.000 cm");
568
569 Property::Pointer_t tp3 = createTwipsProperty(NS_style::LN_position, "1 cm ");
570 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp3->getIntValue() == 567);
571 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp3->getStringValue() == "1.000 cm");
572
573 Property::Pointer_t tp4 = createTwipsProperty(NS_style::LN_position, "0 cm");
574 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp4->getIntValue() == 0);
575 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp4->getStringValue() == "0.000 cm");
576
577 Property::Pointer_t tp5 = createTwipsProperty(NS_style::LN_position, "10mm");
578 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp5->getIntValue() == 567);
579 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp5->getStringValue() == "1.000 cm");
580
581 Property::Pointer_t tp6 = createTwipsProperty(NS_style::LN_position, 567);
582 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp6->getIntValue() == 567);
583 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp6->getStringValue() == "1.000 cm");
584
585 Property::Pointer_t tp7 = createTwipsProperty(NS_style::LN_position, "100pt");
586 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp7->getIntValue() == 2000);
587 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp7->getStringValue() == "3.527 cm");
588
589 Property::Pointer_t tp8 = createTwipsProperty(NS_style::LN_position, "1 in");
590 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp8->getIntValue() == 1440);
591 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp8->getStringValue() == "2.540 cm");
592
593 Property::Pointer_t tp9 = createTwipsProperty(NS_style::LN_position, "-1 cm");
594 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp9->getIntValue() == -567);
595 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp9->getStringValue() == "-1.000 cm");
596
597 Property::Pointer_t tp10 = createTwipsProperty(NS_style::LN_position, "+1 cm");
598 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp10->getIntValue() == 567);
599 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp10->getStringValue() == "1.000 cm");
600
601 Property::Pointer_t tp11 = createTwipsProperty(NS_style::LN_position, "1 pt ");
602 Property::Pointer_t tp12 = createTwipsProperty(NS_style::LN_position, "2pt");
603 CPPUNIT_ASSERT_MESSAGE("Comparing twips properties failed", tp11 < tp12);
604 }
605
testCreateInvalidTwipsProperty()606 void testCreateInvalidTwipsProperty()
607 {
608 try
609 {
610 Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, "0,1 cm");
611 }
612 catch(std::invalid_argument& )
613 {
614 return; // OK
615 }
616 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
617 }
618
testCreateInvalidTwipsProperty2()619 void testCreateInvalidTwipsProperty2()
620 {
621 try
622 {
623 Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, "");
624 }
625 catch(std::invalid_argument& )
626 {
627 return; // OK
628 }
629 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
630 }
631
testCreateInvalidTwipsProperty3()632 void testCreateInvalidTwipsProperty3()
633 {
634 try
635 {
636 Property::Pointer_t tp = createTwipsProperty(NS_style::LN_position, " cm");
637 }
638 catch(std::invalid_argument& )
639 {
640 return; // OK
641 }
642 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
643 }
644
645 CPPUNIT_TEST_SUITE(TestProperty);
646 CPPUNIT_TEST(testCreateIntProperty);
647 CPPUNIT_TEST(testCreateStringProperty);
648 CPPUNIT_TEST(testCreateCompositeProperty);
649 CPPUNIT_TEST(testPropertyBagAsStructure);
650 CPPUNIT_TEST(testNoDuplicatesInPropertyBagStructures);
651 CPPUNIT_TEST(testPropertyBagAsArray);
652 CPPUNIT_TEST(testDuplicateValuesInArray);
653 CPPUNIT_TEST(testCopyPropertyBag);
654 CPPUNIT_TEST(testClearPropertyBag);
655 CPPUNIT_TEST(testSortPropertyBag);
656 CPPUNIT_TEST(testCompareSimpleProperties);
657 CPPUNIT_TEST(testCompareCompositeProperties);
658 CPPUNIT_TEST(testPropertyPool);
659 CPPUNIT_TEST(testComplexParagraphProperty);
660 CPPUNIT_TEST(testInsertEmptyPropertyBag);
661 CPPUNIT_TEST(testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail);
662 CPPUNIT_TEST(testDumpPropertyPool);
663 CPPUNIT_TEST(testDumpEmptyPropertyPool);
664 CPPUNIT_TEST(testInsertPropertySubsets);
665 CPPUNIT_TEST(testPropertyPoolGarbageCollection);
666 CPPUNIT_TEST(testDumpPropertyPoolAfterGarbageCollection);
667 CPPUNIT_TEST(testCreateTwipsProperty);
668 CPPUNIT_TEST(testCreateInvalidTwipsProperty);
669 CPPUNIT_TEST(testCreateInvalidTwipsProperty2);
670 CPPUNIT_TEST(testCreateInvalidTwipsProperty3);
671 CPPUNIT_TEST_SUITE_END();
672 };
673
674 //#####################################
675 // register test suites
676 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestProperty, "TestProperty");
677
678 NOADDITIONAL;
679