sc/qa/unit/filters-test.cxx            |   30 +++++++++++++++-
 sc/qa/unit/helper/qahelper.cxx         |   60 ---------------------------------
 sc/qa/unit/helper/qahelper.hxx         |   27 --------------
 sc/qa/unit/subsequent_filters_test.cxx |   10 ++---
 4 files changed, 35 insertions(+), 92 deletions(-)

New commits:
commit f150727f5df4afdaec13ffb9e80dfc8add9e268c
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Nov 24 12:02:52 2022 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Nov 24 15:39:02 2022 +0100

    ScBootstrapFixture: drop loadDoc and FileFormat
    
    also move createFileURL where is used
    Change-Id: I803706885a1efcb7239f7918fe6a94ccb394bcfe
    
    Change-Id: I2477cecf9ce93d104bd026a2e1d5d503bf6acf9f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143220
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index e539676f44a9..596be632595d 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -29,6 +29,7 @@
 
 #include <svx/svdpage.hxx>
 #include <tools/stream.hxx>
+#include <tools/urlobj.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -60,8 +61,25 @@ public:
     CPPUNIT_TEST(testTooManyColsRows);
 
     CPPUNIT_TEST_SUITE_END();
+
+private:
+    void createFileURL(std::u16string_view aFileBase, std::u16string_view 
aFileExtension, OUString& rFilePath);
 };
 
+void ScFiltersTest::createFileURL(
+    std::u16string_view aFileBase, std::u16string_view aFileExtension, 
OUString& rFilePath)
+{
+    // m_aBaseString and aFileBase may contain multiple segments, so use
+    // GetNewAbsURL instead of insertName for them:
+    INetURLObject url(m_directories.getSrcRootURL());
+    url.setFinalSlash();
+    url.GetNewAbsURL(m_aBaseString, &url);
+    url.insertName(aFileExtension, true);
+    url.GetNewAbsURL(OUString::Concat(aFileBase) + aFileExtension, &url);
+    rFilePath = url.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+}
+
+
 bool ScFiltersTest::load(const OUString &rFilter, const OUString &rURL,
     const OUString &rUserData, SfxFilterFlags nFilterFlags,
     SotClipboardFormatId nClipboardID, unsigned int nFilterVersion)
@@ -117,12 +135,20 @@ void ScFiltersTest::testTooManyColsRows()
 {
     // The intentionally doc has cells beyond our MAXROW/MAXCOL, so there
     // should be a warning on load.
-    ScDocShellRef xDocSh = loadDoc(u"too-many-cols-rows.", FORMAT_ODS, 
/*bCheckErrorCode*/ false);
+    OUString aFileName;
+    createFileURL(u"too-many-cols-rows.", u"ods", aFileName );
+    ScDocShellRef xDocSh = ScBootstrapFixture::load(aFileName, "calc8", 
OUString(), OUString(),
+            ODS_FORMAT_TYPE, SotClipboardFormatId::STARCALC_8);
+
     CPPUNIT_ASSERT(xDocSh->GetErrorCode() == SCWARN_IMPORT_ROW_OVERFLOW
                    || xDocSh->GetErrorCode() == SCWARN_IMPORT_COLUMN_OVERFLOW);
     xDocSh->DoClose();
 
-    xDocSh = loadDoc(u"too-many-cols-rows.", FORMAT_XLSX, /*bCheckErrorCode*/ 
false);
+    createFileURL(u"too-many-cols-rows.", u"xlsx", aFileName );
+    xDocSh = ScBootstrapFixture::load(
+            aFileName, "Calc Office Open XML", OUString(), OUString(),
+            XLSX_FORMAT_TYPE, SotClipboardFormatId::STARCALC_8);
+
     CPPUNIT_ASSERT(xDocSh->GetErrorCode() == SCWARN_IMPORT_ROW_OVERFLOW
                    || xDocSh->GetErrorCode() == SCWARN_IMPORT_COLUMN_OVERFLOW);
     xDocSh->DoClose();
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index e464646ea783..cbeaf9e8ac90 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -98,22 +98,6 @@ std::ostream& operator<<(std::ostream& rStrm, const OpCode& 
rCode)
     return rStrm;
 }
 
-const FileFormat ScBootstrapFixture::aFileFormats[] = {
-    { "ods" , "calc8", "", ODS_FORMAT_TYPE },
-    { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
-    { "xlsx", "Calc Office Open XML" , "Office Open XML Spreadsheet", 
XLSX_FORMAT_TYPE },
-    { "xlsm", "Calc Office Open XML" , "Office Open XML Spreadsheet", 
XLSX_FORMAT_TYPE },
-    { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE },
-    { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE },
-    { "123" , "Lotus", "calc_Lotus", LOTUS123_FORMAT_TYPE },
-    { "dif", "DIF", "calc_DIF", DIF_FORMAT_TYPE },
-    { "xml", "MS Excel 2003 XML Orcus", "calc_MS_Excel_2003_XML", 
XLS_XML_FORMAT_TYPE },
-    { "xlsb", "Calc MS Excel 2007 Binary", "MS Excel 2007 Binary", 
XLSB_XML_FORMAT_TYPE },
-    { "fods", "OpenDocument Spreadsheet Flat XML", "calc_ODS_FlatXML", 
FODS_FORMAT_TYPE },
-    { "gnumeric", "Gnumeric Spreadsheet", "Gnumeric XML", GNUMERIC_FORMAT_TYPE 
},
-    { "xltx", "Calc Office Open XML Template", "Office Open XML Spreadsheet 
Template", XLTX_FORMAT_TYPE }
-};
-
 void ScModelTestBase::loadFile(const OUString& aFileName, std::string& 
aContent)
 {
     OString aOFileName = OUStringToOString(aFileName, RTL_TEXTENCODING_UTF8);
@@ -489,7 +473,7 @@ OUString toString(
 ScDocShellRef ScBootstrapFixture::load(
     const OUString& rURL, const OUString& rFilter, const OUString &rUserData,
     const OUString& rTypeName, SfxFilterFlags nFilterFlags, 
SotClipboardFormatId nClipboardID,
-     sal_Int32 nFilterVersion, const OUString* pPassword )
+     sal_Int32 nFilterVersion )
 {
     auto pFilter = std::make_shared<SfxFilter>(
         rFilter,
@@ -503,10 +487,6 @@ ScDocShellRef ScBootstrapFixture::load(
     pSrcMed->SetFilter(pFilter);
     pSrcMed->UseInteractionHandler(false);
     SfxItemSet* pSet = pSrcMed->GetItemSet();
-    if (pPassword)
-    {
-        pSet->Put(SfxStringItem(SID_PASSWORD, *pPassword));
-    }
     
pSet->Put(SfxUInt16Item(SID_MACROEXECMODE,css::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN));
     SAL_INFO( "sc.qa", "about to load " << rURL );
     if (!xDocShRef->DoLoad(pSrcMed))
@@ -519,47 +499,9 @@ ScDocShellRef ScBootstrapFixture::load(
     return xDocShRef;
 }
 
-ScDocShellRef ScBootstrapFixture::loadDoc(
-    std::u16string_view rFileName, sal_Int32 nFormat, bool bCheckErrorCode )
-{
-    OUString aFileExtension = OUString::fromUtf8(aFileFormats[nFormat].pName);
-    OUString aFileName;
-    createFileURL( rFileName, aFileExtension, aFileName );
-
-    OUString aFilterName(aFileFormats[nFormat].pFilterName, 
strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
-    OUString aFilterType(aFileFormats[nFormat].pTypeName, 
strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
-    SfxFilterFlags nFormatType = aFileFormats[nFormat].nFormatType;
-    SotClipboardFormatId nClipboardId = SotClipboardFormatId::NONE;
-    if (nFormatType != SfxFilterFlags::NONE)
-        nClipboardId = SotClipboardFormatId::STARCALC_8;
-
-    ScDocShellRef xDocShRef = load(aFileName, aFilterName, OUString(), 
aFilterType, nFormatType, nClipboardId, static_cast<sal_uIntPtr>(nFormatType));
-    CPPUNIT_ASSERT_MESSAGE(OString("Failed to load " + 
OUStringToOString(rFileName, RTL_TEXTENCODING_UTF8)).getStr(), xDocShRef.is());
-
-    if (bCheckErrorCode)
-    {
-        CPPUNIT_ASSERT(!xDocShRef->GetErrorCode());
-    }
-
-    return xDocShRef;
-}
-
 ScBootstrapFixture::ScBootstrapFixture( const OUString& rsBaseString ) : 
m_aBaseString( rsBaseString ) {}
 ScBootstrapFixture::~ScBootstrapFixture() {}
 
-void ScBootstrapFixture::createFileURL(
-    std::u16string_view aFileBase, std::u16string_view aFileExtension, 
OUString& rFilePath)
-{
-    // m_aBaseString and aFileBase may contain multiple segments, so use
-    // GetNewAbsURL instead of insertName for them:
-    INetURLObject url(m_directories.getSrcRootURL());
-    url.setFinalSlash();
-    url.GetNewAbsURL(m_aBaseString, &url);
-    url.insertName(aFileExtension, true);
-    url.GetNewAbsURL(OUString::Concat(aFileBase) + aFileExtension, &url);
-    rFilePath = url.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-}
-
 void ScBootstrapFixture::setUp()
 {
     test::BootstrapFixture::setUp();
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index c828135ca01e..139c4ff6e89b 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -47,20 +47,6 @@ namespace utl { class TempFileNamed; }
 #define GNUMERIC_FORMAT_TYPE (SfxFilterFlags::IMPORT | SfxFilterFlags::ALIEN | 
SfxFilterFlags::PREFERED )
 #define XLTX_FORMAT_TYPE     (SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT 
| SfxFilterFlags::TEMPLATE |SfxFilterFlags::ALIEN | 
SfxFilterFlags::STARONEFILTER | SfxFilterFlags::PREFERED)
 
-#define FORMAT_ODS      0
-#define FORMAT_XLS      1
-#define FORMAT_XLSX     2
-#define FORMAT_XLSM     3
-#define FORMAT_CSV      4
-#define FORMAT_HTML     5
-#define FORMAT_LOTUS123 6
-#define FORMAT_DIF      7
-#define FORMAT_XLS_XML  8
-#define FORMAT_XLSB     9
-#define FORMAT_FODS     10
-#define FORMAT_GNUMERIC 11
-#define FORMAT_XLTX     12
-
 enum class StringType { PureString, StringValue };
 
 #define CHECK_OPTIMAL 0x1
@@ -94,10 +80,6 @@ struct RangeNameDef
     sal_uInt16 mnIndex;
 };
 
-struct FileFormat {
-    const char* pName; const char* pFilterName; const char* pTypeName; 
SfxFilterFlags nFormatType;
-};
-
 // Printers for the calc data structures. Needed for the EQUAL assertion
 // macros from CPPUNIT.
 
@@ -144,18 +126,13 @@ public:
 
 class SCQAHELPER_DLLPUBLIC ScBootstrapFixture : public test::BootstrapFixture
 {
-    static const FileFormat aFileFormats[];
 protected:
     OUString m_aBaseString;
 
     ScDocShellRef load(
         const OUString& rURL, const OUString& rFilter, const OUString 
&rUserData,
         const OUString& rTypeName, SfxFilterFlags nFilterFlags, 
SotClipboardFormatId nClipboardID,
-        sal_Int32 nFilterVersion = SOFFICE_FILEFORMAT_CURRENT, const OUString* 
pPassword = nullptr );
-
-    ScDocShellRef loadDoc(
-        std::u16string_view rFileName, sal_Int32 nFormat, bool bCheckErrorCode 
= true );
-
+        sal_Int32 nFilterVersion = SOFFICE_FILEFORMAT_CURRENT );
 private:
     // reference to document interface that we are testing
     css::uno::Reference<css::uno::XInterface> m_xCalcComponent;
@@ -163,8 +140,6 @@ public:
     explicit ScBootstrapFixture( const OUString& rsBaseString );
     virtual ~ScBootstrapFixture() override;
 
-    void createFileURL(std::u16string_view aFileBase, std::u16string_view 
aFileExtension, OUString& rFilePath);
-
     virtual void setUp() override;
     virtual void tearDown() override;
 };
diff --git a/sc/qa/unit/subsequent_filters_test.cxx 
b/sc/qa/unit/subsequent_filters_test.cxx
index f1dc06cce920..fd0aa159467b 100644
--- a/sc/qa/unit/subsequent_filters_test.cxx
+++ b/sc/qa/unit/subsequent_filters_test.cxx
@@ -1123,7 +1123,7 @@ void ScFiltersTest::testFormulaDepDeleteContentsODS()
 
 namespace
 {
-void testDBRanges_Impl(ScDocument& rDoc, sal_Int32 nFormat)
+void testDBRanges_Impl(ScDocument& rDoc, bool bIsODS)
 {
     ScDBCollection* pDBCollection = rDoc.GetDBCollection();
     CPPUNIT_ASSERT_MESSAGE("no database collection", pDBCollection);
@@ -1153,7 +1153,7 @@ void testDBRanges_Impl(ScDocument& rDoc, sal_Int32 
nFormat)
     CPPUNIT_ASSERT_MESSAGE("Sheet1: row 6-end should be visible", !bHidden);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet1: row 6-end should be visible", 
SCROW(6), nRow1);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet1: row 6-end should be visible", 
rDoc.MaxRow(), nRow2);
-    if (nFormat == FORMAT_ODS) //excel doesn't support named db ranges
+    if (bIsODS) //excel doesn't support named db ranges
     {
         double aValue = rDoc.GetValue(0, 10, 1);
         CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet2: A11: formula result is 
incorrect", 4.0, aValue);
@@ -1175,7 +1175,7 @@ void ScFiltersTest::testDatabaseRangesODS()
 
     ScDocument* pDoc = getScDoc();
 
-    testDBRanges_Impl(*pDoc, FORMAT_ODS);
+    testDBRanges_Impl(*pDoc, true);
 }
 
 void ScFiltersTest::testDatabaseRangesXLS()
@@ -1186,7 +1186,7 @@ void ScFiltersTest::testDatabaseRangesXLS()
 
     ScDocument* pDoc = getScDoc();
 
-    testDBRanges_Impl(*pDoc, FORMAT_XLS);
+    testDBRanges_Impl(*pDoc, false);
 }
 
 void ScFiltersTest::testDatabaseRangesXLSX()
@@ -1197,7 +1197,7 @@ void ScFiltersTest::testDatabaseRangesXLSX()
 
     ScDocument* pDoc = getScDoc();
 
-    testDBRanges_Impl(*pDoc, FORMAT_XLSX);
+    testDBRanges_Impl(*pDoc, false);
 }
 
 void ScFiltersTest::testFormatsODS()

Reply via email to