LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/qa/unit - subsequent_export-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 129 149 86.6 %
Date: 2013-07-09 Functions: 19 22 86.4 %
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 <rtl/strbuf.hxx>
      12             : #include <osl/file.hxx>
      13             : 
      14             : #include <sfx2/app.hxx>
      15             : #include <sfx2/docfile.hxx>
      16             : #include <sfx2/frame.hxx>
      17             : #include <sfx2/sfxmodelfactory.hxx>
      18             : #include <svl/stritem.hxx>
      19             : 
      20             : 
      21             : #define CALC_DEBUG_OUTPUT 0
      22             : 
      23             : #include "helper/qahelper.hxx"
      24             : #include "helper/shared_test_impl.hxx"
      25             : 
      26             : #include "docsh.hxx"
      27             : #include "postit.hxx"
      28             : #include "patattr.hxx"
      29             : #include "scitems.hxx"
      30             : #include "document.hxx"
      31             : #include "cellform.hxx"
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36          14 : class ScExportTest : public ScBootstrapFixture
      37             : {
      38             : public:
      39             :     ScExportTest();
      40             : 
      41             :     virtual void setUp();
      42             :     virtual void tearDown();
      43             : 
      44             :     ScDocShellRef saveAndReloadPassword( ScDocShell*, const OUString&, const OUString&, const OUString&, sal_uLong );
      45             : 
      46             :     void test();
      47             :     void testPasswordExport();
      48             :     void testConditionalFormatExportODS();
      49             :     void testConditionalFormatExportXLSX();
      50             :     void testColorScaleExportODS();
      51             :     void testColorScaleExportXLSX();
      52             :     void testDataBarExportODS();
      53             :     void testDataBarExportXLSX();
      54             :     void testMiscRowHeightExport();
      55             : 
      56           2 :     CPPUNIT_TEST_SUITE(ScExportTest);
      57           1 :     CPPUNIT_TEST(test);
      58             : #if !defined(MACOSX) && !defined(DRAGONFLY)
      59           1 :     CPPUNIT_TEST(testPasswordExport);
      60             : #endif
      61           1 :     CPPUNIT_TEST(testConditionalFormatExportODS);
      62           1 :     CPPUNIT_TEST(testConditionalFormatExportXLSX);
      63           1 :     CPPUNIT_TEST(testColorScaleExportODS);
      64           1 :     CPPUNIT_TEST(testColorScaleExportXLSX);
      65           1 :     CPPUNIT_TEST(testMiscRowHeightExport);
      66           2 :     CPPUNIT_TEST_SUITE_END();
      67             : 
      68             : private:
      69             :     uno::Reference<uno::XInterface> m_xCalcComponent;
      70             : 
      71             : };
      72             : 
      73           1 : ScDocShellRef ScExportTest::saveAndReloadPassword(ScDocShell* pShell, const OUString &rFilter,
      74             :     const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType)
      75             : {
      76           1 :     utl::TempFile aTempFile;
      77           1 :     aTempFile.EnableKillingFile();
      78           2 :     SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE );
      79           1 :     sal_uInt32 nExportFormat = 0;
      80           1 :     if (nFormatType == ODS_FORMAT_TYPE)
      81           1 :         nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
      82             :     SfxFilter* pExportFilter = new SfxFilter(
      83             :         rFilter,
      84             :         OUString(), nFormatType, nExportFormat, rTypeName, 0, OUString(),
      85           1 :         rUserData, OUString("private:factory/scalc*") );
      86           1 :     pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
      87           1 :     aStoreMedium.SetFilter(pExportFilter);
      88           1 :     SfxItemSet* pExportSet = aStoreMedium.GetItemSet();
      89           2 :     uno::Sequence< beans::NamedValue > aEncryptionData = comphelper::OStorageHelper::CreatePackageEncryptionData( OUString("test") );
      90           2 :     uno::Any xEncryptionData;
      91           1 :     xEncryptionData <<= aEncryptionData;
      92           1 :     pExportSet->Put(SfxUnoAnyItem(SID_ENCRYPTIONDATA, xEncryptionData));
      93             : 
      94           2 :     uno::Reference< embed::XStorage > xMedStorage = aStoreMedium.GetStorage();
      95           1 :     ::comphelper::OStorageHelper::SetCommonStorageEncryptionData( xMedStorage, aEncryptionData );
      96             : 
      97           1 :     pShell->DoSaveAs( aStoreMedium );
      98           1 :     pShell->DoClose();
      99             : 
     100             :     //std::cout << "File: " << aTempFile.GetURL() << std::endl;
     101             : 
     102           1 :     sal_uInt32 nFormat = 0;
     103           1 :     if (nFormatType == ODS_FORMAT_TYPE)
     104           1 :         nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
     105             : 
     106           2 :     OUString aPass("test");
     107           2 :     return load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat, SOFFICE_FILEFORMAT_CURRENT, &aPass);
     108             : }
     109             : 
     110           1 : void ScExportTest::test()
     111             : {
     112             :     ScDocShell* pShell = new ScDocShell(
     113             :         SFXMODEL_STANDARD |
     114             :         SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
     115           1 :         SFXMODEL_DISABLE_DOCUMENT_RECOVERY);
     116           1 :     pShell->DoInitNew();
     117             : 
     118           1 :     ScDocument* pDoc = pShell->GetDocument();
     119             : 
     120           1 :     pDoc->SetValue(0,0,0, 1.0);
     121           1 :     CPPUNIT_ASSERT(pDoc);
     122             : 
     123           1 :     ScDocShellRef xDocSh = saveAndReload( pShell, ODS );
     124             : 
     125           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     126           1 :     ScDocument* pLoadedDoc = xDocSh->GetDocument();
     127           1 :     double aVal = pLoadedDoc->GetValue(0,0,0);
     128           1 :     ASSERT_DOUBLES_EQUAL(aVal, 1.0);
     129           1 : }
     130             : 
     131           1 : void ScExportTest::testPasswordExport()
     132             : {
     133             :     ScDocShell* pShell = new ScDocShell(
     134             :         SFXMODEL_STANDARD |
     135             :         SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
     136           1 :         SFXMODEL_DISABLE_DOCUMENT_RECOVERY);
     137           1 :     pShell->DoInitNew();
     138             : 
     139           1 :     ScDocument* pDoc = pShell->GetDocument();
     140             : 
     141           1 :     pDoc->SetValue(0,0,0, 1.0);
     142           1 :     CPPUNIT_ASSERT(pDoc);
     143             : 
     144           1 :     sal_Int32 nFormat = ODS;
     145           1 :     OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
     146           2 :     OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
     147           2 :     ScDocShellRef xDocSh = saveAndReloadPassword(pShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
     148             : 
     149           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     150           1 :     ScDocument* pLoadedDoc = xDocSh->GetDocument();
     151           1 :     double aVal = pLoadedDoc->GetValue(0,0,0);
     152           1 :     ASSERT_DOUBLES_EQUAL(aVal, 1.0);
     153             : 
     154           2 :     xDocSh->DoClose();
     155           1 : }
     156             : 
     157           1 : void ScExportTest::testConditionalFormatExportODS()
     158             : {
     159           1 :     ScDocShellRef xShell = loadDoc("new_cond_format_test.", ODS);
     160           1 :     CPPUNIT_ASSERT(xShell.Is());
     161             : 
     162           2 :     ScDocShellRef xDocSh = saveAndReload(&(*xShell), ODS);
     163           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     164           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     165           2 :     OUString aCSVFile("new_cond_format_test.");
     166           2 :     OUString aCSVPath;
     167           1 :     createCSVPath( aCSVFile, aCSVPath );
     168           1 :     testCondFile(aCSVPath, pDoc, 0);
     169             : 
     170           2 :     xDocSh->DoClose();
     171           1 : }
     172             : 
     173           1 : void ScExportTest::testConditionalFormatExportXLSX()
     174             : {
     175           1 :     ScDocShellRef xShell = loadDoc("new_cond_format_test.", XLSX);
     176           1 :     CPPUNIT_ASSERT(xShell.Is());
     177             : 
     178           2 :     ScDocShellRef xDocSh = saveAndReload(&(*xShell), XLSX);
     179           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     180           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     181           2 :     OUString aCSVFile("new_cond_format_test.");
     182           2 :     OUString aCSVPath;
     183           1 :     createCSVPath( aCSVFile, aCSVPath );
     184           1 :     testCondFile(aCSVPath, pDoc, 0);
     185             : 
     186           2 :     xDocSh->DoClose();
     187           1 : }
     188             : 
     189           1 : void ScExportTest::testColorScaleExportODS()
     190             : {
     191           1 :     ScDocShellRef xShell = loadDoc("colorscale.", ODS);
     192           1 :     CPPUNIT_ASSERT(xShell.Is());
     193             : 
     194           2 :     ScDocShellRef xDocSh = saveAndReload(xShell, ODS);
     195           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     196             : 
     197           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     198           1 :     CPPUNIT_ASSERT(pDoc);
     199             : 
     200           1 :     testColorScale2Entry_Impl(pDoc);
     201           1 :     testColorScale3Entry_Impl(pDoc);
     202             : 
     203           2 :     xDocSh->DoClose();
     204           1 : }
     205             : 
     206           1 : void ScExportTest::testColorScaleExportXLSX()
     207             : {
     208           1 :     ScDocShellRef xShell = loadDoc("colorscale.", XLSX);
     209           1 :     CPPUNIT_ASSERT(xShell.Is());
     210             : 
     211           2 :     ScDocShellRef xDocSh = saveAndReload(xShell, XLSX);
     212           1 :     CPPUNIT_ASSERT(xDocSh.Is());
     213             : 
     214           1 :     ScDocument* pDoc = xDocSh->GetDocument();
     215           1 :     CPPUNIT_ASSERT(pDoc);
     216             : 
     217           1 :     testColorScale2Entry_Impl(pDoc);
     218           1 :     testColorScale3Entry_Impl(pDoc);
     219             : 
     220           2 :     xDocSh->DoClose();
     221           1 : }
     222             : 
     223           0 : void ScExportTest::testDataBarExportODS()
     224             : {
     225           0 :     ScDocShellRef xShell = loadDoc("databar.", ODS);
     226           0 :     CPPUNIT_ASSERT(xShell.Is());
     227             : 
     228           0 :     ScDocShellRef xDocSh = saveAndReload(xShell, ODS);
     229           0 :     CPPUNIT_ASSERT(xDocSh.Is());
     230             : 
     231           0 :     ScDocument* pDoc = xDocSh->GetDocument();
     232           0 :     CPPUNIT_ASSERT(pDoc);
     233             : 
     234           0 :     testDataBar_Impl(pDoc);
     235             : 
     236           0 :     xDocSh->DoClose();
     237           0 : }
     238             : 
     239           0 : void ScExportTest::testDataBarExportXLSX()
     240             : {
     241           0 :     ScDocShellRef xShell = loadDoc("databar.", XLSX);
     242           0 :     CPPUNIT_ASSERT(xShell.Is());
     243             : 
     244           0 :     ScDocShellRef xDocSh = saveAndReload(xShell, XLSX);
     245           0 :     CPPUNIT_ASSERT(xDocSh.Is());
     246             : 
     247           0 :     ScDocument* pDoc = xDocSh->GetDocument();
     248           0 :     CPPUNIT_ASSERT(pDoc);
     249             : 
     250           0 :     testDataBar_Impl(pDoc);
     251             : 
     252           0 :     xDocSh->DoClose();
     253           0 : }
     254             : 
     255           1 : void ScExportTest::testMiscRowHeightExport()
     256             : {
     257             :     TestParam::RowData DfltRowData[] =
     258             :     {
     259             :         { 0, 4, 0, 529, 0, false },
     260             :         { 5, 10, 0, 1058, 0, false },
     261             :         { 17, 20, 0, 1767, 0, false },
     262             :         // check last couple of row in document to ensure
     263             :         // they are 5.29mm ( effective default row xlsx height )
     264             :         { 1048573, 1048575, 0, 529, 0, false },
     265           1 :     };
     266             : 
     267             :     TestParam::RowData EmptyRepeatRowData[] =
     268             :     {
     269             :         // rows 0-4, 5-10, 17-20 are all set at various
     270             :         // heights, there is no content in the rows, there
     271             :         // was a bug where only the first row ( of repeated rows )
     272             :         // was set after export
     273             :         { 0, 4, 0, 529, 0, false },
     274             :         { 5, 10, 0, 1058, 0, false },
     275             :         { 17, 20, 0, 1767, 0, false },
     276           1 :     };
     277             : 
     278             :     TestParam aTestValues[] =
     279             :     {
     280             :         // Checks that some distributed ( non-empty ) heights remain set after export (roundtrip)
     281             :         // additionally there is effectively a default row height ( 5.29 mm ). So we test the
     282             :         // unset rows at the end of the document to ensure the effective xlsx default height
     283             :         // is set there too.
     284             :         { "miscrowheights.", XLSX, XLSX, SAL_N_ELEMENTS(DfltRowData), DfltRowData },
     285             :         // Checks that some distributed ( non-empty ) heights remain set after export (to xls)
     286             :         { "miscrowheights.", XLSX, XLS, SAL_N_ELEMENTS(DfltRowData), DfltRowData },
     287             :         // Checks that repreated rows ( of various heights ) remain set after export ( to xlsx )
     288             :         { "miscemptyrepeatedrowheights.", ODS, XLSX, SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData },
     289             :         // Checks that repreated rows ( of various heights ) remain set after export ( to xls )
     290             :         { "miscemptyrepeatedrowheights.", ODS, XLS, SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData },
     291           1 :     };
     292           1 :     miscRowHeightsTest( aTestValues, SAL_N_ELEMENTS(aTestValues) );
     293           1 : }
     294             : 
     295           7 : ScExportTest::ScExportTest()
     296           7 :       : ScBootstrapFixture("/sc/qa/unit/data")
     297             : {
     298           7 : }
     299             : 
     300           7 : void ScExportTest::setUp()
     301             : {
     302           7 :     test::BootstrapFixture::setUp();
     303             : 
     304             :     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     305             :     // which is a private symbol to us, gets called
     306          14 :     m_xCalcComponent =
     307          21 :         getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
     308           7 :     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
     309           7 : }
     310             : 
     311           7 : void ScExportTest::tearDown()
     312             : {
     313           7 :     uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
     314           7 :     test::BootstrapFixture::tearDown();
     315           7 : }
     316             : 
     317           1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
     318             : 
     319           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     320             : 
     321             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10