nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / scannotationshapeobj.cxx
blob5a7a7258e04a2fd9e25140c94f040623ccdd67e1
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/calc_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/lang/XComponent.hpp>
22 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
23 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
24 #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
25 #include <com/sun/star/sheet/XSheetAnnotations.hpp>
26 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
27 #include <com/sun/star/sheet/XSpreadsheet.hpp>
28 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
29 #include <com/sun/star/table/CellAddress.hpp>
30 #include <com/sun/star/table/XCell.hpp>
31 #include <com/sun/star/text/XSimpleText.hpp>
32 #include <com/sun/star/uno/XInterface.hpp>
34 #include <com/sun/star/uno/Reference.hxx>
36 using namespace css;
38 namespace sc_apitest
40 class ScAnnotationShapeObj : public CalcUnoApiTest,
41 public apitest::CaptionShape,
42 public apitest::XGluePointsSupplier,
43 public apitest::XShape,
44 public apitest::XShapeDescriptor,
45 public apitest::XSimpleText,
46 public apitest::XText,
47 public apitest::XTextRange
49 public:
50 ScAnnotationShapeObj();
52 virtual void setUp() override;
53 virtual void tearDown() override;
54 virtual uno::Reference<uno::XInterface> init() override;
55 virtual uno::Reference<text::XTextContent> getTextContent() override;
57 CPPUNIT_TEST_SUITE(ScAnnotationShapeObj);
59 // CaptionShape
60 CPPUNIT_TEST(testCaptionShapeProperties);
62 // XGluePointsSupplier
63 CPPUNIT_TEST(testGetGluePoints);
65 // XShape
66 CPPUNIT_TEST(testGetSetSize);
67 CPPUNIT_TEST(testGetSetPosition);
69 // XShapeDescriptor
70 CPPUNIT_TEST(testGetShapeType);
72 // XSimpleText
73 CPPUNIT_TEST(testCreateTextCursor);
74 CPPUNIT_TEST(testCreateTextCursorByRange);
75 CPPUNIT_TEST(testInsertControlCharacter);
76 CPPUNIT_TEST(testInsertString);
78 // XText
79 CPPUNIT_TEST(testInsertRemoveTextContent);
81 // XTextRange
82 CPPUNIT_TEST(testGetEnd);
83 CPPUNIT_TEST(testGetSetString);
84 CPPUNIT_TEST(testGetStart);
85 CPPUNIT_TEST(testGetText);
87 CPPUNIT_TEST_SUITE_END();
89 private:
90 uno::Reference<lang::XComponent> m_xComponent;
91 static uno::Reference<text::XTextContent> m_xField;
94 uno::Reference<text::XTextContent> ScAnnotationShapeObj::m_xField;
96 ScAnnotationShapeObj::ScAnnotationShapeObj()
97 : CalcUnoApiTest("sc/qa/extras/testdocuments")
98 , XShapeDescriptor("com.sun.star.drawing.CaptionShape")
102 void ScAnnotationShapeObj::setUp()
104 CalcUnoApiTest::setUp();
105 m_xComponent = loadFromDesktop("private:factory/scalc");
108 void ScAnnotationShapeObj::tearDown()
110 m_xField.clear();
111 closeDocument(m_xComponent);
113 CalcUnoApiTest::tearDown();
116 uno::Reference<uno::XInterface> ScAnnotationShapeObj::init()
118 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
120 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), uno::UNO_QUERY_THROW);
121 uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), uno::UNO_QUERY_THROW);
123 // Use cell A1 for this.
124 table::CellAddress aNotePos(0, 0, 0);
125 uno::Reference<sheet::XSheetAnnotationsSupplier> xAnnosSupp(xSheet, uno::UNO_QUERY_THROW);
126 uno::Reference<sheet::XSheetAnnotations> xAnnos(xAnnosSupp->getAnnotations(),
127 uno::UNO_SET_THROW);
128 // non-empty string required by note implementation (real text will be added below)
129 xAnnos->insertNew(aNotePos, OUString(' '));
131 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
132 uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(xCell, uno::UNO_QUERY_THROW);
133 uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(),
134 uno::UNO_SET_THROW);
135 uno::Reference<text::XSimpleText> xAnnoText(xAnnotation, uno::UNO_QUERY_THROW);
136 xAnnoText->setString("ScAnnotationShapeObj");
138 uno::Reference<sheet::XSheetAnnotationShapeSupplier> xShapeSupp(xAnnotation,
139 uno::UNO_QUERY_THROW);
140 uno::Reference<drawing::XShape> xShape(xShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW);
142 return xShape;
145 uno::Reference<text::XTextContent> ScAnnotationShapeObj::getTextContent()
147 if (!m_xField.is())
149 uno::Reference<lang::XMultiServiceFactory> xSM(m_xComponent, uno::UNO_QUERY_THROW);
150 m_xField.set(xSM->createInstance("com.sun.star.text.TextField.DateTime"),
151 uno::UNO_QUERY_THROW);
153 return m_xField;
156 CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnotationShapeObj);
158 } // namespace sc_apitest
160 CPPUNIT_PLUGIN_IMPLEMENT();
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */