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
This commit is contained in:
parent
4432a44e75
commit
b87fa222f1
@ -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 \
|
||||
))
|
||||
|
||||
|
10
extensions/qa/update/simple.xml
Normal file
10
extensions/qa/update/simple.xml
Normal file
@ -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>
|
@ -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
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -50,6 +50,7 @@ SHL1OBJS=$(SLOFILES)
|
||||
|
||||
SHL1IMPLIB=i$(SHL1TARGET)
|
||||
SHL1STDLIBS= \
|
||||
$(COMPHELPERLIB) \
|
||||
$(CPPUHELPERLIB) \
|
||||
$(CPPULIB) \
|
||||
$(SALLIB)
|
||||
|
@ -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::Sequence< beans::PropertyValue > aValues( 1 );
|
||||
aValues[0] = aURLValue;
|
||||
|
||||
uno::Reference< ucb::XCommandProcessor > xCommandProcessor(m_xContentProvider->queryContent(xId), uno::UNO_QUERY_THROW);
|
||||
rtl::Reference< ActiveDataSink > aSink(new ActiveDataSink());
|
||||
::comphelper::MediaDescriptor aMediaDesc( aValues );
|
||||
aMediaDesc.addInputStream();
|
||||
|
||||
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::Reference< ucb::XCommandProcessor2 > xCommandProcessor2(xCommandProcessor, uno::UNO_QUERY);
|
||||
if( xCommandProcessor2.is() )
|
||||
xCommandProcessor2->releaseCommandIdentifier(nCommandId);
|
||||
|
||||
return INPUT_STREAM(aSink->getInputStream());
|
||||
return aMediaDesc.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_INPUTSTREAM(), uno::Reference< io::XInputStream >() );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user