LCOV - code coverage report
Current view: top level - sc/qa/unit/helper - qahelper.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 13 15.4 %
Date: 2014-04-11 Functions: 1 3 33.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             : #ifndef SC_QA_HELPER_HXX
      11             : #define SC_QA_HELPER_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             : #if defined(SCQAHELPER_DLLIMPLEMENTATION)
      36             : #define SCQAHELPER_DLLPUBLIC  SAL_DLLPUBLIC_EXPORT
      37             : #else
      38             : #define SCQAHELPER_DLLPUBLIC  SAL_DLLPUBLIC_IMPORT
      39             : #endif
      40             : 
      41             : #define ODS_FORMAT_TYPE 50331943
      42             : #define XLS_FORMAT_TYPE 318767171
      43             : #define XLSX_FORMAT_TYPE 268959811
      44             : #define LOTUS123_FORMAT_TYPE 268435649
      45             : #define CSV_FORMAT_TYPE  (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
      46             : #define HTML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
      47             : #define DIF_FORMAT_TYPE 195
      48             : #define XLS_XML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN)
      49             : 
      50             : #define ODS      0
      51             : #define XLS      1
      52             : #define XLSX     2
      53             : #define CSV      3
      54             : #define HTML     4
      55             : #define LOTUS123 5
      56             : #define DIF      6
      57             : #define XLS_XML  7
      58             : 
      59             : enum StringType { PureString, FormulaValue, StringValue };
      60             : 
      61             : SCQAHELPER_DLLPUBLIC bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol );
      62             : 
      63             : #define CHECK_OPTIMAL 0x1
      64             : 
      65             : class SdrOle2Obj;
      66             : class ScRangeList;
      67             : class ScTokenArray;
      68             : 
      69             : // data format for row height tests
      70             : struct TestParam
      71             : {
      72             :     struct RowData
      73             :     {
      74             :         SCROW nStartRow;
      75             :         SCROW nEndRow;
      76             :         SCTAB nTab;
      77             :         int nExpectedHeight; // -1 for default height
      78             :         int nCheck; // currently only CHECK_OPTIMAL ( we could add CHECK_MANUAL etc.)
      79             :         bool bOptimal;
      80             :     };
      81             :     const char* sTestDoc;
      82             :     int nImportType;
      83             :     int nExportType; // -1 for import test, otherwise this is an export test
      84             :     int nRowData;
      85             :     RowData* pData;
      86             : };
      87             : 
      88             : struct FileFormat {
      89             :     const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType;
      90             : };
      91             : 
      92             : // Printers for the calc data structures. Needed for the EQUAL assertion
      93             : // macros from CPPUNIT.
      94             : 
      95             : std::ostream& operator<<(std::ostream& rStrm, const ScAddress& rAddr);
      96             : 
      97             : std::ostream& operator<<(std::ostream& rStrm, const ScRange& rRange);
      98             : 
      99             : std::ostream& operator<<(std::ostream& rStrm, const ScRangeList& rList);
     100             : 
     101             : std::ostream& operator<<(std::ostream& rStrm, const Color& rColor);
     102             : 
     103             : // Why is this here and not in osl, and using the already existing file
     104             : // handling APIs? Do we really want to add arbitrary new file handling
     105             : // wrappers here and there (and then having to handle the Android (and
     106             : // eventually perhaps iOS) special cases here, too)?  Please move this to osl,
     107             : // it sure looks gemerally useful. Or am I missing something?
     108             : 
     109             : SCQAHELPER_DLLPUBLIC void loadFile(const OUString& aFileName, std::string& aContent);
     110             : 
     111             : SCQAHELPER_DLLPUBLIC void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, StringType aStringFormat = StringValue);
     112             : 
     113             : //need own handler because conditional formatting strings must be generated
     114             : SCQAHELPER_DLLPUBLIC void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
     115             : 
     116             : SCQAHELPER_DLLPUBLIC const SdrOle2Obj* getSingleChartObject(ScDocument& rDoc, sal_uInt16 nPage);
     117             : 
     118             : SCQAHELPER_DLLPUBLIC std::vector<OUString> getChartRangeRepresentations(const SdrOle2Obj& rChartObj);
     119             : 
     120             : SCQAHELPER_DLLPUBLIC ScRangeList getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj);
     121             : 
     122             : SCQAHELPER_DLLPUBLIC bool checkFormula(ScDocument& rDoc, const ScAddress& rPos, const char* pExpected);
     123             : 
     124             : SCQAHELPER_DLLPUBLIC bool checkFormulaPosition(ScDocument& rDoc, const ScAddress& rPos);
     125             : SCQAHELPER_DLLPUBLIC bool checkFormulaPositions(
     126             :     ScDocument& rDoc, SCTAB nTab, SCCOL nCol, const SCROW* pRows, size_t nRowCount);
     127             : 
     128             : SCQAHELPER_DLLPUBLIC void clearFormulaCellChangedFlag( ScDocument& rDoc, const ScRange& rRange );
     129             : 
     130             : /**
     131             :  * Check if the cell at specified position is a formula cell that doesn't
     132             :  * have an error value.
     133             :  */
     134             : SCQAHELPER_DLLPUBLIC bool isFormulaWithoutError(ScDocument& rDoc, const ScAddress& rPos);
     135             : 
     136             : /**
     137             :  * Convert formula token array to a formula string.
     138             :  */
     139             : SCQAHELPER_DLLPUBLIC OUString toString(
     140             :     ScDocument& rDoc, const ScAddress& rPos, ScTokenArray& rArray,
     141             :     formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_NATIVE);
     142             : 
     143           0 : inline std::string print(const ScAddress& rAddr)
     144             : {
     145           0 :     std::ostringstream str;
     146           0 :     str << "Col: " << rAddr.Col();
     147           0 :     str << " Row: " << rAddr.Row();
     148           0 :     str << " Tab: " << rAddr.Tab();
     149           0 :     return str.str();
     150             : }
     151             : 
     152             : namespace CppUnit {
     153             : 
     154             : template<>
     155             : struct assertion_traits<ScRange>
     156             : {
     157           2 :     static bool equal( const ScRange& x, const ScRange& y )
     158             :     {
     159           2 :         return x == y;
     160             :     }
     161             : 
     162           0 :     static std::string toString( const ScRange& x )
     163             :     {
     164           0 :         std::stringstream str;
     165           0 :         str << "Start: " << print(x.aStart);
     166           0 :         str << "\nEnd: " << print(x.aEnd);
     167           0 :         return str.str();
     168             :     }
     169             : };
     170             : 
     171             : }
     172             : 
     173             : class SCQAHELPER_DLLPUBLIC ScBootstrapFixture : public test::BootstrapFixture
     174             : {
     175             : protected:
     176             :     OUString m_aBaseString;
     177             : 
     178             :     ScDocShellRef load(
     179             :         bool bReadWrite, const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     180             :         const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
     181             :         sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
     182             : 
     183             :     ScDocShellRef load(
     184             :         const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     185             :         const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
     186             :         sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
     187             : 
     188             :     ScDocShellRef loadDoc(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite = false );
     189             : 
     190             : public:
     191             :     static const FileFormat* getFileFormats();
     192             : 
     193             :     ScBootstrapFixture( const OUString& rsBaseString );
     194             :     virtual ~ScBootstrapFixture();
     195             : 
     196             :     void createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath);
     197             : 
     198             :     void createCSVPath(const OUString& aFileBase, OUString& rCSVPath);
     199             : 
     200             :     ScDocShellRef saveAndReload(ScDocShell* pShell, const OUString &rFilter,
     201             :     const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType);
     202             : 
     203             :     ScDocShellRef saveAndReload( ScDocShell* pShell, sal_Int32 nFormat );
     204             : 
     205             :     void miscRowHeightsTest( TestParam* aTestValues, unsigned int numElems );
     206             : };
     207             : 
     208             : #define ASSERT_DOUBLES_EQUAL( expected, result )    \
     209             :     CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 )
     210             : 
     211             : #define ASSERT_DOUBLES_EQUAL_MESSAGE( message, expected, result )   \
     212             :     CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( (message), (expected), (result), 1e-14 )
     213             : 
     214             : #define ASSERT_EQUAL_TYPE( type, expected, result ) \
     215             :     CPPUNIT_ASSERT_EQUAL( static_cast<type>(expected), static_cast<type>(result) );
     216             : 
     217             : SCQAHELPER_DLLPUBLIC void testFormats(ScBootstrapFixture* pTest, ScDocument* pDoc, sal_Int32 nFormat);
     218             : 
     219             : #endif
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10