1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * Major Contributor(s):
16 * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #include <sal/config.h>
30 #include <test/bootstrapfixture.hxx>
31 #include <unotest/macros_test.hxx>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/document/XFilter.hpp>
34 #include <com/sun/star/frame/XStorable.hpp>
36 #include <sfx2/app.hxx>
37 #include <sfx2/docfilt.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <sfx2/sfxmodelfactory.hxx>
40 #include <svl/stritem.hxx>
42 #include <rtl/strbuf.hxx>
43 #include <osl/file.hxx>
45 #include <com/sun/star/frame/XDesktop.hpp>
49 #include <rtl/oustringostreaminserter.hxx>
51 using namespace com::sun::star
;
52 using namespace com::sun::star::uno
;
56 bool compareFiles( const rtl::OUString
& aFileNameOne
, const rtl::OUString
& aFileNameTwo
)
58 rtl::OString aOFileNameOne
= rtl::OUStringToOString(aFileNameOne
, RTL_TEXTENCODING_UTF8
);
59 std::ifstream
aFileOne(aOFileNameOne
.getStr());
60 rtl::OString aOFileNameTwo
= rtl::OUStringToOString(aFileNameTwo
, RTL_TEXTENCODING_UTF8
);
61 std::ifstream
aFileTwo(aOFileNameTwo
.getStr());
63 CPPUNIT_ASSERT_MESSAGE("files not open", aFileOne
.is_open() && aFileTwo
.is_open());
66 while(!aFileOne
.eof() && !aFileTwo
.eof())
68 std::string aLineFileOne
;
69 std::string aLineFileTwo
;
71 std::getline(aFileOne
, aLineFileOne
);
72 std::getline(aFileTwo
, aLineFileTwo
);
74 if( aLineFileOne
!= aLineFileTwo
)
76 rtl::OStringBuffer
aErrorMessage("Mismatch between reference file and exported file in line ");
77 aErrorMessage
.append(nLine
).append(".\nExpected: ");
78 aErrorMessage
.append(aLineFileOne
.c_str()).append("\nFound : ").append(aLineFileTwo
.c_str());
79 CPPUNIT_ASSERT_MESSAGE(aErrorMessage
.getStr(), false);
88 class SwRegressionTest
: public test::BootstrapFixture
, unotest::MacrosTest
94 virtual void tearDown();
98 CPPUNIT_TEST_SUITE(SwRegressionTest
);
100 CPPUNIT_TEST_SUITE_END();
103 uno::Reference
<uno::XInterface
> m_xWriterComponent
;
104 ::rtl::OUString m_aBaseString
;
107 void SwRegressionTest::test()
109 uno::Reference
< lang::XComponent
> xComponent
= loadFromDesktop(getURLFromSrc("/sw/qa/extras/data/odt/test.odt"));
110 CPPUNIT_ASSERT(xComponent
.is());
112 uno::Reference
< frame::XStorable
> xStorable(xComponent
, UNO_QUERY_THROW
);
113 CPPUNIT_ASSERT(xStorable
.is());
115 uno::Sequence
< beans::PropertyValue
> aArgs(2);
117 beans::PropertyValue aValue
;
120 aAny
<<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("writer_layout_dump"));
122 aValue
.Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName"));
124 aValue
.State
= beans::PropertyState_DIRECT_VALUE
;
127 beans::PropertyValue aValue2
;
130 aAny2
<<= (sal_Bool
)sal_True
;
132 aValue2
.Name
= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Overwrite"));
133 aValue2
.Value
= aAny2
;
134 aValue2
.State
= beans::PropertyState_DIRECT_VALUE
;
138 xStorable
->storeToURL(getURLFromSolver("/unittest/sw/test.xml"), aArgs
);
141 SwRegressionTest::SwRegressionTest()
142 : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data"))
146 void SwRegressionTest::setUp()
148 test::BootstrapFixture::setUp();
150 // This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
151 // which is a private symbol to us, gets called
153 getMultiServiceFactory()->createInstance(rtl::OUString(
154 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
155 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xWriterComponent
.is());
156 mxDesktop
= Reference
<com::sun::star::frame::XDesktop
>( getMultiServiceFactory()->createInstance(
157 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY
);
158 CPPUNIT_ASSERT_MESSAGE("", mxDesktop
.is());
161 void SwRegressionTest::tearDown()
163 uno::Reference
< lang::XComponent
>( m_xWriterComponent
, UNO_QUERY_THROW
)->dispose();
164 test::BootstrapFixture::tearDown();
167 CPPUNIT_TEST_SUITE_REGISTRATION(SwRegressionTest
);
169 CPPUNIT_PLUGIN_IMPLEMENT();
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */