nss: upgrade to release 3.73
[LibreOffice.git] / dbaccess / qa / extras / empty-stdlib-save.cxx
blobea9c660a4e87ac6509c6c6a60b142b3274fef93c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <sal/config.h>
11 #include <test/unoapi_test.hxx>
12 #include <com/sun/star/lang/XComponent.hpp>
13 #include <com/sun/star/frame/XStorable.hpp>
14 #include <com/sun/star/document/XEmbeddedScripts.hpp>
15 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
16 #include <com/sun/star/script/XLibraryContainer.hpp>
17 #include <com/sun/star/util/XCloseable.hpp>
18 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
20 #include <vcl/svapp.hxx>
22 using namespace ::com::sun::star;
23 using namespace ::com::sun::star::uno;
26 class DialogSaveTest : public UnoApiTest
28 public:
29 DialogSaveTest();
31 void test();
33 CPPUNIT_TEST_SUITE(DialogSaveTest);
34 // Should we disable this test on MOX and WNT?
35 // #if !defined(MACOSX) && !defined(_WIN32)
36 CPPUNIT_TEST(test);
37 // #endif
38 CPPUNIT_TEST_SUITE_END();
43 DialogSaveTest::DialogSaveTest()
44 : UnoApiTest("/dbaccess/qa/extras/testdocuments")
48 void DialogSaveTest::test()
50 // UnoApiTest::setUp (via InitVCL) puts each test under a locked SolarMutex,
51 // but at least the below xDocCloseable->close call could lead to a deadlock
52 // then, and it looks like none of the code here requires the SolarMutex to
53 // be locked anyway:
54 SolarMutexReleaser rel;
56 const OUString aFileName(m_directories.getURLFromWorkdir("CppunitTest/testEmptyStdlibSave.odb"));
58 uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName);
59 CPPUNIT_ASSERT(xComponent.is());
60 uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW);
61 uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW);
62 uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries());
63 CPPUNIT_ASSERT(xStorBasLib.is());
64 uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW);
65 uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries());
66 CPPUNIT_ASSERT(xStorDlgLib.is());
67 uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW);
68 const OUString sStandard("Standard");
69 xBasLib->loadLibrary(sStandard);
70 xDlgLib->loadLibrary(sStandard);
71 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard));
72 CPPUNIT_ASSERT(xDlgLib->isLibraryLoaded(sStandard));
74 Any a;
75 uno::Reference< container::XNameContainer > xI;
77 a = xBasLib->getByName(sStandard);
78 a >>= xI;
79 CPPUNIT_ASSERT(xI.is());
80 xI->removeByName("Raralix");
82 a = xDlgLib->getByName(sStandard);
83 a >>= xI;
84 CPPUNIT_ASSERT(xI.is());
85 xI->removeByName("Dialog1");
87 // uno::Reference< util::XModifiable > xDlgMod(xDlgLib, UNO_QUERY_THROW);
88 // xDlgMod->setModified(sal_True);
90 // uno::Reference< util::XModifiable > xScrMod(xDocScr, UNO_QUERY_THROW);
91 // xScrMod->setModified(sal_True);
93 // uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW);
94 // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
95 // xDocMod->setModified(sal_True);
96 // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
97 // CPPUNIT_ASSERT(xDocMod->isModified());
99 // now save; the code path to exercise in this test is the "store to same location"
100 // do *not* change to store(As|To|URL)!
101 xDocStorable->store();
103 // close
104 uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW);
105 xDocCloseable->close(false);
107 // All our uno::References are (should?) be invalid now -> let them go out of scope
110 uno::Sequence<uno::Any> args(1);
111 args[0] <<= aFileName;
112 Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW);
113 CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Basic/Standard"));
114 CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Dialogs/Standard"));
118 CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest);
120 CPPUNIT_PLUGIN_IMPLEMENT();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */