Bump for 3.6-28
[LibreOffice.git] / sw / qa / core / layout-test.cxx
blob8d6e36b5a6ba8ddc1faa3d441a35828ec1ae47bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
13 * License.
15 * Major Contributor(s):
16 * Copyright (C) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
17 * (initial developer)
18 * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com>
20 * All Rights Reserved.
22 * For minor contributions see the git repository.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
26 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
27 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
28 * instead of those above.
31 #include <sal/config.h>
32 #include <unotest/macros_test.hxx>
33 #include <test/bootstrapfixture.hxx>
34 #include <rtl/strbuf.hxx>
35 #include <osl/file.hxx>
37 #include <com/sun/star/frame/XDesktop.hpp>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/frame/XComponentLoader.hpp>
41 #include <com/sun/star/document/MacroExecMode.hpp>
43 #include <sfx2/app.hxx>
44 #include <sfx2/docfilt.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <sfx2/sfxmodelfactory.hxx>
47 #include <svl/intitem.hxx>
49 using namespace ::com::sun::star::uno;
50 using namespace com::sun::star;
52 /* Implementation of Macros test */
54 class SwLayoutTest : public test::BootstrapFixture, public unotest::MacrosTest
56 public:
57 SwLayoutTest();
59 void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
61 virtual void setUp();
62 virtual void tearDown();
64 void test();
66 CPPUNIT_TEST_SUITE(SwLayoutTest);
67 #if !defined(MACOSX) && !defined(WNT)
68 CPPUNIT_TEST(test);
69 #endif
70 CPPUNIT_TEST_SUITE_END();
72 private:
73 uno::Reference<uno::XInterface> m_xWriterComponent;
74 ::rtl::OUString m_aBaseString;
77 void SwLayoutTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
79 rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
80 rtl::OUStringBuffer aBuffer( getSrcRootURL() );
81 aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
82 aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
83 rFilePath = aBuffer.makeStringAndClear();
86 void SwLayoutTest::test()
88 rtl::OUString aFilePath;
89 rtl::OUString aFileBase(RTL_CONSTASCII_USTRINGPARAM("test."));
90 rtl::OUString aExtension(RTL_CONSTASCII_USTRINGPARAM("odt"));
91 createFileURL(aFileBase, aExtension, aFilePath);
92 uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFilePath);
93 CPPUNIT_ASSERT(xComponent.is());
97 SwLayoutTest::SwLayoutTest()
98 : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sw/qa/core/data"))
102 void SwLayoutTest::setUp()
104 test::BootstrapFixture::setUp();
106 // This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
107 // which is a private symbol to us, gets called
108 m_xWriterComponent =
109 getMultiServiceFactory()->createInstance(rtl::OUString(
110 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.TextDocument")));
111 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xWriterComponent.is());
112 mxDesktop = Reference<com::sun::star::frame::XDesktop>( getMultiServiceFactory()->createInstance(
113 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY );
114 CPPUNIT_ASSERT_MESSAGE("", mxDesktop.is());
117 void SwLayoutTest::tearDown()
119 uno::Reference< lang::XComponent >( m_xWriterComponent, UNO_QUERY_THROW )->dispose();
120 test::BootstrapFixture::tearDown();
123 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutTest);
125 CPPUNIT_PLUGIN_IMPLEMENT();
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */