From 4d2bb795820ef30f230605194207a3bd50299127 Mon Sep 17 00:00:00 2001 From: Guillaume Smaha Date: Mon, 25 Apr 2016 18:39:27 +0200 Subject: Unit test for tdf#96097: Can't save/pointer null Change-Id: I56af30142bba8579ca7f24bbbb2d12390832051b Reviewed-on: https://gerrit.libreoffice.org/24372 Tested-by: Jenkins Reviewed-by: jan iversen --- xmlsecurity/qa/unit/signing/data/tdf96097.ods | Bin 0 -> 13767 bytes xmlsecurity/qa/unit/signing/data/tdf96097.odt | Bin 0 -> 11791 bytes xmlsecurity/qa/unit/signing/signing.cxx | 111 ++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 xmlsecurity/qa/unit/signing/data/tdf96097.ods create mode 100644 xmlsecurity/qa/unit/signing/data/tdf96097.odt diff --git a/xmlsecurity/qa/unit/signing/data/tdf96097.ods b/xmlsecurity/qa/unit/signing/data/tdf96097.ods new file mode 100644 index 000000000000..58d1b2c771de Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/tdf96097.ods differ diff --git a/xmlsecurity/qa/unit/signing/data/tdf96097.odt b/xmlsecurity/qa/unit/signing/data/tdf96097.odt new file mode 100644 index 000000000000..f0356513c389 Binary files /dev/null and b/xmlsecurity/qa/unit/signing/data/tdf96097.odt differ diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index 83fdd8d8aa5f..45308d218b3a 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -76,6 +76,8 @@ public: void testOOXMLRemove(); /// Test removing all signatures from a document. void testOOXMLRemoveAll(); + void test96097Calc(); + void test96097Doc(); CPPUNIT_TEST_SUITE(SigningTest); CPPUNIT_TEST(testDescription); @@ -88,10 +90,13 @@ public: CPPUNIT_TEST(testOOXMLAppend); CPPUNIT_TEST(testOOXMLRemove); CPPUNIT_TEST(testOOXMLRemoveAll); + CPPUNIT_TEST(test96097Calc); + CPPUNIT_TEST(test96097Doc); CPPUNIT_TEST_SUITE_END(); private: void createDoc(const OUString& rURL = OUString()); + void createCalc(const OUString& rURL = OUString()); uno::Reference getCertificate(XMLSignatureHelper& rSignatureHelper); }; @@ -125,6 +130,16 @@ void SigningTest::createDoc(const OUString& rURL) mxComponent = loadFromDesktop(rURL, "com.sun.star.text.TextDocument"); } +void SigningTest::createCalc(const OUString& rURL) +{ + if (mxComponent.is()) + mxComponent->dispose(); + if (rURL.isEmpty()) + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.sheet.SpreadsheetDocument"); + else + mxComponent = loadFromDesktop(rURL, "com.sun.star.sheet.SpreadsheetDocument"); +} + uno::Reference SigningTest::getCertificate(XMLSignatureHelper& rSignatureHelper) { uno::Reference xSecurityEnvironment = rSignatureHelper.GetSecurityEnvironment(); @@ -364,6 +379,102 @@ void SigningTest::testOOXMLBroken() CPPUNIT_ASSERT_EQUAL(static_cast(SignatureState::BROKEN), static_cast(pObjectShell->GetDocumentSignatureState())); } +void SigningTest::test96097Calc() +{ + createCalc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.ods"); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT_MESSAGE("Failed to access document base model", pBaseModel); + + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pObjectShell); + + SignatureState nActual = pObjectShell->GetScriptingSignatureState(); + CPPUNIT_ASSERT_MESSAGE( + (OString::number( + static_cast::type>(nActual)) + .getStr()), + (nActual == SignatureState::OK + || nActual == SignatureState::NOTVALIDATED + || nActual == SignatureState::INVALID)); + + + uno::Reference xDocStorable(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + // Save a copy + utl::TempFile aTempFileSaveCopy; + aTempFileSaveCopy.EnableKillingFile(); + uno::Sequence descSaveACopy(2); + descSaveACopy[0].Name = "SaveACopy"; + descSaveACopy[0].Value <<= uno::makeAny(true); + descSaveACopy[1].Name = "FilterName"; + descSaveACopy[1].Value <<= OUString("calc8"); + xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy); + + try + { + // Save As + utl::TempFile aTempFileSaveAs; + aTempFileSaveAs.EnableKillingFile(); + uno::Sequence descSaveAs(1); + descSaveAs[0].Name = "FilterName"; + descSaveAs[0].Value <<= OUString("calc8"); + xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs); + } + catch(...) + { + CPPUNIT_FAIL("Fail to save as the document"); + } +} + +void SigningTest::test96097Doc() +{ + createDoc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.odt"); + SfxBaseModel* pBaseModel = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pBaseModel); + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + CPPUNIT_ASSERT(pObjectShell); + + SignatureState nActual = pObjectShell->GetScriptingSignatureState(); + CPPUNIT_ASSERT_MESSAGE( + (OString::number( + static_cast::type>(nActual)) + .getStr()), + (nActual == SignatureState::OK + || nActual == SignatureState::NOTVALIDATED + || nActual == SignatureState::INVALID)); + + + + uno::Reference xDocStorable(mxComponent, uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + // Save a copy + utl::TempFile aTempFileSaveCopy; + aTempFileSaveCopy.EnableKillingFile(); + uno::Sequence descSaveACopy(2); + descSaveACopy[0].Name = "SaveACopy"; + descSaveACopy[0].Value <<= uno::makeAny(true); + descSaveACopy[1].Name = "FilterName"; + descSaveACopy[1].Value <<= OUString("writer8"); + xDocStorable->storeToURL(aTempFileSaveCopy.GetURL(), descSaveACopy); + + try + { + // Save As + utl::TempFile aTempFileSaveAs; + aTempFileSaveAs.EnableKillingFile(); + uno::Sequence descSaveAs(1); + descSaveAs[0].Name = "FilterName"; + descSaveAs[0].Value <<= OUString("writer8"); + xDocStorable->storeAsURL(aTempFileSaveAs.GetURL(), descSaveAs); + } + catch(...) + { + CPPUNIT_FAIL("Fail to save as the document"); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(SigningTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit