LCOV - code coverage report
Current view: top level - sc/qa/unit - filters-test.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 284 306 92.8 %
Date: 2014-04-11 Functions: 28 31 90.3 %
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             : #include <rtl/strbuf.hxx>
      14             : #include <osl/file.hxx>
      15             : 
      16             : #include "scdll.hxx"
      17             : #include <sfx2/app.hxx>
      18             : #include <sfx2/docfilt.hxx>
      19             : #include <sfx2/docfile.hxx>
      20             : #include <sfx2/sfxmodelfactory.hxx>
      21             : #include <svl/stritem.hxx>
      22             : 
      23             : #include "helper/qahelper.hxx"
      24             : 
      25             : #include "docsh.hxx"
      26             : #include "postit.hxx"
      27             : #include "patattr.hxx"
      28             : #include "scitems.hxx"
      29             : #include "document.hxx"
      30             : #include "cellform.hxx"
      31             : #include "drwlayer.hxx"
      32             : #include "userdat.hxx"
      33             : #include "formulacell.hxx"
      34             : #include "tabprotection.hxx"
      35             : 
      36             : #include <svx/svdpage.hxx>
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::uno;
      40             : 
      41             : /* Implementation of Filters test */
      42             : 
      43          24 : class ScFiltersTest
      44             :     : public test::FiltersTest
      45             :     , public ScBootstrapFixture
      46             : {
      47             : public:
      48             :     ScFiltersTest();
      49             : 
      50             :     virtual void setUp() SAL_OVERRIDE;
      51             :     virtual void tearDown() SAL_OVERRIDE;
      52             : 
      53             :     virtual bool load( const OUString &rFilter, const OUString &rURL,
      54             :         const OUString &rUserData, unsigned int nFilterFlags,
      55             :         unsigned int nClipboardID, unsigned int nFilterVersion) SAL_OVERRIDE;
      56             :     /**
      57             :      * Ensure CVEs remain unbroken
      58             :      */
      59             :     void testCVEs();
      60             : 
      61             :     //ods, xls, xlsx filter tests
      62             :     void testRangeNameODS(); // only test ods here, xls and xlsx in subsequent_filters-test
      63             :     void testContentODS();
      64             :     void testContentXLS();
      65             :     void testContentXLSX();
      66             :     void testContentXLSXStrict(); // strict OOXML
      67             :     void testContentLotus123();
      68             :     void testContentDIF();
      69             :     void testContentXLS_XML();
      70             :     void testSharedFormulaXLS();
      71             :     void testSharedFormulaXLSX();
      72             :     void testLegacyCellAnchoredRotatedShape();
      73             :     void testEnhancedProtectionXLS();
      74             :     void testEnhancedProtectionXLSX();
      75             : 
      76           2 :     CPPUNIT_TEST_SUITE(ScFiltersTest);
      77           1 :     CPPUNIT_TEST(testCVEs);
      78           1 :     CPPUNIT_TEST(testRangeNameODS);
      79           1 :     CPPUNIT_TEST(testContentODS);
      80           1 :     CPPUNIT_TEST(testContentXLS);
      81           1 :     CPPUNIT_TEST(testContentXLSX);
      82           1 :     CPPUNIT_TEST(testContentLotus123);
      83           1 :     CPPUNIT_TEST(testContentDIF);
      84             :     //CPPUNIT_TEST(testContentXLS_XML);
      85           1 :     CPPUNIT_TEST(testSharedFormulaXLS);
      86           1 :     CPPUNIT_TEST(testSharedFormulaXLSX);
      87           1 :     CPPUNIT_TEST(testLegacyCellAnchoredRotatedShape);
      88           1 :     CPPUNIT_TEST(testEnhancedProtectionXLS);
      89           1 :     CPPUNIT_TEST(testEnhancedProtectionXLSX);
      90             : 
      91           2 :     CPPUNIT_TEST_SUITE_END();
      92             : 
      93             : private:
      94             :     uno::Reference<uno::XInterface> m_xCalcComponent;
      95             : };
      96             : 
      97          21 : bool ScFiltersTest::load(const OUString &rFilter, const OUString &rURL,
      98             :     const OUString &rUserData, unsigned int nFilterFlags,
      99             :         unsigned int nClipboardID, unsigned int nFilterVersion)
     100             : {
     101             :     ScDocShellRef xDocShRef = ScBootstrapFixture::load(rURL, rFilter, rUserData,
     102          21 :         OUString(), nFilterFlags, nClipboardID, nFilterVersion );
     103          21 :     bool bLoaded = xDocShRef.Is();
     104             :     //reference counting of ScDocShellRef is very confused.
     105          21 :     if (bLoaded)
     106          18 :         xDocShRef->DoClose();
     107          21 :     return bLoaded;
     108             : }
     109             : 
     110           1 : void ScFiltersTest::testCVEs()
     111             : {
     112             : #ifndef DISABLE_CVE_TESTS
     113             :     testDir(OUString("Quattro Pro 6.0"),
     114           1 :         getURLFromSrc("/sc/qa/unit/data/qpro/"), OUString());
     115             : 
     116             :     //warning, the current "sylk filter" in sc (docsh.cxx) automatically
     117             :     //chains on failure on trying as csv, rtf, etc. so "success" may
     118             :     //not indicate that it imported as .slk.
     119             :     testDir(OUString("SYLK"),
     120           1 :         getURLFromSrc("/sc/qa/unit/data/slk/"), OUString());
     121             : 
     122             :     testDir(OUString("MS Excel 97"),
     123           1 :         getURLFromSrc("/sc/qa/unit/data/xls/"), OUString());
     124             : #endif
     125           1 : }
     126             : 
     127             : namespace {
     128             : 
     129           1 : void testRangeNameImpl(ScDocument* pDoc)
     130             : {
     131             :     //check one range data per sheet and one global more detailed
     132             :     //add some more checks here
     133           1 :     ScRangeData* pRangeData = pDoc->GetRangeName()->findByUpperName(OUString("GLOBAL1"));
     134           1 :     CPPUNIT_ASSERT_MESSAGE("range name Global1 not found", pRangeData);
     135             :     double aValue;
     136           1 :     pDoc->GetValue(1,0,0,aValue);
     137           1 :     CPPUNIT_ASSERT_MESSAGE("range name Global1 should reference Sheet1.A1", aValue == 1);
     138           1 :     pRangeData = pDoc->GetRangeName(0)->findByUpperName(OUString("LOCAL1"));
     139           1 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 not found", pRangeData);
     140           1 :     pDoc->GetValue(1,2,0,aValue);
     141           1 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 should reference Sheet1.A3", aValue == 3);
     142           1 :     pRangeData = pDoc->GetRangeName(1)->findByUpperName(OUString("LOCAL2"));
     143           1 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet2.Local2 not found", pRangeData);
     144             :     //check for correct results for the remaining formulas
     145           1 :     pDoc->GetValue(1,1,0, aValue);
     146           1 :     CPPUNIT_ASSERT_MESSAGE("=global2 should be 2", aValue == 2);
     147           1 :     pDoc->GetValue(1,3,0, aValue);
     148           1 :     CPPUNIT_ASSERT_MESSAGE("=local2 should be 4", aValue == 4);
     149           1 :     pDoc->GetValue(2,0,0, aValue);
     150           1 :     CPPUNIT_ASSERT_MESSAGE("=SUM(global3) should be 10", aValue == 10);
     151           1 : }
     152             : 
     153             : }
     154             : 
     155           1 : void ScFiltersTest::testRangeNameODS()
     156             : {
     157           1 :     ScDocShellRef xDocSh = loadDoc("named-ranges-global.", ODS);
     158             : 
     159           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
     160             : 
     161           1 :     xDocSh->DoHardRecalc(true);
     162             : 
     163           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     164           1 :     testRangeNameImpl(pDoc);
     165             : 
     166           2 :     OUString aSheet2CSV("rangeExp_Sheet2.");
     167           2 :     OUString aCSVPath;
     168           1 :     createCSVPath( aSheet2CSV, aCSVPath );
     169           1 :     testFile( aCSVPath, pDoc, 1);
     170           2 :     xDocSh->DoClose();
     171           1 : }
     172             : 
     173             : namespace {
     174             : 
     175           4 : void testContentImpl(ScDocument* pDoc, sal_Int32 nFormat ) //same code for ods, xls, xlsx
     176             : {
     177             :     double fValue;
     178             :     //check value import
     179           4 :     pDoc->GetValue(0,0,0,fValue);
     180           4 :     CPPUNIT_ASSERT_MESSAGE("value not imported correctly", fValue == 1);
     181           4 :     pDoc->GetValue(0,1,0,fValue);
     182           4 :     CPPUNIT_ASSERT_MESSAGE("value not imported correctly", fValue == 2);
     183           4 :     OUString aString = pDoc->GetString(1, 0, 0);
     184             : 
     185             :     //check string import
     186           4 :     CPPUNIT_ASSERT_MESSAGE("string imported not correctly", aString == "String1");
     187           4 :     aString = pDoc->GetString(1, 1, 0);
     188           4 :     CPPUNIT_ASSERT_MESSAGE("string not imported correctly", aString == "String2");
     189             : 
     190             :     //check basic formula import
     191             :     // in case of DIF it just contains values
     192           4 :     pDoc->GetValue(2,0,0,fValue);
     193           4 :     CPPUNIT_ASSERT_MESSAGE("=2*3", fValue == 6);
     194           4 :     pDoc->GetValue(2,1,0,fValue);
     195           4 :     CPPUNIT_ASSERT_MESSAGE("=2+3", fValue == 5);
     196           4 :     pDoc->GetValue(2,2,0,fValue);
     197           4 :     CPPUNIT_ASSERT_MESSAGE("=2-3", fValue == -1);
     198           4 :     pDoc->GetValue(2,3,0,fValue);
     199           4 :     CPPUNIT_ASSERT_MESSAGE("=C1+C2", fValue == 11);
     200             : 
     201             :     //check merged cells import
     202           4 :     if(nFormat != LOTUS123 && nFormat != DIF)
     203             :     {
     204           3 :         SCCOL nCol = 4;
     205           3 :         SCROW nRow = 1;
     206           3 :         pDoc->ExtendMerge(4, 1, nCol, nRow, 0, false);
     207           3 :         CPPUNIT_ASSERT_MESSAGE("merged cells are not imported", nCol == 5 && nRow == 2);
     208             : 
     209             :         //check notes import
     210           3 :         ScAddress aAddress(7, 2, 0);
     211           3 :         ScPostIt* pNote = pDoc->GetNote(aAddress);
     212           3 :         CPPUNIT_ASSERT_MESSAGE("note not imported", pNote);
     213           3 :         CPPUNIT_ASSERT_EQUAL_MESSAGE("note text not imported correctly", pNote->GetText(), OUString("Test"));
     214           4 :     }
     215             : 
     216             :     //add additional checks here
     217           4 : }
     218             : 
     219             : }
     220             : 
     221           1 : void ScFiltersTest::testContentODS()
     222             : {
     223           1 :     ScDocShellRef xDocSh = loadDoc("universal-content.", ODS);
     224           1 :     xDocSh->DoHardRecalc(true);
     225             : 
     226           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     227           1 :     testContentImpl(pDoc, ODS);
     228           1 :     xDocSh->DoClose();
     229           1 : }
     230             : 
     231           1 : void ScFiltersTest::testContentXLS()
     232             : {
     233           1 :     ScDocShellRef xDocSh = loadDoc("universal-content.", XLS);
     234           1 :     xDocSh->DoHardRecalc(true);
     235             : 
     236           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     237           1 :     testContentImpl(pDoc, XLS);
     238           1 :     xDocSh->DoClose();
     239           1 : }
     240             : 
     241           1 : void ScFiltersTest::testContentXLSX()
     242             : {
     243           1 :     ScDocShellRef xDocSh = loadDoc("universal-content.", XLSX);
     244           1 :     xDocSh->DoHardRecalc(true);
     245             : 
     246           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     247           1 :     testContentImpl(pDoc, XLSX);
     248           1 :     xDocSh->DoClose();
     249           1 : }
     250             : 
     251           0 : void ScFiltersTest::testContentXLSXStrict()
     252             : {
     253           0 :     ScDocShellRef xDocSh = loadDoc("universal-content-strict.", XLSX);
     254           0 :     xDocSh->DoHardRecalc(true);
     255             : 
     256           0 :     ScDocument* pDoc = xDocSh->GetDocument();
     257           0 :     testContentImpl(pDoc, XLSX);
     258           0 :     xDocSh->DoClose();
     259           0 : }
     260             : 
     261           1 : void ScFiltersTest::testContentLotus123()
     262             : {
     263           1 :     ScDocShellRef xDocSh = loadDoc("universal-content.", LOTUS123);
     264           1 :     xDocSh->DoHardRecalc(true);
     265             : 
     266           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     267           1 :     CPPUNIT_ASSERT(pDoc);
     268           1 :     testContentImpl(pDoc, LOTUS123);
     269           1 :     xDocSh->DoClose();
     270           1 : }
     271             : 
     272           1 : void ScFiltersTest::testContentDIF()
     273             : {
     274           1 :     ScDocShellRef xDocSh = loadDoc("universal-content.", DIF);
     275             : 
     276           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     277           1 :     CPPUNIT_ASSERT(pDoc);
     278           1 :     xDocSh->DoClose();
     279           1 : }
     280             : 
     281           0 : void ScFiltersTest::testContentXLS_XML()
     282             : {
     283           0 :     ScDocShellRef xDocSh = loadDoc("universal-content.", XLS_XML);
     284           0 :     CPPUNIT_ASSERT(xDocSh);
     285             : 
     286           0 :     ScDocument* pDoc = xDocSh->GetDocument();
     287           0 :     CPPUNIT_ASSERT(pDoc);
     288           0 :     testContentImpl(pDoc, XLS_XML);
     289           0 :     xDocSh->DoClose();
     290           0 : }
     291             : 
     292           1 : void ScFiltersTest::testSharedFormulaXLS()
     293             : {
     294           1 :     ScDocShellRef xDocSh = loadDoc("shared-formula/basic.", XLS);
     295           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     296           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     297           1 :     xDocSh->DoHardRecalc(true);
     298             :     // Check the results of formula cells in the shared formula range.
     299          19 :     for (SCROW i = 1; i <= 18; ++i)
     300             :     {
     301          18 :         double fVal = pDoc->GetValue(ScAddress(1,i,0));
     302          18 :         double fCheck = i*10.0;
     303          18 :         CPPUNIT_ASSERT_EQUAL(fCheck, fVal);
     304             :     }
     305             : 
     306           1 :     ScFormulaCell* pCell = pDoc->GetFormulaCell(ScAddress(1,18,0));
     307           1 :     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pCell);
     308           2 :     ScFormulaCellGroupRef xGroup = pCell->GetCellGroup();
     309           1 :     CPPUNIT_ASSERT_MESSAGE("This cell should be a part of a cell group.", xGroup);
     310           1 :     CPPUNIT_ASSERT_MESSAGE("Incorrect group geometry.", xGroup->mpTopCell->aPos.Row() == 1 && xGroup->mnLength == 18);
     311             : 
     312           1 :     xDocSh->DoClose();
     313             : 
     314             :     // The following file contains shared formula whose range is inaccurate.
     315             :     // Excel can easily mess up shared formula ranges, so we need to be able
     316             :     // to handle these wrong ranges that Excel stores.
     317             : 
     318           1 :     xDocSh = loadDoc("shared-formula/gap.", XLS);
     319           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     320           1 :     pDoc = xDocSh->GetDocument();
     321           1 :     pDoc->CalcAll();
     322             : 
     323           1 :     if (!checkFormula(*pDoc, ScAddress(1,0,0), "A1*20"))
     324           0 :         CPPUNIT_FAIL("Wrong formula.");
     325             : 
     326           1 :     if (!checkFormula(*pDoc, ScAddress(1,1,0), "A2*20"))
     327           0 :         CPPUNIT_FAIL("Wrong formula.");
     328             : 
     329           1 :     if (!checkFormula(*pDoc, ScAddress(1,2,0), "A3*20"))
     330           0 :         CPPUNIT_FAIL("Wrong formula.");
     331             : 
     332             :     // There is an intentional gap at row 4.
     333             : 
     334           1 :     if (!checkFormula(*pDoc, ScAddress(1,4,0), "A5*20"))
     335           0 :         CPPUNIT_FAIL("Wrong formula.");
     336             : 
     337           1 :     if (!checkFormula(*pDoc, ScAddress(1,5,0), "A6*20"))
     338           0 :         CPPUNIT_FAIL("Wrong formula.");
     339             : 
     340           1 :     if (!checkFormula(*pDoc, ScAddress(1,6,0), "A7*20"))
     341           0 :         CPPUNIT_FAIL("Wrong formula.");
     342             : 
     343           1 :     if (!checkFormula(*pDoc, ScAddress(1,7,0), "A8*20"))
     344           0 :         CPPUNIT_FAIL("Wrong formula.");
     345             : 
     346             :     // We re-group formula cells on load. Let's check that as well.
     347             : 
     348           1 :     ScFormulaCell* pFC = pDoc->GetFormulaCell(ScAddress(1,0,0));
     349           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to fetch formula cell.", pFC);
     350           1 :     CPPUNIT_ASSERT_MESSAGE("This should be the top cell in formula group.", pFC->IsSharedTop());
     351           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(3), pFC->GetSharedLength());
     352             : 
     353           1 :     pFC = pDoc->GetFormulaCell(ScAddress(1,4,0));
     354           1 :     CPPUNIT_ASSERT_MESSAGE("Failed to fetch formula cell.", pFC);
     355           1 :     CPPUNIT_ASSERT_MESSAGE("This should be the top cell in formula group.", pFC->IsSharedTop());
     356           1 :     CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(4), pFC->GetSharedLength());
     357             : 
     358           2 :     xDocSh->DoClose();
     359           1 : }
     360             : 
     361           1 : void ScFiltersTest::testSharedFormulaXLSX()
     362             : {
     363           1 :     ScDocShellRef xDocSh = loadDoc("shared-formula/basic.", XLSX);
     364           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     365           1 :     CPPUNIT_ASSERT(pDoc);
     366           1 :     xDocSh->DoHardRecalc(true);
     367             :     // Check the results of formula cells in the shared formula range.
     368          19 :     for (SCROW i = 1; i <= 18; ++i)
     369             :     {
     370          18 :         double fVal = pDoc->GetValue(ScAddress(1,i,0));
     371          18 :         double fCheck = i*10.0;
     372          18 :         CPPUNIT_ASSERT_EQUAL(fCheck, fVal);
     373             :     }
     374             : 
     375           1 :     ScFormulaCell* pCell = pDoc->GetFormulaCell(ScAddress(1,18,0));
     376           1 :     CPPUNIT_ASSERT_MESSAGE("This should be a formula cell.", pCell);
     377           2 :     ScFormulaCellGroupRef xGroup = pCell->GetCellGroup();
     378           1 :     CPPUNIT_ASSERT_MESSAGE("This cell should be a part of a cell group.", xGroup);
     379           1 :     CPPUNIT_ASSERT_MESSAGE("Incorrect group geometry.", xGroup->mpTopCell->aPos.Row() == 1 && xGroup->mnLength == 18);
     380             : 
     381           2 :     xDocSh->DoClose();
     382           1 : }
     383             : 
     384           5 : void impl_testLegacyCellAnchoredRotatedShape( ScDocument* pDoc, Rectangle& aRect, ScDrawObjData& aAnchor, long TOLERANCE = 30 /* 30 hmm */ )
     385             : {
     386           5 :     ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     387           5 :     CPPUNIT_ASSERT_MESSAGE("No drawing layer.", pDrawLayer);
     388           5 :     SdrPage* pPage = pDrawLayer->GetPage(0);
     389           5 :     CPPUNIT_ASSERT_MESSAGE("No page instance for the 1st sheet.", pPage);
     390           5 :     CPPUNIT_ASSERT_EQUAL( sal_uIntPtr(1), pPage->GetObjCount() );
     391             : 
     392           5 :     SdrObject* pObj = pPage->GetObj(0);
     393           5 :     const Rectangle& aSnap = pObj->GetSnapRect();
     394           5 :     printf("expected height %ld actual %ld\n", aRect.GetHeight(), aSnap.GetHeight() );
     395           5 :     CPPUNIT_ASSERT_EQUAL( true, testEqualsWithTolerance( aRect.GetHeight(), aSnap.GetHeight(), TOLERANCE ) );
     396           5 :     printf("expected width %ld actual %ld\n", aRect.GetWidth(), aSnap.GetWidth() );
     397           5 :     CPPUNIT_ASSERT_EQUAL( true, testEqualsWithTolerance( aRect.GetWidth(), aSnap.GetWidth(), TOLERANCE ) );
     398           5 :     printf("expected left %ld actual %ld\n", aRect.Left(), aSnap.Left() );
     399           5 :     CPPUNIT_ASSERT_EQUAL( true, testEqualsWithTolerance( aRect.Left(), aSnap.Left(), TOLERANCE ) );
     400           5 :     printf("expected right %ld actual %ld\n", aRect.Top(), aSnap.Top() );
     401           5 :     CPPUNIT_ASSERT_EQUAL( true, testEqualsWithTolerance( aRect.Top(), aSnap.Top(), TOLERANCE ) );
     402             : 
     403             : 
     404           5 :     ScDrawObjData* pData = ScDrawLayer::GetObjData( pObj );
     405           5 :     CPPUNIT_ASSERT_MESSAGE("expected object meta data", pData);
     406           5 :     printf("expected startrow %" SAL_PRIdINT32 " actual %" SAL_PRIdINT32 "\n", aAnchor.maStart.Row(), pData->maStart.Row()  );
     407           5 :     CPPUNIT_ASSERT_EQUAL( aAnchor.maStart.Row(), pData->maStart.Row() );
     408           5 :     printf("expected startcol %d actual %d\n", aAnchor.maStart.Col(), pData->maStart.Col()  );
     409           5 :     CPPUNIT_ASSERT_EQUAL( aAnchor.maStart.Col(), pData->maStart.Col() );
     410           5 :     printf("expected endrow %" SAL_PRIdINT32 " actual %" SAL_PRIdINT32 "\n", aAnchor.maEnd.Row(), pData->maEnd.Row()  );
     411           5 :     CPPUNIT_ASSERT_EQUAL( aAnchor.maEnd.Row(), pData->maEnd.Row() );
     412           5 :     printf("expected endcol %d actual %d\n", aAnchor.maEnd.Col(), pData->maEnd.Col()  );
     413           5 :     CPPUNIT_ASSERT_EQUAL( aAnchor.maEnd.Col(), pData->maEnd.Col() );
     414           5 : }
     415             : 
     416           1 : void ScFiltersTest::testLegacyCellAnchoredRotatedShape()
     417             : {
     418             :     {
     419             :         // This example doc contains cell anchored shape that is rotated, the
     420             :         // rotated shape is in fact cliped by the sheet boundries ( and thus
     421             :         // is a good edge case test to see if we import it still correctly )
     422           1 :         ScDocShellRef xDocSh = loadDoc("legacycellanchoredrotatedclippedshape.", ODS);
     423             : 
     424           1 :         ScDocument* pDoc = xDocSh->GetDocument();
     425           1 :         CPPUNIT_ASSERT(pDoc);
     426             :         // ensure the imported legacy rotated shape is in the expected position
     427           1 :         Rectangle aRect( 6000, -2000, 8000, 4000 );
     428             :         // ensure the imported ( and converted ) anchor ( note we internally now store the anchor in
     429             :         // terms of the rotated shape ) is more or less contains the correct info
     430           2 :         ScDrawObjData aAnchor;
     431           1 :         aAnchor.maStart.SetRow( 0 );
     432           1 :         aAnchor.maStart.SetCol( 5 );
     433           1 :         aAnchor.maEnd.SetRow( 3 );
     434           1 :         aAnchor.maEnd.SetCol( 7 );
     435           1 :         impl_testLegacyCellAnchoredRotatedShape( pDoc, aRect, aAnchor );
     436             :         // test save and reload
     437             :         // for some reason having this test in subsequent_export-test.cxx causes
     438             :         // a core dump in editeng ( so moved to here )
     439           1 :         xDocSh = saveAndReload( &(*xDocSh), ODS);
     440           1 :         pDoc = xDocSh->GetDocument();
     441           1 :         CPPUNIT_ASSERT(pDoc);
     442           1 :         impl_testLegacyCellAnchoredRotatedShape( pDoc, aRect, aAnchor );
     443             : 
     444           2 :         xDocSh->DoClose();
     445             :     }
     446             :     {
     447             :         // This example doc contains cell anchored shape that is rotated, the
     448             :         // rotated shape is in fact clipped by the sheet boundries, additionally
     449             :         // the shape is completely hidden because the rows the shape occupies
     450             :         // are hidden
     451           1 :         ScDocShellRef xDocSh = loadDoc("legacycellanchoredrotatedhiddenshape.", ODS, true);
     452           1 :         ScDocument* pDoc = xDocSh->GetDocument();
     453           1 :         CPPUNIT_ASSERT(pDoc);
     454             :         // ensure the imported legacy rotated shape is in the expected position
     455             :         // when a shape is fully hidden reloading seems to result is in some errors, usually
     456             :         // ( same but different error happens pre-patch ) - we should do better here, I regard it
     457             :         // as a pre-existing bug though ( #FIXME )
     458             :         //Rectangle aRect( 6000, -2000, 8000, 4000 ); // proper dimensions
     459           1 :         Rectangle aRect( 6000, -2000, 7430, 4000 );
     460             :         // ensure the imported ( and converted ) anchor ( note we internally now store the anchor in
     461             :         // terms of the rotated shape ) is more or less contains the correct info
     462           2 :         ScDrawObjData aAnchor;
     463           1 :         aAnchor.maStart.SetRow( 0 );
     464           1 :         aAnchor.maStart.SetCol( 5 );
     465           1 :         aAnchor.maEnd.SetRow( 3 );
     466           1 :         aAnchor.maEnd.SetCol( 7 );
     467           1 :         pDoc->ShowRows(0, 9, 0, true); // show relavent rows
     468           1 :         pDoc->SetDrawPageSize(0); // trigger recalcpos
     469             : 
     470             :         // apply hefty ( 1 mm ) tolerence here, as some opensuse tinderbox
     471             :         // failing
     472           1 :         impl_testLegacyCellAnchoredRotatedShape( pDoc, aRect, aAnchor, 100 );
     473             : 
     474           2 :         xDocSh->DoClose();
     475             :     }
     476             :     {
     477             :         // This example doc contains cell anchored shape that is rotated
     478           1 :         ScDocShellRef xDocSh = loadDoc("legacycellanchoredrotatedshape.", ODS);
     479             : 
     480           1 :         ScDocument* pDoc = xDocSh->GetDocument();
     481           1 :         CPPUNIT_ASSERT(pDoc);
     482             :         // ensure the imported legacy rotated shape is in the expected position
     483           1 :         Rectangle aRect( 6000, 3000, 8000, 9000 );
     484             :         // ensure the imported ( and converted ) anchor ( note we internally now store the anchor in
     485             :         // terms of the rotated shape ) is more or less contains the correct info
     486             : 
     487           2 :         ScDrawObjData aAnchor;
     488           1 :         aAnchor.maStart.SetRow( 3 );
     489           1 :         aAnchor.maStart.SetCol( 6 );
     490           1 :         aAnchor.maEnd.SetRow( 9 );
     491           1 :         aAnchor.maEnd.SetCol( 7 );
     492             :         // test import
     493           1 :         impl_testLegacyCellAnchoredRotatedShape( pDoc, aRect, aAnchor );
     494             :         // test save and reload
     495           1 :         xDocSh = saveAndReload( &(*xDocSh), ODS);
     496           1 :         pDoc = xDocSh->GetDocument();
     497           1 :         CPPUNIT_ASSERT(pDoc);
     498           1 :         impl_testLegacyCellAnchoredRotatedShape( pDoc, aRect, aAnchor );
     499             : 
     500           2 :         xDocSh->DoClose();
     501             :     }
     502           1 : }
     503             : 
     504           2 : void testEnhancedProtectionImpl( ScDocument* pDoc )
     505             : {
     506           2 :     const ScTableProtection* pProt = pDoc->GetTabProtection(0);
     507             : 
     508           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 0, 0, 0, 0, 0)));  // locked
     509           2 :     CPPUNIT_ASSERT(  pProt->isBlockEditable( ScRange( 0, 1, 0, 0, 1, 0)));  // editable without password
     510           2 :     CPPUNIT_ASSERT(  pProt->isBlockEditable( ScRange( 0, 2, 0, 0, 2, 0)));  // editable without password
     511           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 3, 0, 0, 3, 0)));  // editable with password "foo"
     512           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 4, 0, 0, 4, 0)));  // editable with descriptor
     513           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 5, 0, 0, 5, 0)));  // editable with descriptor and password "foo"
     514           2 :     CPPUNIT_ASSERT(  pProt->isBlockEditable( ScRange( 0, 1, 0, 0, 2, 0)));  // union of two different editables
     515           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 0, 0, 0, 1, 0)));  // union of locked and editable
     516           2 :     CPPUNIT_ASSERT( !pProt->isBlockEditable( ScRange( 0, 2, 0, 0, 3, 0)));  // union of editable and password editable
     517           2 : }
     518             : 
     519           1 : void ScFiltersTest::testEnhancedProtectionXLS()
     520             : {
     521           1 :     ScDocShellRef xDocSh = loadDoc("enhanced-protection.", XLS);
     522           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     523           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     524             : 
     525           1 :     testEnhancedProtectionImpl( pDoc);
     526             : 
     527           1 :     xDocSh->DoClose();
     528           1 : }
     529             : 
     530           1 : void ScFiltersTest::testEnhancedProtectionXLSX()
     531             : {
     532           1 :     ScDocShellRef xDocSh = loadDoc("enhanced-protection.", XLSX);
     533           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     534           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     535             : 
     536           1 :     testEnhancedProtectionImpl( pDoc);
     537             : 
     538           1 :     xDocSh->DoClose();
     539           1 : }
     540             : 
     541          12 : ScFiltersTest::ScFiltersTest()
     542          12 :       : ScBootstrapFixture( "/sc/qa/unit/data" )
     543             : {
     544          12 : }
     545             : 
     546          12 : void ScFiltersTest::setUp()
     547             : {
     548          12 :     test::BootstrapFixture::setUp();
     549             : 
     550             :     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     551             :     // which is a private symbol to us, gets called
     552          24 :     m_xCalcComponent =
     553          36 :         getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
     554          12 :     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
     555          12 : }
     556             : 
     557          12 : void ScFiltersTest::tearDown()
     558             : {
     559          12 :     uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
     560          12 :     test::BootstrapFixture::tearDown();
     561          12 : }
     562             : 
     563           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest);
     564             : 
     565           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     566             : 
     567             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10