LCOV - code coverage report
Current view: top level - sc/qa/unit - filters-test.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 151 151 100.0 %
Date: 2012-08-25 Functions: 23 24 95.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 375 748 50.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * Copyright (C) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
      17                 :            :  *  (initial developer)
      18                 :            :  * Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com>
      19                 :            :  *
      20                 :            :  * All Rights Reserved.
      21                 :            :  *
      22                 :            :  * For minor contributions see the git repository.
      23                 :            :  *
      24                 :            :  * Alternatively, the contents of this file may be used under the terms of
      25                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      26                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      27                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      28                 :            :  * instead of those above.
      29                 :            :  */
      30                 :            : 
      31                 :            : #include <sal/config.h>
      32                 :            : #include <unotest/filters-test.hxx>
      33                 :            : #include <test/bootstrapfixture.hxx>
      34                 :            : #include <rtl/strbuf.hxx>
      35                 :            : #include <osl/file.hxx>
      36                 :            : 
      37                 :            : #include <sfx2/app.hxx>
      38                 :            : #include <sfx2/docfilt.hxx>
      39                 :            : #include <sfx2/docfile.hxx>
      40                 :            : #include <sfx2/sfxmodelfactory.hxx>
      41                 :            : #include <svl/stritem.hxx>
      42                 :            : 
      43                 :            : #define CALC_DEBUG_OUTPUT 0
      44                 :            : #define TEST_BUG_FILES 0
      45                 :            : 
      46                 :            : #include "helper/qahelper.hxx"
      47                 :            : 
      48                 :            : #include "docsh.hxx"
      49                 :            : #include "postit.hxx"
      50                 :            : #include "patattr.hxx"
      51                 :            : #include "scitems.hxx"
      52                 :            : #include "document.hxx"
      53                 :            : #include "cellform.hxx"
      54                 :            : 
      55                 :            : #define ODS_FORMAT_TYPE 50331943
      56                 :            : #define XLS_FORMAT_TYPE 318767171
      57                 :            : #define XLSX_FORMAT_TYPE 268959811
      58                 :            : 
      59                 :            : #define ODS     0
      60                 :            : #define XLS     1
      61                 :            : #define XLSX    2
      62                 :            : 
      63                 :            : using namespace ::com::sun::star;
      64                 :            : using namespace ::com::sun::star::uno;
      65                 :            : 
      66                 :            : namespace {
      67                 :            : 
      68                 :            : struct FileFormat {
      69                 :            :     const char* pName; const char* pFilterName; const char* pTypeName; sal_uLong nFormatType;
      70                 :            : };
      71                 :            : 
      72                 :            : FileFormat aFileFormats[] = {
      73                 :            :     { "ods" , "calc8", "", ODS_FORMAT_TYPE },
      74                 :            :     { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
      75                 :            :     { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE }
      76                 :            : };
      77                 :            : 
      78                 :            : }
      79                 :            : 
      80                 :            : /* Implementation of Filters test */
      81                 :            : 
      82 [ +  - ][ -  + ]:         30 : class ScFiltersTest
      83                 :            :     : public test::FiltersTest
      84                 :            :     , public test::BootstrapFixture
      85                 :            : {
      86                 :            : public:
      87                 :            :     ScFiltersTest();
      88                 :            : 
      89                 :            :     virtual bool load(const rtl::OUString &rFilter, const rtl::OUString &rURL, const rtl::OUString &rUserData);
      90                 :            :     ScDocShellRef load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
      91                 :            :         const rtl::OUString &rUserData, const rtl::OUString& rTypeName, sal_uLong nFormatType=0);
      92                 :            : 
      93                 :            :     void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
      94                 :            :     void createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rFilePath);
      95                 :            : 
      96                 :            :     virtual void setUp();
      97                 :            :     virtual void tearDown();
      98                 :            : 
      99                 :            :     /**
     100                 :            :      * Ensure CVEs remain unbroken
     101                 :            :      */
     102                 :            :     void testCVEs();
     103                 :            : 
     104                 :            :     //ods, xls, xlsx filter tests
     105                 :            :     void testRangeNameODS(); // only test ods here, xls and xlsx in subsequent_filters-test
     106                 :            :     void testContentODS();
     107                 :            :     void testContentXLS();
     108                 :            :     void testContentXLSX();
     109                 :            : 
     110                 :            : #if TEST_BUG_FILES
     111                 :            :     //goes recursively through all files in this dir and tries to open them
     112                 :            :     void testDir(osl::Directory& rDir, sal_Int32 nType);
     113                 :            :     //test Bug Files and search for files that crash LibO
     114                 :            :     void testBugFiles();
     115                 :            :     void testBugFilesXLS();
     116                 :            :     void testBugFilesXLSX();
     117                 :            : #endif
     118                 :            : 
     119 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE(ScFiltersTest);
         [ +  - ][ +  - ]
                 [ #  # ]
     120 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testCVEs);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     121 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testRangeNameODS);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     122 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testContentODS);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     123 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testContentXLS);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     124 [ +  - ][ +  - ]:          3 :     CPPUNIT_TEST(testContentXLSX);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     125                 :            : 
     126                 :            : #if TEST_BUG_FILES
     127                 :            :     CPPUNIT_TEST(testBugFiles);
     128                 :            :     CPPUNIT_TEST(testBugFilesXLS);
     129                 :            :     CPPUNIT_TEST(testBugFilesXLSX);
     130                 :            : #endif
     131 [ +  - ][ +  - ]:          6 :     CPPUNIT_TEST_SUITE_END();
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     132                 :            : 
     133                 :            : private:
     134                 :            :     ScDocShellRef loadDoc(const rtl::OUString& rName, sal_Int32 nFormat);
     135                 :            :     uno::Reference<uno::XInterface> m_xCalcComponent;
     136                 :            :     ::rtl::OUString m_aBaseString;
     137                 :            : };
     138                 :            : 
     139                 :         66 : ScDocShellRef ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
     140                 :            :     const rtl::OUString &rUserData, const rtl::OUString& rTypeName, sal_uLong nFormatType)
     141                 :            : {
     142                 :         66 :     sal_uInt32 nFormat = 0;
     143         [ +  + ]:         66 :     if (nFormatType)
     144                 :         12 :         nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
     145                 :            :     SfxFilter* aFilter = new SfxFilter(
     146                 :            :         rFilter,
     147                 :            :         rtl::OUString(), nFormatType, nFormat, rTypeName, 0, rtl::OUString(),
     148 [ +  - ][ +  - ]:         66 :         rUserData, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc*")) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     149                 :         66 :     aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
     150                 :            : 
     151         [ +  - ]:         66 :     ScDocShellRef xDocShRef = new ScDocShell;
     152 [ +  - ][ +  - ]:         66 :     SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
         [ +  - ][ +  - ]
     153         [ +  - ]:         66 :     pSrcMed->SetFilter(aFilter);
     154 [ +  - ][ +  + ]:         66 :     if (!xDocShRef->DoLoad(pSrcMed))
     155                 :            :     {
     156         [ +  - ]:          6 :         xDocShRef->DoClose();
     157                 :            :         // load failed.
     158         [ +  - ]:          6 :         xDocShRef.Clear();
     159                 :            :     }
     160                 :            : 
     161                 :         66 :     return xDocShRef;
     162                 :            : }
     163                 :            : 
     164                 :         54 : bool ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
     165                 :            :     const rtl::OUString &rUserData)
     166                 :            : {
     167         [ +  - ]:         54 :     ScDocShellRef xDocShRef = load(rFilter, rURL, rUserData, rtl::OUString());
     168                 :         54 :     bool bLoaded = xDocShRef.Is();
     169                 :            :     //reference counting of ScDocShellRef is very confused.
     170         [ +  + ]:         54 :     if (bLoaded)
     171         [ +  - ]:         48 :         xDocShRef->DoClose();
     172         [ +  - ]:         54 :     return bLoaded;
     173                 :            : }
     174                 :            : 
     175                 :         12 : void ScFiltersTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
     176                 :            : {
     177         [ +  - ]:         12 :     rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
     178         [ +  - ]:         12 :     rtl::OUStringBuffer aBuffer( getSrcRootURL() );
     179 [ +  - ][ +  - ]:         12 :     aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
                 [ +  - ]
     180 [ +  - ][ +  - ]:         12 :     aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
                 [ +  - ]
     181         [ +  - ]:         12 :     rFilePath = aBuffer.makeStringAndClear();
     182                 :         12 : }
     183                 :            : 
     184                 :          3 : void ScFiltersTest::createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rCSVPath)
     185                 :            : {
     186         [ +  - ]:          3 :     rtl::OUStringBuffer aBuffer(getSrcRootPath());
     187 [ +  - ][ +  - ]:          3 :     aBuffer.append(m_aBaseString).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/contentCSV/")));
                 [ +  - ]
     188 [ +  - ][ +  - ]:          3 :     aBuffer.append(aFileBase).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("csv")));
                 [ +  - ]
     189         [ +  - ]:          3 :     rCSVPath = aBuffer.makeStringAndClear();
     190                 :          3 : }
     191                 :            : 
     192                 :          3 : void ScFiltersTest::testCVEs()
     193                 :            : {
     194                 :            :     testDir(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Quattro Pro 6.0")),
     195 [ +  - ][ +  - ]:          3 :         getURLFromSrc("/sc/qa/unit/data/qpro/"), rtl::OUString());
                 [ +  - ]
     196                 :            : 
     197                 :            :     //warning, the current "sylk filter" in sc (docsh.cxx) automatically
     198                 :            :     //chains on failure on trying as csv, rtf, etc. so "success" may
     199                 :            :     //not indicate that it imported as .slk.
     200                 :            :     testDir(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYLK")),
     201 [ +  - ][ +  - ]:          3 :         getURLFromSrc("/sc/qa/unit/data/slk/"), rtl::OUString());
                 [ +  - ]
     202                 :            : 
     203                 :            :     testDir(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MS Excel 97")),
     204 [ +  - ][ +  - ]:          3 :         getURLFromSrc("/sc/qa/unit/data/xls/"), rtl::OUString());
                 [ +  - ]
     205                 :          3 : }
     206                 :            : 
     207                 :            : #if TEST_BUG_FILES
     208                 :            : 
     209                 :            : void ScFiltersTest::testDir(osl::Directory& rDir, sal_uInt32 nType)
     210                 :            : {
     211                 :            :     rtl::OUString aFilterName(aFileFormats[nType].pFilterName, strlen(aFileFormats[nType].pFilterName), RTL_TEXTENCODING_UTF8) ;
     212                 :            :     rtl::OUString aFilterType(aFileFormats[nType].pTypeName, strlen(aFileFormats[nType].pTypeName), RTL_TEXTENCODING_UTF8);
     213                 :            : 
     214                 :            :     osl::DirectoryItem aItem;
     215                 :            :     osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type);
     216                 :            :     while (rDir.getNextItem(aItem) == osl::FileBase::E_None)
     217                 :            :     {
     218                 :            :         aItem.getFileStatus(aFileStatus);
     219                 :            :         rtl::OUString sURL = aFileStatus.getFileURL();
     220                 :            :         std::cout << "File: " << rtl::OUStringToOString(sURL, RTL_TEXTENCODING_UTF8).getStr() << std::endl;
     221                 :            :         //rtl::OStringBuffer aMessage("Failed loading: ");
     222                 :            :         //aMessage.append(rtl::OUStringToOString(sURL, RTL_TEXTENCODING_UTF8));
     223                 :            :         ScDocShellRef xDocSh = load( aFilterName,sURL, rtl::OUString(),aFilterType, aFileFormats[nType].nFormatType);
     224                 :            :         // use this only if you're sure that all files can be loaded
     225                 :            :         // pay attention to lock files
     226                 :            :         //CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), xDocSh.Is());
     227                 :            :         if (xDocSh.Is())
     228                 :            :             xDocSh->DoClose();
     229                 :            :     }
     230                 :            : }
     231                 :            : 
     232                 :            : void ScFiltersTest::testBugFiles()
     233                 :            : {
     234                 :            :     rtl::OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugODS/");
     235                 :            :     osl::Directory aDir(aDirName);
     236                 :            : 
     237                 :            :     CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open());
     238                 :            :     testDir(aDir, 0);
     239                 :            : }
     240                 :            : 
     241                 :            : void ScFiltersTest::testBugFilesXLS()
     242                 :            : {
     243                 :            :     rtl::OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugXLS/");
     244                 :            :     osl::Directory aDir(aDirName);
     245                 :            : 
     246                 :            :     CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open());
     247                 :            :     testDir(aDir, 1);
     248                 :            : }
     249                 :            : 
     250                 :            : void ScFiltersTest::testBugFilesXLSX()
     251                 :            : {
     252                 :            :     rtl::OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugXLSX/");
     253                 :            :     osl::Directory aDir(aDirName);
     254                 :            : 
     255                 :            :     CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open());
     256                 :            :     testDir(aDir, 2);
     257                 :            : }
     258                 :            : 
     259                 :            : #endif
     260                 :            : 
     261                 :            : namespace {
     262                 :            : 
     263                 :          3 : void testRangeNameImpl(ScDocument* pDoc)
     264                 :            : {
     265                 :            :     //check one range data per sheet and one global more detailed
     266                 :            :     //add some more checks here
     267 [ +  - ][ +  - ]:          3 :     ScRangeData* pRangeData = pDoc->GetRangeName()->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GLOBAL1")));
                 [ +  - ]
     268 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("range name Global1 not found", pRangeData);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     269                 :            :     double aValue;
     270         [ +  - ]:          3 :     pDoc->GetValue(1,0,0,aValue);
     271 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("range name Global1 should reference Sheet1.A1", aValue == 1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     272 [ +  - ][ +  - ]:          3 :     pRangeData = pDoc->GetRangeName(0)->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOCAL1")));
                 [ +  - ]
     273 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 not found", pRangeData);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     274         [ +  - ]:          3 :     pDoc->GetValue(1,2,0,aValue);
     275 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 should reference Sheet1.A3", aValue == 3);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     276 [ +  - ][ +  - ]:          3 :     pRangeData = pDoc->GetRangeName(1)->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOCAL2")));
                 [ +  - ]
     277 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("range name Sheet2.Local2 not found", pRangeData);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     278                 :            :     //check for correct results for the remaining formulas
     279         [ +  - ]:          3 :     pDoc->GetValue(1,1,0, aValue);
     280 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("=global2 should be 2", aValue == 2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     281         [ +  - ]:          3 :     pDoc->GetValue(1,3,0, aValue);
     282 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("=local2 should be 4", aValue == 4);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     283         [ +  - ]:          3 :     pDoc->GetValue(2,0,0, aValue);
     284 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("=SUM(global3) should be 10", aValue == 10);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     285                 :          3 : }
     286                 :            : 
     287                 :            : }
     288                 :            : 
     289                 :         12 : ScDocShellRef ScFiltersTest::loadDoc(const rtl::OUString& rName, sal_Int32 nFormat)
     290                 :            : {
     291         [ +  - ]:         12 :     rtl::OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
     292         [ +  - ]:         12 :     rtl::OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
     293                 :         12 :     rtl::OUString aFileName;
     294         [ +  - ]:         12 :     createFileURL( rName, aFileExtension, aFileName );
     295         [ +  - ]:         12 :     rtl::OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
     296         [ +  - ]:         12 :     ScDocShellRef xDocSh = load (aFilterName, aFileName, rtl::OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
     297 [ +  - ][ +  - ]:         12 :     CPPUNIT_ASSERT(xDocSh.Is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     298                 :         12 :     return xDocSh;
     299                 :            : }
     300                 :            : 
     301                 :          3 : void ScFiltersTest::testRangeNameODS()
     302                 :            : {
     303         [ +  - ]:          3 :     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
     304         [ +  - ]:          3 :     ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
     305                 :            : 
     306 [ +  - ][ +  - ]:          3 :     CPPUNIT_ASSERT_MESSAGE("Failed to load named-ranges-globals.*", xDocSh.Is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     307                 :            : 
     308         [ +  - ]:          3 :     xDocSh->DoHardRecalc(true);
     309                 :            : 
     310                 :          3 :     ScDocument* pDoc = xDocSh->GetDocument();
     311         [ +  - ]:          3 :     testRangeNameImpl(pDoc);
     312                 :            : 
     313         [ +  - ]:          3 :     rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
     314                 :          3 :     rtl::OUString aCSVPath;
     315         [ +  - ]:          3 :     createCSVPath( aSheet2CSV, aCSVPath );
     316         [ +  - ]:          3 :     testFile( aCSVPath, pDoc, 1);
     317 [ +  - ][ +  - ]:          3 :     xDocSh->DoClose();
     318                 :          3 : }
     319                 :            : 
     320                 :            : namespace {
     321                 :            : 
     322                 :          9 : void testContentImpl(ScDocument* pDoc) //same code for ods, xls, xlsx
     323                 :            : {
     324                 :            :     double fValue;
     325                 :            :     //check value import
     326         [ +  - ]:          9 :     pDoc->GetValue(0,0,0,fValue);
     327 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("value not imported correctly", fValue == 1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     328         [ +  - ]:          9 :     pDoc->GetValue(0,1,0,fValue);
     329 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("value not imported correctly", fValue == 2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     330                 :          9 :     rtl::OUString aString;
     331         [ +  - ]:          9 :     pDoc->GetString(1,0,0,aString);
     332                 :            :     //check string import
     333 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("string imported not correctly", aString == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("String1")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     334         [ +  - ]:          9 :     pDoc->GetString(1,1,0,aString);
     335 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("string not imported correctly", aString == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("String2")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     336                 :            :     //check basic formula import
     337         [ +  - ]:          9 :     pDoc->GetValue(2,0,0,fValue);
     338 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("=2*3", fValue == 6);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     339         [ +  - ]:          9 :     pDoc->GetValue(2,1,0,fValue);
     340 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("=2+3", fValue == 5);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     341         [ +  - ]:          9 :     pDoc->GetValue(2,2,0,fValue);
     342 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("=2-3", fValue == -1);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     343         [ +  - ]:          9 :     pDoc->GetValue(2,3,0,fValue);
     344 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("=C1+C2", fValue == 11);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     345                 :            :     //check merged cells import
     346                 :          9 :     SCCOL nCol = 4;
     347                 :          9 :     SCROW nRow = 1;
     348         [ +  - ]:          9 :     pDoc->ExtendMerge(4, 1, nCol, nRow, 0, false);
     349 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("merged cells are not imported", nCol == 5 && nRow == 2);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ -  + ]
         [ +  - ][ +  - ]
                 [ +  - ]
     350                 :            :     //check notes import
     351                 :          9 :     ScAddress aAddress(7, 2, 0);
     352 [ +  - ][ +  - ]:          9 :     ScPostIt* pNote = pDoc->GetNotes(aAddress.Tab())->findByAddress(aAddress);
     353 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("note not imported", pNote);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     354 [ +  - ][ +  - ]:          9 :     CPPUNIT_ASSERT_MESSAGE("note text not imported correctly", pNote->GetText() == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test")));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     355                 :            :     //add additional checks here
     356                 :          9 : }
     357                 :            : 
     358                 :            : }
     359                 :            : 
     360                 :          3 : void ScFiltersTest::testContentODS()
     361                 :            : {
     362         [ +  - ]:          3 :     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
     363         [ +  - ]:          3 :     ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
     364         [ +  - ]:          3 :     xDocSh->DoHardRecalc(true);
     365                 :            : 
     366                 :          3 :     ScDocument* pDoc = xDocSh->GetDocument();
     367         [ +  - ]:          3 :     testContentImpl(pDoc);
     368 [ +  - ][ +  - ]:          3 :     xDocSh->DoClose();
     369                 :          3 : }
     370                 :            : 
     371                 :          3 : void ScFiltersTest::testContentXLS()
     372                 :            : {
     373         [ +  - ]:          3 :     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
     374         [ +  - ]:          3 :     ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
     375         [ +  - ]:          3 :     xDocSh->DoHardRecalc(true);
     376                 :            : 
     377                 :          3 :     ScDocument* pDoc = xDocSh->GetDocument();
     378         [ +  - ]:          3 :     testContentImpl(pDoc);
     379 [ +  - ][ +  - ]:          3 :     xDocSh->DoClose();
     380                 :          3 : }
     381                 :            : 
     382                 :          3 : void ScFiltersTest::testContentXLSX()
     383                 :            : {
     384         [ +  - ]:          3 :     const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("universal-content."));
     385         [ +  - ]:          3 :     ScDocShellRef xDocSh = loadDoc(aFileNameBase, 2);
     386         [ +  - ]:          3 :     xDocSh->DoHardRecalc(true);
     387                 :            : 
     388                 :          3 :     ScDocument* pDoc = xDocSh->GetDocument();
     389         [ +  - ]:          3 :     testContentImpl(pDoc);
     390 [ +  - ][ +  - ]:          3 :     xDocSh->DoClose();
     391                 :          3 : }
     392                 :            : 
     393                 :         15 : ScFiltersTest::ScFiltersTest()
     394 [ +  - ][ +  - ]:         15 :       : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
     395                 :            : {
     396                 :         15 : }
     397                 :            : 
     398                 :         15 : void ScFiltersTest::setUp()
     399                 :            : {
     400                 :         15 :     test::BootstrapFixture::setUp();
     401                 :            : 
     402                 :            :     // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
     403                 :            :     // which is a private symbol to us, gets called
     404                 :            :     m_xCalcComponent =
     405         [ +  - ]:         30 :         getMultiServiceFactory()->createInstance(rtl::OUString(
     406 [ +  - ][ +  - ]:         15 :         RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.SpreadsheetDocument")));
                 [ +  - ]
     407 [ +  - ][ +  - ]:         15 :     CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     408                 :         15 : }
     409                 :            : 
     410                 :         15 : void ScFiltersTest::tearDown()
     411                 :            : {
     412 [ +  - ][ +  - ]:         15 :     uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
     413                 :         15 :     test::BootstrapFixture::tearDown();
     414                 :         15 : }
     415                 :            : 
     416                 :          3 : CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest);
     417                 :            : 
     418 [ +  - ][ +  - ]:         12 : CPPUNIT_PLUGIN_IMPLEMENT();
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     419                 :            : 
     420                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10