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 <sal/config.h>
11 #include <test/screenshot_test.hxx>
12 #include <rtl/strbuf.hxx>
13 #include <osl/file.hxx>
14 #include <sfx2/app.hxx>
15 #include <svx/svdmodel.hxx>
16 #include <svx/svxdlg.hxx>
17 #include <vcl/abstdlg.hxx>
18 
19 using namespace ::com::sun::star;
20 
21 /// Test opening a dialog in cui
22 class CuiDialogsTest : public ScreenshotTest
23 {
24 private:
25     std::unique_ptr<SdrModel> mxModel;
26     std::unique_ptr<SfxItemSet> mxAttr;
27     SvxAbstractDialogFactory* mpFact;
28 
29     void initialize();
30 
31     /// helper method to populate KnownDialogs, called in setUp(). Needs to be
32     /// written and has to add entries to KnownDialogs
33     virtual void registerKnownDialogsByID(mapType& rKnownDialogs) override;
34 
35     /// dialog creation for known dialogs by ID. Has to be implemented for
36     /// each registered known dialog
37     virtual VclPtr<VclAbstractDialog> createDialogByID(sal_uInt32 nID) override;
38 
39 public:
40     CuiDialogsTest();
41 
42     // try to open a dialog
43     void openAnyDialog();
44 
45     CPPUNIT_TEST_SUITE(CuiDialogsTest);
46     CPPUNIT_TEST(openAnyDialog);
47     CPPUNIT_TEST_SUITE_END();
48 };
49 
CuiDialogsTest()50 CuiDialogsTest::CuiDialogsTest()
51 {
52 }
53 
initialize()54 void CuiDialogsTest::initialize()
55 {
56     mpFact = SvxAbstractDialogFactory::Create();
57     mxModel.reset(new SdrModel(nullptr, nullptr, true));
58     mxModel->GetItemPool().FreezeIdRanges();
59     mxAttr.reset(new SfxItemSet(mxModel->GetItemPool()));
60 }
61 
registerKnownDialogsByID(mapType & rKnownDialogs)62 void CuiDialogsTest::registerKnownDialogsByID(mapType& rKnownDialogs)
63 {
64     // fill map of known dialogs
65     rKnownDialogs["cui/ui/formatcellsdialog.ui"] = 0;
66     rKnownDialogs["cui/ui/textdialog.ui"] = 1;
67 }
68 
createDialogByID(sal_uInt32 nID)69 VclPtr<VclAbstractDialog> CuiDialogsTest::createDialogByID(sal_uInt32 nID)
70 {
71     VclPtr<VclAbstractDialog> pReturnDialog;
72 
73     switch ( nID )
74     {
75         case 0: // "cui/ui/formatcellsdialog.ui"
76         {
77             pReturnDialog = mpFact->CreateSvxFormatCellsDialog(
78                 nullptr, mxAttr.get(), *mxModel);
79             break;
80         }
81 
82         case 1: // "cui/ui/textdialog.ui"
83         {
84             pReturnDialog = mpFact->CreateTextTabDialog(
85                 nullptr, mxAttr.get(), nullptr);
86             break;
87         }
88 
89         default:
90             break;
91     }
92 
93     return pReturnDialog;
94 }
95 
openAnyDialog()96 void CuiDialogsTest::openAnyDialog()
97 {
98     initialize();
99 
100     /// process input file containing the UXMLDescriptions of the dialogs to dump
101     processDialogBatchFile("cui/qa/unit/data/cui-dialogs-test.txt");
102 }
103 
104 CPPUNIT_TEST_SUITE_REGISTRATION(CuiDialogsTest);
105 
106 CPPUNIT_PLUGIN_IMPLEMENT();
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
109