1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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/beans/XPropertySet.hpp>
16 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/lang/XComponent.hpp>
18 #include <com/sun/star/frame/XStorable.hpp>
19 #include <com/sun/star/document/XEmbeddedScripts.hpp>
20 #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
21 #include <com/sun/star/script/XLibraryContainer.hpp>
22 #include <com/sun/star/util/XModifiable.hpp>
23 #include <com/sun/star/util/XCloseable.hpp>
24 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
25 #include <com/sun/star/io/XStream.hpp>
26 #include <com/sun/star/io/XInputStream.hpp>
28 #include <sfx2/app.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <sfx2/sfxmodelfactory.hxx>
33 #include <svl/intitem.hxx>
34 #include <vcl/svapp.hxx>
36 #include <basic/sbxdef.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::uno
;
42 class DialogSaveTest
: public UnoApiTest
49 CPPUNIT_TEST_SUITE(DialogSaveTest
);
50 // Should we disable this test on MOX and WNT?
51 // #if !defined(MACOSX) && !defined(_WIN32)
54 CPPUNIT_TEST_SUITE_END();
59 DialogSaveTest::DialogSaveTest()
60 : UnoApiTest("/dbaccess/qa/extras/testdocuments")
64 void DialogSaveTest::test()
66 // UnoApiTest::setUp (via InitVCL) puts each test under a locked SolarMutex,
67 // but at least the below xDocCloseable->close call could lead to a deadlock
68 // then, and it looks like none of the code here requires the SolarMutex to
70 SolarMutexReleaser rel
;
72 const OUString
sStandard("Standard");
73 const OUString
aFileName(m_directories
.getURLFromWorkdir("CppunitTest/testDialogSave.odb"));
75 uno::Reference
< lang::XComponent
> xComponent
= loadFromDesktop(aFileName
);
76 CPPUNIT_ASSERT(xComponent
.is());
77 uno::Reference
< frame::XStorable
> xDocStorable(xComponent
, UNO_QUERY_THROW
);
78 uno::Reference
< document::XEmbeddedScripts
> xDocScr(xComponent
, UNO_QUERY_THROW
);
79 uno::Reference
< script::XStorageBasedLibraryContainer
> xStorBasLib(xDocScr
->getBasicLibraries());
80 CPPUNIT_ASSERT(xStorBasLib
.is());
81 uno::Reference
< script::XLibraryContainer
> xBasLib(xStorBasLib
, UNO_QUERY_THROW
);
82 uno::Reference
< script::XStorageBasedLibraryContainer
> xStorDlgLib(xDocScr
->getDialogLibraries());
83 CPPUNIT_ASSERT(xStorDlgLib
.is());
84 uno::Reference
< script::XLibraryContainer
> xDlgLib(xStorDlgLib
, UNO_QUERY_THROW
);
85 xBasLib
->loadLibrary(sStandard
);
86 CPPUNIT_ASSERT(xBasLib
->isLibraryLoaded(sStandard
));
87 // the whole point of this test is to test the "save" operation
88 // when the Basic library is loaded, but not the Dialog library
89 CPPUNIT_ASSERT(!xDlgLib
->isLibraryLoaded(sStandard
));
91 // make some change to enable a save
92 // uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSuppl(xComponent, UNO_QUERY_THROW);
93 // uno::Reference< document::XDocumentPropertiesSupplier > xDocProps(xDocPropSuppl->getDocumentProperties());
94 // CPPUNIT_ASSERT(xDocProps.is());
95 // xDocProps.setTitle(xDocProps.getTitle() + " suffix");
96 uno::Reference
< util::XModifiable
> xDocMod(xComponent
, UNO_QUERY_THROW
);
97 xDocMod
->setModified(true);
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();
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 Reference
< beans::XPropertySet
> xPS(xHNA
->getByHierarchicalName("Dialogs/Standard/Dialog1.xml"), UNO_QUERY_THROW
);
115 CPPUNIT_ASSERT(xPS
->getPropertyValue("Size") >>= nSize
);
116 CPPUNIT_ASSERT(nSize
!= 0);
120 CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest
);
122 CPPUNIT_PLUGIN_IMPLEMENT();
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */