Revert "tdf#158280 Replace usage of InputDialog with SvxNameDialog"
[LibreOffice.git] / vcl / qa / cppunit / widgetdraw / WidgetDefinitionReaderTest.cxx
bloba3f329c95562db02a649aa1c41eb09b86fe5cb84
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 <sal/config.h>
12 #include <string_view>
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 #include <cppunit/plugin/TestPlugIn.h>
17 #include <unotest/bootstrapfixturebase.hxx>
19 #include <widgetdraw/WidgetDefinitionReader.hxx>
21 namespace
23 constexpr OUStringLiteral gaDataUrl(u"/vcl/qa/cppunit/widgetdraw/data/");
25 class WidgetDefinitionReaderTest : public test::BootstrapFixtureBase
27 private:
28 OUString getFullUrl(std::u16string_view sFileName)
30 return m_directories.getURLFromSrc(gaDataUrl) + sFileName;
33 public:
34 void testRead();
35 void testReadSettings();
37 CPPUNIT_TEST_SUITE(WidgetDefinitionReaderTest);
38 CPPUNIT_TEST(testRead);
39 CPPUNIT_TEST(testReadSettings);
40 CPPUNIT_TEST_SUITE_END();
43 void WidgetDefinitionReaderTest::testReadSettings()
46 vcl::WidgetDefinition aDefinition;
47 vcl::WidgetDefinitionReader aReader(getFullUrl(u"definitionSettings1.xml"),
48 getFullUrl(u""));
49 CPPUNIT_ASSERT(aReader.read(aDefinition));
50 CPPUNIT_ASSERT_EQUAL(""_ostr, aDefinition.mpSettings->msCenteredTabs);
54 vcl::WidgetDefinition aDefinition;
55 vcl::WidgetDefinitionReader aReader(getFullUrl(u"definitionSettings2.xml"),
56 getFullUrl(u""));
57 CPPUNIT_ASSERT(aReader.read(aDefinition));
58 CPPUNIT_ASSERT_EQUAL("true"_ostr, aDefinition.mpSettings->msCenteredTabs);
62 vcl::WidgetDefinition aDefinition;
63 vcl::WidgetDefinitionReader aReader(getFullUrl(u"definitionSettings3.xml"),
64 getFullUrl(u""));
65 CPPUNIT_ASSERT(aReader.read(aDefinition));
66 CPPUNIT_ASSERT_EQUAL("true"_ostr, aDefinition.mpSettings->msNoActiveTabTextRaise);
67 CPPUNIT_ASSERT_EQUAL("false"_ostr, aDefinition.mpSettings->msCenteredTabs);
68 CPPUNIT_ASSERT_EQUAL("0"_ostr, aDefinition.mpSettings->msListBoxEntryMargin);
69 CPPUNIT_ASSERT_EQUAL("10"_ostr, aDefinition.mpSettings->msDefaultFontSize);
70 CPPUNIT_ASSERT_EQUAL("16"_ostr, aDefinition.mpSettings->msTitleHeight);
71 CPPUNIT_ASSERT_EQUAL("12"_ostr, aDefinition.mpSettings->msFloatTitleHeight);
72 CPPUNIT_ASSERT_EQUAL("15"_ostr, aDefinition.mpSettings->msListBoxPreviewDefaultLogicWidth);
73 CPPUNIT_ASSERT_EQUAL("7"_ostr, aDefinition.mpSettings->msListBoxPreviewDefaultLogicHeight);
77 void WidgetDefinitionReaderTest::testRead()
79 vcl::WidgetDefinition aDefinition;
81 vcl::WidgetDefinitionReader aReader(getFullUrl(u"definition1.xml"), getFullUrl(u""));
82 CPPUNIT_ASSERT(aReader.read(aDefinition));
84 CPPUNIT_ASSERT_EQUAL(u"123456"_ustr, aDefinition.mpStyle->maFaceColor.AsRGBHexString());
85 CPPUNIT_ASSERT_EQUAL(u"234567"_ustr, aDefinition.mpStyle->maCheckedColor.AsRGBHexString());
86 CPPUNIT_ASSERT_EQUAL(u"345678"_ustr, aDefinition.mpStyle->maLightColor.AsRGBHexString());
88 CPPUNIT_ASSERT_EQUAL(u"ffffff"_ustr, aDefinition.mpStyle->maVisitedLinkColor.AsRGBHexString());
89 CPPUNIT_ASSERT_EQUAL(u"ffffff"_ustr, aDefinition.mpStyle->maToolTextColor.AsRGBHexString());
90 CPPUNIT_ASSERT_EQUAL(u"ffffff"_ustr, aDefinition.mpStyle->maWindowTextColor.AsRGBHexString());
92 // Pushbutton
94 ControlState eState
95 = ControlState::DEFAULT | ControlState::ENABLED | ControlState::ROLLOVER;
96 std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
97 = aDefinition.getDefinition(ControlType::Pushbutton, ControlPart::Entire)
98 ->getStates(ControlType::Pushbutton, ControlPart::Entire, eState,
99 PushButtonValue());
101 CPPUNIT_ASSERT_EQUAL(size_t(2), aStates.size());
103 CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size());
104 CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::RECTANGLE,
105 aStates[0]->mpWidgetDrawActions[0]->maType);
106 CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::LINE,
107 aStates[0]->mpWidgetDrawActions[1]->maType);
110 // Radiobutton
112 std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
113 = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire)
114 ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE,
115 ImplControlValue(ButtonValue::On));
116 CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size());
117 CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size());
121 std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
122 = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire)
123 ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE,
124 ImplControlValue(ButtonValue::Off));
125 CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size());
126 CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpWidgetDrawActions.size());
130 } // namespace
132 CPPUNIT_TEST_SUITE_REGISTRATION(WidgetDefinitionReaderTest);
134 CPPUNIT_PLUGIN_IMPLEMENT();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */