Avoid potential negative array index access to cached text.
[LibreOffice.git] / dbaccess / qa / extras / dialog-save.cxx
blob04c12b1c5e8b3501a2caf838484221a8533193e9
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/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/XModifiable.hpp>
18 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
20 using namespace ::com::sun::star;
21 using namespace ::com::sun::star::uno;
24 class DialogSaveTest : public UnoApiTest
26 public:
27 DialogSaveTest();
29 void test();
31 CPPUNIT_TEST_SUITE(DialogSaveTest);
32 // Should we disable this test on MOX and WNT?
33 // #if !defined(MACOSX) && !defined(_WIN32)
34 CPPUNIT_TEST(test);
35 // #endif
36 CPPUNIT_TEST_SUITE_END();
41 DialogSaveTest::DialogSaveTest()
42 : UnoApiTest("/dbaccess/qa/extras/testdocuments")
46 void DialogSaveTest::test()
48 const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testDialogSave.odb"));
50 mxComponent = loadFromDesktop(aFileName);
51 uno::Reference< frame::XStorable > xDocStorable(mxComponent, UNO_QUERY_THROW);
52 uno::Reference< document::XEmbeddedScripts > xDocScr(mxComponent, UNO_QUERY_THROW);
53 uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries());
54 CPPUNIT_ASSERT(xStorBasLib.is());
55 uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW);
56 uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries());
57 CPPUNIT_ASSERT(xStorDlgLib.is());
58 uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW);
59 static constexpr OUString sStandard(u"Standard"_ustr);
60 xBasLib->loadLibrary(sStandard);
61 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard));
62 // the whole point of this test is to test the "save" operation
63 // when the Basic library is loaded, but not the Dialog library
64 CPPUNIT_ASSERT(!xDlgLib->isLibraryLoaded(sStandard));
66 // make some change to enable a save
67 // uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSuppl(mxComponent, UNO_QUERY_THROW);
68 // uno::Reference< document::XDocumentPropertiesSupplier > xDocProps(xDocPropSuppl->getDocumentProperties());
69 // CPPUNIT_ASSERT(xDocProps.is());
70 // xDocProps.setTitle(xDocProps.getTitle() + " suffix");
71 uno::Reference< util::XModifiable > xDocMod(mxComponent, UNO_QUERY_THROW);
72 xDocMod->setModified(true);
74 // now save; the code path to exercise in this test is the "store to same location"
75 // do *not* change to store(As|To|URL)!
76 xDocStorable->store();
78 // All our uno::References are (should?) be invalid now -> let them go out of scope
81 uno::Sequence<uno::Any> args{ uno::Any(aFileName) };
82 Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW);
83 Reference< beans::XPropertySet > xPS(xHNA->getByHierarchicalName("Dialogs/Standard/Dialog1.xml"), UNO_QUERY_THROW);
84 sal_Int64 nSize = 0;
85 CPPUNIT_ASSERT(xPS->getPropertyValue("Size") >>= nSize);
86 CPPUNIT_ASSERT(nSize != 0);
90 CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest);
92 CPPUNIT_PLUGIN_IMPLEMENT();
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */