update emoji autocorrect entries from po-files
[LibreOffice.git] / sc / qa / extras / sceditfieldobj-cell.cxx
blob878210b7ab349d5255b8bc70d4cbc6961a8cf94f
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/xtextfield.hxx>
13 #include <test/text/xtextcontent.hxx>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/container/XEnumerationAccess.hpp>
17 #include <com/sun/star/text/XText.hpp>
18 #include <com/sun/star/text/XTextField.hpp>
19 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/sheet/XSpreadsheet.hpp>
23 #define NUMBER_OF_TESTS 7
25 using namespace css;
26 using namespace css::uno;
28 namespace sc_apitest {
30 class ScEditFieldObj_Cell : public CalcUnoApiTest, apitest::XTextField, apitest::XTextContent, apitest::XPropertySet
32 public:
33 ScEditFieldObj_Cell();
35 virtual void setUp() SAL_OVERRIDE;
36 virtual void tearDown() SAL_OVERRIDE;
37 virtual uno::Reference<uno::XInterface> init() SAL_OVERRIDE;
38 virtual uno::Reference<text::XTextContent> getTextContent() SAL_OVERRIDE;
39 virtual uno::Reference<text::XTextRange> getTextRange() SAL_OVERRIDE;
40 virtual bool isAttachSupported() SAL_OVERRIDE { return true; }
42 void testEditFieldProperties();
44 CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell);
46 // XPropertySet
47 CPPUNIT_TEST(testGetPropertySetInfo);
48 CPPUNIT_TEST(testGetPropertyValue);
49 CPPUNIT_TEST(testSetPropertyValue);
51 // XTextField
52 CPPUNIT_TEST(testGetPresentation);
54 // XTextContent
55 CPPUNIT_TEST(testGetAnchor);
56 CPPUNIT_TEST(testAttach);
58 // Tests specific to this service implementation.
59 CPPUNIT_TEST(testEditFieldProperties);
61 CPPUNIT_TEST_SUITE_END();
63 private:
64 static sal_Int32 nTest;
65 static uno::Reference<lang::XComponent> mxComponent;
66 static uno::Reference<text::XTextField> mxField;
69 sal_Int32 ScEditFieldObj_Cell::nTest = 0;
70 uno::Reference<lang::XComponent> ScEditFieldObj_Cell::mxComponent;
71 uno::Reference<text::XTextField> ScEditFieldObj_Cell::mxField;
73 ScEditFieldObj_Cell::ScEditFieldObj_Cell()
74 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
78 void ScEditFieldObj_Cell::setUp()
80 ++nTest;
81 CalcUnoApiTest::setUp();
84 void ScEditFieldObj_Cell::tearDown()
86 if (nTest == NUMBER_OF_TESTS)
88 mxField.clear();
89 closeDocument(mxComponent);
90 mxComponent.clear();
93 CalcUnoApiTest::tearDown();
96 namespace {
98 uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM)
100 uno::Reference<text::XTextField> xField(
101 xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW);
102 uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW);
103 xPropSet->setPropertyValue("Representation", uno::makeAny(OUString("LibreOffice")));
104 xPropSet->setPropertyValue("URL", uno::makeAny(OUString("http://www.libreoffice.org/")));
105 return xField;
110 uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init()
112 // Return a field that's already in the cell.
113 if (!mxField.is())
115 if (!mxComponent.is())
116 // Load an empty document.
117 mxComponent = loadFromDesktop("private:factory/scalc");
119 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
121 // Create a new URL field object, and populate it with name and URL.
122 mxField = getNewField(xSM);
124 // Insert this field into a cell.
125 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
126 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
127 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
128 // Use cell A1 for this.
129 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
130 uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW);
132 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
133 uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW);
134 uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW);
135 xText->insertTextContent(xRange, xContent, sal_False);
137 return mxField;
140 uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent()
142 // Return a field object that's not yet inserted.
143 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
144 return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW);
147 uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange()
149 // Use cell A2 for this.
150 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
151 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
152 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
153 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1);
154 uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW);
156 uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
157 uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW);
158 return xRange;
161 void ScEditFieldObj_Cell::testEditFieldProperties()
163 CPPUNIT_ASSERT_MESSAGE("component doesn't exist.", mxComponent.is());
164 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
167 // Test properties of date time field.
168 uno::Reference<text::XTextField> xField(
169 xSM->createInstance("com.sun.star.text.textfield.DateTime"), UNO_QUERY_THROW);
170 uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW);
172 uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
173 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is());
175 CPPUNIT_ASSERT_MESSAGE("Calc's date time field should have 'IsFixed' property.",
176 xInfo->hasPropertyByName("IsFixed"));
180 // Test properties of document title field.
181 uno::Reference<text::XTextField> xField(
182 xSM->createInstance("com.sun.star.text.textfield.docinfo.Title"), UNO_QUERY_THROW);
183 uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW);
185 uno::Reference<beans::XPropertySetInfo> xInfo = xPropSet->getPropertySetInfo();
186 CPPUNIT_ASSERT_MESSAGE("failed to retrieve property set info.", xInfo.is());
188 CPPUNIT_ASSERT_MESSAGE("Calc's title field shouldn't have 'IsFixed' property.",
189 !xInfo->hasPropertyByName("IsFixed"));
193 CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell);
197 CPPUNIT_PLUGIN_IMPLEMENT();
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */