1 /* Copyright 2005 Sun Microsystems, Inc. */
3 #include <cppunit/simpleheader.hxx>
4 #include <odiapi/props/Properties.hxx>
5 #include "FileLoggerImpl.hxx"
6 #include "ExternalViewLogger.hxx"
7 #include <osl/file.hxx>
8 #include <osl/thread.hxx>
12 using namespace odiapi::props
;
13 using namespace writerfilter
;
19 /** Helper function, get a temporary file name
21 OString
getTempFileName(const OUString
& fileName
)
24 FileBase::getTempDirURL(ousTmpUrl
);
25 if (!ousTmpUrl
.endsWithIgnoreAsciiCaseAsciiL("/", 1))
26 ousTmpUrl
+= OUString::createFromAscii("/");
27 ousTmpUrl
+= fileName
;
30 FileBase::getSystemPathFromFileURL(ousTmpUrl
, sysTmpPath
);
32 return OUStringToOString(sysTmpPath
, osl_getThreadTextEncoding());
35 class TestProperty
: public CppUnit::TestFixture
38 void testCreateIntProperty()
40 Property::Pointer_t intProp
= createIntegerProperty(NS_fo::LN_font_weight
, 35);
41 CPPUNIT_ASSERT_MESSAGE("Wrong property id", intProp
->getId() == NS_fo::LN_font_weight
);
42 CPPUNIT_ASSERT_MESSAGE("Wrong int value", intProp
->getIntValue() == 35);
43 CPPUNIT_ASSERT_MESSAGE("Wrong string value", intProp
->getStringValue() == "35");
46 void testCreateStringProperty()
48 Property::Pointer_t strProp
= createStringProperty(NS_style::LN_font_face
, "Times New Roman");
49 CPPUNIT_ASSERT_MESSAGE("Wrong property id", strProp
->getId() == NS_style::LN_font_face
);
50 CPPUNIT_ASSERT_MESSAGE("Wrong string value", strProp
->getStringValue() == "Times New Roman");
53 strProp
->getIntValue();
55 catch(const logic_error
& ex
)
59 CPPUNIT_ASSERT_MESSAGE("Operation getIntValue should not be supported by StringProperty", false);
62 void testCreateCompositeProperty()
64 PropertyPool::Pointer_t pool
= createPropertyPool();
66 PropertyBag_Pointer_t pb
= createPropertyBag();
67 pb
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
68 pb
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
69 Property::Pointer_t cp1
= createCompositeProperty(NS_style::LN_paragraph_properties
, pool
->insert(pb
));
71 CPPUNIT_ASSERT_MESSAGE("Failed to get NS_style::LN_font_face", cp1
->findChild(NS_style::LN_font_face
)->getStringValue() == "Times");
72 CPPUNIT_ASSERT_MESSAGE("Failed to get NS_fo::LN_font_weight", cp1
->findChild(NS_fo::LN_font_weight
)->getIntValue() == 12);
75 void testCompareSimpleProperties()
77 Property::Pointer_t pb1
= createStringProperty(NS_style::LN_font_face
, "Times New Roman");
78 Property::Pointer_t pb2
= createStringProperty(NS_style::LN_font_face
, "Times New Roman");
79 CPPUNIT_ASSERT_MESSAGE("pb1 == pb2", pb1
== pb2
);
81 Property::Pointer_t fw
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
82 Property::Pointer_t ff
= createStringProperty(NS_style::LN_font_face
, "Times");
84 CPPUNIT_ASSERT_MESSAGE("fw == fw failed", fw
== fw
);
85 CPPUNIT_ASSERT_MESSAGE("fw > ff failed", ff
< fw
);
86 CPPUNIT_ASSERT_MESSAGE("ff == ff failed", ff
== ff
);
87 CPPUNIT_ASSERT_MESSAGE("!(ff < fw) failed", !(fw
< ff
));
90 void testCompareCompositeProperties()
92 PropertyPool::Pointer_t pool
= createPropertyPool();
94 PropertyBag_Pointer_t pb1
= createPropertyBag();
95 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
96 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
97 Property::Pointer_t cp1
= createCompositeProperty(NS_style::LN_paragraph_properties
, pool
->insert(pb1
));
99 PropertyBag_Pointer_t ps2
= createPropertyBag();
100 ps2
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
101 ps2
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
102 Property::Pointer_t cp2
= createCompositeProperty(NS_style::LN_paragraph_properties
, pool
->insert(ps2
));
104 CPPUNIT_ASSERT_MESSAGE("cp1 == cp2 failed", cp1
== cp2
);
107 void testPropertyBagAsStructure()
109 PropertyBag_Pointer_t propSeq
= createPropertyBag();
110 Property::Pointer_t fontWeight12
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
112 propSeq
->insert(fontWeight12
);
113 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq
->size() == 1);
114 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propSeq
->find(NS_fo::LN_font_weight
)->getIntValue() == 12);
117 void testNoDuplicatesInPropertyBagStructures()
119 PropertyBag_Pointer_t propSeq
= createPropertyBag();
120 Property::Pointer_t fontWeight12
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
121 propSeq
->insert(fontWeight12
);
123 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq
->size() == 1);
124 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 12", propSeq
->find(NS_fo::LN_font_weight
)->getIntValue() == 12);
126 Property::Pointer_t fontWeight14
= createIntegerProperty(NS_fo::LN_font_weight
, 14);
127 propSeq
->insert(fontWeight14
);
129 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with 1 element", propSeq
->size() == 1);
130 CPPUNIT_ASSERT_MESSAGE("Expect property sequence with one int value 14", propSeq
->find(NS_fo::LN_font_weight
)->getIntValue() == 14);
133 void testPropertyBagAsArray()
135 PropertyBag_Pointer_t pb
= createPropertyBag();
136 Property::Pointer_t fontWeight12
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
138 pb
->insert(0, fontWeight12
);
140 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", pb
->size() == 1);
141 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", pb
->get(0)->getIntValue() == 12);
142 CPPUNIT_ASSERT_MESSAGE("Wrong property id", pb
->get(0)->getId() == NS_fo::LN_font_weight
);
144 Iterator
<Property::Pointer_t
>::Pointer_t iter
= pb
->createIterator();
145 for (iter
->first(); !iter
->isDone(); iter
->next())
147 CPPUNIT_ASSERT_MESSAGE("Test property bag as array failed", iter
->getCurrent()->getId() == NS_fo::LN_font_weight
);
151 void testCopyPropertyBag()
153 PropertyBag_Pointer_t propBag
= createPropertyBag();
154 Property::Pointer_t fontWeight12
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
156 propBag
->insert(0, fontWeight12
);
158 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propBag
->size() == 1);
159 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence", propBag
->get(0)->getIntValue() == 12);
160 CPPUNIT_ASSERT_MESSAGE("Wrong property id", propBag
->get(0)->getId() == NS_fo::LN_font_weight
);
162 PropertyBag_Pointer_t propBagCopy
= propBag
->copy();
164 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed, distinct instances expected", propBag
.get() != propBagCopy
.get());
166 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy
->size() == 1);
167 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy
->get(0)->getIntValue() == 12);
168 CPPUNIT_ASSERT_MESSAGE("Copy property bag failed", propBagCopy
->get(0)->getId() == NS_fo::LN_font_weight
);
171 void testClearPropertyBag()
173 PropertyBag_Pointer_t pb
= createPropertyBag();
174 pb
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
175 pb
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
177 CPPUNIT_ASSERT_MESSAGE("Insert into property bag failed", pb
->size() == 2);
181 CPPUNIT_ASSERT_MESSAGE("Clearing property bag failed", pb
->size() == 0);
184 void testSortPropertyBag()
186 QName_t sortedOrder
[] = { NS_style::LN_font_face
, NS_fo::LN_font_weight
};
188 PropertyBag_Pointer_t pb
= createPropertyBag();
189 pb
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
190 pb
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
194 Iterator
<Property::Pointer_t
>::Pointer_t iter
= pb
->createIterator();
196 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++)
198 CPPUNIT_ASSERT_MESSAGE("Sorting property bag failed", sortedOrder
[i
] == iter
->getCurrent()->getId());
202 void testDuplicateValuesInArray()
204 PropertyBag_Pointer_t propSeq
= createPropertyBag();
206 Property::Pointer_t fontWeight1
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
207 propSeq
->insert(0, fontWeight1
);
209 Property::Pointer_t fontWeight2
= createIntegerProperty(NS_fo::LN_font_weight
, 12);
210 propSeq
->insert(1, fontWeight2
);
212 CPPUNIT_ASSERT_MESSAGE("Inserting property into property sequence failed", propSeq
->size() == 2);
213 CPPUNIT_ASSERT_MESSAGE("Property not in property sequence",
214 propSeq
->get(0)->getId() == propSeq
->get(1)->getId() &&
215 propSeq
->get(0)->getIntValue() == propSeq
->get(1)->getIntValue());
218 void testPropertyPool()
220 PropertyPool::Pointer_t pool
= createPropertyPool();
222 PropertyBag_Pointer_t pb1
= createPropertyBag();
223 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
224 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
225 PropertyPoolHandle_Pointer_t ph1
= pool
->insert(pb1
);
227 PropertyBag_Pointer_t ps2
= createPropertyBag();
228 ps2
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
229 ps2
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
230 PropertyPoolHandle_Pointer_t ph2
= pool
->insert(ps2
);
232 CPPUNIT_ASSERT_MESSAGE("ph1 == ph2 failed", ph1
== ph2
);
234 PropertyBag_Pointer_t ps3
= createPropertyBag();
235 ps3
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 14));
236 ps3
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
238 PropertyPoolHandle_Pointer_t ph3
= pool
->insert(ps3
);
240 CPPUNIT_ASSERT_MESSAGE("ph2 != ph3 failed", ph2
!= ph3
);
242 PropertyBag_Pointer_t ps4
= createPropertyBag();
243 ps4
->insert(0, createIntegerProperty(NS_fo::LN_font_weight
, 12));
244 ps4
->insert(1, createIntegerProperty(NS_fo::LN_font_weight
, 12));
245 ps4
->insert(2, createIntegerProperty(NS_fo::LN_font_weight
, 12));
246 ps4
->insert(3, createIntegerProperty(NS_fo::LN_font_weight
, 12));
250 OString tmpFileName
= getTempFileName(OUString::createFromAscii("testPropertyPool_int.dot"));
251 printf("Pool dump: %s\n", tmpFileName
.getStr());
252 FileLoggerImpl
fl(tmpFileName
.getStr());
255 OString tmpFileName2
= getTempFileName(OUString::createFromAscii("testPropertyPool_ext.dot"));
256 printf("Pool dump: %s\n", tmpFileName2
.getStr());
257 ExternalViewLoggerImpl
evl(tmpFileName2
.getStr());
261 void testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail()
263 PropertyPool::Pointer_t pool
= createPropertyPool();
265 PropertyBag_Pointer_t pb1
= createPropertyBag();
266 pb1
->insert(createIntegerProperty(NS_style::LN_tab_stop
, 100));
267 pb1
->insert(createStringProperty(NS_style::LN_type
, "left"));
268 Property::Pointer_t tab100
= createCompositeProperty(NS_style::LN_tab_stop
, pool
->insert(pb1
));
271 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
272 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times New Roman"));
273 Property::Pointer_t charProps1
= createCompositeProperty(NS_style::LN_char
, pool
->insert(pb1
));
276 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
277 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times New Roman"));
278 Property::Pointer_t charProps2
= createCompositeProperty(NS_style::LN_char
, pool
->insert(pb1
));
280 CPPUNIT_ASSERT_MESSAGE("CharProps1 == CharProps2 failed", charProps1
== charProps2
);
283 void testComplexParagraphProperty()
285 PropertyPool::Pointer_t pool
= createPropertyPool();
286 PropertyBag_Pointer_t pb1
= createPropertyBag();
288 pb1
->insert(createIntegerProperty(NS_style::LN_position
, 100));
289 pb1
->insert(createStringProperty(NS_style::LN_type
, "left"));
290 Property::Pointer_t tab100
= createCompositeProperty(NS_style::LN_tab_stop
, pool
->insert(pb1
));
294 pb1
->insert(createIntegerProperty(NS_style::LN_position
, 200));
295 pb1
->insert(createStringProperty(NS_style::LN_type
, "center"));
296 Property::Pointer_t tab200
= createCompositeProperty(NS_style::LN_tab_stop
, pool
->insert(pb1
));
298 CPPUNIT_ASSERT_MESSAGE("tab100 != tab200 failed", tab100
!= tab200
);
301 pb1
->insert(100, tab100
);
302 pb1
->insert(200, tab200
);
303 Property::Pointer_t tabs
= createCompositeProperty(NS_style::LN_tab_stops
, pool
->insert(pb1
));
306 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
307 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times New Roman"));
308 Property::Pointer_t charProps
= createCompositeProperty(NS_style::LN_char
, pool
->insert(pb1
));
311 pb1
->insert(createIntegerProperty(NS_fo::LN_line_height
, 20));
313 pb1
->insert(charProps
);
314 Property::Pointer_t paraProps
= createCompositeProperty(NS_style::LN_paragraph_properties
, pool
->insert(pb1
));
317 pb1
->insert(createIntegerProperty(NS_style::LN_position
, 100));
318 pb1
->insert(createStringProperty(NS_style::LN_type
, "left"));
319 Property::Pointer_t tab300
= createCompositeProperty(NS_style::LN_tab_stop
, pool
->insert(pb1
));
322 pb1
->insert(createIntegerProperty(NS_style::LN_position
, 200));
323 pb1
->insert(createStringProperty(NS_style::LN_type
, "center"));
324 Property::Pointer_t tab400
= createCompositeProperty(NS_style::LN_tab_stop
, pool
->insert(pb1
));
326 CPPUNIT_ASSERT_MESSAGE("tab300 != tab400 failed", tab300
!= tab400
);
329 pb1
->insert(100, tab300
);
330 pb1
->insert(200, tab400
);
331 Property::Pointer_t tabulators
= createCompositeProperty(NS_style::LN_tab_stops
, pool
->insert(pb1
));
333 CPPUNIT_ASSERT_MESSAGE("tabs == tabulators failed", tabs
== tabulators
);
336 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
337 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times New Roman"));
338 Property::Pointer_t characterProps
= createCompositeProperty(NS_style::LN_char
, pool
->insert(pb1
));
340 CPPUNIT_ASSERT_MESSAGE("Comparison of character properties failed", charProps
== characterProps
);
343 pb1
->insert(createIntegerProperty(NS_fo::LN_line_height
, 20));
344 pb1
->insert(tabulators
);
345 pb1
->insert(characterProps
);
346 Property::Pointer_t paragraphProps
= createCompositeProperty(NS_style::LN_paragraph_properties
, pool
->insert(pb1
));
348 CPPUNIT_ASSERT_MESSAGE("paraProps == failed failed", paraProps
== paragraphProps
);
350 OString tmpFileName
= getTempFileName(OUString::createFromAscii("testComplexParaProps_int.dot"));
351 printf("Pool dump: %s\n", tmpFileName
.getStr());
352 FileLoggerImpl
fl(tmpFileName
.getStr());
355 OString tmpFileName2
= getTempFileName(OUString::createFromAscii("testComplexParaProps_ext.dot"));
356 printf("Pool dump: %s\n", tmpFileName2
.getStr());
357 ExternalViewLoggerImpl
evl(tmpFileName2
.getStr());
361 void testInsertEmptyPropertyBag()
363 PropertyPool::Pointer_t pool
= createPropertyPool();
364 PropertyBag_Pointer_t pb
= createPropertyBag();
365 PropertyPoolHandle_Pointer_t ph
= pool
->insert(pb
);
367 CPPUNIT_ASSERT_MESSAGE("Inserting empty property bag failed", ph
->getPropertyBag()->size() == 0);
370 void testDumpPropertyPool()
372 PropertyPool::Pointer_t pool
= createPropertyPool();
373 PropertyBag_Pointer_t pb1
= createPropertyBag();
374 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
375 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
376 PropertyPoolHandle_Pointer_t ph1
= pool
->insert(pb1
);
378 Iterator
<PropertyBag_Pointer_t
>::Pointer_t iter
= pool
->createIterator();
381 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /* nothing to do */;
383 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 1);
385 /* Insert an equal PropertyBag again, as PropertyBags in the
386 pool are unique there must be still just one PropertyBag in the pool
388 PropertyBag_Pointer_t pb2
= createPropertyBag();
389 pb2
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
390 pb2
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
391 PropertyPoolHandle_Pointer_t ph2
= pool
->insert(pb2
);
393 iter
= pool
->createIterator();
396 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /* nothing to do */;
398 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 1);
402 /* Insert a different PropertyBag into the pool now there must be
403 two PropertyBags in the pool */
404 PropertyBag_Pointer_t pb3
= createPropertyBag();
405 pb3
->insert(createIntegerProperty(NS_style::LN_position
, 12));
406 pb3
->insert(createStringProperty(NS_style::LN_type
, "left"));
407 PropertyPoolHandle_Pointer_t ph3
= pool
->insert(pb3
);
409 iter
= pool
->createIterator();
412 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /* nothing to do */;
414 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 2);
418 /* as pb3 is only valid in the above scope the property pool must
419 now contain just one property bag
421 iter
= pool
->createIterator();
424 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /*nothing to do*/;
426 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 1);
429 void testInsertPropertySubsets()
431 PropertyPool::Pointer_t pool
= createPropertyPool();
433 PropertyBag_Pointer_t pb1
= createPropertyBag();
434 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
435 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
436 PropertyPoolHandle_Pointer_t ph1
= pool
->insert(pb1
);
438 /* Insert an equal PropertyBag again, as PropertyBags in the
439 pool are unique there must be still just one PropertyBag in the pool
442 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
443 PropertyPoolHandle_Pointer_t ph2
= pool
->insert(pb1
);
445 CPPUNIT_ASSERT_MESSAGE("ph1 != ph2 failed", ph1
!= ph2
);
447 Iterator
<PropertyBag_Pointer_t
>::Pointer_t iter
= pool
->createIterator();
450 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /* nothing to do */;
452 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 2);
455 void testDumpEmptyPropertyPool()
457 PropertyPool::Pointer_t pool
= createPropertyPool();
458 Iterator
<PropertyBag_Pointer_t
>::Pointer_t iter
= pool
->createIterator();
461 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /*nothing to do*/;
463 CPPUNIT_ASSERT_MESSAGE("Dump PropertyBags failed", i
== 0);
466 void testPropertyPoolGarbageCollection()
468 PropertyPool::Pointer_t pool
= createPropertyPool();
470 PropertyBag_Pointer_t pb1
= createPropertyBag();
471 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
472 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
473 pb1
->insert(createIntegerProperty(NS_fo::LN_line_height
, 20));
474 PropertyPoolHandle_Pointer_t ph1
= pool
->insert(pb1
);
477 PropertyBag_Pointer_t pb2
= createPropertyBag();
478 pb2
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
479 pb2
->insert(createStringProperty(NS_style::LN_font_face
, "Roman"));
480 PropertyPoolHandle_Pointer_t ph2
= pool
->insert(pb2
);
482 OString tmpFileName
= getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_1.dot"));
483 printf("Pool dump: %s\n", tmpFileName
.getStr());
484 FileLoggerImpl
fl(tmpFileName
.getStr());
489 OString tmpFileName
= getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_2.dot"));
490 printf("Pool dump: %s\n", tmpFileName
.getStr());
491 FileLoggerImpl
fl(tmpFileName
.getStr());
494 pool
->garbageCollection();
496 OString tmpFileName2
= getTempFileName(OUString::createFromAscii("testPropPoolGarbageColl_after.dot"));
497 printf("Pool dump: %s\n", tmpFileName2
.getStr());
498 FileLoggerImpl
fl2(tmpFileName2
.getStr());
503 void testDumpPropertyPoolAfterGarbageCollection()
505 PropertyPool::Pointer_t pool
= createPropertyPool();
507 PropertyBag_Pointer_t pb1
= createPropertyBag();
508 pb1
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
509 pb1
->insert(createStringProperty(NS_style::LN_font_face
, "Times"));
510 pb1
->insert(createIntegerProperty(NS_fo::LN_line_height
, 20));
511 PropertyPoolHandle_Pointer_t ph1
= pool
->insert(pb1
);
514 PropertyBag_Pointer_t pb2
= createPropertyBag();
515 pb2
->insert(createIntegerProperty(NS_fo::LN_font_weight
, 12));
516 pb2
->insert(createStringProperty(NS_style::LN_font_face
, "Roman"));
517 PropertyPoolHandle_Pointer_t ph2
= pool
->insert(pb2
);
519 Iterator
<PropertyBag_Pointer_t
>::Pointer_t iter
= pool
->createIterator();
522 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /*nothing to do*/;
524 CPPUNIT_ASSERT_MESSAGE("Expectation '2 PropertyBags in PropertyPool' failed", i
== 2);
527 pool
->garbageCollection();
529 Iterator
<PropertyBag_Pointer_t
>::Pointer_t iter
= pool
->createIterator();
532 for (iter
->first(); !iter
->isDone(); iter
->next(), i
++) /*nothing to do*/;
534 CPPUNIT_ASSERT_MESSAGE("Expectation '1 PropertyBag in PropertyPool' failed", i
== 1);
537 // 'cm', 'mm', 'inch', 'pt', 'px', 'pc'
538 void testCreateTwipsProperty()
540 Property::Pointer_t tp1
= createTwipsProperty(NS_style::LN_position
, "1cm");
541 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp1
->getIntValue() == 567);
542 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp1
->getStringValue() == "1.000 cm");
544 Property::Pointer_t tp2
= createTwipsProperty(NS_style::LN_position
, "1 cm");
545 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp2
->getIntValue() == 567);
546 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp2
->getStringValue() == "1.000 cm");
548 Property::Pointer_t tp3
= createTwipsProperty(NS_style::LN_position
, "1 cm ");
549 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp3
->getIntValue() == 567);
550 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp3
->getStringValue() == "1.000 cm");
552 Property::Pointer_t tp4
= createTwipsProperty(NS_style::LN_position
, "0 cm");
553 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp4
->getIntValue() == 0);
554 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp4
->getStringValue() == "0.000 cm");
556 Property::Pointer_t tp5
= createTwipsProperty(NS_style::LN_position
, "10mm");
557 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp5
->getIntValue() == 567);
558 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp5
->getStringValue() == "1.000 cm");
560 Property::Pointer_t tp6
= createTwipsProperty(NS_style::LN_position
, 567);
561 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp6
->getIntValue() == 567);
562 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp6
->getStringValue() == "1.000 cm");
564 Property::Pointer_t tp7
= createTwipsProperty(NS_style::LN_position
, "100pt");
565 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp7
->getIntValue() == 2000);
566 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp7
->getStringValue() == "3.527 cm");
568 Property::Pointer_t tp8
= createTwipsProperty(NS_style::LN_position
, "1 in");
569 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp8
->getIntValue() == 1440);
570 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp8
->getStringValue() == "2.540 cm");
572 Property::Pointer_t tp9
= createTwipsProperty(NS_style::LN_position
, "-1 cm");
573 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp9
->getIntValue() == -567);
574 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp9
->getStringValue() == "-1.000 cm");
576 Property::Pointer_t tp10
= createTwipsProperty(NS_style::LN_position
, "+1 cm");
577 CPPUNIT_ASSERT_MESSAGE("getIntValue: wrong twips value returned", tp10
->getIntValue() == 567);
578 CPPUNIT_ASSERT_MESSAGE("getStringValue: wrong twips value returned", tp10
->getStringValue() == "1.000 cm");
580 Property::Pointer_t tp11
= createTwipsProperty(NS_style::LN_position
, "1 pt ");
581 Property::Pointer_t tp12
= createTwipsProperty(NS_style::LN_position
, "2pt");
582 CPPUNIT_ASSERT_MESSAGE("Comparing twips properties failed", tp11
< tp12
);
585 void testCreateInvalidTwipsProperty()
589 Property::Pointer_t tp
= createTwipsProperty(NS_style::LN_position
, "0,1 cm");
591 catch(std::invalid_argument
& )
595 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
598 void testCreateInvalidTwipsProperty2()
602 Property::Pointer_t tp
= createTwipsProperty(NS_style::LN_position
, "");
604 catch(std::invalid_argument
& )
608 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
611 void testCreateInvalidTwipsProperty3()
615 Property::Pointer_t tp
= createTwipsProperty(NS_style::LN_position
, " cm");
617 catch(std::invalid_argument
& )
621 CPPUNIT_ASSERT_MESSAGE("Creating an twips property with invalid number must fail", false);
624 CPPUNIT_TEST_SUITE(TestProperty
);
625 CPPUNIT_TEST(testCreateIntProperty
);
626 CPPUNIT_TEST(testCreateStringProperty
);
627 CPPUNIT_TEST(testCreateCompositeProperty
);
628 CPPUNIT_TEST(testPropertyBagAsStructure
);
629 CPPUNIT_TEST(testNoDuplicatesInPropertyBagStructures
);
630 CPPUNIT_TEST(testPropertyBagAsArray
);
631 CPPUNIT_TEST(testDuplicateValuesInArray
);
632 CPPUNIT_TEST(testCopyPropertyBag
);
633 CPPUNIT_TEST(testClearPropertyBag
);
634 CPPUNIT_TEST(testSortPropertyBag
);
635 CPPUNIT_TEST(testCompareSimpleProperties
);
636 CPPUNIT_TEST(testCompareCompositeProperties
);
637 CPPUNIT_TEST(testPropertyPool
);
638 CPPUNIT_TEST(testComplexParagraphProperty
);
639 CPPUNIT_TEST(testInsertEmptyPropertyBag
);
640 CPPUNIT_TEST(testCompareEqualPropertyTypesWithDifferentIdsDoesNotFail
);
641 CPPUNIT_TEST(testDumpPropertyPool
);
642 CPPUNIT_TEST(testDumpEmptyPropertyPool
);
643 CPPUNIT_TEST(testInsertPropertySubsets
);
644 CPPUNIT_TEST(testPropertyPoolGarbageCollection
);
645 CPPUNIT_TEST(testDumpPropertyPoolAfterGarbageCollection
);
646 CPPUNIT_TEST(testCreateTwipsProperty
);
647 CPPUNIT_TEST(testCreateInvalidTwipsProperty
);
648 CPPUNIT_TEST(testCreateInvalidTwipsProperty2
);
649 CPPUNIT_TEST(testCreateInvalidTwipsProperty3
);
650 CPPUNIT_TEST_SUITE_END();
653 //#####################################
654 // register test suites
655 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestProperty
, "TestProperty");