LCOV - code coverage report
Current view: top level - sc/qa/unit - copy_paste_test.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 62 62 100.0 %
Date: 2015-06-13 12:38:46 Functions: 15 16 93.8 %
Legend: Lines: hit not hit

          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/config.h>
      11             : #include <unotest/filters-test.hxx>
      12             : #include <test/bootstrapfixture.hxx>
      13             : 
      14             : #include "docsh.hxx"
      15             : #include "tabvwsh.hxx"
      16             : 
      17             : #include <com/sun/star/frame/Desktop.hpp>
      18             : #include <com/sun/star/frame/XModel.hpp>
      19             : #include <com/sun/star/frame/XModel2.hpp>
      20             : 
      21             : #include "helper/qahelper.hxx"
      22             : 
      23             : using namespace ::com::sun::star;
      24             : using namespace ::com::sun::star::uno;
      25             : 
      26           2 : class ScCopyPasteTest : public ScBootstrapFixture
      27             : {
      28             : public:
      29             :     ScCopyPasteTest();
      30             : 
      31             :     virtual void setUp() SAL_OVERRIDE;
      32             :     virtual void tearDown() SAL_OVERRIDE;
      33             : 
      34             :     void testCopyPasteXLS();
      35             : 
      36           2 :     CPPUNIT_TEST_SUITE(ScCopyPasteTest);
      37           1 :     CPPUNIT_TEST(testCopyPasteXLS);
      38           5 :     CPPUNIT_TEST_SUITE_END();
      39             : 
      40             : private:
      41             : 
      42             :     uno::Reference<uno::XInterface> m_xCalcComponent;
      43             : };
      44             : 
      45             : // tdf#83366
      46           1 : void ScCopyPasteTest::testCopyPasteXLS()
      47             : {
      48           1 :     uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
      49           1 :     CPPUNIT_ASSERT( xDesktop.is() );
      50             : 
      51             :     // create a frame
      52           2 :     Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( OUString("_blank"), 0 );
      53           1 :     CPPUNIT_ASSERT( xTargetFrame.is() );
      54             : 
      55             :     // 1. Open the document
      56           2 :     ScDocShellRef xDocSh = loadDoc("chartx.", XLS);
      57           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to load chartx.xls.", xDocSh.Is());
      58             : 
      59           2 :     uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
      60           1 :     CPPUNIT_ASSERT( xModel2.is() );
      61             : 
      62           2 :     Reference< frame::XController2 > xController ( xModel2->createDefaultViewController( xTargetFrame ), UNO_QUERY );
      63           1 :     CPPUNIT_ASSERT( xController.is() );
      64             : 
      65             :     // introduce model/view/controller to each other
      66           1 :     xController->attachModel( xModel2.get() );
      67           1 :     xModel2->connectController( xController.get() );
      68           1 :     xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
      69           1 :     xController->attachFrame( xTargetFrame );
      70           1 :     xModel2->setCurrentController( xController.get() );
      71             : 
      72           1 :     ScDocument& rDoc = xDocSh->GetDocument();
      73             : 
      74             :     // Get the document controller
      75           1 :     ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
      76           1 :     CPPUNIT_ASSERT(pViewShell != NULL);
      77             : 
      78             :     // 2. Highlight B2:C5
      79           1 :     ScRange aSrcRange;
      80           1 :     sal_uInt16 nRes = aSrcRange.Parse("B2:C5", &rDoc, rDoc.GetAddressConvention());
      81           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & SCA_VALID) != 0);
      82             : 
      83           2 :     ScMarkData aMark;
      84           1 :     aMark.SetMarkArea(aSrcRange);
      85             : 
      86           1 :     pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
      87             : 
      88             :     // 3. Copy
      89           2 :     ScDocument aClipDoc(SCDOCMODE_CLIP);
      90           1 :     pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
      91             : 
      92             :     // 4. Close the document (Ctrl-W)
      93           1 :     xDocSh->DoClose();
      94             : 
      95             :     // 5. Create a new Spreadsheet
      96           2 :     Sequence < beans::PropertyValue > args(1);
      97           1 :     args[0].Name = "Hidden";
      98           1 :     args[0].Value <<= sal_True;
      99             : 
     100           1 :     uno::Reference< lang::XComponent > xComponent = xDesktop->loadComponentFromURL(
     101             :             OUString("private:factory/scalc"),
     102             :             OUString("_blank"),
     103             :             0,
     104           2 :             args );
     105           1 :     CPPUNIT_ASSERT( xComponent.is() );
     106             : 
     107             :     // Get the document model
     108           1 :     SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
     109           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
     110             : 
     111           1 :     xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
     112           1 :     CPPUNIT_ASSERT(xDocSh != NULL);
     113             : 
     114             :     // Get the document controller
     115           1 :     pViewShell = xDocSh->GetBestViewShell(false);
     116           1 :     CPPUNIT_ASSERT(pViewShell != NULL);
     117             : 
     118             :     // 6. Paste
     119           1 :     pViewShell->GetViewData().GetView()->PasteFromClip(IDF_ALL, &aClipDoc);
     120             : 
     121           2 :     xDocSh->DoClose();
     122           1 : }
     123             : 
     124           1 : ScCopyPasteTest::ScCopyPasteTest()
     125           1 :       : ScBootstrapFixture( "/sc/qa/unit/data" )
     126             : {
     127           1 : }
     128             : 
     129           1 : void ScCopyPasteTest::setUp()
     130             : {
     131           1 :     test::BootstrapFixture::setUp();
     132             : 
     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           2 :     m_xCalcComponent =
     136           3 :         getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
     137           1 :     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
     138           1 : }
     139             : 
     140           1 : void ScCopyPasteTest::tearDown()
     141             : {
     142           1 :     uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
     143           1 :     test::BootstrapFixture::tearDown();
     144           1 : }
     145             : 
     146           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScCopyPasteTest);
     147             : 
     148           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     149             : 
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11