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 <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>
34 :
35 : #include <vcl/svapp.hxx>
36 :
37 : #include <swmodeltestbase.hxx>
38 : #include <bordertest.hxx>
39 :
40 6 : class Test : public SwModelTestBase
41 : {
42 : public:
43 : void testN757910();
44 : void testN760294();
45 : void testN750255();
46 : void testN652364();
47 : void testN757118();
48 : void testN757905();
49 : void testAllGapsWord();
50 :
51 4 : CPPUNIT_TEST_SUITE(Test);
52 : #if !defined(MACOSX) && !defined(WNT)
53 2 : CPPUNIT_TEST(run);
54 : #endif
55 4 : CPPUNIT_TEST_SUITE_END();
56 :
57 : private:
58 : void run();
59 : };
60 :
61 2 : void Test::run()
62 : {
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},
71 2 : };
72 16 : for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
73 : {
74 14 : MethodEntry<Test>& rEntry = aMethods[i];
75 14 : mxComponent = loadFromDesktop(getURLFromSrc("/sw/qa/extras/ww8import/data/") + OUString::createFromAscii(rEntry.pName));
76 14 : (this->*rEntry.pMethod)();
77 : }
78 2 : }
79 :
80 2 : void Test::testN757910()
81 : {
82 : // The internal margin was larger than 0.28cm
83 2 : uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
84 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
85 2 : uno::Reference<beans::XPropertySet> xPropertySet(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
86 2 : sal_Int32 nValue = 0;
87 2 : xPropertySet->getPropertyValue("LeftBorderDistance") >>= nValue;
88 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(280), nValue);
89 :
90 : // The border width was zero
91 2 : table::BorderLine2 aBorder;
92 2 : xPropertySet->getPropertyValue("LeftBorder") >>= aBorder;
93 2 : CPPUNIT_ASSERT(aBorder.LineWidth > 0);
94 2 : }
95 :
96 2 : void Test::testN760294()
97 : {
98 2 : uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
99 2 : uno::Reference<container::XIndexAccess> xIndexAccess(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
100 2 : uno::Reference<beans::XPropertySet> xTable(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
101 2 : table::TableBorder aTableBorder;
102 2 : xTable->getPropertyValue("TableBorder") >>= aTableBorder;
103 2 : CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.OuterLineWidth);
104 2 : CPPUNIT_ASSERT_EQUAL(aTableBorder.TopLine.InnerLineWidth, aTableBorder.TopLine.LineDistance);
105 2 : }
106 :
107 2 : void Test::testN750255()
108 : {
109 : /*
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
113 : enum.nextElement
114 : para1 = enum.nextElement
115 : xray para1.String
116 : xray para1.PageStyleName
117 : para2 = enum.nextElement
118 : xray para2.String
119 : xray para2.PageStyleName
120 : */
121 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
122 2 : uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
123 : // list of paragraphs
124 2 : uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
125 : // go to 1st paragraph
126 2 : (void) paraEnum->nextElement();
127 : // get the 2nd and 3rd paragraph
128 2 : uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
129 2 : uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
130 2 : uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
131 2 : uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
132 2 : CPPUNIT_ASSERT_EQUAL( OUString( "one" ), text1->getString());
133 2 : CPPUNIT_ASSERT_EQUAL( OUString( "two" ), text2->getString());
134 2 : uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
135 2 : uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
136 2 : OUString pageStyle1, pageStyle2;
137 2 : paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
138 2 : paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
139 2 : CPPUNIT_ASSERT_EQUAL( OUString( "Convert 1" ), pageStyle1 );
140 2 : CPPUNIT_ASSERT_EQUAL( OUString( "Convert 2" ), pageStyle2 );
141 :
142 2 : }
143 :
144 2 : void Test::testN652364()
145 : {
146 : /*
147 : Related to 750255 above, column break with columns on the page however should be a column break.
148 : enum = ThisComponent.Text.createEnumeration
149 : enum.nextElement
150 : para1 = enum.nextElement
151 : xray para1.String
152 : xray para1.PageStyleName
153 : enum.nextElement
154 : para2 = enum.nextElement
155 : xray para2.String
156 : xray para2.PageStyleName
157 : */
158 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
159 2 : uno::Reference<container::XEnumerationAccess> paraEnumAccess(textDocument->getText(), uno::UNO_QUERY);
160 : // list of paragraphs
161 2 : uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
162 : // get the 2nd and 4th paragraph
163 2 : (void) paraEnum->nextElement();
164 2 : uno::Reference<uno::XInterface> paragraph1(paraEnum->nextElement(), uno::UNO_QUERY);
165 2 : (void) paraEnum->nextElement();
166 2 : uno::Reference<uno::XInterface> paragraph2(paraEnum->nextElement(), uno::UNO_QUERY);
167 2 : uno::Reference<text::XTextRange> text1(paragraph1, uno::UNO_QUERY);
168 2 : uno::Reference<text::XTextRange> text2(paragraph2, uno::UNO_QUERY);
169 2 : CPPUNIT_ASSERT_EQUAL( OUString( "text1" ), text1->getString());
170 2 : CPPUNIT_ASSERT_EQUAL( OUString( "text2" ), text2->getString());
171 2 : uno::Reference<beans::XPropertySet> paragraphProperties1(paragraph1, uno::UNO_QUERY);
172 2 : uno::Reference<beans::XPropertySet> paragraphProperties2(paragraph2, uno::UNO_QUERY);
173 2 : OUString pageStyle1, pageStyle2;
174 2 : paragraphProperties1->getPropertyValue( "PageStyleName" ) >>= pageStyle1;
175 2 : paragraphProperties2->getPropertyValue( "PageStyleName" ) >>= pageStyle2;
176 : // "Standard" is the style for the first page (2nd is "Convert 1").
177 2 : CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle1 );
178 2 : CPPUNIT_ASSERT_EQUAL( OUString( "Standard" ), pageStyle2 );
179 2 : }
180 :
181 2 : void Test::testN757118()
182 : {
183 : /*
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
187 : */
188 2 : uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
189 2 : uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
190 2 : uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
191 2 : uno::Reference<drawing::XShape> rule1, rule2, rule3, rule4;
192 2 : drawPage->getByIndex(0) >>= rule1;
193 2 : drawPage->getByIndex(1) >>= rule2;
194 2 : drawPage->getByIndex(2) >>= rule3;
195 2 : drawPage->getByIndex(3) >>= rule4;
196 2 : uno::Reference<beans::XPropertySet> ruleProperties1(rule1, uno::UNO_QUERY);
197 2 : uno::Reference<beans::XPropertySet> ruleProperties2(rule2, uno::UNO_QUERY);
198 2 : uno::Reference<beans::XPropertySet> ruleProperties3(rule3, uno::UNO_QUERY);
199 2 : uno::Reference<beans::XPropertySet> ruleProperties4(rule4, uno::UNO_QUERY);
200 2 : awt::Rectangle boundRect1, boundRect2, boundRect3, boundRect4;
201 2 : ruleProperties1->getPropertyValue( "BoundRect" ) >>= boundRect1;
202 2 : ruleProperties2->getPropertyValue( "BoundRect" ) >>= boundRect2;
203 2 : ruleProperties3->getPropertyValue( "BoundRect" ) >>= boundRect3;
204 2 : ruleProperties4->getPropertyValue( "BoundRect" ) >>= boundRect4;
205 : // compare, allow for < 5 differences because of rounding errors
206 2 : CPPUNIT_ASSERT( abs( boundRect1.Width - boundRect3.Width ) < 5 );
207 2 : CPPUNIT_ASSERT( abs( boundRect2.Width - boundRect4.Width ) < 5 );
208 2 : }
209 :
210 2 : void Test::testN757905()
211 : {
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.
216 :
217 2 : OUString aHeight = parseDump("/root/page/body/txt/infos/bounds", "height");
218 2 : CPPUNIT_ASSERT(sal_Int32(31) < aHeight.toInt32());
219 2 : }
220 :
221 2 : void Test::testAllGapsWord()
222 : {
223 2 : BorderTest borderTest;
224 2 : borderTest.testTheBorders(mxComponent);
225 2 : }
226 :
227 :
228 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
229 :
230 8 : CPPUNIT_PLUGIN_IMPLEMENT();
231 :
232 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|