1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/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>
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
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
);
59 CPPUNIT_TEST(testCaptionShapeProperties
);
61 // XGluePointsSupplier
62 CPPUNIT_TEST(testGetGluePoints
);
65 CPPUNIT_TEST(testGetSetSize
);
66 CPPUNIT_TEST(testGetSetPosition
);
69 CPPUNIT_TEST(testGetShapeType
);
72 CPPUNIT_TEST(testCreateTextCursor
);
73 CPPUNIT_TEST(testCreateTextCursorByRange
);
74 CPPUNIT_TEST(testInsertControlCharacter
);
75 CPPUNIT_TEST(testInsertString
);
78 CPPUNIT_TEST(testInsertRemoveTextContent
);
81 CPPUNIT_TEST(testGetEnd
);
82 CPPUNIT_TEST(testGetSetString
);
83 CPPUNIT_TEST(testGetStart
);
84 CPPUNIT_TEST(testGetText
);
86 CPPUNIT_TEST_SUITE_END();
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()
103 loadFromURL(u
"private:factory/scalc"_ustr
);
106 void ScAnnotationShapeObj::tearDown()
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(),
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(),
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
);
141 uno::Reference
<text::XTextContent
> ScAnnotationShapeObj::getTextContent()
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
);
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: */