1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* This file is part of the libvisio project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <iostream>
#include <memory>
#include <cppunit/extensions/HelperMacros.h>
#include <libvisio/libvisio.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include "xmldrawinggenerator.h"
namespace librevenge
{
/// Allows using CPPUNIT_ASSERT_EQUAL() on librevenge::RVNGString instances.
std::ostream &operator <<(std::ostream &s, const RVNGString &string)
{
return s << string.cstr();
}
}
namespace
{
/// Caller must call xmlXPathFreeObject.
xmlXPathObjectPtr getXPathNode(xmlDocPtr doc, const librevenge::RVNGString &xpath)
{
xmlXPathContextPtr xpathContext = xmlXPathNewContext(doc);
xmlXPathObjectPtr xpathObject = xmlXPathEvalExpression(BAD_CAST(xpath.cstr()), xpathContext);
xmlXPathFreeContext(xpathContext);
return xpathObject;
}
/// Same as the assertXPath(), but don't assert: return the string instead.
librevenge::RVNGString getXPath(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &attribute)
{
CPPUNIT_ASSERT(doc);
std::unique_ptr<xmlXPathObject, void(*)(xmlXPathObjectPtr)> xpathobject{getXPathNode(doc, xpath), xmlXPathFreeObject};
xmlNodeSetPtr nodeset = xpathobject->nodesetval;
librevenge::RVNGString message("XPath '");
message.append(xpath);
message.append("': number of nodes is incorrect.");
CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), 1, xmlXPathNodeSetGetLength(nodeset));
if (attribute.empty())
return librevenge::RVNGString();
xmlNodePtr node = nodeset->nodeTab[0];
xmlChar *prop = xmlGetProp(node, BAD_CAST(attribute.cstr()));
librevenge::RVNGString s((const char *)prop);
xmlFree(prop);
return s;
}
/**
* Assert that xpath exists, and xpath returns exactly one node.
* xpath's attribute's value must equal to the expectedValue value.
*/
void assertXPath(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &attribute, const librevenge::RVNGString &expectedValue)
{
librevenge::RVNGString actualValue = getXPath(doc, xpath, attribute);
librevenge::RVNGString message("Attribute '");
message.append(attribute);
message.append("' of '");
message.append(xpath);
message.append("': incorrect value.");
CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), expectedValue, actualValue);
}
/// Assert that xpath exists, and does not contain the given attribute
void assertXPathNoAttribute(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &attribute)
{
xmlXPathObjectPtr xpathobject = getXPathNode(doc, xpath);
xmlNodeSetPtr nodeset = xpathobject->nodesetval;
librevenge::RVNGString message1("In <");
message1.append(doc->name);
message1.append(">, XPath '");
message1.append(xpath);
message1.append("' number of nodes is incorrect");
CPPUNIT_ASSERT_EQUAL_MESSAGE(message1.cstr(), 1, xmlXPathNodeSetGetLength(nodeset));
xmlNodePtr node = nodeset->nodeTab[0];
librevenge::RVNGString message2("In <");
message2.append(doc->name);
message2.append(">, XPath '");
message2.append(xpath);
message2.append("' unexpected '");
message2.append(attribute);
message2.append("' attribute");
CPPUNIT_ASSERT_EQUAL_MESSAGE(message2.cstr(), static_cast<xmlChar *>(0), xmlGetProp(node, BAD_CAST(attribute.cstr())));
xmlXPathFreeObject(xpathobject);
}
void assertBmpDataOffset(xmlDocPtr doc, const librevenge::RVNGString &xpath, const unsigned expectedValue)
{
const librevenge::RVNGBinaryData bitmap(getXPath(doc, xpath, "binary-data"));
librevenge::RVNGString message("BMP at '");
message.append(xpath);
message.append("': wrong data offset.");
librevenge::RVNGInputStream *const input = bitmap.getDataStream();
CPPUNIT_ASSERT(input);
CPPUNIT_ASSERT_EQUAL(0, input->seek(10, librevenge::RVNG_SEEK_SET));
unsigned long numBytesRead = 0;
const unsigned char *const bytes = input->read(4, numBytesRead);
CPPUNIT_ASSERT_EQUAL(4ul, numBytesRead);
const unsigned actualValue = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), expectedValue, actualValue);
}
/// Same as the assertXPathContent(), but don't assert: return the string instead.
librevenge::RVNGString getXPathContent(xmlDocPtr doc, const librevenge::RVNGString &xpath)
{
std::unique_ptr<xmlXPathObject, void(*)(xmlXPathObjectPtr)> xpathobject{getXPathNode(doc, xpath), xmlXPathFreeObject};
switch (xpathobject->type)
{
case XPATH_UNDEFINED:
CPPUNIT_FAIL("Undefined XPath type");
case XPATH_NODESET:
{
xmlNodeSetPtr nodeset = xpathobject->nodesetval;
librevenge::RVNGString message("XPath '");
message.append(xpath);
message.append("': not found.");
CPPUNIT_ASSERT_MESSAGE(message.cstr(), xmlXPathNodeSetGetLength(nodeset) > 0);
xmlNodePtr xmlnode = nodeset->nodeTab[0];
xmlNodePtr xmlchild = xmlnode->children;
librevenge::RVNGString s;
while (xmlchild && xmlchild->type != XML_TEXT_NODE)
xmlchild = xmlchild->next;
if (xmlchild && xmlchild->type == XML_TEXT_NODE)
s = (reinterpret_cast<char *>((xmlnode->children[0]).content));
return s;
}
case XPATH_BOOLEAN:
return xpathobject->boolval ? librevenge::RVNGString("true") : librevenge::RVNGString("false");
case XPATH_STRING:
return librevenge::RVNGString(reinterpret_cast<char *>(xpathobject->stringval));
case XPATH_NUMBER:
#ifdef LIBXML_XPTR_LOCS_ENABLED
case XPATH_POINT:
case XPATH_RANGE:
case XPATH_LOCATIONSET:
#endif
case XPATH_USERS:
case XPATH_XSLT_TREE:
CPPUNIT_FAIL("Unsupported XPath type");
}
CPPUNIT_FAIL("Invalid XPath type");
}
/// Assert that xpath exists, and its content equals to content.
void assertXPathContent(xmlDocPtr doc, const librevenge::RVNGString &xpath, const librevenge::RVNGString &content)
{
librevenge::RVNGString message("XPath '");
message.append(xpath);
message.append("': contents of child does not match.");
CPPUNIT_ASSERT_EQUAL_MESSAGE(message.cstr(), content, getXPathContent(doc, xpath));
}
/// Paints an XML representation of filename into buffer, then returns the parsed buffer content.
xmlDocPtr parse(const char *filename, xmlBufferPtr buffer)
{
librevenge::RVNGString path(TDOC "/");
path.append(filename);
librevenge::RVNGFileStream input(path.cstr());
CPPUNIT_ASSERT(libvisio::VisioDocument::isSupported(&input));
xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
CPPUNIT_ASSERT(writer);
xmlTextWriterStartDocument(writer, 0, 0, 0);
libvisio::XmlDrawingGenerator painter(writer);
CPPUNIT_ASSERT(libvisio::VisioDocument::parse(&input, &painter));
xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
// std::cerr << "XML is '" << (const char *)xmlBufferContent(buffer) << "'" << std::endl;
return xmlParseMemory((const char *)xmlBufferContent(buffer), xmlBufferLength(buffer));
}
}
class ImportTest : public CPPUNIT_NS::TestFixture
{
// disable copying
ImportTest(const ImportTest &);
ImportTest &operator=(const ImportTest &);
CPPUNIT_TEST_SUITE(ImportTest);
CPPUNIT_TEST(testVsdxMetadataTitle);
CPPUNIT_TEST(testVsdMetadataTitleMs1252);
CPPUNIT_TEST(testVsdMetadataTitleUtf8);
CPPUNIT_TEST(testVsdUserDefinedMetadata);
CPPUNIT_TEST(testVsdxUserDefinedMetadata);
CPPUNIT_TEST(testVsdxImportBgColorFromTheme);
#if LIBXML_VERSION >= 20902
CPPUNIT_TEST(testVsdxCharBgColor);
#endif
CPPUNIT_TEST(testVsdTextBlockWithoutBgColor);
CPPUNIT_TEST(testVsdxTextBkgndColorFromStylesheet);
CPPUNIT_TEST(testVsdNumericFormat);
CPPUNIT_TEST(testVsdDateTimeFormatting);
CPPUNIT_TEST(testVsd11FormatLine);
CPPUNIT_TEST(testVsd6TextfieldsWithUnits);
CPPUNIT_TEST(testVsd11TextfieldsWithUnits);
CPPUNIT_TEST(testVsd11DrawingUnitsType);
CPPUNIT_TEST(testBmpFileHeader);
CPPUNIT_TEST(testBmpFileHeader2);
CPPUNIT_TEST(testVsdxImportDefaultFillColour);
CPPUNIT_TEST(testVsdxQuickStyleFillMatrix);
CPPUNIT_TEST(testVsdxQuickStyleFillStyle);
CPPUNIT_TEST_SUITE_END();
void testVsdxMetadataTitle();
void testVsdMetadataTitleMs1252();
void testVsdMetadataTitleUtf8();
void testVsdUserDefinedMetadata();
void testVsdxUserDefinedMetadata();
void testVsdxImportBgColorFromTheme();
void testVsdxCharBgColor();
void testVsdTextBlockWithoutBgColor();
void testVsdxTextBkgndColorFromStylesheet();
void testVsdNumericFormat();
void testVsd11FormatLine();
void testVsdDateTimeFormatting();
void testVsd6TextfieldsWithUnits();
void testVsd11TextfieldsWithUnits();
void testVsd11DrawingUnitsType();
void testBmpFileHeader();
void testBmpFileHeader2();
void testVsdxImportDefaultFillColour();
void testVsdxQuickStyleFillMatrix();
void testVsdxQuickStyleFillStyle();
xmlBufferPtr m_buffer;
xmlDocPtr m_doc;
public:
ImportTest();
virtual void setUp();
virtual void tearDown();
};
ImportTest::ImportTest()
: m_buffer(0),
m_doc(0)
{
}
void ImportTest::setUp()
{
CPPUNIT_ASSERT(!m_buffer);
m_buffer = xmlBufferCreate();
CPPUNIT_ASSERT(m_buffer);
CPPUNIT_ASSERT(!m_doc);
}
void ImportTest::tearDown()
{
xmlFreeDoc(m_doc);
m_doc = 0;
xmlBufferFree(m_buffer);
m_buffer = 0;
}
void ImportTest::testVsdxMetadataTitle()
{
m_doc = parse("fdo86664.vsdx", m_buffer);
// The setDocumentMetaData() call was missing, so the node did not exist.
assertXPath(m_doc, "/document/setDocumentMetaData", "title", "mytitle");
assertXPath(m_doc, "/document/setDocumentMetaData", "subject", "mysubject");
assertXPath(m_doc, "/document/setDocumentMetaData", "initial-creator", "vmiklos creator");
// Test <dcterms:created> and <dcterms:modified>.
assertXPath(m_doc, "/document/setDocumentMetaData", "creation-date", "2014-11-24T10:35:17Z");
assertXPath(m_doc, "/document/setDocumentMetaData", "date", "2014-11-24T10:41:22Z");
assertXPath(m_doc, "/document/setDocumentMetaData", "keyword", "mytag");
assertXPath(m_doc, "/document/setDocumentMetaData", "description", "mycomment");
assertXPath(m_doc, "/document/setDocumentMetaData", "creator", "vmiklos modifier");
assertXPath(m_doc, "/document/setDocumentMetaData", "category", "mycategory");
}
void ImportTest::testVsdMetadataTitleMs1252()
{
m_doc = parse("fdo86729-ms1252.vsd", m_buffer);
// Test windows-1252 -> UTF-8 conversion, provided by ICU.
assertXPath(m_doc, "/document/setDocumentMetaData", "title", "mytitle\xC3\xA9\xC3\xA1");
assertXPath(m_doc, "/document/setDocumentMetaData", "subject", "mysubject");
assertXPath(m_doc, "/document/setDocumentMetaData", "initial-creator", "vmiklos creator");
// There is only one author/last-modifier field in the file, so make sure creator is the same as initial-creator.
assertXPath(m_doc, "/document/setDocumentMetaData", "creator", "vmiklos creator");
assertXPath(m_doc, "/document/setDocumentMetaData", "keyword", "mytag");
assertXPath(m_doc, "/document/setDocumentMetaData", "description", "mycomment");
}
void ImportTest::testVsdMetadataTitleUtf8()
{
m_doc = parse("fdo86729-utf8.vsd", m_buffer);
// Test the case when the string is UTF-8 encoded already in the file.
assertXPath(m_doc, "/document/setDocumentMetaData", "title", "mytitle\xC3\xA9\xC3\xA1\xC5\x91\xC5\xB1");
// Test <dcterms:created> and <dcterms:modified>.
assertXPath(m_doc, "/document/setDocumentMetaData", "creation-date", "2014-11-26T08:24:56Z");
assertXPath(m_doc, "/document/setDocumentMetaData", "date", "2014-11-26T08:24:56Z");
}
void ImportTest::testVsdUserDefinedMetadata()
{
m_doc = parse("dwg.vsd", m_buffer);
assertXPath(m_doc, "/document/setDocumentMetaData", "category", "Category test");
assertXPath(m_doc, "/document/setDocumentMetaData", "company", "Company test");
assertXPath(m_doc, "/document/setDocumentMetaData", "template", "BASICD_M.VSTX");
}
void ImportTest::testVsdxUserDefinedMetadata()
{
m_doc = parse("dwg.vsdx", m_buffer);
assertXPath(m_doc, "/document/setDocumentMetaData", "category", "Category test");
assertXPath(m_doc, "/document/setDocumentMetaData", "company", "Company test");
assertXPath(m_doc, "/document/setDocumentMetaData", "language", "en-US");
assertXPath(m_doc, "/document/setDocumentMetaData", "template", "BASICD_M.VSTX");
}
void ImportTest::testVsdxImportBgColorFromTheme()
{
m_doc = parse("color-boxes.vsdx", m_buffer);
assertXPath(m_doc, "/document/page/layer[1]//setStyle[2]", "fill-color", "#759fcc");
assertXPath(m_doc, "/document/page/layer[2]//setStyle[2]", "fill-color", "#70ad47");
assertXPath(m_doc, "/document/page/layer[3]//setStyle[2]", "fill-color", "#fec000");
assertXPath(m_doc, "/document/page/layer[4]//setStyle[2]", "fill-color", "#41719c");
assertXPath(m_doc, "/document/page/layer[5]//setStyle[2]", "fill-color", "#ed7d31");
assertXPath(m_doc, "/document/page/layer[6]//setStyle[2]", "fill-color", "#bdd0e9");
assertXPath(m_doc, "/document/page/layer[7]//setStyle[2]", "fill-color", "#5b9bd5");
}
void ImportTest::testVsdxCharBgColor()
{
m_doc = parse("bgcolor.vsdx", m_buffer);
assertXPathNoAttribute(m_doc, "/document/page/layer[1]/textObject/paragraph[1]/span", "background-color");
assertXPathNoAttribute(m_doc, "/document/page/layer[1]/textObject/paragraph[2]/span", "background-color");
assertXPath(m_doc, "/document/page/layer[2]/textObject/paragraph[1]/span", "background-color", "#9dbb61");
assertXPath(m_doc, "/document/page/layer[2]/textObject/paragraph[2]/span", "background-color", "#9dbb61");
assertXPath(m_doc, "/document/page/layer[3]/textObject/paragraph[1]/span", "background-color", "#9dbb61");
assertXPath(m_doc, "/document/page/layer[3]/textObject/paragraph[2]/span", "background-color", "#9dbb61");
}
void ImportTest::testVsdTextBlockWithoutBgColor()
{
m_doc = parse("no-bgcolor.vsd", m_buffer);
assertXPathNoAttribute(m_doc, "/document/page/layer[5]/textObject/paragraph[1]/span", "background-color");
}
void ImportTest::testVsdxTextBkgndColorFromStylesheet()
{
m_doc = parse("tdf136564-WhiteTextBackground.vsdx", m_buffer);
assertXPathNoAttribute(m_doc, "/document/page/layer[2]/textObject/paragraph/span", "background-color");
assertXPathContent(m_doc, "/document/page/layer[2]/textObject/paragraph/span/insertText", "First triangle without background");
assertXPathNoAttribute(m_doc, "/document/page/layer[3]/textObject/paragraph/span", "background-color");
assertXPathContent(m_doc, "/document/page/layer[3]/textObject/paragraph/span/insertText", "Second triangle without background");
// Without the accompanying fix in place, this test would have failed with:
// equality assertion failed
// - Expected: #ffffff
// - Actual :
assertXPath(m_doc, "/document/page/layer[4]/textObject/paragraph/span", "background-color", "#ffffff");
assertXPath(m_doc, "/document/page/layer[4]/textObject/paragraph/span", "color", "#000000");
assertXPathContent(m_doc, "/document/page/layer[4]/textObject/paragraph/span/insertText", "By default Text is with white Background");
}
void ImportTest::testVsdNumericFormat()
{
m_doc = parse("tdf76829-numeric-format.vsd", m_buffer);
assertXPathContent(m_doc, "/document/page[1]/textObject[1]/paragraph[1]/span/insertText", "Number of lines, generic format: 1");
assertXPathContent(m_doc, "/document/page[1]/textObject[2]/paragraph[1]/span/insertText", "Number of lines, Number decimal places:: 1.00");
assertXPathContent(m_doc, "/document/page[1]/textObject[4]/paragraph[1]/span/insertText", "Creation date, generic: 07/06/2019");
assertXPathContent(m_doc, "/document/page[1]/textObject[6]/paragraph[1]/span/insertText", "Creation date, {{dd.MM.yyyy}}/Polish custom format: 07/06/2019");
//TODO Add support for custom formatting:
//assertXPathContent(m_doc, "/document/page[1]/textObject[3]/paragraph[1]/span/insertText", "Number of lines, percentage format: 100.00%");
//assertXPathContent(m_doc, "/document/page[1]/textObject[7]/paragraph[1]/span/insertText", "Creation date, {{dd.MM.yyyy}} German format:: 07.06.2019");
}
void ImportTest::testVsdDateTimeFormatting()
{
m_doc = parse("tdf76829-datetime-format.vsd", m_buffer);
assertXPathContent(m_doc, "/document/page/textObject/paragraph/span/insertText", "11/30/2005");
}
// tdf#126402
void ImportTest::testVsd11FormatLine()
{
m_doc = parse("Visio11FormatLine.vsd", m_buffer);
assertXPathNoAttribute(m_doc, "/document/page/setStyle[4]", "marker-end-center");
// Centered filled circle, copied from LO to be able to edit
assertXPath(m_doc, "/document/page/setStyle[5]", "marker-end-path",
"m462 1118-102-29-102-51-93-72-72-93-51-102-29-102-13-105 13-102 29-106 51-102 72-89 93-72 102-50 102-34 106-9 101 9 106 34 98 50 93 72 72 89 51 102 29 106 13 102-13 105-29 102-51 102-72 93-93 72-98 51-106 29-101 13z");
assertXPath(m_doc, "/document/page/setStyle[5]", "marker-end-center", "true");
// Centered line
assertXPath(m_doc, "/document/page/setStyle[5]", "marker-start-path", "M1 2l1 -1l20 20l-1 1zM11 11v12h1v-10z");
assertXPath(m_doc, "/document/page/setStyle[5]", "marker-start-center", "true");
assertXPath(m_doc, "/document/page/setStyle[6]", "marker-end-path",
"m1286 0 1200 2789v211h-114l-986-2392v2392h-200v-2392l-1072 2392h-114v-211z");
assertXPathNoAttribute(m_doc, "/document/page/setStyle[6]", "marker-end-center");
assertXPath(m_doc, "/document/page/setStyle[6]", "marker-start-center", "true");
assertXPathNoAttribute(m_doc, "/document/page/setStyle[11]", "marker-start-center");
assertXPath(m_doc, "/document/page/setStyle[11]", "marker-end-center", "true");
assertXPathNoAttribute(m_doc, "/document/page/setStyle[12]", "marker-end-center");
assertXPath(m_doc, "/document/page/setStyle[12]", "marker-start-center", "true");
}
// tdf#126292
void ImportTest::testVsd6TextfieldsWithUnits()
{
m_doc = parse("Visio11TextFieldsWithUnits.vsd", m_buffer);
assertXPathContent(m_doc, "/document/page/textObject[2]/paragraph[1]/span/insertText", "Number1 with unit [cm] 1 cm");
assertXPathContent(m_doc, "/document/page/textObject[3]/paragraph[1]/span/insertText", "Number 1 with unit [cm] hidden 1");
assertXPathContent(m_doc, "/document/page/textObject[4]/paragraph[1]/span/insertText", "Number 1 without unit 1");
assertXPathContent(m_doc, "/document/page/textObject[5]/paragraph[1]/span/insertText[2]", "with unit [mm] 1 mm");
assertXPathContent(m_doc, "/document/page/textObject[6]/paragraph[1]/span/insertText", "Number 1 with [%] unit 1%");
assertXPathContent(m_doc, "/document/page/textObject[7]/paragraph[1]/span/insertText", "Number -1 without unit -1");
assertXPathContent(m_doc, "/document/page/textObject[8]/paragraph[1]/span/insertText", "1 Ciceros 1 c");
// TODO assertXPathContent(m_doc, "/document/page/textObject[9]/paragraph[1]/span/insertText", "1 (31.12.1899) date without unit 31.12.1899");
assertXPathContent(m_doc, "/document/page/textObject[10]/paragraph[1]/span/insertText", "1 degrees 1 deg");
assertXPathContent(m_doc, "/document/page/textObject[11]/paragraph[1]/span/insertText", "1 elapsed week 1 ew.");
//TODO assertXPathContent(m_doc, "/document/page/textObject[12]/paragraph[1]/span/insertText", "1 Acre 1 acres");
//TODO assertXPathContent(m_doc, "/document/page/textObject[13]/paragraph[1]/span/insertText", "1 sq. Centimeter 1 cm^2");
//TODO assertXPathContent(m_doc, "/document/page/textObject[14]/paragraph[1]/span/insertText", "1 sq. hectares 1 ha");
//TODO assertXPathContent(m_doc, "/document/page/textObject[15]/paragraph[1]/span/insertText", "1 sq inches 1 in^2");
assertXPathContent(m_doc, "/document/page/textObject[16]/paragraph[1]/span/insertText", "Number 100 with [%] unit 100%");
assertXPathContent(m_doc, "/document/page/textObject[17]/paragraph[1]/span/insertText", "Didots 1 d");
//TODO Add check with 1000 didots
assertXPathContent(m_doc, "/document/page/textObject[18]/paragraph[1]/span/insertText", "Points 1 pt");
assertXPathContent(m_doc, "/document/page/textObject[19]/paragraph[1]/span/insertText", "Picas 1 p");
assertXPathContent(m_doc, "/document/page/textObject[20]/paragraph[1]/span/insertText", "Inch 1 in");
assertXPathContent(m_doc, "/document/page/textObject[21]/paragraph[1]/span/insertText", "Feet 1 ft");
assertXPathContent(m_doc, "/document/page/textObject[22]/paragraph[1]/span/insertText", "1 elapsed day 1 ed.");
assertXPathContent(m_doc, "/document/page/textObject[23]/paragraph[1]/span/insertText", "1 kilometer 1 km");
assertXPathContent(m_doc, "/document/page/textObject[24]/paragraph[1]/span/insertText", "1 radians 1 rad");
assertXPathContent(m_doc, "/document/page/textObject[25]/paragraph[1]/span/insertText", "1 yard 1 yd");
// TODO assertXPathContent(m_doc, "/document/page/textObject[26]/paragraph[1]/span/insertText", "1 sq Feet 1 ft^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[27]/paragraph[1]/span/insertText", "1 kilometers 1 km^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[28]/paragraph[1]/span/insertText", "1 miles 1 mi^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[29]/paragraph[1]/span/insertText", "1 Inches in fractions 1,5 in");
assertXPathContent(m_doc, "/document/page/textObject[30]/paragraph[1]/span/insertText", "1 elapsed hours1 eh. ");
assertXPathContent(m_doc, "/document/page/textObject[31]/paragraph[1]/span/insertText", "1 el. Minutes 1 em.");
assertXPathContent(m_doc, "/document/page/textObject[32]/paragraph[1]/span/insertText", "1 el. Sec 1 es.");
assertXPathContent(m_doc, "/document/page/textObject[33]/paragraph[1]/span/insertText", "1 miles 1 mi");
assertXPathContent(m_doc, "/document/page/textObject[34]/paragraph[1]/span/insertText", "1 nautical miles 1 nm.");
assertXPathContent(m_doc, "/document/page/textObject[37]/paragraph[1]/span/insertText", "1000 didots 1000 d");
// TODO assertXPathContent(m_doc, "/document/page/textObject[38]/paragraph[1]/span/insertText", "1 date with unitout unit 31.12.1899");
// TODO assertXPathContent(m_doc, "/document/page/textObject[39]/paragraph[1]/span/insertText", "1 date with radians unit 31.12.1899");
// TODO assertXPathContent(m_doc, "/document/page/textObject[40]/paragraph[1]/span/insertText", "1 date with currency unit zł 1,00");
}
// tdf#126292
void ImportTest::testVsd11TextfieldsWithUnits()
{
m_doc = parse("Visio11TextFieldsWithUnits.vsd", m_buffer);
assertXPathContent(m_doc, "/document/page/textObject[2]/paragraph[1]/span/insertText", "Number1 with unit [cm] 1 cm");
assertXPathContent(m_doc, "/document/page/textObject[3]/paragraph[1]/span/insertText", "Number 1 with unit [cm] hidden 1");
assertXPathContent(m_doc, "/document/page/textObject[4]/paragraph[1]/span/insertText", "Number 1 without unit 1");
assertXPathContent(m_doc, "/document/page/textObject[5]/paragraph[1]/span/insertText[2]", "with unit [mm] 1 mm");
assertXPathContent(m_doc, "/document/page/textObject[6]/paragraph[1]/span/insertText", "Number 1 with [%] unit 1%");
assertXPathContent(m_doc, "/document/page/textObject[7]/paragraph[1]/span/insertText", "Number -1 without unit -1");
assertXPathContent(m_doc, "/document/page/textObject[8]/paragraph[1]/span/insertText", "1 Ciceros 1 c");
// TODO assertXPathContent(m_doc, "/document/page/textObject[9]/paragraph[1]/span/insertText", "1 (31.12.1899) date without unit 31.12.1899");
assertXPathContent(m_doc, "/document/page/textObject[10]/paragraph[1]/span/insertText", "1 degrees 1 deg");
assertXPathContent(m_doc, "/document/page/textObject[11]/paragraph[1]/span/insertText", "1 elapsed week 1 ew.");
//TODO assertXPathContent(m_doc, "/document/page/textObject[12]/paragraph[1]/span/insertText", "1 Acre 1 acres");
//TODO assertXPathContent(m_doc, "/document/page/textObject[13]/paragraph[1]/span/insertText", "1 sq. Centimeter 1 cm^2");
//TODO assertXPathContent(m_doc, "/document/page/textObject[14]/paragraph[1]/span/insertText", "1 sq. hectares 1 ha");
//TODO assertXPathContent(m_doc, "/document/page/textObject[15]/paragraph[1]/span/insertText", "1 sq inches 1 in^2");
assertXPathContent(m_doc, "/document/page/textObject[16]/paragraph[1]/span/insertText", "Number 100 with [%] unit 100%");
assertXPathContent(m_doc, "/document/page/textObject[17]/paragraph[1]/span/insertText", "Didots 1 d");
//TODO Add check with 1000 didots
assertXPathContent(m_doc, "/document/page/textObject[18]/paragraph[1]/span/insertText", "Points 1 pt");
assertXPathContent(m_doc, "/document/page/textObject[19]/paragraph[1]/span/insertText", "Picas 1 p");
assertXPathContent(m_doc, "/document/page/textObject[20]/paragraph[1]/span/insertText", "Inch 1 in");
assertXPathContent(m_doc, "/document/page/textObject[21]/paragraph[1]/span/insertText", "Feet 1 ft");
assertXPathContent(m_doc, "/document/page/textObject[22]/paragraph[1]/span/insertText", "1 elapsed day 1 ed.");
assertXPathContent(m_doc, "/document/page/textObject[23]/paragraph[1]/span/insertText", "1 kilometer 1 km");
assertXPathContent(m_doc, "/document/page/textObject[24]/paragraph[1]/span/insertText", "1 radians 1 rad");
assertXPathContent(m_doc, "/document/page/textObject[25]/paragraph[1]/span/insertText", "1 yard 1 yd");
// TODO assertXPathContent(m_doc, "/document/page/textObject[26]/paragraph[1]/span/insertText", "1 sq Feet 1 ft^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[27]/paragraph[1]/span/insertText", "1 kilometers 1 km^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[28]/paragraph[1]/span/insertText", "1 miles 1 mi^2");
// TODO assertXPathContent(m_doc, "/document/page/textObject[29]/paragraph[1]/span/insertText", "1 Inches in fractions 1,5 in");
assertXPathContent(m_doc, "/document/page/textObject[30]/paragraph[1]/span/insertText", "1 elapsed hours1 eh. ");
assertXPathContent(m_doc, "/document/page/textObject[31]/paragraph[1]/span/insertText", "1 el. Minutes 1 em.");
assertXPathContent(m_doc, "/document/page/textObject[32]/paragraph[1]/span/insertText", "1 el. Sec 1 es.");
assertXPathContent(m_doc, "/document/page/textObject[33]/paragraph[1]/span/insertText", "1 miles 1 mi");
assertXPathContent(m_doc, "/document/page/textObject[34]/paragraph[1]/span/insertText", "1 nautical miles 1 nm.");
// TODO assertXPathContent(m_doc, "/document/page/textObject[35]/paragraph[1]/span/insertText", "ANGLE 1 seconds 0 deg 0 min 1 sec");
// TODO assertXPathContent(m_doc, "/document/page/textObject[36]/paragraph[1]/span/insertText", "ANGLE seconds 130 deg 49 min 9 sec");
assertXPathContent(m_doc, "/document/page/textObject[37]/paragraph[1]/span/insertText", "1000 didots 1000 d");
// TODO assertXPathContent(m_doc, "/document/page/textObject[38]/paragraph[1]/span/insertText", "1 date with unitout unit 31.12.1899");
// TODO assertXPathContent(m_doc, "/document/page/textObject[39]/paragraph[1]/span/insertText", "1 date with radians unit 31.12.1899");
// TODO assertXPathContent(m_doc, "/document/page/textObject[40]/paragraph[1]/span/insertText", "1 date with currency unit zł 1,00");
}
void ImportTest::testVsd11DrawingUnitsType()
{
// Without the accompanying fix in place, this test would have failed with:
// Test name: ImportTest::testVsd11DrawingUnitsTypeequality assertion failed
// - Expected: 180.0 cm x 394.0 cm
// - Actual : 70.9 x 394.0 cm
// - XPath '/document/page/textObject[12]/paragraph/span/insertText': contents of child does not match.
m_doc = parse("tdf154379-DrawingUnits-type.vsd", m_buffer);
assertXPathContent(m_doc, "/document/page/textObject[12]/paragraph/span/insertText", "180.0 cm x 394.0 cm");
}
void ImportTest::testBmpFileHeader()
{
m_doc = parse("bitmaps.vsd", m_buffer);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[1]", 62);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[2]", 62);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[3]", 62);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[4]", 118);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[5]", 118);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[6]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[7]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[8]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[9]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[10]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[11]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[12]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[13]", 1078);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[14]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[15]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[16]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[17]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[18]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[19]", 54);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[20]", 54);
}
void ImportTest::testBmpFileHeader2()
{
m_doc = parse("bitmaps2.vsd", m_buffer);
assertBmpDataOffset(m_doc, "/document/page/drawGraphicObject[1]", 62);
assertBmpDataOffset(m_doc, "/document/page/layer/drawGraphicObject[1]", 330);
}
void ImportTest::testVsdxImportDefaultFillColour()
{
// Without the accompanying fix in place, this test would have failed with:
// equality assertion failed
// - Expected: #5b9bd5
// - Actual : #ffffff
m_doc = parse("blue-box.vsdx", m_buffer);
assertXPath(m_doc, "/document/page/layer[1]//setStyle[2]", "fill-color", "#5b9bd5");
}
void ImportTest::testVsdxQuickStyleFillMatrix()
{
// Without the accompanying fix in place, this test would have failed with:
// equality assertion failed
// - Expected: #ffffff
// - Actual : #5b9bd5
// - Attribute 'fill-color' of '/document/page/layer/layer/setStyle[1]': incorrect value.
m_doc = parse("tdf154379-QuickStyleFillMatrix.vsdx", m_buffer);
assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "fill", "solid");
assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "fill-color", "#ffffff");
assertXPath(m_doc, "/document/page/layer/layer/setStyle[1]", "stroke-color", "#5b9bd5");
assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "fill", "none");
assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "fill-color", "#ffffff");
assertXPath(m_doc, "/document/page/layer/layer/setStyle[2]", "stroke-color", "#5b9bd5");
assertXPath(m_doc, "/document/page/layer/textObject/paragraph[1]/span", "color", "#5b9bd5");
assertXPathNoAttribute(m_doc, "/document/page/layer/textObject/paragraph[1]/span", "background-color");
assertXPathContent(m_doc, "/document/page/layer/textObject/paragraph[1]/span/insertText", " Kommissionierungs");
assertXPath(m_doc, "/document/page/layer/textObject/paragraph[2]/span", "color", "#5b9bd5");
assertXPathNoAttribute(m_doc, "/document/page/layer/textObject/paragraph[2]/span", "background-color");
assertXPathContent(m_doc, "/document/page/layer/textObject/paragraph[2]/span/insertText", "Beleg ");
}
void ImportTest::testVsdxQuickStyleFillStyle()
{
// Without the accompanying fix in place, this test would have failed with:
// equality assertion failed
// - Expected: #ffffff
// - Actual : #fec000
m_doc = parse("qs-box.vsdx", m_buffer);
assertXPath(m_doc, "/document/page/layer[1]//setStyle[2]", "fill-color", "#ffffff");
}
CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|