nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / unit / screenshots / screenshots.cxx
blob8cd66991674f81b96aea1e5885bd43ee89ec0b98
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 <memory>
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>
19 #include <docsh.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>
29 using namespace css;
31 class ScScreenshotTest : public ScreenshotTest
33 private:
34 /// members
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;
44 /// helper
45 void initialize();
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;
55 public:
56 ScScreenshotTest();
58 void testOpeningModalDialogs();
59 #if 0
60 void testMultiViewCopyPaste();
61 #endif
63 CPPUNIT_TEST_SUITE(ScScreenshotTest);
64 CPPUNIT_TEST(testOpeningModalDialogs);
65 #if 0
66 CPPUNIT_TEST(testMultiViewCopyPaste);
67 #endif
68 CPPUNIT_TEST_SUITE_END();
71 ScScreenshotTest::ScScreenshotTest()
72 : mxComponent(),
73 mpFoundShell(nullptr),
74 mxDocSh(),
75 mpViewShell(nullptr),
76 mpFact(nullptr),
77 mCsv("some, strings, here, separated, by, commas"),
78 mpStream(),
79 mpItemSet()
83 void ScScreenshotTest::initialize()
85 if (mxComponent.is())
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 );
103 #ifdef OSL_BIGENDIAN
104 pNewMemStream->SetEndian(SvStreamEndian::BIG);
105 #else
106 pNewMemStream->SetEndian(SvStreamEndian::LITTLE);
107 #endif
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");
137 switch ( nID )
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);
147 break;
150 case 1: // "modules/scalc/ui/deletecells.ui"
152 pReturnDialog = mpFact->CreateScDeleteCellDlg(mpViewShell->GetFrameWeld(), false);
153 break;
156 case 2: // "modules/scalc/ui/pastespecial.ui"
158 pReturnDialog = mpFact->CreateScInsertContentsDlg(mpViewShell->GetFrameWeld());
159 break;
162 case 3: // "modules/scalc/ui/changesourcedialog.ui"
164 pReturnDialog = mpFact->CreateScColRowLabelDlg(mpViewShell->GetFrameWeld(), true, false);
165 break;
168 case 4: // "modules/scalc/ui/selectdatasource.ui"
170 pReturnDialog = mpFact->CreateScDataPilotDatabaseDlg(mpViewShell->GetFrameWeld());
171 break;
173 case 5: // "modules/scalc/ui/selectsource.ui"
175 pReturnDialog = mpFact->CreateScDataPilotSourceTypeDlg(mpViewShell->GetFrameWeld(), true);
176 break;
179 case 6: // "modules/scalc/ui/deletecontents.ui"
181 pReturnDialog = mpFact->CreateScDeleteContentsDlg(mpViewShell->GetFrameWeld());
182 break;
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
191 break;
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", "" );
199 break;
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) );
207 break;
210 case 10: // "modules/scalc/ui/textimportoptions.ui"
212 pReturnDialog = mpFact->CreateScTextImportOptionsDlg(mpViewShell->GetFrameWeld());
213 break;
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);
221 break;
224 case 12: // "modules/scalc/ui/movecopysheet.ui"
226 pReturnDialog = mpFact->CreateScMoveTableDlg(mpViewShell->GetFrameWeld(), aDefaultSheetName);
227 break;
230 case 13: // "modules/scalc/ui/textimportcsv.ui"
232 pReturnDialog = mpFact->CreateScImportAsciiDlg(mpViewShell->GetFrameWeld(), OUString(), mpStream.get(), SC_PASTETEXT);
233 break;
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());
253 break;
255 default:
256 break;
259 //CPPUNIT_ASSERT_MESSAGE( "Failed to create dialog", pReturnDialog );
260 return pReturnDialog;
263 void ScScreenshotTest::testOpeningModalDialogs()
265 initialize();
267 /// process input file containing the UXMLDescriptions of the dialogs to dump
268 processDialogBatchFile("sc/qa/unit/screenshots/data/screenshots.txt");
270 mxComponent->dispose();
271 mxComponent.clear();
274 #if 0
275 void ScScreenshotTest::testMultiViewCopyPaste()
277 initialize();
279 ScDocument& rDoc = mxDocSh->GetDocument();
281 rDoc.SetString(ScAddress(0, 0, 0), "TestCopy1");
282 rDoc.SetString(ScAddress(1, 0, 0), "TestCopy2");
284 // view #1
285 ScTabViewShell* pView1 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
286 CPPUNIT_ASSERT(pView1);
288 // view #2
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));
299 // copy text view 1
300 pView1->SetCursor(0, 0);
301 pView1->GetViewFrame()->GetBindings().Execute(SID_COPY);
303 // copy text view 2
304 pView2->SetCursor(1, 0);
305 pView2->GetViewFrame()->GetBindings().Execute(SID_COPY);
307 // paste text view 1
308 pView1->SetCursor(0, 1);
309 pView1->GetViewFrame()->GetBindings().Execute(SID_PASTE);
311 // paste text view 2
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();
319 mxComponent.clear();
321 #endif
323 CPPUNIT_TEST_SUITE_REGISTRATION(ScScreenshotTest);
325 CPPUNIT_PLUGIN_IMPLEMENT();
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */