Bump version to 5.0-14
[LibreOffice.git] / sc / qa / unit / copy_paste_test.cxx
blob73259e649ed88a1a44a4a4441fef2a7c78dbbdf7
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/config.h>
11 #include <unotest/filters-test.hxx>
12 #include <test/bootstrapfixture.hxx>
14 #include "docsh.hxx"
15 #include "tabvwsh.hxx"
17 #include <com/sun/star/frame/Desktop.hpp>
18 #include <com/sun/star/frame/XModel.hpp>
19 #include <com/sun/star/frame/XModel2.hpp>
21 #include "helper/qahelper.hxx"
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
26 class ScCopyPasteTest : public ScBootstrapFixture
28 public:
29 ScCopyPasteTest();
31 virtual void setUp() SAL_OVERRIDE;
32 virtual void tearDown() SAL_OVERRIDE;
34 void testCopyPasteXLS();
36 CPPUNIT_TEST_SUITE(ScCopyPasteTest);
37 CPPUNIT_TEST(testCopyPasteXLS);
38 CPPUNIT_TEST_SUITE_END();
40 private:
42 uno::Reference<uno::XInterface> m_xCalcComponent;
45 // tdf#83366
46 void ScCopyPasteTest::testCopyPasteXLS()
48 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
49 CPPUNIT_ASSERT( xDesktop.is() );
51 // create a frame
52 Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( OUString("_blank"), 0 );
53 CPPUNIT_ASSERT( xTargetFrame.is() );
55 // 1. Open the document
56 ScDocShellRef xDocSh = loadDoc("chartx.", XLS);
57 CPPUNIT_ASSERT_MESSAGE("Failed to load chartx.xls.", xDocSh.Is());
59 uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
60 CPPUNIT_ASSERT( xModel2.is() );
62 Reference< frame::XController2 > xController ( xModel2->createDefaultViewController( xTargetFrame ), UNO_QUERY );
63 CPPUNIT_ASSERT( xController.is() );
65 // introduce model/view/controller to each other
66 xController->attachModel( xModel2.get() );
67 xModel2->connectController( xController.get() );
68 xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
69 xController->attachFrame( xTargetFrame );
70 xModel2->setCurrentController( xController.get() );
72 ScDocument& rDoc = xDocSh->GetDocument();
74 // Get the document controller
75 ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
76 CPPUNIT_ASSERT(pViewShell != NULL);
78 // 2. Highlight B2:C5
79 ScRange aSrcRange;
80 sal_uInt16 nRes = aSrcRange.Parse("B2:C5", &rDoc, rDoc.GetAddressConvention());
81 CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
83 ScMarkData aMark;
84 aMark.SetMarkArea(aSrcRange);
86 pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
88 // 3. Copy
89 ScDocument aClipDoc(SCDOCMODE_CLIP);
90 pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
92 // 4. Close the document (Ctrl-W)
93 xDocSh->DoClose();
95 // 5. Create a new Spreadsheet
96 Sequence < beans::PropertyValue > args(1);
97 args[0].Name = "Hidden";
98 args[0].Value <<= sal_True;
100 uno::Reference< lang::XComponent > xComponent = xDesktop->loadComponentFromURL(
101 OUString("private:factory/scalc"),
102 OUString("_blank"),
104 args );
105 CPPUNIT_ASSERT( xComponent.is() );
107 // Get the document model
108 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
109 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
111 xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
112 CPPUNIT_ASSERT(xDocSh != NULL);
114 // Get the document controller
115 pViewShell = xDocSh->GetBestViewShell(false);
116 CPPUNIT_ASSERT(pViewShell != NULL);
118 // 6. Paste
119 pViewShell->GetViewData().GetView()->PasteFromClip(IDF_ALL, &aClipDoc);
121 xDocSh->DoClose();
124 ScCopyPasteTest::ScCopyPasteTest()
125 : ScBootstrapFixture( "/sc/qa/unit/data" )
129 void ScCopyPasteTest::setUp()
131 test::BootstrapFixture::setUp();
133 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
134 // which is a private symbol to us, gets called
135 m_xCalcComponent =
136 getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
137 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
140 void ScCopyPasteTest::tearDown()
142 uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
143 test::BootstrapFixture::tearDown();
146 CPPUNIT_TEST_SUITE_REGISTRATION(ScCopyPasteTest);
148 CPPUNIT_PLUGIN_IMPLEMENT();
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */