/* -*- 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/.
*/
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::OFOPXML)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
try
{
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
} catch (css::packages::zip::ZipIOException const&)
{ // check that this doesn't crash, it doesn't matter if it succeeds or not
}
}
// unclear if this should be allowed?
CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
ZipPackage, args, m_xContext),
css::packages::zip::ZipIOException);
// recovery should work
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
};
m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2,
m_xContext);
}
// don't load zip file with DD on directory
CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
ZipPackage, args, m_xContext),
css::packages::zip::ZipIOException);
// recovery should work
uno::Sequence<uno::Any> const args2{
uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::PACKAGE)))
};
CPPUNIT_ASSERT(xZip.is());
uno::Reference<beans::XPropertySet> xStream{ xZip->getByHierarchicalName(u"manifest.rdf"_ustr),
uno::UNO_QUERY };
CPPUNIT_ASSERT(xStream.is()); // check that the size was recovered from data descriptor
CPPUNIT_ASSERT_EQUAL(sal_Int64(899), xStream->getPropertyValue(u"Size"_ustr).get<sal_Int64>());
}
CPPUNIT_TEST_FIXTURE(ZipPackageTest, testTdf166862)
{ // This package is broken; but the actual issue was incorrect CRC calculation for an image
OUString aURL = m_directories.getURLFromSrc(u"/package/qa/cppunit/data/tdf166862.odt");
uno::Sequence<uno::Any> args{ uno::Any(aURL), uno::Any(beans::NamedValue{ u"RepairPackage"_ustr,
uno::Any(true) }) };
auto xMgr = m_xContext->getServiceManager();
auto xZip(xMgr->createInstanceWithArgumentsAndContext(ZipPackage, args, m_xContext)
.queryThrow<container::XHierarchicalNameAccess>()); static constexpr OUString picURL = u"Pictures/1000000000000596000000AE0BDDB537.jpg"_ustr;
CPPUNIT_ASSERT(xZip->hasByHierarchicalName(picURL)); auto aPic = xZip->getByHierarchicalName(picURL).queryThrow<beans::XPropertySet>(); // Before the fix, this was 0: the size was reset because of unmatched CRC
CPPUNIT_ASSERT_EQUAL(sal_Int64(43886), aPic->getPropertyValue(u"Size"_ustr).get<sal_Int64>());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.