cid#1640468 Dereference after null check
[LibreOffice.git] / extensions / qa / update / test_update.cxx
blobcfc5c4a5941452d1dbfc16b2cd5b690f220081e8
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 <sal/config.h>
11 #include <cstddef>
13 #include <test/bootstrapfixture.hxx>
15 #include <com/sun/star/deployment/UpdateInformationEntry.hpp>
16 #include <com/sun/star/deployment/UpdateInformationProvider.hpp>
17 #include <com/sun/star/xml/dom/XNodeList.hpp>
19 #include "../../source/update/check/updatecheck.hxx"
20 #include "../../source/update/check/updateprotocol.hxx"
22 using namespace com::sun::star;
23 using namespace com::sun::star::xml;
25 namespace testupdate {
27 class Test : public test::BootstrapFixture
29 public:
30 virtual void setUp() override
32 // so that comphelper::getProcessServiceFactory() works, m_xContext is
33 // set up, etc.
34 test::BootstrapFixture::setUp();
36 if ( !m_xProvider.is() )
37 m_xProvider = deployment::UpdateInformationProvider::create( m_xContext );
39 // repositories that we will be checking
40 m_aRepositoryList = { m_directories.getURLFromSrc( u"/extensions/qa/update/simple.xml" ) };
43 virtual void tearDown() override
45 m_xProvider.clear();
46 m_aRepositoryList.realloc( 0 );
47 test::BootstrapFixture::tearDown();
50 protected:
51 // test the getUpdateInformationEnumeration() method
52 void testGetUpdateInformationEnumeration()
54 uno::Reference< container::XEnumeration > aUpdateInfoEnumeration =
55 m_xProvider->getUpdateInformationEnumeration(
56 m_aRepositoryList,
57 u"TODO"_ustr ); // unused when we do not have a 'feed'
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_EQUAL( u"description"_ustr, aEntry.UpdateDocument->getNodeName() );
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_EQUAL( sal_Int32(13), xChildNodes->getLength() );
86 //uno::Reference< dom::XElement > xChildId( xChildNodes->item( 0 ), uno::UNO_QUERY );
87 //CPPUNIT_ASSERT( xChildId.is() );
88 //CPPUNIT_ASSERT( xChildId->getNodeValue() == "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 u"Linux",
105 u"x86",
106 m_aRepositoryList,
107 u"111111-222222-333333-444444",
108 u"InstallSetID"_ustr ) )
110 CPPUNIT_ASSERT_EQUAL( std::size_t(1), aInfo.Sources.size() );
111 CPPUNIT_ASSERT_EQUAL( u"http://www.libreoffice.org/download/"_ustr, aInfo.Sources[0].URL );
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 u"Linux",
125 u"x86",
126 m_aRepositoryList,
127 u"123456-abcdef-1a2b3c-4d5e6f",
128 u"InstallSetID"_ustr ) )
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: */