Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / dbaccess / qa / extras / empty-stdlib-save.cxx
blobae9a9234dca9c8250654061ef673648db8731568
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/frame/XStorable.hpp>
13 #include <com/sun/star/document/XEmbeddedScripts.hpp>
14 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
15 #include <com/sun/star/script/XLibraryContainer.hpp>
16 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
18 using namespace ::com::sun::star;
19 using namespace ::com::sun::star::uno;
22 class DialogSaveTest : public UnoApiTest
24 public:
25 DialogSaveTest();
27 void test();
29 CPPUNIT_TEST_SUITE(DialogSaveTest);
30 // Should we disable this test on MOX and WNT?
31 // #if !defined(MACOSX) && !defined(_WIN32)
32 CPPUNIT_TEST(test);
33 // #endif
34 CPPUNIT_TEST_SUITE_END();
39 DialogSaveTest::DialogSaveTest()
40 : UnoApiTest("/dbaccess/qa/extras/testdocuments")
44 void DialogSaveTest::test()
46 const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testEmptyStdlibSave.odb"));
48 mxComponent = loadFromDesktop(aFileName);
49 uno::Reference< frame::XStorable > xDocStorable(mxComponent, UNO_QUERY_THROW);
50 uno::Reference< document::XEmbeddedScripts > xDocScr(mxComponent, UNO_QUERY_THROW);
51 uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries());
52 CPPUNIT_ASSERT(xStorBasLib.is());
53 uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW);
54 uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries());
55 CPPUNIT_ASSERT(xStorDlgLib.is());
56 uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW);
57 static const OUStringLiteral sStandard(u"Standard");
58 xBasLib->loadLibrary(sStandard);
59 xDlgLib->loadLibrary(sStandard);
60 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard));
61 CPPUNIT_ASSERT(xDlgLib->isLibraryLoaded(sStandard));
63 Any a;
64 uno::Reference< container::XNameContainer > xI;
66 a = xBasLib->getByName(sStandard);
67 a >>= xI;
68 CPPUNIT_ASSERT(xI.is());
69 xI->removeByName("Raralix");
71 a = xDlgLib->getByName(sStandard);
72 a >>= xI;
73 CPPUNIT_ASSERT(xI.is());
74 xI->removeByName("Dialog1");
76 // uno::Reference< util::XModifiable > xDlgMod(xDlgLib, UNO_QUERY_THROW);
77 // xDlgMod->setModified(sal_True);
79 // uno::Reference< util::XModifiable > xScrMod(xDocScr, UNO_QUERY_THROW);
80 // xScrMod->setModified(sal_True);
82 // uno::Reference< util::XModifiable > xDocMod(mxComponent, UNO_QUERY_THROW);
83 // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
84 // xDocMod->setModified(sal_True);
85 // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl;
86 // CPPUNIT_ASSERT(xDocMod->isModified());
88 // now save; the code path to exercise in this test is the "store to same location"
89 // do *not* change to store(As|To|URL)!
90 xDocStorable->store();
92 // All our uno::References are (should?) be invalid now -> let them go out of scope
95 uno::Sequence<uno::Any> args{ uno::Any(aFileName) };
96 Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW);
97 CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Basic/Standard"));
98 CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Dialogs/Standard"));
102 CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest);
104 CPPUNIT_PLUGIN_IMPLEMENT();
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */