Update git submodules
[LibreOffice.git] / sc / qa / extras / scannotationshapeobj.cxx
blobbee2158e82d009a94e0c44f0685cfc5ae24deb21
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/unoapi_test.hxx>
11 #include <test/drawing/captionshape.hxx>
12 #include <test/drawing/xgluepointssupplier.hxx>
13 #include <test/drawing/xshape.hxx>
14 #include <test/drawing/xshapedescriptor.hxx>
15 #include <test/text/xsimpletext.hxx>
16 #include <test/text/xtext.hxx>
17 #include <test/text/xtextrange.hxx>
19 #include <com/sun/star/container/XIndexAccess.hpp>
20 #include <com/sun/star/drawing/XShape.hpp>
21 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
22 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
23 #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
24 #include <com/sun/star/sheet/XSheetAnnotations.hpp>
25 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
26 #include <com/sun/star/sheet/XSpreadsheet.hpp>
27 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28 #include <com/sun/star/table/CellAddress.hpp>
29 #include <com/sun/star/table/XCell.hpp>
30 #include <com/sun/star/text/XSimpleText.hpp>
31 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/uno/Reference.hxx>
35 using namespace css;
37 namespace sc_apitest
39 class ScAnnotationShapeObj : public UnoApiTest,
40 public apitest::CaptionShape,
41 public apitest::XGluePointsSupplier,
42 public apitest::XShape,
43 public apitest::XShapeDescriptor,
44 public apitest::XSimpleText,
45 public apitest::XText,
46 public apitest::XTextRange
48 public:
49 ScAnnotationShapeObj();
51 virtual void setUp() override;
52 virtual void tearDown() override;
53 virtual uno::Reference<uno::XInterface> init() override;
54 virtual uno::Reference<text::XTextContent> getTextContent() override;
56 CPPUNIT_TEST_SUITE(ScAnnotationShapeObj);
58 // CaptionShape
59 CPPUNIT_TEST(testCaptionShapeProperties);
61 // XGluePointsSupplier
62 CPPUNIT_TEST(testGetGluePoints);
64 // XShape
65 CPPUNIT_TEST(testGetSetSize);
66 CPPUNIT_TEST(testGetSetPosition);
68 // XShapeDescriptor
69 CPPUNIT_TEST(testGetShapeType);
71 // XSimpleText
72 CPPUNIT_TEST(testCreateTextCursor);
73 CPPUNIT_TEST(testCreateTextCursorByRange);
74 CPPUNIT_TEST(testInsertControlCharacter);
75 CPPUNIT_TEST(testInsertString);
77 // XText
78 CPPUNIT_TEST(testInsertRemoveTextContent);
80 // XTextRange
81 CPPUNIT_TEST(testGetEnd);
82 CPPUNIT_TEST(testGetSetString);
83 CPPUNIT_TEST(testGetStart);
84 CPPUNIT_TEST(testGetText);
86 CPPUNIT_TEST_SUITE_END();
88 private:
89 static uno::Reference<text::XTextContent> m_xField;
92 uno::Reference<text::XTextContent> ScAnnotationShapeObj::m_xField;
94 ScAnnotationShapeObj::ScAnnotationShapeObj()
95 : UnoApiTest(u"sc/qa/extras/testdocuments"_ustr)
96 , XShapeDescriptor(u"com.sun.star.drawing.CaptionShape"_ustr)
100 void ScAnnotationShapeObj::setUp()
102 UnoApiTest::setUp();
103 loadFromURL(u"private:factory/scalc"_ustr);
106 void ScAnnotationShapeObj::tearDown()
108 m_xField.clear();
109 UnoApiTest::tearDown();
112 uno::Reference<uno::XInterface> ScAnnotationShapeObj::init()
114 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, uno::UNO_QUERY_THROW);
116 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
117 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
119 // Use cell A1 for this.
120 table::CellAddress aNotePos(0, 0, 0);
121 uno::Reference<sheet::XSheetAnnotationsSupplier> xAnnosSupp(xSheet, uno::UNO_QUERY_THROW);
122 uno::Reference<sheet::XSheetAnnotations> xAnnos(xAnnosSupp->getAnnotations(),
123 uno::UNO_SET_THROW);
124 // non-empty string required by note implementation (real text will be added below)
125 xAnnos->insertNew(aNotePos, OUString(' '));
127 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
128 uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(xCell, uno::UNO_QUERY_THROW);
129 uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(),
130 uno::UNO_SET_THROW);
131 uno::Reference<text::XSimpleText> xAnnoText(xAnnotation, uno::UNO_QUERY_THROW);
132 xAnnoText->setString(u"ScAnnotationShapeObj"_ustr);
134 uno::Reference<sheet::XSheetAnnotationShapeSupplier> xShapeSupp(xAnnotation,
135 uno::UNO_QUERY_THROW);
136 uno::Reference<drawing::XShape> xShape(xShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW);
138 return xShape;
141 uno::Reference<text::XTextContent> ScAnnotationShapeObj::getTextContent()
143 if (!m_xField.is())
145 uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, uno::UNO_QUERY_THROW);
146 m_xField.set(xSM->createInstance(u"com.sun.star.text.TextField.DateTime"_ustr),
147 uno::UNO_QUERY_THROW);
149 return m_xField;
152 CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnotationShapeObj);
154 } // namespace sc_apitest
156 CPPUNIT_PLUGIN_IMPLEMENT();
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */