diff options
-rw-r--r-- | sc/qa/unit/data/ods/password.ods | bin | 0 -> 10042 bytes | |||
-rw-r--r-- | sc/qa/unit/filters-test.cxx | 40 |
2 files changed, 40 insertions, 0 deletions
diff --git a/sc/qa/unit/data/ods/password.ods b/sc/qa/unit/data/ods/password.ods Binary files differnew file mode 100644 index 000000000000..28c5f4940a40 --- /dev/null +++ b/sc/qa/unit/data/ods/password.ods diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index b9e9e239218c..487ee2237009 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -38,6 +38,7 @@ #include <sfx2/docfile.hxx> #include <sfx2/sfxmodelfactory.hxx> #include <svl/intitem.hxx> +#include <svl/stritem.hxx> #include <editeng/brshitem.hxx> #include <editeng/justifyitem.hxx> @@ -174,6 +175,9 @@ public: void testBugFixesXLS(); void testBugFixesXLSX(); + //misc tests unrelated to the import filters + void testPassword(); + CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testCVEs); CPPUNIT_TEST(testRangeName); @@ -185,6 +189,7 @@ public: CPPUNIT_TEST(testBugFixesODS); CPPUNIT_TEST(testBugFixesXLS); CPPUNIT_TEST(testBugFixesXLSX); + //CPPUNIT_TEST(testPassword); CPPUNIT_TEST_SUITE_END(); @@ -612,6 +617,41 @@ void ScFiltersTest::testBugFixesXLSX() xDocSh->DoClose(); } +void ScFiltersTest::testPassword() +{ + const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("password.")); + rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 ); + rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ; + rtl::OUString aFileName; + createFileURL(aFileNameBase, aFileExtension, aFileName); + rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8); + std::cout << aFileFormats[0].pName << " Test" << std::endl; + + sal_uInt32 nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS; + SfxFilter* aFilter = new SfxFilter( + aFilterName, + rtl::OUString(), aFileFormats[0].nFormatType, nFormat, aFilterType, 0, rtl::OUString(), + rtl::OUString(), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc*")) ); + aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); + + ScDocShellRef xDocSh = new ScDocShell; + SfxMedium* pMedium = new SfxMedium(aFileName, STREAM_STD_READWRITE, true); + SfxItemSet* pSet = pMedium->GetItemSet(); + pSet->Put(SfxStringItem(SID_PASSWORD, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")))); + pMedium->SetFilter(aFilter); + if (!xDocSh->DoLoad(pMedium)) + { + xDocSh->DoClose(); + // load failed. + xDocSh.Clear(); + } + + CPPUNIT_ASSERT_MESSAGE("Failed to load password.ods", xDocSh.Is()); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test + xDocSh->DoClose(); +} + ScFiltersTest::ScFiltersTest() : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data")) { |