2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
10 #include <com/sun/star/table/BorderLine2.hpp>
11 #include <com/sun/star/table/TableBorder.hpp>
12 #include <com/sun/star/text/XDependentTextField.hpp>
13 #include <com/sun/star/text/XTextFramesSupplier.hpp>
14 #include <com/sun/star/text/XTextTablesSupplier.hpp>
16 #include <vcl/svapp.hxx>
18 #include <swmodeltestbase.hxx>
19 #include <bordertest.hxx>
21 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
23 class Test
: public SwModelTestBase
32 void testAllGapsWord();
36 void testPageBorder();
40 CPPUNIT_TEST_SUITE(Test
);
41 #if !defined(MACOSX) && !defined(WNT)
44 CPPUNIT_TEST_SUITE_END();
52 MethodEntry
<Test
> aMethods
[] = {
53 {"n757910.doc", &Test::testN757910
},
54 {"n760294.doc", &Test::testN760294
},
55 {"n750255.doc", &Test::testN750255
},
56 {"n652364.doc", &Test::testN652364
},
57 {"n757118.doc", &Test::testN757118
},
58 {"n757905.doc", &Test::testN757905
},
59 {"all_gaps_word.doc", &Test::testAllGapsWord
},
60 {"i120158.doc", &Test::testI120158
},
61 {"n816603.doc", &Test::testN816603
},
62 {"n816593.doc", &Test::testN816593
},
63 {"page-border.doc", &Test::testPageBorder
},
64 {"n823651.doc", &Test::testN823651
},
65 {"bnc821208.doc", &Test::testBnc821208
},
68 for (unsigned int i
= 0; i
< SAL_N_ELEMENTS(aMethods
); ++i
)
70 MethodEntry
<Test
>& rEntry
= aMethods
[i
];
71 load("/sw/qa/extras/ww8import/data/", rEntry
.pName
);
72 (this->*rEntry
.pMethod
)();
77 void Test::testN757910()
79 // The internal margin was larger than 0.28cm
80 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
81 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
82 uno::Reference
<beans::XPropertySet
> xPropertySet(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
84 xPropertySet
->getPropertyValue("LeftBorderDistance") >>= nValue
;
85 CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue
);
87 // The border width was zero
88 table::BorderLine2 aBorder
;
89 xPropertySet
->getPropertyValue("LeftBorder") >>= aBorder
;
90 CPPUNIT_ASSERT(aBorder
.LineWidth
> 0);
93 void Test::testN760294()
95 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
96 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
97 uno::Reference
<beans::XPropertySet
> xTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
98 table::TableBorder aTableBorder
;
99 xTable
->getPropertyValue("TableBorder") >>= aTableBorder
;
100 CPPUNIT_ASSERT_EQUAL(aTableBorder
.TopLine
.InnerLineWidth
, aTableBorder
.TopLine
.OuterLineWidth
);
101 CPPUNIT_ASSERT_EQUAL(aTableBorder
.TopLine
.InnerLineWidth
, aTableBorder
.TopLine
.LineDistance
);
104 void Test::testN750255()
107 Column break without columns on the page is a page break, so check those paragraphs
108 are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
109 enum = ThisComponent.Text.createEnumeration
111 para1 = enum.nextElement
113 xray para1.PageStyleName
114 para2 = enum.nextElement
116 xray para2.PageStyleName
118 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
119 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
120 // list of paragraphs
121 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
122 // go to 1st paragraph
123 (void) paraEnum
->nextElement();
124 // get the 2nd and 3rd paragraph
125 uno::Reference
<uno::XInterface
> paragraph1(paraEnum
->nextElement(), uno::UNO_QUERY
);
126 uno::Reference
<uno::XInterface
> paragraph2(paraEnum
->nextElement(), uno::UNO_QUERY
);
127 uno::Reference
<text::XTextRange
> text1(paragraph1
, uno::UNO_QUERY
);
128 uno::Reference
<text::XTextRange
> text2(paragraph2
, uno::UNO_QUERY
);
129 CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1
->getString());
130 CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2
->getString());
131 uno::Reference
<beans::XPropertySet
> paragraphProperties1(paragraph1
, uno::UNO_QUERY
);
132 uno::Reference
<beans::XPropertySet
> paragraphProperties2(paragraph2
, uno::UNO_QUERY
);
133 OUString pageStyle1
, pageStyle2
;
134 paragraphProperties1
->getPropertyValue( "PageStyleName" ) >>= pageStyle1
;
135 paragraphProperties2
->getPropertyValue( "PageStyleName" ) >>= pageStyle2
;
136 CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1
);
137 CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2
);
141 void Test::testN652364()
144 Related to 750255 above, column break with columns on the page however should be a column break.
145 enum = ThisComponent.Text.createEnumeration
147 para1 = enum.nextElement
149 xray para1.PageStyleName
151 para2 = enum.nextElement
153 xray para2.PageStyleName
155 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
156 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
157 // list of paragraphs
158 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
159 // get the 2nd and 4th paragraph
160 (void) paraEnum
->nextElement();
161 uno::Reference
<uno::XInterface
> paragraph1(paraEnum
->nextElement(), uno::UNO_QUERY
);
162 (void) paraEnum
->nextElement();
163 uno::Reference
<uno::XInterface
> paragraph2(paraEnum
->nextElement(), uno::UNO_QUERY
);
164 uno::Reference
<text::XTextRange
> text1(paragraph1
, uno::UNO_QUERY
);
165 uno::Reference
<text::XTextRange
> text2(paragraph2
, uno::UNO_QUERY
);
166 CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1
->getString());
167 CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2
->getString());
168 uno::Reference
<beans::XPropertySet
> paragraphProperties1(paragraph1
, uno::UNO_QUERY
);
169 uno::Reference
<beans::XPropertySet
> paragraphProperties2(paragraph2
, uno::UNO_QUERY
);
170 OUString pageStyle1
, pageStyle2
;
171 paragraphProperties1
->getPropertyValue( "PageStyleName" ) >>= pageStyle1
;
172 paragraphProperties2
->getPropertyValue( "PageStyleName" ) >>= pageStyle2
;
173 // "Standard" is the style for the first page (2nd is "Convert 1").
174 CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1
);
175 CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2
);
178 void Test::testN757118()
181 Two pairs of horizontal rules (one absolute width, one relative width)
182 have the same width (full page width, half page width).
183 xray ThisComponent.DrawPage.getByIndex(0).BoundRect
185 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
186 uno::Reference
<drawing::XDrawPageSupplier
> drawPageSupplier(textDocument
, uno::UNO_QUERY
);
187 uno::Reference
<drawing::XDrawPage
> drawPage
= drawPageSupplier
->getDrawPage();
188 uno::Reference
<drawing::XShape
> rule1
, rule2
, rule3
, rule4
;
189 drawPage
->getByIndex(0) >>= rule1
;
190 drawPage
->getByIndex(1) >>= rule2
;
191 drawPage
->getByIndex(2) >>= rule3
;
192 drawPage
->getByIndex(3) >>= rule4
;
193 uno::Reference
<beans::XPropertySet
> ruleProperties1(rule1
, uno::UNO_QUERY
);
194 uno::Reference
<beans::XPropertySet
> ruleProperties2(rule2
, uno::UNO_QUERY
);
195 uno::Reference
<beans::XPropertySet
> ruleProperties3(rule3
, uno::UNO_QUERY
);
196 uno::Reference
<beans::XPropertySet
> ruleProperties4(rule4
, uno::UNO_QUERY
);
197 awt::Rectangle boundRect1
, boundRect2
, boundRect3
, boundRect4
;
198 ruleProperties1
->getPropertyValue( "BoundRect" ) >>= boundRect1
;
199 ruleProperties2
->getPropertyValue( "BoundRect" ) >>= boundRect2
;
200 ruleProperties3
->getPropertyValue( "BoundRect" ) >>= boundRect3
;
201 ruleProperties4
->getPropertyValue( "BoundRect" ) >>= boundRect4
;
202 // compare, allow for < 5 differences because of rounding errors
203 CPPUNIT_ASSERT( abs( boundRect1
.Width
- boundRect3
.Width
) < 5 );
204 CPPUNIT_ASSERT( abs( boundRect2
.Width
- boundRect4
.Width
) < 5 );
207 void Test::testN757905()
209 // The problem was that the paragraph had only a single fly
210 // (as-character-anchored), and the height of that was smallar than the
211 // paragraph height. When in Word-compat mode, we should take the max of
212 // the two, not just the height of the fly.
214 OUString aHeight
= parseDump("/root/page/body/txt/infos/bounds", "height");
215 CPPUNIT_ASSERT(sal_Int32(31) < aHeight
.toInt32());
218 void Test::testAllGapsWord()
220 BorderTest borderTest
;
221 borderTest
.testTheBorders(mxComponent
);
224 void Test::testI120158()
226 // See https://issues.apache.org/ooo/show_bug.cgi?id=120158
227 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
228 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
229 // list of paragraphs
230 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
231 // get contents of 1st paragraph as text
232 uno::Reference
<uno::XInterface
> paragraph0(paraEnum
->nextElement(), uno::UNO_QUERY
);
233 uno::Reference
<text::XTextRange
> text0(paragraph0
, uno::UNO_QUERY
);
234 OUString sFieldResult
= text0
->getString();
235 CPPUNIT_ASSERT(sFieldResult
.endsWith("AM") || sFieldResult
.endsWith("PM"));
238 void Test::testN816603()
240 // Bugdoc was 5 page in Word, 1 in Writer due to pointlessly wrapping the
241 // table in a frame. Exact layout may depend on fonts available, etc. --
242 // but at least make sure that our table spans over multiple pages now.
243 CPPUNIT_ASSERT(getPages() > 1);
246 void Test::testN816593()
248 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
249 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
250 // Make sure that even if we import the two tables as non-floating, we
251 // still consider them different, and not merge them.
252 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
255 void Test::testPageBorder()
257 // Page border was missing (LineWidth was 0), due to wrong interpretation of pgbApplyTo.
258 table::BorderLine2 aBorder
= getProperty
<table::BorderLine2
>(getStyles("PageStyles")->getByName(DEFAULT_STYLE
), "TopBorder");
259 CPPUNIT_ASSERT_EQUAL(sal_uInt32(TWIP_TO_MM100(6 * 20)), aBorder
.LineWidth
);
262 void Test::testN823651()
264 // Character height was 10pt instead of 7.5pt in the header.
265 uno::Reference
<beans::XPropertySet
> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE
), uno::UNO_QUERY
);
266 uno::Reference
<text::XText
> xText
= getProperty
< uno::Reference
<text::XTextRange
> >(xStyle
, "HeaderTextFirst")->getText();
267 CPPUNIT_ASSERT_EQUAL(7.5f
, getProperty
<float>(getParagraphOfText(1, xText
), "CharHeight"));
270 void Test::testBnc821208()
272 // WW8Num1z0 earned a Symbol font, turning numbers into rectangles.
273 uno::Reference
<beans::XPropertyState
> xPropertyState(getStyles("CharacterStyles")->getByName("WW8Num1z0"), uno::UNO_QUERY
);
274 beans::PropertyState ePropertyState
= xPropertyState
->getPropertyState("CharFontName");
275 // This was beans::PropertyState_DIRECT_VALUE.
276 CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DEFAULT_VALUE
, ePropertyState
);
278 // Background of the numbering itself should have been the default, was yellow (0xffff00).
279 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getProperty
<sal_Int32
>(xPropertyState
, "CharBackColor"));
282 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
284 CPPUNIT_PLUGIN_IMPLEMENT();
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */