Debian Codegraph @

framework/qa/cppunit/CheckXTitle.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10 #include <test/unoapi_test.hxx>
11
12 #include <com/sun/star/frame/XFrame.hpp>
13 #include <com/sun/star/frame/XTitle.hpp>
14 #include <com/sun/star/frame/XDispatchHelper.hpp>
15 #include <com/sun/star/frame/XFrame2.hpp>
16 #include <com/sun/star/util/URLTransformer.hpp>
17
18 #include <comphelper/propertyvalue.hxx>
19 #include <comphelper/processfactory.hxx>
20
21 #include <vcl/scheduler.hxx>
22
23 using namespace ::com::sun::star;
24
25 namespace
26 {
27 // These were JUnit tests from framework/qa/complex/XTitle/CheckXTitle.java
28 class Test : public UnoApiTest
29 {
30 public:
31 Test()
32 : UnoApiTest(u"/framework/qa/cppunit/data/"_ustr)
33 {
34 }
35 };
36
37 CPPUNIT_TEST_FIXTURE(Test, checkDefaultTitle)
38 {
39 // Cycles through default view and print preview
40 // and asserts that the title doesn't change.
41
42 // Load document
43 uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
44 false) };
45 loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);
46
47 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
48 uno::Reference<frame::XController> xController(xModel->getCurrentController());
49 uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
50
51 uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
52 OUString defaultTitle = xTitle->getTitle();
53
54 uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));
55
56 // Open print preview window and get title.
57 util::URL printPreviewURL;
58 printPreviewURL.Complete = u".uno::PrintPreview"_ustr;
59 xParser->parseStrict(printPreviewURL);
60 uno::Reference<frame::XDispatchProvider> xDispatchProvider(xModel->getCurrentController(),
61 uno::UNO_QUERY);
62 xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
63 uno::Reference<frame::XTitle> xTitle2(xFrame, css::uno::UNO_QUERY);
64 Scheduler::ProcessEventsToIdle();
65
66 // Default window title and print preview window title should be the same.
67 CPPUNIT_ASSERT_EQUAL(defaultTitle, xTitle2->getTitle());
68
69 // Close print preview window and check to see if default window title has changed
70 util::URL closePreviewURL;
71 closePreviewURL.Complete = u".uno::ClosePreview"_ustr;
72 xParser->parseStrict(closePreviewURL);
73 uno::Reference<frame::XDispatchProvider> xDispatchProvider2(xModel->getCurrentController(),
74 uno::UNO_QUERY);
75 xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
76 uno::Reference<frame::XTitle> xTitle3(xFrame, css::uno::UNO_QUERY);
77 Scheduler::ProcessEventsToIdle();
78
79 // Default window title should be the same after closing print preview window.
80 CPPUNIT_ASSERT_EQUAL(defaultTitle, xTitle3->getTitle());
81 }
82
83 CPPUNIT_TEST_FIXTURE(Test, checkTitleSuggestedFileName)
84 {
85 uno::Sequence<beans::PropertyValue> aArguments
86 = { comphelper::makePropertyValue(u"SuggestedSaveAsName"_ustr, u"suggestedname.odt"_ustr),
87 comphelper::makePropertyValue(u"Hidden"_ustr, false) };
88 loadWithParams(u"private:factory/swriter"_ustr, aArguments);
89 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
90 uno::Reference<frame::XController> xController(xModel->getCurrentController());
91 uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
92
93 uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
94 OUString windowTitle = xTitle->getTitle();
95
96 CPPUNIT_ASSERT(windowTitle.startsWith("suggestedname.odt"));
97 }
98
99 CPPUNIT_TEST_FIXTURE(Test, setTitleAndCheck)
100 {
101 // Set the frame title, then cycle through default and print preview. Close the window
102 // and check for infinite recursion.
103
104 uno::Sequence<beans::PropertyValue> aLoadArgs{ comphelper::makePropertyValue(u"Hidden"_ustr,
105 false) };
106 loadWithParams(u"private:factory/swriter"_ustr, aLoadArgs);
107
108 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
109 uno::Reference<frame::XController> xController(xModel->getCurrentController());
110 uno::Reference<frame::XFrame2> xFrame(xController->getFrame(), uno::UNO_QUERY);
111
112 xFrame->setTitle(u"documentTitle"_ustr);
113
114 uno::Reference<frame::XDispatchProvider> xDispatchProvider(xModel->getCurrentController(),
115 uno::UNO_QUERY);
116 uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(m_xContext));
117
118 util::URL printPreviewURL;
119 printPreviewURL.Complete = u".uno::PrintPreview"_ustr;
120 xParser->parseStrict(printPreviewURL);
121 xDispatchProvider->queryDispatch(printPreviewURL, u""_ustr, 0);
122 Scheduler::ProcessEventsToIdle();
123
124 util::URL closePreviewURL;
125 closePreviewURL.Complete = u".uno::ClosePreview"_ustr;
126 xParser->parseStrict(closePreviewURL);
127 uno::Reference<frame::XDispatchProvider> xDispatchProvider2(xModel->getCurrentController(),
128 uno::UNO_QUERY);
129 xDispatchProvider2->queryDispatch(closePreviewURL, u""_ustr, 0);
130 Scheduler::ProcessEventsToIdle();
131
132 util::URL closeDocURL;
133 closeDocURL.Complete = u".uno::CloseWin"_ustr;
134 xParser->parseStrict(closeDocURL);
135 uno::Reference<frame::XDispatchProvider> xDispatchProvider3(xModel->getCurrentController(),
136 uno::UNO_QUERY);
137 uno::Reference<frame::XTitle> xTitle(xFrame, css::uno::UNO_QUERY);
138 OUString windowTitle = xTitle->getTitle();
139
140 CPPUNIT_ASSERT_EQUAL(windowTitle, u"documentTitle"_ustr);
141
142 xDispatchProvider3->queryDispatch(closeDocURL, u""_ustr, 0);
143 Scheduler::ProcessEventsToIdle();
144 }
145 }
146
147 CPPUNIT_PLUGIN_IMPLEMENT();
148
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */