Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / sd / qa / unit / uimpress.cxx
blob74678dc7d920d2152e952a11117041cdccc6cb93
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/types.h>
11 #include <cppunit/TestAssert.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <cppuhelper/bootstrap.hxx>
17 #include <comphelper/processfactory.hxx>
19 #include <vcl/svapp.hxx>
20 #include <sddll.hxx>
21 #include <drawdoc.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 using namespace ::com::sun::star;
29 namespace {
31 class Test : public CppUnit::TestFixture {
32 public:
33 Test();
34 virtual ~Test() override;
36 virtual void setUp() override;
37 virtual void tearDown() override;
39 void testAddPage();
40 void testCustomShow();
42 CPPUNIT_TEST_SUITE(Test);
43 CPPUNIT_TEST(testAddPage);
44 CPPUNIT_TEST(testCustomShow);
45 CPPUNIT_TEST_SUITE_END();
47 private:
48 uno::Reference< uno::XComponentContext > m_xContext;
49 std::unique_ptr<SdDrawDocument> m_pDoc;
52 Test::Test()
54 m_xContext = cppu::defaultBootstrap_InitialComponentContext();
56 uno::Reference<lang::XMultiComponentFactory> xFactory(m_xContext->getServiceManager());
57 uno::Reference<lang::XMultiServiceFactory> xSM(xFactory, uno::UNO_QUERY_THROW);
59 //Without this we're crashing because callees are using
60 //getProcessServiceFactory. In general those should be removed in favour
61 //of retaining references to the root ServiceFactory as it's passed around
62 comphelper::setProcessServiceFactory(xSM);
64 InitVCL();
66 SdDLL::Init();
69 void Test::setUp()
71 m_pDoc.reset(new SdDrawDocument(DocumentType::Impress, nullptr));
74 void Test::tearDown()
76 m_pDoc.reset();
79 Test::~Test()
81 uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
84 void Test::testAddPage()
86 SdrPage* pPage = m_pDoc->AllocPage(false);
87 m_pDoc->InsertPage(pPage);
88 CPPUNIT_ASSERT_EQUAL_MESSAGE("added one page to model",
89 static_cast<sal_uInt16>(1), m_pDoc->GetPageCount());
90 m_pDoc->DeletePage(0);
91 CPPUNIT_ASSERT_EQUAL_MESSAGE("removed one page to model",
92 static_cast<sal_uInt16>(0), m_pDoc->GetPageCount());
94 SdrPage* pMasterPage = m_pDoc->AllocPage(true);
95 m_pDoc->InsertMasterPage(pMasterPage);
96 CPPUNIT_ASSERT_EQUAL_MESSAGE("added one master page to model",
97 static_cast<sal_uInt16>(1), m_pDoc->GetMasterPageCount());
98 m_pDoc->DeleteMasterPage(0);
99 CPPUNIT_ASSERT_EQUAL_MESSAGE("removed one master page to model",
100 static_cast<sal_uInt16>(0), m_pDoc->GetMasterPageCount());
103 void Test::testCustomShow()
105 CPPUNIT_ASSERT_MESSAGE("test generation of custom show list!",
106 m_pDoc->GetCustomShowList(true));
109 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
113 CPPUNIT_PLUGIN_IMPLEMENT();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */