2 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Initial Developer of the Original Code is
15 * Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
16 * Portions created by the Initial Developer are Copyright (C) 2012 the
17 * Initial Developer. All Rights Reserved.
21 * Alternatively, the contents of this file may be used under the terms of
22 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
23 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
24 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
25 * instead of those above.
28 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29 #include <com/sun/star/table/BorderLine2.hpp>
30 #include <com/sun/star/table/TableBorder.hpp>
31 #include <com/sun/star/text/XDependentTextField.hpp>
32 #include <com/sun/star/text/XTextFramesSupplier.hpp>
33 #include <com/sun/star/text/XTextTablesSupplier.hpp>
35 #include <vcl/svapp.hxx>
37 #include <swmodeltestbase.hxx>
38 #include <bordertest.hxx>
40 class Test
: public SwModelTestBase
49 void testAllGapsWord();
51 CPPUNIT_TEST_SUITE(Test
);
52 #if !defined(MACOSX) && !defined(WNT)
55 CPPUNIT_TEST_SUITE_END();
63 MethodEntry
<Test
> aMethods
[] = {
64 {"n757910.doc", &Test::testN757910
},
65 {"n760294.doc", &Test::testN760294
},
66 {"n750255.doc", &Test::testN750255
},
67 {"n652364.doc", &Test::testN652364
},
68 {"n757118.doc", &Test::testN757118
},
69 {"n757905.doc", &Test::testN757905
},
70 {"all_gaps_word.doc", &Test::testAllGapsWord
},
72 for (unsigned int i
= 0; i
< SAL_N_ELEMENTS(aMethods
); ++i
)
74 MethodEntry
<Test
>& rEntry
= aMethods
[i
];
75 mxComponent
= loadFromDesktop(getURLFromSrc("/sw/qa/extras/ww8import/data/") + OUString::createFromAscii(rEntry
.pName
));
76 (this->*rEntry
.pMethod
)();
80 void Test::testN757910()
82 // The internal margin was larger than 0.28cm
83 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
84 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(), uno::UNO_QUERY
);
85 uno::Reference
<beans::XPropertySet
> xPropertySet(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
87 xPropertySet
->getPropertyValue("LeftBorderDistance") >>= nValue
;
88 CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue
);
90 // The border width was zero
91 table::BorderLine2 aBorder
;
92 xPropertySet
->getPropertyValue("LeftBorder") >>= aBorder
;
93 CPPUNIT_ASSERT(aBorder
.LineWidth
> 0);
96 void Test::testN760294()
98 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
99 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(), uno::UNO_QUERY
);
100 uno::Reference
<beans::XPropertySet
> xTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
101 table::TableBorder aTableBorder
;
102 xTable
->getPropertyValue("TableBorder") >>= aTableBorder
;
103 CPPUNIT_ASSERT_EQUAL(aTableBorder
.TopLine
.InnerLineWidth
, aTableBorder
.TopLine
.OuterLineWidth
);
104 CPPUNIT_ASSERT_EQUAL(aTableBorder
.TopLine
.InnerLineWidth
, aTableBorder
.TopLine
.LineDistance
);
107 void Test::testN750255()
110 Column break without columns on the page is a page break, so check those paragraphs
111 are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
112 enum = ThisComponent.Text.createEnumeration
114 para1 = enum.nextElement
116 xray para1.PageStyleName
117 para2 = enum.nextElement
119 xray para2.PageStyleName
121 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
122 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
123 // list of paragraphs
124 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
125 // go to 1st paragraph
126 (void) paraEnum
->nextElement();
127 // get the 2nd and 3rd paragraph
128 uno::Reference
<uno::XInterface
> paragraph1(paraEnum
->nextElement(), uno::UNO_QUERY
);
129 uno::Reference
<uno::XInterface
> paragraph2(paraEnum
->nextElement(), uno::UNO_QUERY
);
130 uno::Reference
<text::XTextRange
> text1(paragraph1
, uno::UNO_QUERY
);
131 uno::Reference
<text::XTextRange
> text2(paragraph2
, uno::UNO_QUERY
);
132 CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1
->getString());
133 CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2
->getString());
134 uno::Reference
<beans::XPropertySet
> paragraphProperties1(paragraph1
, uno::UNO_QUERY
);
135 uno::Reference
<beans::XPropertySet
> paragraphProperties2(paragraph2
, uno::UNO_QUERY
);
136 OUString pageStyle1
, pageStyle2
;
137 paragraphProperties1
->getPropertyValue( "PageStyleName" ) >>= pageStyle1
;
138 paragraphProperties2
->getPropertyValue( "PageStyleName" ) >>= pageStyle2
;
139 CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1
);
140 CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2
);
144 void Test::testN652364()
147 Related to 750255 above, column break with columns on the page however should be a column break.
148 enum = ThisComponent.Text.createEnumeration
150 para1 = enum.nextElement
152 xray para1.PageStyleName
154 para2 = enum.nextElement
156 xray para2.PageStyleName
158 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
159 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess(textDocument
->getText(), uno::UNO_QUERY
);
160 // list of paragraphs
161 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
162 // get the 2nd and 4th paragraph
163 (void) paraEnum
->nextElement();
164 uno::Reference
<uno::XInterface
> paragraph1(paraEnum
->nextElement(), uno::UNO_QUERY
);
165 (void) paraEnum
->nextElement();
166 uno::Reference
<uno::XInterface
> paragraph2(paraEnum
->nextElement(), uno::UNO_QUERY
);
167 uno::Reference
<text::XTextRange
> text1(paragraph1
, uno::UNO_QUERY
);
168 uno::Reference
<text::XTextRange
> text2(paragraph2
, uno::UNO_QUERY
);
169 CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1
->getString());
170 CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2
->getString());
171 uno::Reference
<beans::XPropertySet
> paragraphProperties1(paragraph1
, uno::UNO_QUERY
);
172 uno::Reference
<beans::XPropertySet
> paragraphProperties2(paragraph2
, uno::UNO_QUERY
);
173 OUString pageStyle1
, pageStyle2
;
174 paragraphProperties1
->getPropertyValue( "PageStyleName" ) >>= pageStyle1
;
175 paragraphProperties2
->getPropertyValue( "PageStyleName" ) >>= pageStyle2
;
176 // "Standard" is the style for the first page (2nd is "Convert 1").
177 CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1
);
178 CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2
);
181 void Test::testN757118()
184 Two pairs of horizontal rules (one absolute width, one relative width)
185 have the same width (full page width, half page width).
186 xray ThisComponent.DrawPage.getByIndex(0).BoundRect
188 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
189 uno::Reference
<drawing::XDrawPageSupplier
> drawPageSupplier(textDocument
, uno::UNO_QUERY
);
190 uno::Reference
<drawing::XDrawPage
> drawPage
= drawPageSupplier
->getDrawPage();
191 uno::Reference
<drawing::XShape
> rule1
, rule2
, rule3
, rule4
;
192 drawPage
->getByIndex(0) >>= rule1
;
193 drawPage
->getByIndex(1) >>= rule2
;
194 drawPage
->getByIndex(2) >>= rule3
;
195 drawPage
->getByIndex(3) >>= rule4
;
196 uno::Reference
<beans::XPropertySet
> ruleProperties1(rule1
, uno::UNO_QUERY
);
197 uno::Reference
<beans::XPropertySet
> ruleProperties2(rule2
, uno::UNO_QUERY
);
198 uno::Reference
<beans::XPropertySet
> ruleProperties3(rule3
, uno::UNO_QUERY
);
199 uno::Reference
<beans::XPropertySet
> ruleProperties4(rule4
, uno::UNO_QUERY
);
200 awt::Rectangle boundRect1
, boundRect2
, boundRect3
, boundRect4
;
201 ruleProperties1
->getPropertyValue( "BoundRect" ) >>= boundRect1
;
202 ruleProperties2
->getPropertyValue( "BoundRect" ) >>= boundRect2
;
203 ruleProperties3
->getPropertyValue( "BoundRect" ) >>= boundRect3
;
204 ruleProperties4
->getPropertyValue( "BoundRect" ) >>= boundRect4
;
205 // compare, allow for < 5 differences because of rounding errors
206 CPPUNIT_ASSERT( abs( boundRect1
.Width
- boundRect3
.Width
) < 5 );
207 CPPUNIT_ASSERT( abs( boundRect2
.Width
- boundRect4
.Width
) < 5 );
210 void Test::testN757905()
212 // The problem was that the paragraph had only a single fly
213 // (as-character-anchored), and the height of that was smallar than the
214 // paragraph height. When in Word-compat mode, we should take the max of
215 // the two, not just the height of the fly.
217 OUString aHeight
= parseDump("/root/page/body/txt/infos/bounds", "height");
218 CPPUNIT_ASSERT(sal_Int32(31) < aHeight
.toInt32());
221 void Test::testAllGapsWord()
223 BorderTest borderTest
;
224 borderTest
.testTheBorders(mxComponent
);
228 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
230 CPPUNIT_PLUGIN_IMPLEMENT();
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */