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/.
11 #include <test/screenshot_test.hxx>
13 #include <sfx2/sfxdlg.hxx>
14 #include <svx/numinf.hxx>
15 #include <svx/svxids.hrc>
16 #include <tools/stream.hxx>
18 #include <tabvwsh.hxx>
20 #include <document.hxx>
21 #include <scabstdlg.hxx>
22 #include <scui_def.hxx>
23 #include <patattr.hxx>
25 #include <strings.hrc>
26 #include <scresid.hxx>
27 #include <scitems.hxx>
31 class ScScreenshotTest
: public ScreenshotTest
35 uno::Reference
<lang::XComponent
> mxComponent
;
36 SfxObjectShell
* mpFoundShell
;
37 ScDocShellRef mxDocSh
;
38 ScTabViewShell
* mpViewShell
;
39 ScAbstractDialogFactory
* mpFact
;
40 OUString mCsv
; // needs to outlive mpStream
41 std::unique_ptr
<SvMemoryStream
> mpStream
;
42 std::unique_ptr
<SfxItemSet
> mpItemSet
;
47 /// helper method to populate KnownDialogs, called in setUp(). Needs to be
48 /// written and has to add entries to KnownDialogs
49 virtual void registerKnownDialogsByID(mapType
& rKnownDialogs
) override
;
51 /// dialog creation for known dialogs by ID. Has to be implemented for
52 /// each registered known dialog
53 virtual VclPtr
<VclAbstractDialog
> createDialogByID(sal_uInt32 nID
) override
;
58 void testOpeningModalDialogs();
60 void testMultiViewCopyPaste();
63 CPPUNIT_TEST_SUITE(ScScreenshotTest
);
64 CPPUNIT_TEST(testOpeningModalDialogs
);
66 CPPUNIT_TEST(testMultiViewCopyPaste
);
68 CPPUNIT_TEST_SUITE_END();
71 ScScreenshotTest::ScScreenshotTest()
73 mpFoundShell(nullptr),
77 mCsv("some, strings, here, separated, by, commas"),
83 void ScScreenshotTest::initialize()
86 mxComponent
->dispose();
87 // use new, empty doc to avoid file locking
88 mxComponent
= loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument");
90 mpFoundShell
= SfxObjectShell::GetShellFromComponent(mxComponent
);
91 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", mpFoundShell
);
93 mxDocSh
= dynamic_cast<ScDocShell
*>(mpFoundShell
);
94 CPPUNIT_ASSERT(mxDocSh
!= nullptr);
96 mpViewShell
= mxDocSh
->GetBestViewShell(false);
97 CPPUNIT_ASSERT(mpViewShell
!= nullptr);
99 mpFact
= ScAbstractDialogFactory::Create();
101 SvMemoryStream
* pNewMemStream
= new SvMemoryStream(const_cast<sal_Unicode
*>(mCsv
.getStr()), mCsv
.getLength() * sizeof(sal_Unicode
), StreamMode::READ
);
102 pNewMemStream
->SetStreamCharSet( RTL_TEXTENCODING_UNICODE
);
104 pNewMemStream
->SetEndian(SvStreamEndian::BIG
);
106 pNewMemStream
->SetEndian(SvStreamEndian::LITTLE
);
108 mpStream
.reset(pNewMemStream
);
111 void ScScreenshotTest::registerKnownDialogsByID(mapType
& rKnownDialogs
)
113 // fill map of known dialogs
114 rKnownDialogs
["modules/scalc/ui/insertsheet.ui"] = 0;
115 rKnownDialogs
["modules/scalc/ui/deletecells.ui"] = 1;
116 rKnownDialogs
["modules/scalc/ui/pastespecial.ui"] = 2;
117 rKnownDialogs
["modules/scalc/ui/changesourcedialog.ui"] = 3;
118 rKnownDialogs
["modules/scalc/ui/selectdatasource.ui"] = 4;
119 rKnownDialogs
["modules/scalc/ui/selectsource.ui"] = 5;
120 rKnownDialogs
["modules/scalc/ui/deletecontents.ui"] = 6;
121 rKnownDialogs
["modules/scalc/ui/createnamesdialog.ui"] = 7;
122 rKnownDialogs
["modules/scalc/ui/inputstringdialog.ui"] = 8;
123 rKnownDialogs
["modules/scalc/ui/tabcolordialog.ui"] = 9;
124 rKnownDialogs
["modules/scalc/ui/textimportoptions.ui"] = 10;
125 rKnownDialogs
["modules/scalc/ui/dataform.ui"] = 11;
126 rKnownDialogs
["modules/scalc/ui/movecopysheet.ui"] = 12;
127 rKnownDialogs
["modules/scalc/ui/textimportcsv.ui"] = 13;
128 rKnownDialogs
["modules/scalc/ui/formatcellsdialog.ui"] = 14;
131 VclPtr
<VclAbstractDialog
> ScScreenshotTest::createDialogByID(sal_uInt32 nID
)
133 VclPtr
<VclAbstractDialog
> pReturnDialog
;
134 ////FIXME: translatable string here
135 const OUString
aDefaultSheetName("Sheet1");
139 case 0: // "modules/scalc/ui/insertsheet.ui"
141 ScViewData
& rViewData
= mpViewShell
->GetViewData();
142 SCTAB nTabSelCount
= rViewData
.GetMarkData().GetSelectCount();
144 pReturnDialog
= mpFact
->CreateScInsertTableDlg(
145 mpViewShell
->GetFrameWeld(), rViewData
, nTabSelCount
, false);
150 case 1: // "modules/scalc/ui/deletecells.ui"
152 pReturnDialog
= mpFact
->CreateScDeleteCellDlg(mpViewShell
->GetFrameWeld(), false);
156 case 2: // "modules/scalc/ui/pastespecial.ui"
158 pReturnDialog
= mpFact
->CreateScInsertContentsDlg(mpViewShell
->GetFrameWeld());
162 case 3: // "modules/scalc/ui/changesourcedialog.ui"
164 pReturnDialog
= mpFact
->CreateScColRowLabelDlg(mpViewShell
->GetFrameWeld(), true, false);
168 case 4: // "modules/scalc/ui/selectdatasource.ui"
170 pReturnDialog
= mpFact
->CreateScDataPilotDatabaseDlg(mpViewShell
->GetFrameWeld());
173 case 5: // "modules/scalc/ui/selectsource.ui"
175 pReturnDialog
= mpFact
->CreateScDataPilotSourceTypeDlg(mpViewShell
->GetFrameWeld(), true);
179 case 6: // "modules/scalc/ui/deletecontents.ui"
181 pReturnDialog
= mpFact
->CreateScDeleteContentsDlg(mpViewShell
->GetFrameWeld());
185 case 7: // "modules/scalc/ui/createnamesdialog.ui"
187 pReturnDialog
= mpFact
->CreateScNameCreateDlg(
188 mpViewShell
->GetFrameWeld(),
189 CreateNameFlags::Left
| CreateNameFlags::Top
);
190 // just fake some flags
194 case 8: // "modules/scalc/ui/inputstringdialog.ui"
196 pReturnDialog
= mpFact
->CreateScStringInputDlg(mpViewShell
->GetFrameWeld(),
197 ScResId(SCSTR_APDTABLE
), ScResId(SCSTR_NAME
),
198 aDefaultSheetName
, "modules/scalc/ui/inputstringdialog/InputStringDialog", "" );
202 case 9: // "modules/scalc/ui/tabcolordialog.ui"
204 pReturnDialog
= mpFact
->CreateScTabBgColorDlg(mpViewShell
->GetFrameWeld(),
205 ScResId(SCSTR_SET_TAB_BG_COLOR
),
206 ScResId(SCSTR_NO_TAB_BG_COLOR
), Color(0xff00ff) );
210 case 10: // "modules/scalc/ui/textimportoptions.ui"
212 pReturnDialog
= mpFact
->CreateScTextImportOptionsDlg(mpViewShell
->GetFrameWeld());
216 case 11: // "modules/scalc/ui/dataform.ui"
218 ////FIXME: looks butt-ugly w/ empty file, move it elsewhere, where
219 ////we actually have some data
220 pReturnDialog
= mpFact
->CreateScDataFormDlg(mpViewShell
->GetFrameWeld(), mpViewShell
);
224 case 12: // "modules/scalc/ui/movecopysheet.ui"
226 pReturnDialog
= mpFact
->CreateScMoveTableDlg(mpViewShell
->GetFrameWeld(), aDefaultSheetName
);
230 case 13: // "modules/scalc/ui/textimportcsv.ui"
232 pReturnDialog
= mpFact
->CreateScImportAsciiDlg(mpViewShell
->GetFrameWeld(), OUString(), mpStream
.get(), SC_PASTETEXT
);
235 case 14: // "modules/scalc/ui/formatcellsdialog.ui"
237 ScViewData
& rViewData
= mpViewShell
->GetViewData();
238 ScDocument
& rDoc
= rViewData
.GetDocument();
240 const ScPatternAttr
*pAttr
= mpViewShell
->GetSelectionPattern();
241 std::unique_ptr
<SvxNumberInfoItem
> pNumberInfoItem
;
243 mpItemSet
.reset(new SfxItemSet(pAttr
->GetItemSet()));
244 mpItemSet
->Put(SfxUInt32Item(ATTR_VALUE_FORMAT
,
245 pAttr
->GetNumberFormat( rDoc
.GetFormatTable() ) ) );
247 pNumberInfoItem
= ScTabViewShell::MakeNumberInfoItem(rDoc
, &rViewData
);
249 mpItemSet
->MergeRange(SID_ATTR_NUMBERFORMAT_INFO
, SID_ATTR_NUMBERFORMAT_INFO
);
250 mpItemSet
->Put(*pNumberInfoItem
);
252 pReturnDialog
= mpFact
->CreateScAttrDlg(mpViewShell
->GetFrameWeld(), mpItemSet
.get());
259 //CPPUNIT_ASSERT_MESSAGE( "Failed to create dialog", pReturnDialog );
260 return pReturnDialog
;
263 void ScScreenshotTest::testOpeningModalDialogs()
267 /// process input file containing the UXMLDescriptions of the dialogs to dump
268 processDialogBatchFile("sc/qa/unit/screenshots/data/screenshots.txt");
270 mxComponent
->dispose();
275 void ScScreenshotTest::testMultiViewCopyPaste()
279 ScDocument
& rDoc
= mxDocSh
->GetDocument();
281 rDoc
.SetString(ScAddress(0, 0, 0), "TestCopy1");
282 rDoc
.SetString(ScAddress(1, 0, 0), "TestCopy2");
285 ScTabViewShell
* pView1
= dynamic_cast<ScTabViewShell
*>(SfxViewShell::Current());
286 CPPUNIT_ASSERT(pView1
);
289 SfxLokHelper::createView();
290 ScTabViewShell
* pView2
= dynamic_cast<ScTabViewShell
*>(SfxViewShell::Current());
291 CPPUNIT_ASSERT(pView1
!= pView2
);
293 std::unique_ptr
<SfxPoolItem
> xItem1
;
294 std::unique_ptr
<SfxPoolItem
> xItem2
;
295 CPPUNIT_ASSERT(SfxItemState::DISABLED
!= pView1
->GetViewFrame()->GetBindings().QueryState(SID_PASTE
, xItem1
));
296 CPPUNIT_ASSERT(SfxItemState::DISABLED
!= pView2
->GetViewFrame()->GetBindings().QueryState(SID_PASTE
, xItem2
));
300 pView1
->SetCursor(0, 0);
301 pView1
->GetViewFrame()->GetBindings().Execute(SID_COPY
);
304 pView2
->SetCursor(1, 0);
305 pView2
->GetViewFrame()->GetBindings().Execute(SID_COPY
);
308 pView1
->SetCursor(0, 1);
309 pView1
->GetViewFrame()->GetBindings().Execute(SID_PASTE
);
312 pView2
->SetCursor(1, 1);
313 pView2
->GetViewFrame()->GetBindings().Execute(SID_PASTE
);
315 CPPUNIT_ASSERT_EQUAL(OUString("TestCopy2"), rDoc
.GetString(ScAddress(0, 1, 0)));
316 CPPUNIT_ASSERT_EQUAL(OUString("TestCopy2"), rDoc
.GetString(ScAddress(1, 1, 0)));
318 mxComponent
->dispose();
323 CPPUNIT_TEST_SUITE_REGISTRATION(ScScreenshotTest
);
325 CPPUNIT_PLUGIN_IMPLEMENT();
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */