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 <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"
15 :
16 : #include <cppuhelper/bootstrap.hxx>
17 : #include <comphelper/processfactory.hxx>
18 :
19 : #include <vcl/svapp.hxx>
20 : #include <sddll.hxx>
21 : #include <drawdoc.hxx>
22 :
23 : #include <iostream>
24 : #include <vector>
25 :
26 : using namespace ::com::sun::star;
27 :
28 : namespace {
29 :
30 : class Test : public CppUnit::TestFixture {
31 : public:
32 : Test();
33 : virtual ~Test();
34 :
35 : virtual void setUp() SAL_OVERRIDE;
36 : virtual void tearDown() SAL_OVERRIDE;
37 :
38 : void testAddPage();
39 : void testCustomShow();
40 :
41 4 : CPPUNIT_TEST_SUITE(Test);
42 2 : CPPUNIT_TEST(testAddPage);
43 2 : CPPUNIT_TEST(testCustomShow);
44 4 : CPPUNIT_TEST_SUITE_END();
45 :
46 : private:
47 : uno::Reference< uno::XComponentContext > m_xContext;
48 : SdDrawDocument* m_pDoc;
49 : };
50 :
51 4 : Test::Test()
52 4 : : m_pDoc(0)
53 : {
54 4 : m_xContext = cppu::defaultBootstrap_InitialComponentContext();
55 :
56 4 : uno::Reference<lang::XMultiComponentFactory> xFactory(m_xContext->getServiceManager());
57 8 : uno::Reference<lang::XMultiServiceFactory> xSM(xFactory, uno::UNO_QUERY_THROW);
58 :
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 its passed around
62 4 : comphelper::setProcessServiceFactory(xSM);
63 :
64 4 : InitVCL();
65 :
66 8 : SdDLL::Init();
67 4 : }
68 :
69 4 : void Test::setUp()
70 : {
71 4 : m_pDoc = new SdDrawDocument(DOCUMENT_TYPE_IMPRESS, NULL);
72 4 : }
73 :
74 4 : void Test::tearDown()
75 : {
76 4 : delete m_pDoc;
77 4 : }
78 :
79 12 : Test::~Test()
80 : {
81 4 : uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
82 8 : }
83 :
84 2 : void Test::testAddPage()
85 : {
86 2 : SdrPage* pPage = m_pDoc->AllocPage(false);
87 2 : m_pDoc->InsertPage(pPage);
88 4 : CPPUNIT_ASSERT_MESSAGE("added one page to model",
89 2 : m_pDoc->GetPageCount()==1);
90 2 : m_pDoc->DeletePage(0);
91 4 : CPPUNIT_ASSERT_MESSAGE("removed one page to model",
92 2 : m_pDoc->GetPageCount()==0);
93 :
94 2 : SdrPage* pMasterPage = m_pDoc->AllocPage(true);
95 2 : m_pDoc->InsertMasterPage(pMasterPage);
96 4 : CPPUNIT_ASSERT_MESSAGE("added one master page to model",
97 2 : m_pDoc->GetMasterPageCount()==1);
98 2 : m_pDoc->DeleteMasterPage(0);
99 4 : CPPUNIT_ASSERT_MESSAGE("removed one master page to model",
100 2 : m_pDoc->GetMasterPageCount()==0);
101 2 : }
102 :
103 2 : void Test::testCustomShow()
104 : {
105 4 : CPPUNIT_ASSERT_MESSAGE("test generation of custom show list!",
106 2 : m_pDoc->GetCustomShowList(true));
107 2 : }
108 :
109 2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
110 :
111 : }
112 :
113 8 : CPPUNIT_PLUGIN_IMPLEMENT();
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|