nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / sceditfieldobj-cell.cxx
blob53f3332699897b39ba1e0ec0a1e5867f7e71659e
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 <test/calc_unoapi_test.hxx>
11 #include <test/beans/xpropertyset.hxx>
12 #include <test/text/textcontent.hxx>
13 #include <test/text/xtextfield.hxx>
14 #include <test/text/xtextcontent.hxx>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/container/XIndexAccess.hpp>
18 #include <com/sun/star/sheet/XSpreadsheet.hpp>
19 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
20 #include <com/sun/star/table/XCell.hpp>
21 #include <com/sun/star/text/TextContentAnchorType.hpp>
22 #include <com/sun/star/text/WrapTextMode.hpp>
23 #include <com/sun/star/text/XText.hpp>
24 #include <com/sun/star/text/XTextContent.hpp>
25 #include <com/sun/star/text/XTextCursor.hpp>
26 #include <com/sun/star/text/XTextField.hpp>
27 #include <com/sun/star/text/XTextRange.hpp>
28 #include <com/sun/star/uno/XInterface.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
32 using namespace css;
34 namespace sc_apitest
36 class ScEditFieldObj_Cell : public CalcUnoApiTest,
37 public apitest::TextContent,
38 public apitest::XPropertySet,
39 public apitest::XTextContent,
40 public apitest::XTextField
42 public:
43 ScEditFieldObj_Cell();
45 virtual void setUp() override;
46 virtual void tearDown() override;
47 virtual uno::Reference<uno::XInterface> init() override;
48 virtual uno::Reference<text::XTextContent> getTextContent() override;
49 virtual uno::Reference<text::XTextRange> getTextRange() override;
50 virtual bool isAttachSupported() override { return true; }
52 void testEditFieldProperties();
54 CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell);
56 // TextContent
57 CPPUNIT_TEST(testTextContentProperties);
59 // XPropertySet
60 CPPUNIT_TEST(testGetPropertySetInfo);
61 CPPUNIT_TEST(testGetPropertyValue);
62 CPPUNIT_TEST(testSetPropertyValue);
63 CPPUNIT_TEST(testPropertyChangeListener);
64 CPPUNIT_TEST(testVetoableChangeListener);
66 // XTextField
67 CPPUNIT_TEST(testGetPresentation);
69 // XTextContent
70 CPPUNIT_TEST(testGetAnchor);
71 CPPUNIT_TEST(testAttach);
73 // Tests specific to this service implementation.
74 CPPUNIT_TEST(testEditFieldProperties);
76 CPPUNIT_TEST_SUITE_END();
78 private:
79 uno::Reference<lang::XComponent> mxComponent;
80 static uno::Reference<text::XTextField> mxField;
83 uno::Reference<text::XTextField> ScEditFieldObj_Cell::mxField;
85 ScEditFieldObj_Cell::ScEditFieldObj_Cell()
86 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
87 , TextContent(text::TextContentAnchorType_AS_CHARACTER,
88 text::TextContentAnchorType_AS_CHARACTER, text::WrapTextMode_NONE,
89 text::WrapTextMode_NONE)
93 void ScEditFieldObj_Cell::setUp()
95 CalcUnoApiTest::setUp();
96 // Load an empty document.
97 mxComponent = loadFromDesktop("private:factory/scalc");
100 void ScEditFieldObj_Cell::tearDown()
102 mxField.clear();
103 closeDocument(mxComponent);
104 CalcUnoApiTest::tearDown();
107 namespace
109 uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM)
111 uno::Reference<text::XTextField> xField(xSM->createInstance("com.sun.star.text.TextField.URL"),
112 uno::UNO_QUERY_THROW);
113 uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW);
114 xPropSet->setPropertyValue("Representation", uno::makeAny(OUString("LibreOffice")));
115 xPropSet->setPropertyValue("URL", uno::makeAny(OUString("http://www.libreoffice.org/")));
116 return xField;
119 } // namespace
121 uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init()
123 // Return a field that's already in the cell.
124 if (!mxField.is())
126 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
128 // Create a new URL field object, and populate it with name and URL.
129 mxField = getNewField(xSM);
131 // Insert this field into a cell.
132 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
133 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
134 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
135 // Use cell A1 for this.
136 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
137 uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW);
139 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
140 uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW);
141 uno::Reference<text::XTextContent> xContent(mxField, uno::UNO_QUERY_THROW);
142 xText->insertTextContent(xRange, xContent, false);
144 return mxField;
147 uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent()
149 // Return a field object that's not yet inserted.
150 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
151 return uno::Reference<text::XTextContent>(getNewField(xSM), uno::UNO_QUERY_THROW);
154 uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange()
156 // Use cell A2 for this.
157 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
158 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
159 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
160 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1);
161 uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY_THROW);
163 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
164 uno::Reference<text::XTextRange> xRange(xCursor, uno::UNO_QUERY_THROW);
165 return xRange;
168 void ScEditFieldObj_Cell::testEditFieldProperties()
170 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
173 // Test properties of date time field.
174 uno::Reference<text::XTextField> xField(
175 xSM->createInstance("com.sun.star.text.textfield.DateTime"), uno::UNO_QUERY_THROW);
176 uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW);
178 uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
179 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is());
181 CPPUNIT_ASSERT_MESSAGE("Calc's date time field should have 'IsFixed' property.",
182 xInfo->hasPropertyByName("IsFixed"));
186 // Test properties of document title field.
187 uno::Reference<text::XTextField> xField(
188 xSM->createInstance("com.sun.star.text.textfield.docinfo.Title"), uno::UNO_QUERY_THROW);
189 uno::Reference<beans::XPropertySet> xPropSet(xField, uno::UNO_QUERY_THROW);
191 uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
192 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is());
194 CPPUNIT_ASSERT_MESSAGE("Calc's title field shouldn't have 'IsFixed' property.",
195 !xInfo->hasPropertyByName("IsFixed"));
199 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell);
201 } // namespace sc_apitest
203 CPPUNIT_PLUGIN_IMPLEMENT();
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */