[Libreoffice-commits] core.git: xmlsecurity/qa
Guillaume Smaha
guillaume.smaha at gmail.com
Thu Apr 28 07:20:26 UTC 2016
xmlsecurity/qa/unit/signing/data/tdf96097.ods |binary
xmlsecurity/qa/unit/signing/data/tdf96097.odt |binary
xmlsecurity/qa/unit/signing/signing.cxx | 111 ++++++++++++++++++++++++++
3 files changed, 111 insertions(+)
New commits:
commit 4d2bb795820ef30f230605194207a3bd50299127
Author: Guillaume Smaha <guillaume.smaha at gmail.com>
Date: Mon Apr 25 18:39:27 2016 +0200
Unit test for tdf#96097: Can't save/pointer null
Change-Id: I56af30142bba8579ca7f24bbbb2d12390832051b
Reviewed-on: https://gerrit.libreoffice.org/24372
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: jan iversen <jani at documentfoundation.org>
diff --git a/xmlsecurity/qa/unit/signing/data/tdf96097.ods b/xmlsecurity/qa/unit/signing/data/tdf96097.ods
new file mode 100644
index 0000000..58d1b2c
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 0000000..f035651
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 83fdd8d8..45308d2 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<security::XCertificate> 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<security::XCertificate> SigningTest::getCertificate(XMLSignatureHelper& rSignatureHelper)
{
uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = rSignatureHelper.GetSecurityEnvironment();
@@ -364,6 +379,102 @@ void SigningTest::testOOXMLBroken()
CPPUNIT_ASSERT_EQUAL(static_cast<int>(SignatureState::BROKEN), static_cast<int>(pObjectShell->GetDocumentSignatureState()));
}
+void SigningTest::test96097Calc()
+{
+ createCalc(m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf96097.ods");
+ SfxBaseModel* pBaseModel = dynamic_cast<SfxBaseModel*>(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<std::underlying_type<SignatureState>::type>(nActual))
+ .getStr()),
+ (nActual == SignatureState::OK
+ || nActual == SignatureState::NOTVALIDATED
+ || nActual == SignatureState::INVALID));
+
+
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDocStorable.is());
+
+ // Save a copy
+ utl::TempFile aTempFileSaveCopy;
+ aTempFileSaveCopy.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> 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<beans::PropertyValue> 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<SfxBaseModel*>(mxComponent.get());
+ CPPUNIT_ASSERT(pBaseModel);
+ SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
+ CPPUNIT_ASSERT(pObjectShell);
+
+ SignatureState nActual = pObjectShell->GetScriptingSignatureState();
+ CPPUNIT_ASSERT_MESSAGE(
+ (OString::number(
+ static_cast<std::underlying_type<SignatureState>::type>(nActual))
+ .getStr()),
+ (nActual == SignatureState::OK
+ || nActual == SignatureState::NOTVALIDATED
+ || nActual == SignatureState::INVALID));
+
+
+
+ uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xDocStorable.is());
+
+ // Save a copy
+ utl::TempFile aTempFileSaveCopy;
+ aTempFileSaveCopy.EnableKillingFile();
+ uno::Sequence<beans::PropertyValue> 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<beans::PropertyValue> 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();
More information about the Libreoffice-commits
mailing list