LCOV - code coverage report
Current view: top level - dbaccess/qa/extras - empty-stdlib-save.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 53 53 100.0 %
Date: 2014-11-03 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include <sal/config.h>
      11             : #include <test/bootstrapfixture.hxx>
      12             : #include <test/unoapi_test.hxx>
      13             : #include <rtl/strbuf.hxx>
      14             : #include <osl/file.hxx>
      15             : #include <com/sun/star/frame/Desktop.hpp>
      16             : #include <com/sun/star/lang/XComponent.hpp>
      17             : #include <com/sun/star/frame/XStorable.hpp>
      18             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      19             : #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
      20             : #include <com/sun/star/script/XLibraryContainer.hpp>
      21             : #include <com/sun/star/util/XModifiable.hpp>
      22             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      23             : #include <com/sun/star/io/XStream.hpp>
      24             : #include <com/sun/star/io/XInputStream.hpp>
      25             : 
      26             : #include <sfx2/app.hxx>
      27             : #include <sfx2/docfilt.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <sfx2/objsh.hxx>
      30             : #include <sfx2/sfxmodelfactory.hxx>
      31             : #include <svl/intitem.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : 
      34             : #include <basic/sbxdef.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::uno;
      38             : 
      39             : 
      40           4 : class DialogSaveTest : public UnoApiTest
      41             : {
      42             : public:
      43             :     DialogSaveTest();
      44             : 
      45             :     void test();
      46             : 
      47           4 :     CPPUNIT_TEST_SUITE(DialogSaveTest);
      48             : // Should we disable this test on MOX and WNT?
      49             : // #if !defined(MACOSX) && !defined(WNT)
      50           2 :     CPPUNIT_TEST(test);
      51             : // #endif
      52           4 :     CPPUNIT_TEST_SUITE_END();
      53             : 
      54             : };
      55             : 
      56             : 
      57           2 : DialogSaveTest::DialogSaveTest()
      58           2 :       : UnoApiTest("/dbaccess/qa/extras/testdocuments")
      59             : {
      60           2 : }
      61             : 
      62           2 : void DialogSaveTest::test()
      63             : {
      64             :     // UnoApiTest::setUp (via InitVCL) puts each test under a locked SolarMutex,
      65             :     // but at least the below xDocCloseable->close call could lead to a deadlock
      66             :     // then, and it looks like none of the code here requires the SolarMutex to
      67             :     // be locked anyway:
      68           2 :     SolarMutexReleaser rel;
      69             : 
      70           4 :     const OUString sStandard("Standard");
      71           4 :     const OUString aFileName(getURLFromWorkdir("CppunitTest/testEmptyStdlibSave.odb"));
      72             :     {
      73           2 :         uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName);
      74           2 :         CPPUNIT_ASSERT(xComponent.is());
      75           4 :         uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW);
      76           2 :         CPPUNIT_ASSERT(xDocStorable.is());
      77           4 :         uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW);
      78           2 :         CPPUNIT_ASSERT(xDocScr.is());
      79           4 :         uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries());
      80           2 :         CPPUNIT_ASSERT(xStorBasLib.is());
      81           4 :         uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW);
      82           2 :         CPPUNIT_ASSERT(xBasLib.is());
      83           4 :         uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries());
      84           2 :         CPPUNIT_ASSERT(xStorDlgLib.is());
      85           4 :         uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW);
      86           2 :         CPPUNIT_ASSERT(xDlgLib.is());
      87           2 :         xBasLib->loadLibrary(sStandard);
      88           2 :         xDlgLib->loadLibrary(sStandard);
      89           2 :         CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard));
      90           2 :         CPPUNIT_ASSERT(xDlgLib->isLibraryLoaded(sStandard));
      91             : 
      92           4 :         Any a;
      93           4 :         uno::Reference< container::XNameContainer > xI;
      94             : 
      95           2 :         a = xBasLib->getByName(sStandard);
      96           2 :         a >>= xI;
      97           2 :         CPPUNIT_ASSERT(xI.is());
      98           2 :         xI->removeByName("Raralix");
      99             : 
     100           2 :         a = xDlgLib->getByName(sStandard);
     101           2 :         a >>= xI;
     102           2 :         CPPUNIT_ASSERT(xI.is());
     103           2 :         xI->removeByName("Dialog1");
     104             : 
     105             :         // uno::Reference< util::XModifiable > xDlgMod(xDlgLib, UNO_QUERY_THROW);
     106             :         // CPPUNIT_ASSERT(xDlgMod.is());
     107             :         // xDlgMod->setModified(sal_True);
     108             : 
     109             :         // uno::Reference< util::XModifiable > xScrMod(xDocScr, UNO_QUERY_THROW);
     110             :         // CPPUNIT_ASSERT(xScrMod.is());
     111             :         // xScrMod->setModified(sal_True);
     112             : 
     113             :         // uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW);
     114             :         // CPPUNIT_ASSERT(xDocMod.is());
     115             :         // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
     116             :         // xDocMod->setModified(sal_True);
     117             :         // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
     118             :         // CPPUNIT_ASSERT(xDocMod->isModified());
     119             : 
     120             :         // now save; the code path to exercise in this test is the "store to same location"
     121             :         //           do *not* change to store(As|To|URL)!
     122           2 :         xDocStorable->store();
     123             : 
     124             :         // close
     125           4 :         uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW);
     126           2 :         CPPUNIT_ASSERT(xDocCloseable.is());
     127           4 :         xDocCloseable->close(false);
     128             : 
     129             :         // All our uno::References are (should?) be invalid now -> let them go out of scope
     130             :     }
     131             :     {
     132           2 :         uno::Sequence<uno::Any> args(1);
     133           2 :         args[0] <<= aFileName;
     134           4 :         Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW);
     135           2 :         CPPUNIT_ASSERT(xHNA.is());
     136           2 :         CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Basic/Standard"));
     137           4 :         CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Dialogs/Standard"));
     138           2 :     }
     139           2 : }
     140             : 
     141           2 : CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest);
     142             : 
     143           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10