Create a new library to store shared qa code for sc.

Change-Id: I38aa1461d05e3dee096e69b7cd95e2ddfccc9594
This commit is contained in:
Kohei Yoshida 2013-07-08 18:08:30 -04:00
parent 93ab5bc4da
commit eef5362279
15 changed files with 354 additions and 246 deletions

View File

@ -432,6 +432,7 @@ $(eval $(call gb_Helper_register_libraries,PLAINLIBS_NONE, \
unobootstrapprotector \
unoexceptionprotector \
unotest \
scqahelper \
))
$(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_URE,ure, \

View File

@ -44,6 +44,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_filters_test, \
salhelper \
sax \
sc \
scqahelper \
sfx \
sot \
svl \

View File

@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_export_test, \
salhelper \
sax \
sc \
scqahelper \
sfx \
sot \
svl \

View File

@ -38,6 +38,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_subsequent_filters_test, \
salhelper \
sax \
sc \
scqahelper \
sfx \
sot \
svl \

View File

@ -51,6 +51,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_ucalc, \
salhelper \
sax \
sb \
scqahelper \
sfx \
sot \
svl \

48
sc/Library_scqahelper.mk Normal file
View File

@ -0,0 +1,48 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Library_Library,scqahelper))
$(eval $(call gb_Library_set_include,scqahelper,\
-I$(SRCDIR)/sc/inc \
-I$(SRCDIR)/sc/source/ui/inc \
$$(INCLUDE) \
))
$(eval $(call gb_Library_use_externals,scqahelper, \
boost_headers \
mdds_headers \
orcus \
orcus-parser \
cppunit \
))
$(eval $(call gb_Library_use_sdk_api,scqahelper))
$(eval $(call gb_Library_use_libraries,scqahelper,\
comphelper \
cppu \
cppuhelper \
sal \
sfx \
sot \
svl \
svt \
tl \
utl \
sc \
ucbhelper \
$(gb_UWINAPI) \
))
$(eval $(call gb_Library_add_exception_objects,scqahelper,\
sc/qa/unit/helper/qahelper \
))
# vim: set noet sw=4 ts=4:

View File

@ -16,6 +16,7 @@ $(eval $(call gb_Module_add_targets,sc,\
Library_scd \
Library_scfilt \
Library_scui \
Library_scqahelper \
UIConfig_scalc \
))

View File

@ -20,7 +20,6 @@
#include <sfx2/sfxmodelfactory.hxx>
#include <svl/stritem.hxx>
#define CALC_DEBUG_OUTPUT 0
#define TEST_BUG_FILES 0
#include "helper/qahelper.hxx"

View File

@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef SC_QA_CSV_HANDLER_HXX
#define SC_QA_CSV_HANDLER_HXX
#include <iostream>
#include "docsh.hxx"
@ -17,6 +20,10 @@
#include "cellform.hxx"
#include "cellvalue.hxx"
#include "rtl/strbuf.hxx"
#include <test/bootstrapfixture.hxx>
#define DEBUG_CSV_HANDLER 0
namespace {
@ -221,4 +228,6 @@ private:
SCTAB mnTab;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -10,11 +10,6 @@
#ifndef SC_DEBUG_HELPER_HXX
#define SC_DEBUG_HELPER_HXX
/**
* Print nicely formatted sheet content to stdout. Indispensable when
* debugging the unit test code involving testing of sheet contents.
*/
#include <rtl/strbuf.hxx>
#include <rtl/ustring.hxx>
@ -32,13 +27,19 @@
#include <iostream>
#define CALC_DEBUG_OUTPUT 0
#define CALC_TEST_PERF 0
using namespace ::com::sun::star;
using ::std::cout;
using ::std::cerr;
using ::std::endl;
using ::std::vector;
/**
* Print nicely formatted sheet content to stdout. Indispensable when
* debugging the unit test code involving testing of sheet contents.
*/
class SheetPrinter
{
typedef ::mdds::mixed_type_matrix<OUString, bool> MatrixType;

View File

@ -0,0 +1,251 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "qahelper.hxx"
#define __ORCUS_STATIC_LIB
#include <orcus/csv_parser.hpp>
#include <fstream>
bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol )
{
return ( labs( nVal1 - nVal2 ) <= nTol );
}
void loadFile(const OUString& aFileName, std::string& aContent)
{
OString aOFileName = OUStringToOString(aFileName, RTL_TEXTENCODING_UTF8);
#ifdef ANDROID
size_t size;
if (strncmp(aOFileName.getStr(), "/assets/", sizeof("/assets/")-1) == 0) {
const char *contents = (const char *) lo_apkentry(aOFileName.getStr(), &size);
if (contents != 0) {
aContent = std::string(contents, size);
return;
}
}
#endif
std::ifstream aFile(aOFileName.getStr());
OStringBuffer aErrorMsg("Could not open csv file: ");
aErrorMsg.append(aOFileName);
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), aFile);
std::ostringstream aOStream;
aOStream << aFile.rdbuf();
aFile.close();
aContent = aOStream.str();
}
void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, StringType aStringFormat)
{
csv_handler aHandler(pDoc, nTab, aStringFormat);
orcus::csv_parser_config aConfig;
aConfig.delimiters.push_back(',');
aConfig.delimiters.push_back(';');
aConfig.text_qualifier = '"';
aConfig.trim_cell_value = false;
std::string aContent;
loadFile(aFileName, aContent);
orcus::csv_parser<csv_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
try
{
parser.parse();
}
catch (const orcus::csv_parse_error& e)
{
std::cout << "reading csv content file failed: " << e.what() << std::endl;
OStringBuffer aErrorMsg("csv parser error: ");
aErrorMsg.append(e.what());
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), false);
}
}
void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
{
conditional_format_handler aHandler(pDoc, nTab);
orcus::csv_parser_config aConfig;
aConfig.delimiters.push_back(',');
aConfig.delimiters.push_back(';');
aConfig.text_qualifier = '"';
std::string aContent;
loadFile(aFileName, aContent);
orcus::csv_parser<conditional_format_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
try
{
parser.parse();
}
catch (const orcus::csv_parse_error& e)
{
std::cout << "reading csv content file failed: " << e.what() << std::endl;
OStringBuffer aErrorMsg("csv parser error: ");
aErrorMsg.append(e.what());
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), false);
}
}
ScDocShellRef ScBootstrapFixture::load( bool bReadWrite,
const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
sal_uIntPtr nFilterVersion, const OUString* pPassword )
{
SfxFilter* pFilter = new SfxFilter(
rFilter,
OUString(), nFilterFlags, nClipboardID, rTypeName, 0, OUString(),
rUserData, OUString("private:factory/scalc*"));
pFilter->SetVersion(nFilterVersion);
ScDocShellRef xDocShRef = new ScDocShell;
xDocShRef->GetDocument()->EnableUserInteraction(false);
SfxMedium* pSrcMed = new SfxMedium(rURL, bReadWrite ? STREAM_STD_READWRITE : STREAM_STD_READ );
pSrcMed->SetFilter(pFilter);
pSrcMed->UseInteractionHandler(false);
if (pPassword)
{
SfxItemSet* pSet = pSrcMed->GetItemSet();
pSet->Put(SfxStringItem(SID_PASSWORD, *pPassword));
}
printf("about to load %s\n", OUStringToOString( rURL, RTL_TEXTENCODING_UTF8 ).getStr() );
if (!xDocShRef->DoLoad(pSrcMed))
{
xDocShRef->DoClose();
// load failed.
xDocShRef.Clear();
}
return xDocShRef;
}
ScDocShellRef ScBootstrapFixture::load(
const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
sal_uIntPtr nFilterVersion, const OUString* pPassword )
{
return load( false, rURL, rFilter, rUserData, rTypeName, nFilterFlags, nClipboardID, nFilterVersion, pPassword );
}
ScDocShellRef ScBootstrapFixture::loadDoc(
const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite )
{
OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
OUString aFileName;
createFileURL( rFileName, aFileExtension, aFileName );
OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
unsigned int nFormatType = aFileFormats[nFormat].nFormatType;
unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
return load(bReadWrite, aFileName, aFilterName, OUString(), aFilterType, nFormatType, nClipboardId, nFormatType);
}
void ScBootstrapFixture::createFileURL(
const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath)
{
OUString aSep("/");
OUStringBuffer aBuffer( getSrcRootURL() );
aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
rFilePath = aBuffer.makeStringAndClear();
}
void ScBootstrapFixture::createCSVPath(const OUString& aFileBase, OUString& rCSVPath)
{
OUStringBuffer aBuffer( getSrcRootPath());
aBuffer.append(m_aBaseString).append(OUString("/contentCSV/"));
aBuffer.append(aFileBase).append(OUString("csv"));
rCSVPath = aBuffer.makeStringAndClear();
}
ScDocShellRef ScBootstrapFixture::saveAndReload(
ScDocShell* pShell, const OUString &rFilter,
const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType)
{
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE );
sal_uInt32 nExportFormat = 0;
if (nFormatType == ODS_FORMAT_TYPE)
nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
SfxFilter* pExportFilter = new SfxFilter(
rFilter,
OUString(), nFormatType, nExportFormat, rTypeName, 0, OUString(),
rUserData, OUString("private:factory/scalc*") );
pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
aStoreMedium.SetFilter(pExportFilter);
pShell->DoSaveAs( aStoreMedium );
pShell->DoClose();
//std::cout << "File: " << aTempFile.GetURL() << std::endl;
sal_uInt32 nFormat = 0;
if (nFormatType == ODS_FORMAT_TYPE)
nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
return load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat );
}
ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell* pShell, sal_Int32 nFormat )
{
OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
ScDocShellRef xDocSh = saveAndReload(pShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
CPPUNIT_ASSERT(xDocSh.Is());
return xDocSh;
}
void ScBootstrapFixture::miscRowHeightsTest( TestParam* aTestValues, unsigned int numElems )
{
for ( unsigned int index=0; index<numElems; ++index )
{
OUString sFileName = OUString::createFromAscii( aTestValues[ index ].sTestDoc );
printf("aTestValues[%u] %s\n", index, OUStringToOString( sFileName, RTL_TEXTENCODING_UTF8 ).getStr() );
int nImportType = aTestValues[ index ].nImportType;
int nExportType = aTestValues[ index ].nExportType;
ScDocShellRef xShell = loadDoc( sFileName, nImportType );
CPPUNIT_ASSERT(xShell.Is());
if ( nExportType != -1 )
xShell = saveAndReload(&(*xShell), nExportType );
CPPUNIT_ASSERT(xShell.Is());
ScDocument* pDoc = xShell->GetDocument();
for (int i=0; i<aTestValues[ index ].nRowData; ++i)
{
SCROW nRow = aTestValues[ index ].pData[ i].nStartRow;
SCROW nEndRow = aTestValues[ index ].pData[ i ].nEndRow;
SCTAB nTab = aTestValues[ index ].pData[ i ].nTab;
int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight;
if ( nExpectedHeight == -1 )
nExpectedHeight = sc::TwipsToHMM( ScGlobal::nStdRowHeight );
bool bCheckOpt = ( ( aTestValues[ index ].pData[ i ].nCheck & CHECK_OPTIMAL ) == CHECK_OPTIMAL );
for ( ; nRow <= nEndRow; ++nRow )
{
printf("\t checking row %" SAL_PRIdINT32 " for height %d\n", nRow, nExpectedHeight );
int nHeight = sc::TwipsToHMM( pDoc->GetRowHeight(nRow, nTab, false) );
if ( bCheckOpt )
{
bool bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CR_MANUALSIZE);
CPPUNIT_ASSERT_EQUAL(aTestValues[ index ].pData[ i ].bOptimal, bOpt);
}
CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight);
}
}
xShell->DoClose();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -10,15 +10,11 @@
#ifndef SC_QA_HELPER_HXX
#define SC_QA_HELPER_HXX
#include <test/bootstrapfixture.hxx>
#define __ORCUS_STATIC_LIB
#include "helper/csv_handler.hxx"
#include "helper/debughelper.hxx"
#include "orcus/csv_parser.hpp"
#include <fstream>
#include <string>
#include <sstream>
#include "scdllapi.h"
#include "debughelper.hxx"
#include "csv_handler.hxx"
#include <test/bootstrapfixture.hxx>
#include <comphelper/documentconstants.hxx>
#include <osl/detail/android-bootstrap.h>
@ -26,6 +22,11 @@
#include <unotools/tempfile.hxx>
#include <comphelper/storagehelper.hxx>
#include <sfx2/docfilt.hxx>
#include "sfx2/docfile.hxx"
#include "svl/stritem.hxx"
#include <string>
#include <sstream>
#define ODS_FORMAT_TYPE 50331943
#define XLS_FORMAT_TYPE 318767171
@ -43,14 +44,7 @@
#define LOTUS123 5
#define DIF 6
bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol )
{
return ( labs( nVal1 - nVal2 ) <= nTol );
}
struct FileFormat {
const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType;
};
SC_DLLPUBLIC bool testEqualsWithTolerance( long nVal1, long nVal2, long nTol );
#define CHECK_OPTIMAL 0x1
@ -73,6 +67,10 @@ struct TestParam
RowData* pData;
};
struct FileFormat {
const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType;
};
FileFormat aFileFormats[] = {
{ "ods" , "calc8", "", ODS_FORMAT_TYPE },
{ "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
@ -89,35 +87,16 @@ FileFormat aFileFormats[] = {
// eventually perhaps iOS) special cases here, too)? Please move this to osl,
// it sure looks gemerally useful. Or am I missing something?
void loadFile(const OUString& aFileName, std::string& aContent)
{
OString aOFileName = OUStringToOString(aFileName, RTL_TEXTENCODING_UTF8);
SC_DLLPUBLIC void loadFile(const OUString& aFileName, std::string& aContent);
#ifdef ANDROID
size_t size;
if (strncmp(aOFileName.getStr(), "/assets/", sizeof("/assets/")-1) == 0) {
const char *contents = (const char *) lo_apkentry(aOFileName.getStr(), &size);
if (contents != 0) {
aContent = std::string(contents, size);
return;
}
}
#endif
SC_DLLPUBLIC void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, StringType aStringFormat = StringValue);
std::ifstream aFile(aOFileName.getStr());
OStringBuffer aErrorMsg("Could not open csv file: ");
aErrorMsg.append(aOFileName);
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), aFile);
std::ostringstream aOStream;
aOStream << aFile.rdbuf();
aFile.close();
aContent = aOStream.str();
}
//need own handler because conditional formatting strings must be generated
SC_DLLPUBLIC void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab);
std::string print(const ScAddress& rAddr)
{
std::stringstream str;
std::ostringstream str;
str << "Col: " << rAddr.Col();
str << " Row: " << rAddr.Row();
str << " Tab: " << rAddr.Tab();
@ -145,213 +124,38 @@ struct assertion_traits<ScRange>
}
class ScBootstrapFixture : public test::BootstrapFixture
class SC_DLLPUBLIC ScBootstrapFixture : public test::BootstrapFixture
{
protected:
OUString m_aBaseString;
ScDocShellRef load( bool bReadWrite,
const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID, sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL )
{
SfxFilter* pFilter = new SfxFilter(
rFilter,
OUString(), nFilterFlags, nClipboardID, rTypeName, 0, OUString(),
rUserData, OUString("private:factory/scalc*"));
pFilter->SetVersion(nFilterVersion);
ScDocShellRef xDocShRef = new ScDocShell;
xDocShRef->GetDocument()->EnableUserInteraction(false);
SfxMedium* pSrcMed = new SfxMedium(rURL, bReadWrite ? STREAM_STD_READWRITE : STREAM_STD_READ );
pSrcMed->SetFilter(pFilter);
pSrcMed->UseInteractionHandler(false);
if (pPassword)
{
SfxItemSet* pSet = pSrcMed->GetItemSet();
pSet->Put(SfxStringItem(SID_PASSWORD, *pPassword));
}
printf("about to load %s\n", OUStringToOString( rURL, RTL_TEXTENCODING_UTF8 ).getStr() );
if (!xDocShRef->DoLoad(pSrcMed))
{
xDocShRef->DoClose();
// load failed.
xDocShRef.Clear();
}
return xDocShRef;
}
ScDocShellRef load(
bool bReadWrite, const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
ScDocShellRef load(
const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID, sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL )
{
return load( false, rURL, rFilter, rUserData, rTypeName, nFilterFlags, nClipboardID, nFilterVersion, pPassword );
}
ScDocShellRef loadDoc(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite = false )
{
OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
OUString aFileName;
createFileURL( rFileName, aFileExtension, aFileName );
OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
unsigned int nFormatType = aFileFormats[nFormat].nFormatType;
unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
return load(bReadWrite, aFileName, aFilterName, OUString(), aFilterType, nFormatType, nClipboardId, nFormatType);
}
const OUString& rTypeName, unsigned int nFilterFlags, unsigned int nClipboardID,
sal_uIntPtr nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* pPassword = NULL );
ScDocShellRef loadDoc(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite = false );
public:
ScBootstrapFixture( const OUString& rsBaseString ) : m_aBaseString( rsBaseString ) {}
void createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath)
{
OUString aSep("/");
OUStringBuffer aBuffer( getSrcRootURL() );
aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
rFilePath = aBuffer.makeStringAndClear();
}
void createCSVPath(const OUString& aFileBase, OUString& rCSVPath)
{
OUStringBuffer aBuffer( getSrcRootPath());
aBuffer.append(m_aBaseString).append(OUString("/contentCSV/"));
aBuffer.append(aFileBase).append(OUString("csv"));
rCSVPath = aBuffer.makeStringAndClear();
}
void createFileURL(const OUString& aFileBase, const OUString& aFileExtension, OUString& rFilePath);
void createCSVPath(const OUString& aFileBase, OUString& rCSVPath);
ScDocShellRef saveAndReload(ScDocShell* pShell, const OUString &rFilter,
const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType)
{
const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType);
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
SfxMedium aStoreMedium( aTempFile.GetURL(), STREAM_STD_WRITE );
sal_uInt32 nExportFormat = 0;
if (nFormatType == ODS_FORMAT_TYPE)
nExportFormat = SFX_FILTER_EXPORT | SFX_FILTER_USESOPTIONS;
SfxFilter* pExportFilter = new SfxFilter(
rFilter,
OUString(), nFormatType, nExportFormat, rTypeName, 0, OUString(),
rUserData, OUString("private:factory/scalc*") );
pExportFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
aStoreMedium.SetFilter(pExportFilter);
pShell->DoSaveAs( aStoreMedium );
pShell->DoClose();
ScDocShellRef saveAndReload( ScDocShell* pShell, sal_Int32 nFormat );
//std::cout << "File: " << aTempFile.GetURL() << std::endl;
sal_uInt32 nFormat = 0;
if (nFormatType == ODS_FORMAT_TYPE)
nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
return load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat );
}
ScDocShellRef saveAndReload( ScDocShell* pShell, sal_Int32 nFormat )
{
OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
ScDocShellRef xDocSh = saveAndReload(pShell, aFilterName, OUString(), aFilterType, aFileFormats[nFormat].nFormatType);
CPPUNIT_ASSERT(xDocSh.Is());
return xDocSh;
}
void miscRowHeightsTest( TestParam* aTestValues, unsigned int numElems )
{
for ( unsigned int index=0; index<numElems; ++index )
{
OUString sFileName = OUString::createFromAscii( aTestValues[ index ].sTestDoc );
printf("aTestValues[%u] %s\n", index, OUStringToOString( sFileName, RTL_TEXTENCODING_UTF8 ).getStr() );
int nImportType = aTestValues[ index ].nImportType;
int nExportType = aTestValues[ index ].nExportType;
ScDocShellRef xShell = loadDoc( sFileName, nImportType );
CPPUNIT_ASSERT(xShell.Is());
if ( nExportType != -1 )
xShell = saveAndReload(&(*xShell), nExportType );
CPPUNIT_ASSERT(xShell.Is());
ScDocument* pDoc = xShell->GetDocument();
for (int i=0; i<aTestValues[ index ].nRowData; ++i)
{
SCROW nRow = aTestValues[ index ].pData[ i].nStartRow;
SCROW nEndRow = aTestValues[ index ].pData[ i ].nEndRow;
SCTAB nTab = aTestValues[ index ].pData[ i ].nTab;
int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight;
if ( nExpectedHeight == -1 )
nExpectedHeight = sc::TwipsToHMM( ScGlobal::nStdRowHeight );
bool bCheckOpt = ( ( aTestValues[ index ].pData[ i ].nCheck & CHECK_OPTIMAL ) == CHECK_OPTIMAL );
for ( ; nRow <= nEndRow; ++nRow )
{
printf("\t checking row %" SAL_PRIdINT32 " for height %d\n", nRow, nExpectedHeight );
int nHeight = sc::TwipsToHMM( pDoc->GetRowHeight(nRow, nTab, false) );
if ( bCheckOpt )
{
bool bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CR_MANUALSIZE);
CPPUNIT_ASSERT_EQUAL(aTestValues[ index ].pData[ i ].bOptimal, bOpt);
}
CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight);
}
}
xShell->DoClose();
}
}
void miscRowHeightsTest( TestParam* aTestValues, unsigned int numElems );
};
void testFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab, StringType aStringFormat = StringValue)
{
csv_handler aHandler(pDoc, nTab, aStringFormat);
orcus::csv_parser_config aConfig;
aConfig.delimiters.push_back(',');
aConfig.delimiters.push_back(';');
aConfig.text_qualifier = '"';
aConfig.trim_cell_value = false;
std::string aContent;
loadFile(aFileName, aContent);
orcus::csv_parser<csv_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
try
{
parser.parse();
}
catch (const orcus::csv_parse_error& e)
{
std::cout << "reading csv content file failed: " << e.what() << std::endl;
OStringBuffer aErrorMsg("csv parser error: ");
aErrorMsg.append(e.what());
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), false);
}
}
//need own handler because conditional formatting strings must be generated
void testCondFile(OUString& aFileName, ScDocument* pDoc, SCTAB nTab)
{
conditional_format_handler aHandler(pDoc, nTab);
orcus::csv_parser_config aConfig;
aConfig.delimiters.push_back(',');
aConfig.delimiters.push_back(';');
aConfig.text_qualifier = '"';
std::string aContent;
loadFile(aFileName, aContent);
orcus::csv_parser<conditional_format_handler> parser ( &aContent[0], aContent.size() , aHandler, aConfig);
try
{
parser.parse();
}
catch (const orcus::csv_parse_error& e)
{
std::cout << "reading csv content file failed: " << e.what() << std::endl;
OStringBuffer aErrorMsg("csv parser error: ");
aErrorMsg.append(e.what());
CPPUNIT_ASSERT_MESSAGE(aErrorMsg.getStr(), false);
}
}
#define ASSERT_DOUBLES_EQUAL( expected, result ) \
CPPUNIT_ASSERT_DOUBLES_EQUAL( (expected), (result), 1e-14 )

View File

@ -17,9 +17,6 @@
#include <sfx2/sfxmodelfactory.hxx>
#include <svl/stritem.hxx>
#define CALC_DEBUG_OUTPUT 0
#include "helper/qahelper.hxx"
#include "helper/shared_test_impl.hxx"

View File

@ -53,7 +53,6 @@
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/chart2/data/XDataReceiver.hpp>
#define CALC_DEBUG_OUTPUT 0
#define TEST_BUG_FILES 0
#include "helper/qahelper.hxx"

View File

@ -80,14 +80,8 @@
#include <sstream>
#include <vector>
#define CALC_DEBUG_OUTPUT 0
#define CALC_TEST_PERF 0
#include "helper/debughelper.hxx"
#include "helper/qahelper.hxx"
const int indeterminate = 2;
using namespace ::com::sun::star;
using ::std::cout;