bump product version to 4.1.6.2
[LibreOffice.git] / extensions / qa / update / test_update.cxx
blob4e6577660c584328c68b356e5741faa87e8bd7c4
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
9 #include <test/bootstrapfixture.hxx>
10 #include <cppuhelper/bootstrap.hxx>
12 #include <com/sun/star/deployment/UpdateInformationEntry.hpp>
13 #include <com/sun/star/deployment/UpdateInformationProvider.hpp>
14 #include <com/sun/star/xml/dom/XNodeList.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include "../../source/update/check/updatecheck.hxx"
19 #include "../../source/update/check/updateprotocol.hxx"
21 using namespace com::sun::star;
22 using namespace com::sun::star::xml;
24 namespace testupdate {
26 class Test : public test::BootstrapFixture
28 public:
29 virtual void setUp()
31 // so that comphelper::getProcessServiceFactory() works, m_xContext is
32 // set up, etc.
33 test::BootstrapFixture::setUp();
35 if ( !m_xProvider.is() )
36 m_xProvider = deployment::UpdateInformationProvider::create( m_xContext );
38 // repositories that we will be checking
39 m_aRepositoryList.realloc( 1 );
40 m_aRepositoryList[0] = getURLFromSrc( "/extensions/qa/update/simple.xml" );
43 virtual void tearDown()
45 m_xProvider.clear();
46 m_aRepositoryList.realloc( 0 );
47 test::BootstrapFixture::tearDown();
50 protected:
51 // test the getUpdateInformationEnumeration() method
52 void testGetUpdateInformationEnumeration()
54 OUString aInstallSetID( "TODO" ); // unused when we do not have a 'feed'
56 uno::Reference< container::XEnumeration > aUpdateInfoEnumeration =
57 m_xProvider->getUpdateInformationEnumeration( m_aRepositoryList, aInstallSetID );
59 if ( !aUpdateInfoEnumeration.is() )
60 CPPUNIT_FAIL( "Calling getUpdateInformationEnumeration() with TODO failed." );
62 if ( !aUpdateInfoEnumeration->hasMoreElements() )
63 CPPUNIT_FAIL( "Should have more elements (this one is 1st)." );
65 deployment::UpdateInformationEntry aEntry;
66 if ( aUpdateInfoEnumeration->nextElement() >>= aEntry )
68 CPPUNIT_ASSERT( aEntry.UpdateDocument->getNodeName() == OUString( "description" ) );
70 uno::Reference< dom::XNodeList> xChildNodes = aEntry.UpdateDocument->getChildNodes();
71 CPPUNIT_ASSERT( xChildNodes.is() );
72 #if 0
73 for ( int i = 0; i < xChildNodes->getLength(); ++i )
75 fprintf( stderr, "node == %d\n", i );
76 uno::Reference< dom::XElement > xChildId( xChildNodes->item( i ), uno::UNO_QUERY );
77 if ( xChildId.is() )
79 fprintf( stderr, "Name == %s\n", OUStringToOString( xChildId->getNodeName(), RTL_TEXTENCODING_UTF8 ).getStr() );
80 fprintf( stderr, "Value == %s\n", OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() );
83 #endif
84 CPPUNIT_ASSERT( xChildNodes->getLength() == 13 );
86 //uno::Reference< dom::XElement > xChildId( xChildNodes->item( 0 ), uno::UNO_QUERY );
87 //CPPUNIT_ASSERT( xChildId.is() );
88 //CPPUNIT_ASSERT( xChildId->getNodeValue() == OUString( "LibreOffice_3.4" ) );
89 //fprintf( stderr, "Attribute == %s\n", OUStringToOString( aEntry.UpdateDocument->getAttribute( OUString( "test" ) ), RTL_TEXTENCODING_UTF8 ).getStr() );
90 //fprintf( stderr, "Value == %s\n", OUStringToOString( xChildId->getNodeValue(), RTL_TEXTENCODING_UTF8 ).getStr() );
91 // TODO check more deeply
93 else
94 CPPUNIT_FAIL( "Wrong type of the entry." );
97 // test the checkForUpdates() method - update is available
98 void testCheckUpdateAvailable()
100 UpdateInfo aInfo;
101 rtl::Reference< UpdateCheck > aController( UpdateCheck::get() );
103 if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider,
104 OUString( "Linux" ),
105 OUString( "x86" ),
106 m_aRepositoryList,
107 OUString( "111111-222222-333333-444444" ),
108 OUString( "InstallSetID" ) ) )
110 CPPUNIT_ASSERT( aInfo.Sources.size() == 1 );
111 CPPUNIT_ASSERT( aInfo.Sources[0].URL == OUString( "http://www.libreoffice.org/download/" ) );
113 else
114 CPPUNIT_FAIL( "Calling checkForUpdates() failed." );
117 // test the checkForUpdates() method - we are up-to-date
118 void testCheckUpToDate()
120 UpdateInfo aInfo;
121 rtl::Reference< UpdateCheck > aController( UpdateCheck::get() );
123 if ( checkForUpdates( aInfo, m_xContext, aController->getInteractionHandler(), m_xProvider,
124 OUString( "Linux" ),
125 OUString( "x86" ),
126 m_aRepositoryList,
127 OUString( "123456-abcdef-1a2b3c-4d5e6f" ),
128 OUString( "InstallSetID" ) ) )
130 CPPUNIT_ASSERT( aInfo.Sources.empty() );
132 else
133 CPPUNIT_FAIL( "Calling checkForUpdates() failed." );
136 CPPUNIT_TEST_SUITE(Test);
137 CPPUNIT_TEST(testGetUpdateInformationEnumeration);
138 CPPUNIT_TEST(testCheckUpdateAvailable);
139 CPPUNIT_TEST(testCheckUpToDate);
140 CPPUNIT_TEST_SUITE_END();
142 private:
143 uno::Reference< deployment::XUpdateInformationProvider > m_xProvider;
144 uno::Sequence< OUString > m_aRepositoryList;
147 CPPUNIT_TEST_SUITE_REGISTRATION(testupdate::Test);
148 } // namespace testupdate
150 CPPUNIT_PLUGIN_IMPLEMENT();
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */