Branch data Line data Source code
1 : : /*
2 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
3 : : *
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/
8 : : *
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
12 : : * License.
13 : : *
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.
18 : : *
19 : : * Contributor(s):
20 : : *
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.
26 : : */
27 : :
28 : : #include "../swmodeltestbase.hxx"
29 : : #include "bordertest.hxx"
30 : :
31 : : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
32 : : #include <com/sun/star/table/BorderLine2.hpp>
33 : : #include <com/sun/star/table/TableBorder.hpp>
34 : : #include <com/sun/star/text/XDependentTextField.hpp>
35 : : #include <com/sun/star/text/XTextFramesSupplier.hpp>
36 : : #include <com/sun/star/text/XTextTablesSupplier.hpp>
37 : :
38 : : #include <vcl/svapp.hxx>
39 : :
40 : : using rtl::OString;
41 : : using rtl::OUString;
42 : : using rtl::OUStringBuffer;
43 : :
44 [ - + ]: 63 : class Test : public SwModelTestBase
45 : : {
46 : : public:
47 : : void testN757910();
48 : : void testN760294();
49 : : void testN750255();
50 : : void testN652364();
51 : : void testN757118();
52 : : void testN757905();
53 : : void testAllGapsWord();
54 : :
55 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE(Test);
[ + - ][ + - ]
[ # # ]
56 : : #if !defined(MACOSX) && !defined(WNT)
57 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN757910);
[ + - ][ + - ]
[ + - ][ + - ]
58 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN760294);
[ + - ][ + - ]
[ + - ][ + - ]
59 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN750255);
[ + - ][ + - ]
[ + - ][ + - ]
60 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN652364);
[ + - ][ + - ]
[ + - ][ + - ]
61 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN757118);
[ + - ][ + - ]
[ + - ][ + - ]
62 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testN757905);
[ + - ][ + - ]
[ + - ][ + - ]
63 [ + - ][ + - ]: 3 : CPPUNIT_TEST(testAllGapsWord);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
64 : : #endif
65 [ + - ][ + - ]: 6 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
66 : :
67 : : private:
68 : : /// Load a WW8 file and make the document available via mxComponent.
69 : : void load(const OUString& rURL);
70 : : };
71 : :
72 : 21 : void Test::load(const OUString& rFilename)
73 : : {
74 [ + - ][ + - ]: 21 : mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/ww8import/data/") + rFilename);
75 : 21 : }
76 : :
77 : 3 : void Test::testN757910()
78 : : {
79 [ + - ]: 3 : load("n757910.doc");
80 : :
81 : : // The internal margin was larger than 0.28cm
82 [ + - ]: 3 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
83 [ + - ][ + - ]: 3 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
[ + - ]
84 [ + - ][ + - ]: 3 : uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
[ + - ]
85 : 3 : sal_Int32 nValue = 0;
86 [ + - ][ + - ]: 3 : xPropertySet->getPropertyValue("LeftBorderDistance") >>= nValue;
87 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue);
[ + - ][ + - ]
[ + - ]
88 : :
89 : : // The border width was zero
90 : 3 : table::BorderLine2 aBorder;
91 [ + - ][ + - ]: 3 : xPropertySet->getPropertyValue("LeftBorder") >>= aBorder;
[ + - ]
92 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(aBorder.LineWidth > 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
93 : 3 : }
94 : :
95 : 3 : void Test::testN760294()
96 : : {
97 [ + - ]: 3 : load("n760294.doc");
98 : :
99 [ + - ]: 3 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
100 [ + - ][ + - ]: 3 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
[ + - ]
101 [ + - ][ + - ]: 3 : uno::Reference<beans::XPropertySet> xTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
[ + - ]
102 : 3 : table::TableBorder aTableBorder;
103 [ + - ][ + - ]: 3 : xTable->getPropertyValue("TableBorder") >>= aTableBorder;
[ + - ]
104 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.OuterLineWidth);
[ + - ][ + - ]
[ + - ]
105 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.LineDistance);
[ + - ][ + - ]
[ + - ]
106 : 3 : }
107 : :
108 : 3 : void Test::testN750255()
109 : : {
110 [ + - ]: 3 : load( "n750255.doc" );
111 : :
112 : : /*
113 : : Column break without columns on the page is a page break, so check those paragraphs
114 : : are on page 2 (page style 'Convert 1') and page 3 (page style 'Convert 2')
115 : : enum = ThisComponent.Text.createEnumeration
116 : : enum.nextElement
117 : : para1 = enum.nextElement
118 : : xray para1.String
119 : : xray para1.PageStyleName
120 : : para2 = enum.nextElement
121 : : xray para2.String
122 : : xray para2.PageStyleName
123 : : */
124 [ + - ]: 3 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
125 [ + - ][ + - ]: 3 : uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
[ + - ]
126 : : // list of paragraphs
127 [ + - ][ + - ]: 3 : uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
128 : : // go to 1st paragraph
129 [ + - ][ + - ]: 3 : (void) paraEnum->nextElement();
130 : : // get the 2nd and 3rd paragraph
131 [ + - ][ + - ]: 3 : uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
[ + - ]
132 [ + - ][ + - ]: 3 : uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
[ + - ]
133 [ + - ]: 3 : uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
134 [ + - ]: 3 : uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
135 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
136 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
137 [ + - ]: 3 : uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
138 [ + - ]: 3 : uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
139 : 3 : OUString pageStyle1, pageStyle2;
140 [ + - ][ + - ]: 3 : paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
141 [ + - ][ + - ]: 3 : paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
142 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1 );
[ + - ][ + - ]
[ + - ]
143 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2 );
[ + - ][ + - ]
[ + - ]
144 : :
145 : 3 : }
146 : :
147 : 3 : void Test::testN652364()
148 : : {
149 [ + - ]: 3 : load( "n652364.doc" );
150 : :
151 : : /*
152 : : Related to 750255 above, column break with columns on the page however should be a column break.
153 : : enum = ThisComponent.Text.createEnumeration
154 : : enum.nextElement
155 : : para1 = enum.nextElement
156 : : xray para1.String
157 : : xray para1.PageStyleName
158 : : enum.nextElement
159 : : para2 = enum.nextElement
160 : : xray para2.String
161 : : xray para2.PageStyleName
162 : : */
163 [ + - ]: 3 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
164 [ + - ][ + - ]: 3 : uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
[ + - ]
165 : : // list of paragraphs
166 [ + - ][ + - ]: 3 : uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
167 : : // get the 2nd and 4th paragraph
168 [ + - ][ + - ]: 3 : (void) paraEnum->nextElement();
169 [ + - ][ + - ]: 3 : uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
[ + - ]
170 [ + - ][ + - ]: 3 : (void) paraEnum->nextElement();
171 [ + - ][ + - ]: 3 : uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
[ + - ]
172 [ + - ]: 3 : uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
173 [ + - ]: 3 : uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
174 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
175 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
176 [ + - ]: 3 : uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
177 [ + - ]: 3 : uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
178 : 3 : OUString pageStyle1, pageStyle2;
179 [ + - ][ + - ]: 3 : paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
180 [ + - ][ + - ]: 3 : paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
181 : : // "Standard" is the style for the first page (2nd is "Convert 1").
182 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
[ + - ][ + - ]
[ + - ]
183 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
[ + - ][ + - ]
[ + - ]
184 : 3 : }
185 : :
186 : 3 : void Test::testN757118()
187 : : {
188 [ + - ]: 3 : load( "n757118.doc" );
189 : : /*
190 : : Two pairs of horizontal rules (one absolute width, one relative width)
191 : : have the same width (full page width, half page width).
192 : : xray ThisComponent.DrawPage.getByIndex(0).BoundRect
193 : : */
194 [ + - ]: 3 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
195 [ + - ]: 3 : uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
196 [ + - ][ + - ]: 3 : uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
197 : 3 : uno::Reference<drawing::XShape> rule1, rule2, rule3, rule4;
198 [ + - ][ + - ]: 3 : drawPage->getByIndex(0) >>= rule1;
[ + - ]
199 [ + - ][ + - ]: 3 : drawPage->getByIndex(1) >>= rule2;
[ + - ]
200 [ + - ][ + - ]: 3 : drawPage->getByIndex(2) >>= rule3;
[ + - ]
201 [ + - ][ + - ]: 3 : drawPage->getByIndex(3) >>= rule4;
[ + - ]
202 [ + - ]: 3 : uno::Reference<beans::XPropertySet> ruleProperties1(rule1, uno::UNO_QUERY);
203 [ + - ]: 3 : uno::Reference<beans::XPropertySet> ruleProperties2(rule2, uno::UNO_QUERY);
204 [ + - ]: 3 : uno::Reference<beans::XPropertySet> ruleProperties3(rule3, uno::UNO_QUERY);
205 [ + - ]: 3 : uno::Reference<beans::XPropertySet> ruleProperties4(rule4, uno::UNO_QUERY);
206 : 3 : awt::Rectangle boundRect1, boundRect2, boundRect3, boundRect4;
207 [ + - ][ + - ]: 3 : ruleProperties1->getPropertyValue( "BoundRect" ) >>= boundRect1;
[ + - ]
208 [ + - ][ + - ]: 3 : ruleProperties2->getPropertyValue( "BoundRect" ) >>= boundRect2;
[ + - ]
209 [ + - ][ + - ]: 3 : ruleProperties3->getPropertyValue( "BoundRect" ) >>= boundRect3;
[ + - ]
210 [ + - ][ + - ]: 3 : ruleProperties4->getPropertyValue( "BoundRect" ) >>= boundRect4;
[ + - ]
211 : : // compare, allow for < 5 differences because of rounding errors
212 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT( abs( boundRect1.Width - boundRect3.Width ) < 5 );
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ][ + - ]
213 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT( abs( boundRect2.Width - boundRect4.Width ) < 5 );
[ + - ][ + - ]
[ + - ][ - + ]
[ + - ][ + - ]
[ + - ][ + - ]
214 : 3 : }
215 : :
216 : 3 : void Test::testN757905()
217 : : {
218 : : // The problem was that the paragraph had only a single fly
219 : : // (as-character-anchored), and the height of that was smallar than the
220 : : // paragraph height. When in Word-compat mode, we should take the max of
221 : : // the two, not just the height of the fly.
222 : :
223 [ + - ]: 3 : load("n757905.doc");
224 : :
225 [ + - ]: 3 : OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
226 [ + - ][ + - ]: 3 : CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
227 : 3 : }
228 : :
229 : 3 : void Test::testAllGapsWord()
230 : : {
231 [ + - ]: 3 : load("all_gaps_word.doc");
232 : 3 : BorderTest borderTest;
233 [ + - ]: 3 : borderTest.testTheBorders(mxComponent);
234 : 3 : }
235 : :
236 : :
237 : 3 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
238 : :
239 [ + - ][ + - ]: 12 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
240 : :
241 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|