LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / dbaccess / qa / extras / dialog-save.cxx
blobff4f612dc86977f2ada990e6e93fa0915a8211e7
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/beans/XPropertySet.hpp>
13 #include <com/sun/star/lang/XComponent.hpp>
14 #include <com/sun/star/frame/XStorable.hpp>
15 #include <com/sun/star/document/XEmbeddedScripts.hpp>
16 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
17 #include <com/sun/star/script/XLibraryContainer.hpp>
18 #include <com/sun/star/util/XModifiable.hpp>
19 #include <com/sun/star/util/XCloseable.hpp>
20 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
22 #include <vcl/svapp.hxx>
24 using namespace ::com::sun::star;
25 using namespace ::com::sun::star::uno;
28 class DialogSaveTest : public UnoApiTest
30 public:
31 DialogSaveTest();
33 void test();
35 CPPUNIT_TEST_SUITE(DialogSaveTest);
36 // Should we disable this test on MOX and WNT?
37 // #if !defined(MACOSX) && !defined(_WIN32)
38 CPPUNIT_TEST(test);
39 // #endif
40 CPPUNIT_TEST_SUITE_END();
45 DialogSaveTest::DialogSaveTest()
46 : UnoApiTest("/dbaccess/qa/extras/testdocuments")
50 void DialogSaveTest::test()
52 // UnoApiTest::setUp (via InitVCL) puts each test under a locked SolarMutex,
53 // but at least the below xDocCloseable->close call could lead to a deadlock
54 // then, and it looks like none of the code here requires the SolarMutex to
55 // be locked anyway:
56 SolarMutexReleaser rel;
58 const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testDialogSave.odb"));
60 uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName);
61 uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW);
62 uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW);
63 uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries());
64 CPPUNIT_ASSERT(xStorBasLib.is());
65 uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW);
66 uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries());
67 CPPUNIT_ASSERT(xStorDlgLib.is());
68 uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW);
69 static const OUStringLiteral sStandard(u"Standard");
70 xBasLib->loadLibrary(sStandard);
71 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard));
72 // the whole point of this test is to test the "save" operation
73 // when the Basic library is loaded, but not the Dialog library
74 CPPUNIT_ASSERT(!xDlgLib->isLibraryLoaded(sStandard));
76 // make some change to enable a save
77 // uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSuppl(xComponent, UNO_QUERY_THROW);
78 // uno::Reference< document::XDocumentPropertiesSupplier > xDocProps(xDocPropSuppl->getDocumentProperties());
79 // CPPUNIT_ASSERT(xDocProps.is());
80 // xDocProps.setTitle(xDocProps.getTitle() + " suffix");
81 uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW);
82 xDocMod->setModified(true);
84 // now save; the code path to exercise in this test is the "store to same location"
85 // do *not* change to store(As|To|URL)!
86 xDocStorable->store();
88 // close
89 uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW);
90 xDocCloseable->close(false);
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 Reference< beans::XPropertySet > xPS(xHNA->getByHierarchicalName("Dialogs/Standard/Dialog1.xml"), UNO_QUERY_THROW);
98 sal_Int64 nSize = 0;
99 CPPUNIT_ASSERT(xPS->getPropertyValue("Size") >>= nSize);
100 CPPUNIT_ASSERT(nSize != 0);
104 CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest);
106 CPPUNIT_PLUGIN_IMPLEMENT();
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */