LCOV - code coverage report
Current view: top level - sc/qa/unit/helper - qahelper.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 22 37 59.5 %
Date: 2014-11-03 Functions: 5 7 71.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             : #ifndef INCLUDED_SC_QA_UNIT_HELPER_QAHELPER_HXX
      11             : #define INCLUDED_SC_QA_UNIT_HELPER_QAHELPER_HXX
      12             : 
      13             : #include "scdllapi.h"
      14             : #include "debughelper.hxx"
      15             : #include "docsh.hxx"
      16             : #include "address.hxx"
      17             : 
      18             : #include <test/bootstrapfixture.hxx>
      19             : #include <comphelper/documentconstants.hxx>
      20             : 
      21             : #include <osl/detail/android-bootstrap.h>
      22             : 
      23             : #include <unotools/tempfile.hxx>
      24             : #include <comphelper/storagehelper.hxx>
      25             : #include <sfx2/docfilt.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <svl/stritem.hxx>
      28             : #include <formula/grammar.hxx>
      29             : 
      30             : #include <string>
      31             : #include <sstream>
      32             : 
      33             : #include <sal/types.h>
      34             : 
      35             : #include <boost/shared_ptr.hpp>
      36             : 
      37             : #if defined(SCQAHELPER_DLLIMPLEMENTATION)
      38             : #define SCQAHELPER_DLLPUBLIC  SAL_DLLPUBLIC_EXPORT
      39             : #else
      40             : #define SCQAHELPER_DLLPUBLIC  SAL_DLLPUBLIC_IMPORT
      41             : #endif
      42             : 
      43             : #define ODS_FORMAT_TYPE 50331943
      44             : #define XLS_FORMAT_TYPE 318767171
      45             : #define XLSX_FORMAT_TYPE 268959811
      46             : #define LOTUS123_FORMAT_TYPE 268435649
      47             : #define CSV_FORMAT_TYPE  (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
      48             : #define HTML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
      49             : #define DIF_FORMAT_TYPE 195
      50             : #define XLS_XML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN)
      51             : 
      52             : #define ODS      0
      53             : #define XLS      1
      54             : #define XLSX     2
      55             : #define XLSM     3
      56             : #define CSV      4
      57             : #define HTML     5
      58             : #define LOTUS123 6
      59             : #define DIF      7
      60             : #define XLS_XML  8
      61             : 
      62             : enum StringType { PureString, FormulaValue, StringValue };
      63             : 
      64             : SCQAHELPER_DLLPUBLIC bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol );
      65             : 
      66             : #define CHECK_OPTIMAL 0x1
      67             : 
      68             : class SdrOle2Obj;
      69             : class ScRangeList;
      70             : class ScTokenArray;
      71             : 
      72             : // data format for row height tests
      73             : struct TestParam
      74             : {
      75             :     struct RowData
      76             :     {
      77             :         SCROW nStartRow;
      78             :         SCROW nEndRow;
      79             :         SCTAB nTab;
      80             :         int nExpectedHeight; // -1 for default height
      81             :         int nCheck; // currently only CHECK_OPTIMAL ( we could add CHECK_MANUAL etc.)
      82             :         bool bOptimal;
      83             :     };
      84             :     const char* sTestDoc;
      85             :     int nImportType;
      86             :     int nExportType; // -1 for import test, otherwise this is an export test
      87             :     int nRowData;
      88             :     RowData* pData;
      89             : };
      90             : 
      91             : struct FileFormat {
      92             :     const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType;
      93             : };
      94             : 
      95             : // Printers for the calc data structures. Needed for the EQUAL assertion
      96             : // macros from CPPUNIT.
      97             : 
      98             : std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr);
      99             : 
     100             : std::ostream& operator<<(std::ostream& rStrm, const ScRange& rRange);
     101             : 
     102             : std::ostream& operator<<(std::ostream& rStrm, const ScRangeList& rList);
     103             : 
     104             : std::ostream& operator<<(std::ostream& rStrm, const Color& rColor);
     105             : 
     106             : // Why is this here and not in osl, and using the already existing file
     107             : // handling APIs? Do we really want to add arbitrary new file handling
     108             : // wrappers here and there (and then having to handle the Android (and
     109             : // eventually perhaps iOS) special cases here, too)?  Please move this to osl,
     110             : // it sure looks gemerally useful. Or am I missing something?
     111             : 
     112             : SCQAHELPER_DLLPUBLIC void loadFile(const OUString& aFileName, std::string& aContent);
     113             : 
     114             : SCQAHELPER_DLLPUBLIC void testFile(OUString& aFileName, ScDocument& rDoc, SCTAB nTab, StringType aStringFormat = StringValue);
     115             : 
     116             : //need own handler because conditional formatting strings must be generated
     117             : SCQAHELPER_DLLPUBLIC void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
     118             : 
     119             : SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
     120             : 
     121             : SCQAHELPER_DLLPUBLIC std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj);
     122             : 
     123             : SCQAHELPER_DLLPUBLIC ScRangeList getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj);
     124             : 
     125             : SCQAHELPER_DLLPUBLIC bool checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* pExpected);
     126             : 
     127             : SCQAHELPER_DLLPUBLIC bool checkFormulaPosition(ScDocument& rDoc, const ScAddress& rPos);
     128             : SCQAHELPER_DLLPUBLIC bool checkFormulaPositions(
     129             :     ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SCROW* pRows, size_t nRowCount);
     130             : 
     131             : SCQAHELPER_DLLPUBLIC ScTokenArray* compileFormula(
     132             :     ScDocument* pDoc, const OUString& rFormula, const ScAddress* pPos = NULL,
     133             :     formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_NATIVE );
     134             : 
     135             : template<size_t _Size>
     136         106 : bool checkOutput(ScDocument* pDoc, const ScRange& aOutRange, const char* aOutputCheck[][_Size], const char* pCaption)
     137             : {
     138         106 :     bool bResult = true;
     139         106 :     const ScAddress& s = aOutRange.aStart;
     140         106 :     const ScAddress& e = aOutRange.aEnd;
     141         106 :     svl::GridPrinter printer(e.Row() - s.Row() + 1, e.Col() - s.Col() + 1, CALC_DEBUG_OUTPUT != 0);
     142         106 :     SCROW nOutRowSize = e.Row() - s.Row() + 1;
     143         106 :     SCCOL nOutColSize = e.Col() - s.Col() + 1;
     144         736 :     for (SCROW nRow = 0; nRow < nOutRowSize; ++nRow)
     145             :     {
     146        2436 :         for (SCCOL nCol = 0; nCol < nOutColSize; ++nCol)
     147             :         {
     148        1806 :             OUString aVal = pDoc->GetString(nCol + s.Col(), nRow + s.Row(), s.Tab());
     149        1806 :             printer.set(nRow, nCol, aVal);
     150        1806 :             const char* p = aOutputCheck[nRow][nCol];
     151        1806 :             if (p)
     152             :             {
     153        1512 :                 OUString aCheckVal = OUString::createFromAscii(p);
     154        1512 :                 bool bEqual = aCheckVal.equals(aVal);
     155        1512 :                 if (!bEqual)
     156             :                 {
     157           0 :                     cout << "Expected: " << aCheckVal << "  Actual: " << aVal << endl;
     158           0 :                     bResult = false;
     159        1512 :                 }
     160             :             }
     161         294 :             else if (!aVal.isEmpty())
     162             :             {
     163           0 :                 cout << "Empty cell expected" << endl;
     164           0 :                 bResult = false;
     165             :             }
     166             :         }
     167             :     }
     168         106 :     printer.print(pCaption);
     169         106 :     return bResult;
     170             : }
     171             : 
     172             : SCQAHELPER_DLLPUBLIC void clearFormulaCellChangedFlag( ScDocument& rDoc, const ScRange& rRange );
     173             : 
     174             : /**
     175             :  * Check if the cell at specified position is a formula cell that doesn't
     176             :  * have an error value.
     177             :  */
     178             : SCQAHELPER_DLLPUBLIC bool isFormulaWithoutError(ScDocument& rDoc, const ScAddress& rPos);
     179             : 
     180             : /**
     181             :  * Convert formula token array to a formula string.
     182             :  */
     183             : SCQAHELPER_DLLPUBLIC OUString toString(
     184             :     ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rArray,
     185             :     formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_NATIVE);
     186             : 
     187           0 : inline std::string print(const ScAddress& rAddr)
     188             : {
     189           0 :     std::ostringstream str;
     190           0 :     str << "Col: " << rAddr.Col();
     191           0 :     str << " Row: " << rAddr.Row();
     192           0 :     str << " Tab: " << rAddr.Tab();
     193           0 :     return str.str();
     194             : }
     195             : 
     196             : namespace CppUnit {
     197             : 
     198             : template<>
     199             : struct assertion_traits<ScRange>
     200             : {
     201           4 :     static bool equal( const ScRange& x, const ScRange& y )
     202             :     {
     203           4 :         return x == y;
     204             :     }
     205             : 
     206           0 :     static std::string toString( const ScRange& x )
     207             :     {
     208           0 :         std::stringstream str;
     209           0 :         str << "Start: " << print(x.aStart);
     210           0 :         str << "\nEnd: " << print(x.aEnd);
     211           0 :         return str.str();
     212             :     }
     213             : };
     214             : 
     215             : }
     216             : 
     217             : class SCQAHELPER_DLLPUBLIC ScBootstrapFixture : public test::BootstrapFixture
     218             : {
     219             : protected:
     220             :     OUString m_aBaseString;
     221             : 
     222             :     ScDocShellRef load(
     223             :         bool bReadWrite, const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     224             :         const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
     225             :         sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
     226             : 
     227             :     ScDocShellRef load(
     228             :         const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     229             :         const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
     230             :         sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
     231             : 
     232             :     ScDocShellRef loadDoc(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite = false );
     233             : 
     234             : public:
     235             :     static const FileFormat* getFileFormats();
     236             : 
     237             :     ScBootstrapFixture( const OUString& rsBaseString );
     238             :     virtual ~ScBootstrapFixture();
     239             : 
     240             :     void createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath);
     241             : 
     242             :     void createCSVPath(const OUString& aFileBase, OUString& rCSVPath);
     243             : 
     244             :     ScDocShellRef saveAndReload(ScDocShell* pShell, const OUString &rFilter,
     245             :     const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType);
     246             : 
     247             :     ScDocShellRef saveAndReload( ScDocShell* pShell, sal_Int32 nFormat );
     248             : 
     249             :     static boost::shared_ptr<utl::TempFile> exportTo( ScDocShell* pShell, sal_Int32 nFormat );
     250             : 
     251             :     void miscRowHeightsTest( TestParam* aTestValues, unsigned int numElems );
     252             : };
     253             : 
     254             : #define ASSERT_DOUBLES_EQUAL( expected, result )    \
     255             :     CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 )
     256             : 
     257             : #define ASSERT_DOUBLES_EQUAL_MESSAGE( message, expected, result )   \
     258             :     CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( (message), (expected), (result), 1e-14 )
     259             : 
     260             : #define ASSERT_EQUAL_TYPE( type, expected, result ) \
     261             :     CPPUNIT_ASSERT_EQUAL( static_cast<type>(expected), static_cast<type>(result) );
     262             : 
     263             : SCQAHELPER_DLLPUBLIC void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat);
     264             : 
     265             : #endif
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10