1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <swmodeltestbase.hxx>
12 #include <o3tl/string_view.hxx>
15 #include <unotxdoc.hxx>
19 /// Covers sw/source/core/layout/paintfrm.cxx fixes.
20 class Test
: public SwModelTestBase
24 : SwModelTestBase("/sw/qa/core/layout/data/")
29 CPPUNIT_TEST_FIXTURE(Test
, testSplitTableBorder
)
31 // Given a document with a split table, table borders are defined, but cell borders are not:
32 createSwDoc("split-table-border.odt");
33 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
34 SwDocShell
* pShell
= pTextDoc
->GetDocShell();
36 // When rendering that document:
37 std::shared_ptr
<GDIMetaFile
> xMetaFile
= pShell
->GetPreviewMetaFile();
39 // Then make sure that the master table has a bottom border and the follow table has a top
41 MetafileXmlDump aDumper
;
42 xmlDocUniquePtr pXmlDoc
= dumpAndParse(aDumper
, *xMetaFile
);
43 xmlXPathObjectPtr pXmlObj
= getXPathNode(pXmlDoc
, "//polyline[@style='solid']/point");
44 xmlNodeSetPtr pXmlNodes
= pXmlObj
->nodesetval
;
45 int nHorizontalBorders
= 0;
46 // Count the horizontal borders:
47 for (int i
= 0; i
< xmlXPathNodeSetGetLength(pXmlNodes
); i
+= 2)
49 xmlNodePtr pStart
= pXmlNodes
->nodeTab
[i
];
50 xmlNodePtr pEnd
= pXmlNodes
->nodeTab
[i
+ 1];
51 xmlChar
* pStartY
= xmlGetProp(pStart
, BAD_CAST("y"));
52 xmlChar
* pEndY
= xmlGetProp(pEnd
, BAD_CAST("y"));
53 sal_Int32 nStartY
= o3tl::toInt32(reinterpret_cast<char const*>(pStartY
));
54 sal_Int32 nEndY
= o3tl::toInt32(reinterpret_cast<char const*>(pEndY
));
63 xmlXPathFreeObject(pXmlObj
);
64 // Without the accompanying fix in place, this test would have failed with:
67 // i.e. the bottom border in the master table and the top border in the follow table were
69 CPPUNIT_ASSERT_EQUAL(4, nHorizontalBorders
);
72 CPPUNIT_TEST_FIXTURE(Test
, testRTLBorderMerge
)
74 // Given a document with an RTL table:
75 createSwDoc("rtl-table.docx");
76 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
77 SwDocShell
* pShell
= pTextDoc
->GetDocShell();
79 // When rendering that document:
80 std::shared_ptr
<GDIMetaFile
> xMetaFile
= pShell
->GetPreviewMetaFile();
82 // Then make sure the 5 columns all have left and right vertical borders:
83 MetafileXmlDump aDumper
;
84 xmlDocUniquePtr pXmlDoc
= dumpAndParse(aDumper
, *xMetaFile
);
85 xmlXPathObjectPtr pXmlObj
= getXPathNode(pXmlDoc
, "//polyline[@style='solid']/point");
86 xmlNodeSetPtr pXmlNodes
= pXmlObj
->nodesetval
;
87 int nVerticalBorders
= 0;
88 // Count the vertical borders:
89 for (int i
= 0; i
< xmlXPathNodeSetGetLength(pXmlNodes
); i
+= 2)
91 xmlNodePtr pStart
= pXmlNodes
->nodeTab
[i
];
92 xmlNodePtr pEnd
= pXmlNodes
->nodeTab
[i
+ 1];
93 xmlChar
* pStartY
= xmlGetProp(pStart
, BAD_CAST("y"));
94 xmlChar
* pEndY
= xmlGetProp(pEnd
, BAD_CAST("y"));
95 sal_Int32 nStartY
= o3tl::toInt32(reinterpret_cast<char const*>(pStartY
));
96 sal_Int32 nEndY
= o3tl::toInt32(reinterpret_cast<char const*>(pEndY
));
105 xmlXPathFreeObject(pXmlObj
);
106 // Without the accompanying fix in place, this test would have failed with:
109 // i.e. the 2nd and 5th vertical border was missing.
110 CPPUNIT_ASSERT_EQUAL(6, nVerticalBorders
);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */