extensions/CppunitTest_extensions_test_update.mk | 25 +++++ extensions/qa/update/simple.xml | 10 ++ extensions/qa/update/test_update.cxx | 94 ++++++++++++++++++---- extensions/source/update/check/updateprotocol.cxx | 27 +++++- extensions/source/update/check/updateprotocol.hxx | 14 +++ extensions/source/update/feed/makefile.mk | 1 extensions/source/update/feed/updatefeed.cxx | 68 +++------------ 7 files changed, 164 insertions(+), 75 deletions(-)
New commits: commit cb937da55c3ab3d238b97d6e0e709ea2a04d2c26 Author: Jan Holesovsky <ke...@suse.cz> Date: Wed Nov 30 00:11:01 2011 +0100 online update: Now check even the checkForUpdates(). diff --git a/extensions/qa/update/test_update.cxx b/extensions/qa/update/test_update.cxx index 57ff71c..84cbc4f 100644 --- a/extensions/qa/update/test_update.cxx +++ b/extensions/qa/update/test_update.cxx @@ -128,14 +128,14 @@ protected: rtl::Reference< UpdateCheck > aController( UpdateCheck::get() ); if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider, - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OS" ) ), - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Arch" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Linux" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "x86" ) ), m_aRepositoryList, - rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BuildID" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "100" ) ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InstallSetID" ) ) ) ) { - //aController->setUpdateInfo( aInfo ); - // TODO check the result + CPPUNIT_ASSERT( aInfo.Sources.size() == 1 ); + CPPUNIT_ASSERT( aInfo.Sources[0].URL == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "http://www.libreoffice.org/download/" ) ) ); } else CPPUNIT_FAIL( "Calling checkForUpdates() failed." ); commit 358ce1e9c1d85ae7590ecc2b2ddee9db81cf8b84 Author: Jan Holesovsky <ke...@suse.cz> Date: Tue Nov 29 22:48:29 2011 +0100 online update: Cleanup after UpdateInformationProvider::load() rewrite. diff --git a/extensions/source/update/feed/updatefeed.cxx b/extensions/source/update/feed/updatefeed.cxx index f5caafc..21bfecf 100644 --- a/extensions/source/update/feed/updatefeed.cxx +++ b/extensions/source/update/feed/updatefeed.cxx @@ -210,15 +210,11 @@ private: uno::Reference< ucb::XCommandProcessor > const & rxCommandProcessor); UpdateInformationProvider(const uno::Reference<uno::XComponentContext>& xContext, - const uno::Reference< ucb::XContentIdentifierFactory >& xContentIdFactory, - const uno::Reference< ucb::XContentProvider >& xContentProvider, const uno::Reference< xml::dom::XDocumentBuilder >& xDocumentBuilder, const uno::Reference< xml::xpath::XXPathAPI >& xXPathAPI); const uno::Reference< uno::XComponentContext> m_xContext; - const uno::Reference< ucb::XContentIdentifierFactory > m_xContentIdFactory; - const uno::Reference< ucb::XContentProvider > m_xContentProvider; const uno::Reference< xml::dom::XDocumentBuilder > m_xDocumentBuilder; const uno::Reference< xml::xpath::XXPathAPI > m_xXPathAPI; @@ -331,12 +327,10 @@ private: UpdateInformationProvider::UpdateInformationProvider( const uno::Reference<uno::XComponentContext>& xContext, - const uno::Reference< ucb::XContentIdentifierFactory >& xContentIdFactory, - const uno::Reference< ucb::XContentProvider >& xContentProvider, const uno::Reference< xml::dom::XDocumentBuilder >& xDocumentBuilder, const uno::Reference< xml::xpath::XXPathAPI >& xXPathAPI -) : m_xContext(xContext), m_xContentIdFactory(xContentIdFactory), - m_xContentProvider(xContentProvider), m_xDocumentBuilder(xDocumentBuilder), +) : m_xContext(xContext), + m_xDocumentBuilder(xDocumentBuilder), m_xXPathAPI(xXPathAPI), m_aRequestHeaderList(1) { uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider( @@ -410,12 +404,6 @@ UpdateInformationProvider::createInstance(const uno::Reference<uno::XComponentCo UNISTRING( "unable to obtain service manager from component context" ), uno::Reference< uno::XInterface > ()); - uno::Reference< ucb::XContentIdentifierFactory > xContentIdFactory( - xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.ucb.UniversalContentBroker" ), xContext ), - uno::UNO_QUERY_THROW); - - uno::Reference< ucb::XContentProvider > xContentProvider(xContentIdFactory, uno::UNO_QUERY_THROW); - uno::Reference< xml::dom::XDocumentBuilder > xDocumentBuilder( xServiceManager->createInstanceWithContext( UNISTRING( "com.sun.star.xml.dom.DocumentBuilder" ), xContext ), uno::UNO_QUERY_THROW); @@ -426,7 +414,7 @@ UpdateInformationProvider::createInstance(const uno::Reference<uno::XComponentCo xXPath->registerNS( UNISTRING("atom"), UNISTRING("http://www.w3.org/2005/Atom") ); - return *new UpdateInformationProvider(xContext, xContentIdFactory, xContentProvider, xDocumentBuilder, xXPath); + return *new UpdateInformationProvider(xContext, xDocumentBuilder, xXPath); } //------------------------------------------------------------------------------ commit b87fa222f1cc58e17b57fe5ef08438520976faae Author: Jan Holesovsky <ke...@suse.cz> Date: Tue Nov 29 21:52:43 2011 +0100 online update: Unit testing framework + rewrite of load(). - introduce first two basic tests (to be improved) - rewrite of UpdateInformationProvider::load() to use comphelper - smaller splitting of functions to be able to unit test diff --git a/extensions/CppunitTest_extensions_test_update.mk b/extensions/CppunitTest_extensions_test_update.mk index ebd86b4..b864a15 100644 --- a/extensions/CppunitTest_extensions_test_update.mk +++ b/extensions/CppunitTest_extensions_test_update.mk @@ -42,6 +42,8 @@ $(eval $(call gb_CppunitTest_add_linked_libs,extensions_test_update, \ cppuhelper \ curl \ sal \ + test \ + unotest \ $(gb_STDLIBS) \ )) @@ -69,6 +71,7 @@ $(eval $(call gb_CppunitTest_add_components,extensions_test_update,\ $(eval $(call gb_CppunitTest_add_old_components,extensions_test_update,\ configmgr \ ucb1 \ + ucpfile1 \ updatefeed \ )) diff --git a/extensions/qa/update/simple.xml b/extensions/qa/update/simple.xml new file mode 100644 index 0000000..6a6af12 --- /dev/null +++ b/extensions/qa/update/simple.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<inst:description xmlns:inst="http://update.libreoffice.org/description"> + <inst:id>LibreOffice_3.4</inst:id> + <inst:version>3.4.2</inst:version> + <inst:buildid>102</inst:buildid> + <inst:os>Linux</inst:os> + <inst:arch>x86</inst:arch> + + <inst:update type="text/html" src="http://www.libreoffice.org/download/" /> +</inst:description> diff --git a/extensions/qa/update/test_update.cxx b/extensions/qa/update/test_update.cxx index d699da9..57ff71c 100644 --- a/extensions/qa/update/test_update.cxx +++ b/extensions/qa/update/test_update.cxx @@ -27,6 +27,7 @@ #include <sal/config.h> #include <sal/precppunit.hxx> +#include <test/bootstrapfixture.hxx> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> @@ -35,7 +36,9 @@ #include <cppuhelper/bootstrap.hxx> +#include <com/sun/star/deployment/UpdateInformationEntry.hpp> #include <com/sun/star/deployment/UpdateInformationProvider.hpp> +#include <com/sun/star/xml/dom/XNodeList.hpp> #include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/uno/XComponentContext.hpp> @@ -43,50 +46,111 @@ #include "../../source/update/check/updateprotocol.hxx" using namespace com::sun::star; +using namespace com::sun::star::xml; namespace testupdate { -class Test : public CppUnit::TestFixture +class Test : public test::BootstrapFixture { public: - void setUp() + virtual void setUp() { - if (!m_xContext.is()) - m_xContext = cppu::defaultBootstrap_InitialComponentContext(); + // so that comphelper::getProcessServiceFactory() works, m_xContext is + // set up, etc. + test::BootstrapFixture::setUp(); + + if ( !m_xProvider.is() ) + m_xProvider = deployment::UpdateInformationProvider::create( m_xContext ); + + // repositories that we will be checking + m_aRepositoryList.realloc( 1 ); + m_aRepositoryList[0] = getURLFromSrc( "/extensions/qa/update/simple.xml" ); } - void tearDown() + virtual void tearDown() { - uno::Reference< lang::XComponent >( m_xContext, uno::UNO_QUERY_THROW)->dispose(); + m_xProvider.clear(); + m_aRepositoryList.realloc( 0 ); + test::BootstrapFixture::tearDown(); } protected: + // test the getUpdateInformationEnumeration() method + void testGetUpdateInformationEnumeration() + { + ::rtl::OUString aInstallSetID( RTL_CONSTASCII_USTRINGPARAM( "TODO" ) ); // unused when we do not have a 'feed' + + uno::Reference< container::XEnumeration > aUpdateInfoEnumeration = + m_xProvider->getUpdateInformationEnumeration( m_aRepositoryList, aInstallSetID ); + + if ( !aUpdateInfoEnumeration.is() ) + CPPUNIT_FAIL( "Calling getUpdateInformationEnumeration() with TODO failed." ); + + if ( !aUpdateInfoEnumeration->hasMoreElements() ) + CPPUNIT_FAIL( "Should have more elements (this one is 1st)." ); + + deployment::UpdateInformationEntry aEntry; + if ( aUpdateInfoEnumeration->nextElement() >>= aEntry ) + { + CPPUNIT_ASSERT( aEntry.UpdateDocument->getNodeName() == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "description" ) ) ); + + uno::Reference< dom::XNodeList> xChildNodes = aEntry.UpdateDocument->getChildNodes(); + CPPUNIT_ASSERT( xChildNodes.is() ); +#if 0 + for ( int i = 0; i < xChildNodes->getLength(); ++i ) + { + fprintf( stderr, "node == %d\n", i ); + uno::Reference< dom::XElement > xChildId( xChildNodes->item( i ), uno::UNO_QUERY ); + if ( xChildId.is() ) + { + fprintf( stderr, "Name == %s\n", rtl::OUStringToOString( xChildId->getNodeName(), RTL_TEXTENCODING_UTF8 ).getStr() ); + fprintf( stderr, "Value == %s\n", rtl::OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() ); + } + } +#endif + CPPUNIT_ASSERT( xChildNodes->getLength() == 13 ); + + //uno::Reference< dom::XElement > xChildId( xChildNodes->item( 0 ), uno::UNO_QUERY ); + //CPPUNIT_ASSERT( xChildId.is() ); + //CPPUNIT_ASSERT( xChildId->getNodeValue() == rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LibreOffice_3.4" ) ) ); + //fprintf( stderr, "Attribute == %s\n", rtl::OUStringToOString( aEntry.UpdateDocument->getAttribute( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "test" ) ) ), RTL_TEXTENCODING_UTF8 ).getStr() ); + //fprintf( stderr, "Value == %s\n", rtl::OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() ); + // TODO check more deeply + } + else + CPPUNIT_FAIL( "Wrong type of the entry." ); + } + // test the checkForUpdates() method void testCheckForUpdates() { - UpdateInfo aInfo; rtl::Reference< UpdateCheck > aController( UpdateCheck::get() ); - uno::Reference< deployment::XUpdateInformationProvider > m_xProvider( deployment::UpdateInformationProvider::create( m_xContext ) ); - if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider ) ) + if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider, + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OS" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Arch" ) ), + m_aRepositoryList, + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BuildID" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InstallSetID" ) ) ) ) { - aController->setUpdateInfo( aInfo ); + //aController->setUpdateInfo( aInfo ); + // TODO check the result } else - CPPUNIT_FAIL("Calling checkForUpdates() failed."); + CPPUNIT_FAIL( "Calling checkForUpdates() failed." ); } CPPUNIT_TEST_SUITE(Test); - // FIXME CPPUNIT_TEST(testCheckForUpdates); + CPPUNIT_TEST(testGetUpdateInformationEnumeration); + CPPUNIT_TEST(testCheckForUpdates); CPPUNIT_TEST_SUITE_END(); private: - static uno::Reference< uno::XComponentContext > m_xContext; + uno::Reference< deployment::XUpdateInformationProvider > m_xProvider; + uno::Sequence< rtl::OUString > m_aRepositoryList; }; -uno::Reference< uno::XComponentContext > Test::m_xContext; - CPPUNIT_TEST_SUITE_REGISTRATION(testupdate::Test); } // namespace testupdate diff --git a/extensions/source/update/check/updateprotocol.cxx b/extensions/source/update/check/updateprotocol.cxx index cf86410..bbe5494 100644 --- a/extensions/source/update/check/updateprotocol.cxx +++ b/extensions/source/update/check/updateprotocol.cxx @@ -109,6 +109,23 @@ checkForUpdates( if( ! ( getBootstrapData(aRepositoryList, aBuildID, aInstallSetID) && (aRepositoryList.getLength() > 0) ) ) return false; + return checkForUpdates( o_rUpdateInfo, rxContext, rxInteractionHandler, rUpdateInfoProvider, + myOS, myArch, + aRepositoryList, aBuildID, aInstallSetID ); +} + +bool +checkForUpdates( + UpdateInfo& o_rUpdateInfo, + const uno::Reference< uno::XComponentContext > & rxContext, + const uno::Reference< task::XInteractionHandler > & rxInteractionHandler, + const uno::Reference< deployment::XUpdateInformationProvider >& rUpdateInfoProvider, + const rtl::OUString &rOS, + const rtl::OUString &rArch, + const uno::Sequence< rtl::OUString > &rRepositoryList, + const rtl::OUString &rBuildID, + const rtl::OUString &rInstallSetID ) +{ if( !rxContext.is() ) throw uno::RuntimeException( UNISTRING( "checkForUpdates: empty component context" ), uno::Reference< uno::XInterface >() ); @@ -120,7 +137,7 @@ checkForUpdates( rxContext->getServiceManager()->createInstanceWithContext( UNISTRING( "com.sun.star.xml.xpath.XPathAPI" ), rxContext ), uno::UNO_QUERY_THROW); - xXPath->registerNS( UNISTRING("inst"), UNISTRING("http://installation.openoffice.org/description") ); + xXPath->registerNS( UNISTRING("inst"), UNISTRING("http://update.libreoffice.org/description") ); if( rxInteractionHandler.is() ) rUpdateInfoProvider->setInteractionHandler(rxInteractionHandler); @@ -128,18 +145,18 @@ checkForUpdates( try { uno::Reference< container::XEnumeration > aUpdateInfoEnumeration = - rUpdateInfoProvider->getUpdateInformationEnumeration( aRepositoryList, aInstallSetID ); + rUpdateInfoProvider->getUpdateInformationEnumeration( rRepositoryList, rInstallSetID ); if ( !aUpdateInfoEnumeration.is() ) return false; // something went wrong .. rtl::OUStringBuffer aBuffer; aBuffer.appendAscii("/child::inst:description[inst:os=\'"); - aBuffer.append( myOS ); + aBuffer.append( rOS ); aBuffer.appendAscii("\' and inst:arch=\'"); - aBuffer.append( myArch ); + aBuffer.append( rArch ); aBuffer.appendAscii("\' and inst:buildid>"); - aBuffer.append( aBuildID ); + aBuffer.append( rBuildID ); aBuffer.appendAscii("]"); rtl::OUString aXPathExpression = aBuffer.makeStringAndClear(); diff --git a/extensions/source/update/check/updateprotocol.hxx b/extensions/source/update/check/updateprotocol.hxx index ef7d150..9488373 100644 --- a/extensions/source/update/check/updateprotocol.hxx +++ b/extensions/source/update/check/updateprotocol.hxx @@ -41,6 +41,20 @@ bool checkForUpdates( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XUpdateInformationProvider >& rxProvider ); +// The same as above, that does not read the info from bootstrap +bool +checkForUpdates( + UpdateInfo& o_rUpdateInfo, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & rxContext, + const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > & rxInteractionHandler, + const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XUpdateInformationProvider >& rUpdateInfoProvider, + const rtl::OUString &rOS, + const rtl::OUString &rArch, + const ::com::sun::star::uno::Sequence< rtl::OUString > &rRepositoryList, + const rtl::OUString &rBuildID, + const rtl::OUString &rInstallID +); + // Returns 'true' if there are updates for any extension bool checkForExtensionUpdates( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext diff --git a/extensions/source/update/feed/makefile.mk b/extensions/source/update/feed/makefile.mk index 6361f20..496842d 100644 --- a/extensions/source/update/feed/makefile.mk +++ b/extensions/source/update/feed/makefile.mk @@ -50,6 +50,7 @@ SHL1OBJS=$(SLOFILES) SHL1IMPLIB=i$(SHL1TARGET) SHL1STDLIBS= \ + $(COMPHELPERLIB) \ $(CPPUHELPERLIB) \ $(CPPULIB) \ $(SALLIB) diff --git a/extensions/source/update/feed/updatefeed.cxx b/extensions/source/update/feed/updatefeed.cxx index 42a7301..f5caafc 100644 --- a/extensions/source/update/feed/updatefeed.cxx +++ b/extensions/source/update/feed/updatefeed.cxx @@ -27,10 +27,12 @@ ************************************************************************/ +#include <comphelper/mediadescriptor.hxx> #include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase4.hxx> #include <cppuhelper/implementationentry.hxx> #include <com/sun/star/beans/Property.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/configuration/theDefaultProvider.hpp> @@ -472,49 +474,17 @@ UpdateInformationProvider::storeCommandInfo( uno::Reference< io::XInputStream > UpdateInformationProvider::load(const rtl::OUString& rURL) { - uno::Reference< ucb::XContentIdentifier > xId = m_xContentIdFactory->createContentIdentifier(rURL); + beans::PropertyValue aURLValue; + aURLValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); + aURLValue.Value <<= rURL; - if( !xId.is() ) - throw uno::RuntimeException( - UNISTRING( "unable to obtain universal content id" ), *this); - - uno::Reference< ucb::XCommandProcessor > xCommandProcessor(m_xContentProvider->queryContent(xId), uno::UNO_QUERY_THROW); - rtl::Reference< ActiveDataSink > aSink(new ActiveDataSink()); - - ucb::OpenCommandArgument2 aOpenArgument; - aOpenArgument.Mode = ucb::OpenMode::DOCUMENT; - aOpenArgument.Priority = 32768; - aOpenArgument.Sink = *aSink; - - ucb::Command aCommand; - aCommand.Name = UNISTRING("open"); - aCommand.Argument = uno::makeAny(aOpenArgument); - - sal_Int32 nCommandId = xCommandProcessor->createCommandIdentifier(); - - storeCommandInfo(nCommandId, xCommandProcessor); - try - { - uno::Any aResult = xCommandProcessor->execute(aCommand, nCommandId, - static_cast < XCommandEnvironment *> (this)); - } - catch( const uno::Exception & /* e */ ) - { - storeCommandInfo(0, uno::Reference< ucb::XCommandProcessor > ()); - - uno::Reference< ucb::XCommandProcessor2 > xCommandProcessor2(xCommandProcessor, uno::UNO_QUERY); - if( xCommandProcessor2.is() ) - xCommandProcessor2->releaseCommandIdentifier(nCommandId); - - throw; - } - storeCommandInfo(0, uno::Reference< ucb::XCommandProcessor > ()); + uno::Sequence< beans::PropertyValue > aValues( 1 ); + aValues[0] = aURLValue; - uno::Reference< ucb::XCommandProcessor2 > xCommandProcessor2(xCommandProcessor, uno::UNO_QUERY); - if( xCommandProcessor2.is() ) - xCommandProcessor2->releaseCommandIdentifier(nCommandId); + ::comphelper::MediaDescriptor aMediaDesc( aValues ); + aMediaDesc.addInputStream(); - return INPUT_STREAM(aSink->getInputStream()); + return aMediaDesc.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_INPUTSTREAM(), uno::Reference< io::XInputStream >() ); } //------------------------------------------------------------------------------ commit 4432a44e75c2ead9b226838014a480d68f7900e9 Author: Jan Holesovsky <ke...@suse.cz> Date: Wed Nov 23 23:58:48 2011 +0100 online update: Make the test for update to actually start (still fails). diff --git a/extensions/CppunitTest_extensions_test_update.mk b/extensions/CppunitTest_extensions_test_update.mk index 8132823..ebd86b4 100644 --- a/extensions/CppunitTest_extensions_test_update.mk +++ b/extensions/CppunitTest_extensions_test_update.mk @@ -56,4 +56,26 @@ $(eval $(call gb_CppunitTest_add_api,extensions_test_update,\ udkapi \ )) +$(eval $(call gb_CppunitTest_uses_ure,extensions_test_update)) + +$(eval $(call gb_CppunitTest_add_type_rdbs,extensions_test_update,\ + types \ +)) + +$(eval $(call gb_CppunitTest_add_components,extensions_test_update,\ + unoxml/source/service/unoxml \ +)) + +$(eval $(call gb_CppunitTest_add_old_components,extensions_test_update,\ + configmgr \ + ucb1 \ + updatefeed \ +)) + +$(eval $(call gb_CppunitTest_set_args,extensions_test_update,\ + --headless \ + --protector unoexceptionprotector$(gb_Library_DLLEXT) unoexceptionprotector \ + "-env:CONFIGURATION_LAYERS=xcsxcu:$(call gb_CppunitTarget__make_url,$(OUTDIR)/xml/registry)" \ +)) + # vim:set shiftwidth=4 softtabstop=4 noexpandtab: _______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits