Line data Source code
1 : /*
2 : * This file is part of the LibreOffice project.
3 : *
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/.
7 : */
8 :
9 : #include <swmodeltestbase.hxx>
10 :
11 : #if !defined(MACOSX) && !defined(WNT)
12 :
13 : #include <com/sun/star/form/validation/XValidatableFormComponent.hpp>
14 : #include <com/sun/star/frame/XStorable.hpp>
15 : #include <com/sun/star/drawing/XControlShape.hpp>
16 : #include <com/sun/star/beans/XPropertySet.hpp>
17 : #include <com/sun/star/view/XViewSettingsSupplier.hpp>
18 : #include <com/sun/star/table/ShadowFormat.hpp>
19 : #include <com/sun/star/table/TableBorder2.hpp>
20 :
21 24 : class Test : public SwModelTestBase
22 : {
23 : public:
24 24 : Test() : SwModelTestBase("/sw/qa/extras/ww8export/data/", "MS Word 97") {}
25 :
26 12 : bool mustTestImportOf(const char* filename) const SAL_OVERRIDE
27 : {
28 : // If the testcase is stored in some other format, it's pointless to test.
29 12 : return OString(filename).endsWith(".doc");
30 : }
31 : };
32 :
33 : #define DECLARE_WW8EXPORT_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, Test)
34 :
35 14 : DECLARE_WW8EXPORT_TEST(testN325936, "n325936.doc")
36 : {
37 : /*
38 : * The problem was that the transparent background of the drawing in the
39 : * header was exported as non-transparent.
40 : *
41 : * xray ThisComponent.DrawPage(0).BackColorTransparency
42 : */
43 :
44 2 : uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
45 2 : sal_Int32 nValue = getProperty< sal_Int32 >(getShape(1), "BackColorTransparency");
46 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(100), nValue);
47 2 : }
48 :
49 13 : DECLARE_WW8EXPORT_TEST(testFdo45724, "fdo45724.odt")
50 : {
51 : // The text and background color of the control shape was not correct.
52 1 : uno::Reference<drawing::XControlShape> xControlShape(getShape(1), uno::UNO_QUERY);
53 2 : uno::Reference<form::validation::XValidatableFormComponent> xComponent(xControlShape->getControl(), uno::UNO_QUERY);
54 1 : CPPUNIT_ASSERT_EQUAL(COL_WHITE, getProperty<sal_uInt32>(xComponent, "BackgroundColor"));
55 2 : CPPUNIT_ASSERT_EQUAL(OUString("xxx"), xComponent->getCurrentValue().get<OUString>());
56 1 : }
57 :
58 13 : DECLARE_WW8EXPORT_TEST(testFdo46020, "fdo46020.odt")
59 : {
60 : // The footnote in that document wasn't exported, check that it is actually exported
61 1 : uno::Reference<text::XFootnotesSupplier> xFootnotesSupplier(mxComponent, uno::UNO_QUERY);
62 2 : uno::Reference<container::XIndexAccess> xFootnotes(xFootnotesSupplier->getFootnotes(), uno::UNO_QUERY);
63 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFootnotes->getCount());
64 1 : }
65 :
66 14 : DECLARE_WW8EXPORT_TEST(testFirstHeaderFooter, "first-header-footer.doc")
67 : {
68 : // Test import and export of a section's headerf/footerf properties.
69 :
70 : // The document has 6 pages. Note that we don't test if 4 or just 2 page
71 : // styles are created, the point is that layout should be correct.
72 2 : CPPUNIT_ASSERT_EQUAL(OUString("First page header"), parseDump("/root/page[1]/header/txt/text()"));
73 2 : CPPUNIT_ASSERT_EQUAL(OUString("First page footer"), parseDump("/root/page[1]/footer/txt/text()"));
74 2 : CPPUNIT_ASSERT_EQUAL(OUString("Even page header"), parseDump("/root/page[2]/header/txt/text()"));
75 2 : CPPUNIT_ASSERT_EQUAL(OUString("Even page footer"), parseDump("/root/page[2]/footer/txt/text()"));
76 2 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page header"), parseDump("/root/page[3]/header/txt/text()"));
77 2 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer"), parseDump("/root/page[3]/footer/txt/text()"));
78 2 : CPPUNIT_ASSERT_EQUAL(OUString("First page header2"), parseDump("/root/page[4]/header/txt/text()"));
79 2 : CPPUNIT_ASSERT_EQUAL(OUString("First page footer 2"), parseDump("/root/page[4]/footer/txt/text()"));
80 2 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page header 2"), parseDump("/root/page[5]/header/txt/text()"));
81 2 : CPPUNIT_ASSERT_EQUAL(OUString("Odd page footer 2"), parseDump("/root/page[5]/footer/txt/text()"));
82 2 : CPPUNIT_ASSERT_EQUAL(OUString("Even page header 2"), parseDump("/root/page[6]/header/txt/text()"));
83 2 : CPPUNIT_ASSERT_EQUAL(OUString("Even page footer 2"), parseDump("/root/page[6]/footer/txt/text()"));
84 2 : }
85 :
86 14 : DECLARE_WW8EXPORT_TEST(testZoom, "zoom.doc")
87 : {
88 2 : uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
89 4 : uno::Reference<view::XViewSettingsSupplier> xViewSettingsSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
90 4 : uno::Reference<beans::XPropertySet> xPropertySet(xViewSettingsSupplier->getViewSettings());
91 2 : sal_Int16 nValue = 0;
92 2 : xPropertySet->getPropertyValue("ZoomValue") >>= nValue;
93 4 : CPPUNIT_ASSERT_EQUAL(sal_Int16(42), nValue);
94 2 : }
95 :
96 14 : DECLARE_WW8EXPORT_TEST(test56513, "fdo56513.doc")
97 : {
98 2 : CPPUNIT_ASSERT_EQUAL(OUString("This is the header of the first section"), parseDump("/root/page[1]/header/txt/text()"));
99 2 : CPPUNIT_ASSERT_EQUAL(OUString("This is the first page header of the second section"), parseDump("/root/page[2]/header/txt/text()"));
100 2 : CPPUNIT_ASSERT_EQUAL(OUString("This is the non-first-page header of the second section"), parseDump("/root/page[3]/header/txt/text()"));
101 2 : }
102 :
103 14 : DECLARE_WW8EXPORT_TEST(testNewPageStylesTable, "new-page-styles.doc")
104 : {
105 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals and Results (Page 1)*"), parseDump("/root/page[1]/header/txt/text()"));
106 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Assessment (Page 2)****"), parseDump("/root/page[2]/header/txt/text()"));
107 2 : CPPUNIT_ASSERT_EQUAL(OUString("Sigma Space Performance Goals: Next Year (Page 3)*******"), parseDump("/root/page[3]/header/txt/text()"));
108 2 : }
109 :
110 13 : DECLARE_WW8EXPORT_TEST(testFdo42144, "fdo42144.odt")
111 : {
112 : // Footer wasn't disabled -- instead empty footer was exported.
113 1 : uno::Reference<beans::XPropertySet> xStyle(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY);
114 1 : CPPUNIT_ASSERT_EQUAL(false, bool(getProperty<sal_Bool>(xStyle, "FooterIsOn")));
115 1 : }
116 :
117 13 : DECLARE_WW8EXPORT_TEST(testCharacterBorder, "charborder.odt")
118 : {
119 1 : uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1),1), uno::UNO_QUERY);
120 : // WW8 has just one border attribute (sprmCBrc) for text border so all side has
121 : // the same border
122 : // Border
123 : {
124 1 : const table::BorderLine2 aTopBorder = getProperty<table::BorderLine2>(xRun,"CharTopBorder");
125 1 : CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF3333,0,318,0,0,318), aTopBorder);
126 1 : CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharLeftBorder"));
127 1 : CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharBottomBorder"));
128 1 : CPPUNIT_ASSERT_BORDER_EQUAL(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharRightBorder"));
129 : }
130 :
131 : // Padding (dptSpace) it is constant 0
132 : {
133 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharTopBorderDistance"));
134 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharLeftBorderDistance"));
135 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharBottomBorderDistance"));
136 1 : CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xRun,"CharRightBorderDistance"));
137 : }
138 :
139 : // Shadow (fShadow)
140 : /* WW8 use just one bool value for shadow so the next conversions
141 : are made during an export-import round
142 : color: any -> black
143 : location: any -> bottom-right
144 : width: any -> border width */
145 : {
146 1 : const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xRun, "CharShadowFormat");
147 1 : CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color));
148 1 : CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location);
149 1 : CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth);
150 1 : }
151 1 : }
152 :
153 14 : DECLARE_WW8EXPORT_TEST(testFdo59530, "fdo59530.doc")
154 : {
155 : // See ooxmlexport's testFdo38244().
156 : // Test comment range feature.
157 2 : uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
158 4 : uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xTextDocument->getText(), uno::UNO_QUERY);
159 4 : uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
160 4 : uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY);
161 4 : uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
162 2 : xRunEnum->nextElement();
163 4 : uno::Reference<beans::XPropertySet> xPropertySet(xRunEnum->nextElement(), uno::UNO_QUERY);
164 2 : CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType"));
165 2 : xRunEnum->nextElement();
166 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
167 2 : CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
168 :
169 : // Test initials.
170 4 : uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
171 4 : uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
172 4 : uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
173 2 : xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY);
174 2 : CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty<OUString>(xPropertySet, "Initials"));
175 :
176 : // Test commented text range which spans over more text nodes
177 : // Comment starts in the second paragraph
178 2 : xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
179 2 : xRunEnum = xRunEnumAccess->createEnumeration();
180 2 : xRunEnum->nextElement();
181 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
182 2 : CPPUNIT_ASSERT_EQUAL(OUString("Annotation"), getProperty<OUString>(xPropertySet, "TextPortionType"));
183 : // Comment ends in the third paragraph
184 2 : xRunEnumAccess.set(xParaEnum->nextElement(), uno::UNO_QUERY);
185 2 : xRunEnum = xRunEnumAccess->createEnumeration();
186 2 : xRunEnum->nextElement();
187 2 : xPropertySet.set(xRunEnum->nextElement(), uno::UNO_QUERY);
188 4 : CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"), getProperty<OUString>(xPropertySet, "TextPortionType"));
189 2 : }
190 :
191 14 : DECLARE_WW8EXPORT_TEST(testCommentsNested, "comments-nested.doc")
192 : {
193 2 : uno::Reference<beans::XPropertySet> xOuter(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 2), "TextField"), uno::UNO_QUERY);
194 2 : CPPUNIT_ASSERT_EQUAL(OUString("Outer"), getProperty<OUString>(xOuter, "Content"));
195 :
196 4 : uno::Reference<beans::XPropertySet> xInner(getProperty< uno::Reference<beans::XPropertySet> >(getRun(getParagraph(1), 4), "TextField"), uno::UNO_QUERY);
197 4 : CPPUNIT_ASSERT_EQUAL(OUString("Inner"), getProperty<OUString>(xInner, "Content"));
198 2 : }
199 :
200 13 : DECLARE_WW8EXPORT_TEST(testBorderColoursExport, "bordercolours.odt")
201 : {
202 : // This is very close to testBorderColours in ww8import.cxx, but for export
203 :
204 : // The following 6 colours can only be represented with WW9 (Word 2000)
205 : // BRC (BoRder Control) structures. We can tell that they have been
206 : // exported/imported using a WW8 (Word '97) BRC if they instead come
207 : // through as one of the 16 colours listed at this link:
208 : // http://msdn.microsoft.com/en-us/library/dd773060.aspx
209 1 : table::BorderLine2 expectedTop(0xFA670C, 0, 53, 0, 1, 53);
210 1 : table::BorderLine2 expectedLeft(0xD99594, 0, 79, 0, 0, 79);
211 1 : table::BorderLine2 expectedRight(0xB2A1C7, 53, 53, 53, 3, 159);
212 1 : table::BorderLine2 expectedBottom(0xB6DDE8, 0, 106, 0, 14, 106);
213 1 : table::BorderLine2 expectedDashedRed(0xFA670C, 0, 53, 0, 2, 53);
214 1 : table::BorderLine2 expectedDoubleGreen(0xC2D69B, 26, 106, 26, 4, 159);
215 :
216 : // Paragraph border
217 : uno::Reference<text::XBookmarksSupplier> bookmarksSupplier(mxComponent,
218 1 : uno::UNO_QUERY);
219 : uno::Reference<container::XNameAccess> bookmarks(
220 2 : bookmarksSupplier->getBookmarks(), uno::UNO_QUERY);
221 : uno::Reference<text::XTextContent> bookmark(
222 2 : bookmarks->getByName("ParagraphBorder"), uno::UNO_QUERY);
223 2 : uno::Reference<text::XTextRange> anchor(bookmark->getAnchor());
224 1 : table::BorderLine2 border;
225 1 : border = getProperty<table::BorderLine2>(anchor, "TopBorder");
226 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
227 1 : border = getProperty<table::BorderLine2>(anchor, "LeftBorder");
228 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
229 1 : border = getProperty<table::BorderLine2>(anchor, "RightBorder");
230 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
231 1 : border = getProperty<table::BorderLine2>(anchor, "BottomBorder");
232 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
233 :
234 : // Page border
235 2 : OUString pageStyleName = getProperty<OUString>(anchor, "PageStyleName");
236 : uno::Reference<style::XStyle> pageStyle(
237 2 : getStyles("PageStyles")->getByName(pageStyleName), uno::UNO_QUERY);
238 1 : border = getProperty<table::BorderLine2>(pageStyle, "TopBorder");
239 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
240 1 : border = getProperty<table::BorderLine2>(pageStyle, "LeftBorder");
241 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
242 1 : border = getProperty<table::BorderLine2>(pageStyle, "RightBorder");
243 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
244 1 : border = getProperty<table::BorderLine2>(pageStyle, "BottomBorder");
245 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
246 :
247 : // Character border
248 1 : bookmark.set(bookmarks->getByName("CharBorder"), uno::UNO_QUERY);
249 1 : anchor = bookmark->getAnchor();
250 1 : border = getProperty<table::BorderLine2>(anchor, "CharTopBorder");
251 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
252 1 : border = getProperty<table::BorderLine2>(anchor, "CharLeftBorder");
253 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
254 1 : border = getProperty<table::BorderLine2>(anchor, "CharRightBorder");
255 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
256 1 : border = getProperty<table::BorderLine2>(anchor, "CharBottomBorder");
257 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
258 :
259 : // Table border
260 : uno::Reference<text::XTextTablesSupplier> tablesSupplier(mxComponent,
261 2 : uno::UNO_QUERY);
262 : uno::Reference<container::XNameAccess> tables(
263 2 : tablesSupplier->getTextTables(), uno::UNO_QUERY);
264 : uno::Reference<text::XTextTable> table(
265 2 : tables->getByName("Table1"), uno::UNO_QUERY);
266 : table::TableBorder2 tableBorder = getProperty<table::TableBorder2>(
267 1 : table, "TableBorder2");
268 1 : CPPUNIT_ASSERT_EQUAL(expectedTop.Color, tableBorder.TopLine.Color);
269 1 : CPPUNIT_ASSERT_EQUAL(expectedLeft.Color, tableBorder.LeftLine.Color);
270 1 : CPPUNIT_ASSERT_EQUAL(expectedRight.Color, tableBorder.RightLine.Color);
271 : #if 0
272 : // #if'd out because the "fine dashed" border line style for table borders
273 : // does not seem to save or load correctly in odt format at present
274 : CPPUNIT_ASSERT_EQUAL(expectedBottom.Color, tableBorder.BottomLine.Color);
275 : #endif
276 :
277 : // Table cells
278 : uno::Reference<table::XCell> cell(
279 2 : table->getCellByName("A2"), uno::UNO_QUERY);
280 1 : border = getProperty<table::BorderLine2>(cell, "TopBorder");
281 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
282 1 : border = getProperty<table::BorderLine2>(cell, "LeftBorder");
283 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
284 1 : border = getProperty<table::BorderLine2>(cell, "BottomBorder");
285 : #if 0
286 : // #if'd out because the "fine dashed" border line style for table borders
287 : // does not seem to save or load correctly in odt format at present
288 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
289 : #endif
290 :
291 1 : cell.set(table->getCellByName("B2"), uno::UNO_QUERY);
292 1 : border = getProperty<table::BorderLine2>(cell, "TopBorder");
293 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
294 1 : border = getProperty<table::BorderLine2>(cell, "LeftBorder");
295 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
296 1 : border = getProperty<table::BorderLine2>(cell, "BottomBorder");
297 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
298 :
299 1 : cell.set(table->getCellByName("C2"), uno::UNO_QUERY);
300 1 : border = getProperty<table::BorderLine2>(cell, "TopBorder");
301 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
302 1 : border = getProperty<table::BorderLine2>(cell, "LeftBorder");
303 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedDashedRed, border);
304 1 : border = getProperty<table::BorderLine2>(cell, "RightBorder");
305 1 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
306 1 : border = getProperty<table::BorderLine2>(cell, "BottomBorder");
307 2 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedDoubleGreen, border);
308 :
309 : // Picture border
310 : // (#if'd out as they are not yet exported with correct colours)
311 : #if 0
312 : bookmark.set(bookmarks->getByName("PictureBorder"),uno::UNO_QUERY);
313 : anchor = bookmark->getAnchor();
314 : border = getProperty<table::BorderLine2>(anchor, "TopBorder");
315 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedTop, border);
316 : border = getProperty<table::BorderLine2>(anchor, "LeftBorder");
317 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedLeft, border);
318 : border = getProperty<table::BorderLine2>(anchor, "RightBorder");
319 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedRight, border);
320 : border = getProperty<table::BorderLine2>(anchor, "BottomBorder");
321 : CPPUNIT_ASSERT_BORDER_EQUAL(expectedBottom, border);
322 : #endif
323 1 : }
324 : #endif
325 :
326 4 : CPPUNIT_PLUGIN_IMPLEMENT();
327 :
328 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|