Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <swmodeltestbase.hxx>
11 :
12 : #if !defined(MACOSX) && !defined(WNT)
13 :
14 : #include <com/sun/star/awt/Gradient.hpp>
15 : #include <com/sun/star/drawing/FillStyle.hpp>
16 : #include <rtl/byteseq.hxx>
17 :
18 : #include <swmodule.hxx>
19 : #include <usrpref.hxx>
20 :
21 : #include <libxml/HTMLparser.h>
22 : #include <libxml/HTMLtree.h>
23 :
24 : using namespace rtl;
25 :
26 6 : class Test : public SwModelTestBase
27 : {
28 : private:
29 : FieldUnit m_eUnit;
30 :
31 : public:
32 6 : Test() :
33 : SwModelTestBase("/sw/qa/extras/htmlexport/data/", "HTML (StarWriter)"),
34 6 : m_eUnit(FUNIT_NONE)
35 6 : {}
36 :
37 : protected:
38 2 : htmlDocPtr parseHtml()
39 : {
40 2 : SvFileStream aFileStream(m_aTempFile.GetURL(), STREAM_READ);
41 2 : sal_Size nSize = aFileStream.remainingSize();
42 :
43 4 : ByteSequence aBuffer(nSize + 1);
44 2 : aFileStream.Read(aBuffer.getArray(), nSize);
45 :
46 2 : aBuffer[nSize] = 0;
47 4 : return htmlParseDoc(reinterpret_cast<xmlChar*>(aBuffer.getArray()), NULL);
48 : }
49 :
50 : private:
51 7 : bool mustCalcLayoutOf(const char* filename) SAL_OVERRIDE
52 : {
53 7 : return OString(filename) != "fdo62336.docx";
54 : }
55 :
56 2 : bool mustTestImportOf(const char* filename) const SAL_OVERRIDE
57 : {
58 2 : return OString(filename) != "fdo62336.docx";
59 : }
60 :
61 5 : void preTest(const char* filename) SAL_OVERRIDE
62 : {
63 5 : if (getTestName() == "testExportOfImagesWithSkipImageEnabled")
64 1 : setFilterOptions("SkipImages");
65 : else
66 4 : setFilterOptions("");
67 :
68 5 : if (OString(filename) == "charborder.odt" && SW_MOD())
69 : {
70 : // FIXME if padding-top gets exported as inches, not cms, we get rounding errors.
71 2 : SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
72 2 : m_eUnit = pPref->GetMetric();
73 2 : pPref->SetMetric(FUNIT_CM);
74 : }
75 5 : }
76 :
77 5 : void postTest(const char* filename) SAL_OVERRIDE
78 : {
79 5 : if (OString(filename) == "charborder.odt" && SW_MOD())
80 : {
81 2 : SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
82 2 : pPref->SetMetric(m_eUnit);
83 : }
84 5 : }
85 : };
86 :
87 : #define DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, Test)
88 :
89 14 : DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testFdo62336, "fdo62336.docx")
90 : {
91 : // The problem was essentially a crash during table export as docx/rtf/html
92 : // If either of no-calc-layout or no-test-import is enabled, the crash does not occur
93 1 : }
94 :
95 16 : DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testCharacterBorder, "charborder.odt")
96 : {
97 :
98 2 : uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1),1), uno::UNO_QUERY);
99 : // Different Border
100 : {
101 2 : CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0x6666FF,12,12,12,3,37), getProperty<table::BorderLine2>(xRun,"CharTopBorder"));
102 2 : CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF9900,0,99,0,2,99), getProperty<table::BorderLine2>(xRun,"CharLeftBorder"));
103 2 : CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0xFF0000,0,169,0,1,169), getProperty<table::BorderLine2>(xRun,"CharBottomBorder"));
104 2 : CPPUNIT_ASSERT_BORDER_EQUAL(table::BorderLine2(0x0000FF,0,169,0,0,169), getProperty<table::BorderLine2>(xRun,"CharRightBorder"));
105 : }
106 :
107 : // Different Padding
108 : {
109 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(450), getProperty<sal_Int32>(xRun,"CharTopBorderDistance"));
110 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(550), getProperty<sal_Int32>(xRun,"CharLeftBorderDistance"));
111 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(150), getProperty<sal_Int32>(xRun,"CharBottomBorderDistance"));
112 2 : CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xRun,"CharRightBorderDistance"));
113 2 : }
114 :
115 : // No shadow
116 2 : }
117 :
118 : #define DECLARE_HTMLEXPORT_TEST(TestName, filename) DECLARE_SW_EXPORT_TEST(TestName, filename, Test)
119 :
120 10 : DECLARE_HTMLEXPORT_TEST(testExportOfImages, "textAndImage.docx")
121 : {
122 1 : htmlDocPtr pDoc = parseHtml();
123 1 : if (pDoc)
124 : {
125 1 : assertXPath(pDoc, "/html/body", 1);
126 1 : assertXPath(pDoc, "/html/body/p/img", 1);
127 : }
128 1 : }
129 :
130 10 : DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.docx")
131 : {
132 1 : htmlDocPtr pDoc = parseHtml();
133 1 : if (pDoc)
134 : {
135 1 : assertXPath(pDoc, "/html/body", 1);
136 1 : assertXPath(pDoc, "/html/body/p/img", 0);
137 : }
138 1 : }
139 :
140 : #endif
141 :
142 4 : CPPUNIT_PLUGIN_IMPLEMENT();
143 :
144 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|