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/.
10 #include <test/unoapi_test.hxx>
11 #include <test/beans/xpropertyset.hxx>
12 #include <test/lang/xcomponent.hxx>
13 #include <test/text/textcontent.hxx>
14 #include <test/text/xtextfield.hxx>
15 #include <test/text/xtextcontent.hxx>
17 #include <com/sun/star/beans/XPropertySet.hpp>
18 #include <com/sun/star/container/XIndexAccess.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/table/XCell.hpp>
22 #include <com/sun/star/text/TextContentAnchorType.hpp>
23 #include <com/sun/star/text/WrapTextMode.hpp>
24 #include <com/sun/star/text/XText.hpp>
25 #include <com/sun/star/text/XTextContent.hpp>
26 #include <com/sun/star/text/XTextCursor.hpp>
27 #include <com/sun/star/text/XTextField.hpp>
28 #include <com/sun/star/text/XTextRange.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
37 class ScEditFieldObj_Cell
: public UnoApiTest
,
38 public apitest::TextContent
,
39 public apitest::XComponent
,
40 public apitest::XPropertySet
,
41 public apitest::XTextContent
,
42 public apitest::XTextField
45 ScEditFieldObj_Cell();
47 virtual void setUp() override
;
48 virtual void tearDown() override
;
49 virtual uno::Reference
<uno::XInterface
> init() override
;
50 virtual uno::Reference
<text::XTextContent
> getTextContent() override
;
51 virtual uno::Reference
<text::XTextRange
> getTextRange() override
;
52 virtual bool isAttachSupported() override
{ return true; }
53 virtual void triggerDesktopTerminate() override
{};
55 void testEditFieldProperties();
57 CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell
);
60 CPPUNIT_TEST(testTextContentProperties
);
63 CPPUNIT_TEST(testAddEventListener
);
64 CPPUNIT_TEST(testRemoveEventListener
);
65 CPPUNIT_TEST(testDispose
);
68 CPPUNIT_TEST(testGetPropertySetInfo
);
69 CPPUNIT_TEST(testGetPropertyValue
);
70 CPPUNIT_TEST(testSetPropertyValue
);
71 CPPUNIT_TEST(testPropertyChangeListener
);
72 CPPUNIT_TEST(testVetoableChangeListener
);
75 CPPUNIT_TEST(testGetPresentation
);
78 CPPUNIT_TEST(testGetAnchor
);
79 CPPUNIT_TEST(testAttach
);
81 // Tests specific to this service implementation.
82 CPPUNIT_TEST(testEditFieldProperties
);
84 CPPUNIT_TEST_SUITE_END();
87 static uno::Reference
<text::XTextField
> mxField
;
90 uno::Reference
<text::XTextField
> ScEditFieldObj_Cell::mxField
;
92 ScEditFieldObj_Cell::ScEditFieldObj_Cell()
93 : UnoApiTest("/sc/qa/extras/testdocuments")
94 , TextContent(text::TextContentAnchorType_AS_CHARACTER
,
95 text::TextContentAnchorType_AS_CHARACTER
, text::WrapTextMode_NONE
,
96 text::WrapTextMode_NONE
)
100 void ScEditFieldObj_Cell::setUp()
103 // Load an empty document.
104 mxComponent
= loadFromDesktop("private:factory/scalc");
107 void ScEditFieldObj_Cell::tearDown()
110 UnoApiTest::tearDown();
115 uno::Reference
<text::XTextField
> getNewField(const uno::Reference
<lang::XMultiServiceFactory
>& xSM
)
117 uno::Reference
<text::XTextField
> xField(xSM
->createInstance("com.sun.star.text.TextField.URL"),
118 uno::UNO_QUERY_THROW
);
119 uno::Reference
<beans::XPropertySet
> xPropSet(xField
, uno::UNO_QUERY_THROW
);
120 xPropSet
->setPropertyValue("Representation", uno::Any(OUString("LibreOffice")));
121 xPropSet
->setPropertyValue("URL", uno::Any(OUString("http://www.libreoffice.org/")));
127 uno::Reference
<uno::XInterface
> ScEditFieldObj_Cell::init()
129 // Return a field that's already in the cell.
132 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, uno::UNO_QUERY_THROW
);
134 // Create a new URL field object, and populate it with name and URL.
135 mxField
= getNewField(xSM
);
137 // Insert this field into a cell.
138 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
139 uno::Reference
<container::XIndexAccess
> xIA(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
140 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
141 // Use cell A1 for this.
142 uno::Reference
<table::XCell
> xCell
= xSheet
->getCellByPosition(0, 0);
143 uno::Reference
<text::XText
> xText(xCell
, uno::UNO_QUERY_THROW
);
145 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
146 uno::Reference
<text::XTextRange
> xRange(xCursor
, uno::UNO_QUERY_THROW
);
147 uno::Reference
<text::XTextContent
> xContent(mxField
, uno::UNO_QUERY_THROW
);
148 xText
->insertTextContent(xRange
, xContent
, false);
153 uno::Reference
<text::XTextContent
> ScEditFieldObj_Cell::getTextContent()
155 // Return a field object that's not yet inserted.
156 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, uno::UNO_QUERY_THROW
);
157 return uno::Reference
<text::XTextContent
>(getNewField(xSM
), uno::UNO_QUERY_THROW
);
160 uno::Reference
<text::XTextRange
> ScEditFieldObj_Cell::getTextRange()
162 // Use cell A2 for this.
163 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
164 uno::Reference
<container::XIndexAccess
> xIA(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
165 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
166 uno::Reference
<table::XCell
> xCell
= xSheet
->getCellByPosition(0, 1);
167 uno::Reference
<text::XText
> xText(xCell
, uno::UNO_QUERY_THROW
);
169 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursor();
170 uno::Reference
<text::XTextRange
> xRange(xCursor
, uno::UNO_QUERY_THROW
);
174 void ScEditFieldObj_Cell::testEditFieldProperties()
176 uno::Reference
<lang::XMultiServiceFactory
> xSM(mxComponent
, uno::UNO_QUERY_THROW
);
179 // Test properties of date time field.
180 uno::Reference
<text::XTextField
> xField(
181 xSM
->createInstance("com.sun.star.text.textfield.DateTime"), uno::UNO_QUERY_THROW
);
182 uno::Reference
<beans::XPropertySet
> xPropSet(xField
, uno::UNO_QUERY_THROW
);
184 uno::Reference
<beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
185 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo
.is());
187 CPPUNIT_ASSERT_MESSAGE("Calc's date time field should have 'IsFixed' property.",
188 xInfo
->hasPropertyByName("IsFixed"));
192 // Test properties of document title field.
193 uno::Reference
<text::XTextField
> xField(
194 xSM
->createInstance("com.sun.star.text.textfield.docinfo.Title"), uno::UNO_QUERY_THROW
);
195 uno::Reference
<beans::XPropertySet
> xPropSet(xField
, uno::UNO_QUERY_THROW
);
197 uno::Reference
<beans::XPropertySetInfo
> xInfo
= xPropSet
->getPropertySetInfo();
198 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo
.is());
200 CPPUNIT_ASSERT_MESSAGE("Calc's title field shouldn't have 'IsFixed' property.",
201 !xInfo
->hasPropertyByName("IsFixed"));
205 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell
);
207 } // namespace sc_apitest
209 CPPUNIT_PLUGIN_IMPLEMENT();
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */