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/calc_unoapi_test.hxx>
11 #include <test/container/xchild.hxx>
12 #include <test/lang/xserviceinfo.hxx>
13 #include <test/sheet/xsheetannotation.hxx>
14 #include <test/sheet/xsheetannotationshapesupplier.hxx>
15 #include <test/text/xsimpletext.hxx>
16 #include <test/text/xtextrange.hxx>
18 #include <com/sun/star/lang/XComponent.hpp>
19 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
20 #include <com/sun/star/sheet/XSpreadsheet.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/table/CellAddress.hpp>
23 #include <com/sun/star/table/XCell.hpp>
24 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/uno/Reference.hxx>
32 class ScAnnontationObj
: public CalcUnoApiTest
,
33 public apitest::XChild
,
34 public apitest::XServiceInfo
,
35 public apitest::XSheetAnnotation
,
36 public apitest::XSheetAnnotationShapeSupplier
,
37 public apitest::XSimpleText
,
38 public apitest::XTextRange
43 virtual void setUp() override
;
44 virtual void tearDown() override
;
46 virtual uno::Reference
<uno::XInterface
> init() override
;
47 virtual uno::Reference
<sheet::XSheetAnnotation
> getAnnotation(table::CellAddress
&) override
;
49 CPPUNIT_TEST_SUITE(ScAnnontationObj
);
52 CPPUNIT_TEST(testGetSetParent
);
55 CPPUNIT_TEST(testGetImplementationName
);
56 CPPUNIT_TEST(testGetSupportedServiceNames
);
57 CPPUNIT_TEST(testSupportsService
);
60 CPPUNIT_TEST(testGetPosition
);
61 CPPUNIT_TEST(testGetAuthor
);
62 CPPUNIT_TEST(testGetDate
);
63 CPPUNIT_TEST(testGetIsVisible
);
64 CPPUNIT_TEST(testSetIsVisible
);
66 // XSheetAnnotationShapeSupplier
67 CPPUNIT_TEST(testGetAnnotationShape
);
70 CPPUNIT_TEST(testCreateTextCursor
);
71 CPPUNIT_TEST(testCreateTextCursorByRange
);
72 CPPUNIT_TEST(testInsertString
);
73 CPPUNIT_TEST(testInsertControlCharacter
);
76 CPPUNIT_TEST(testGetEnd
);
77 CPPUNIT_TEST(testGetSetString
);
78 CPPUNIT_TEST(testGetStart
);
79 CPPUNIT_TEST(testGetText
);
81 CPPUNIT_TEST_SUITE_END();
84 uno::Reference
<lang::XComponent
> mxComponent
;
87 ScAnnontationObj::ScAnnontationObj()
88 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
89 , XServiceInfo("ScAnnotationObj", "com.sun.star.sheet.CellAnnotation")
93 uno::Reference
<sheet::XSheetAnnotation
>
94 ScAnnontationObj::getAnnotation(table::CellAddress
& xCellAddress
)
97 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
98 uno::Reference
<container::XIndexAccess
> xIndex(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
99 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(xCellAddress
.Sheet
),
100 uno::UNO_QUERY_THROW
);
103 uno::Reference
<table::XCell
> xCell(
104 xSheet
->getCellByPosition(xCellAddress
.Column
, xCellAddress
.Row
), uno::UNO_SET_THROW
);
106 // get the annotation from cell
107 uno::Reference
<sheet::XSheetAnnotationAnchor
> xAnnotationAnchor(xCell
, uno::UNO_QUERY_THROW
);
108 uno::Reference
<sheet::XSheetAnnotation
> xSheetAnnotation(xAnnotationAnchor
->getAnnotation(),
111 return xSheetAnnotation
;
114 uno::Reference
<uno::XInterface
> ScAnnontationObj::init()
116 // tested annotation is in sheet 0 cell C2
117 table::CellAddress aCellAddress
;
118 aCellAddress
.Sheet
= 0;
119 aCellAddress
.Row
= 1;
120 aCellAddress
.Column
= 2;
122 return getAnnotation(aCellAddress
);
125 void ScAnnontationObj::setUp()
127 CalcUnoApiTest::setUp();
131 createFileURL("ScAnnotationObj.ods", aFileURL
);
132 mxComponent
= loadFromDesktop(aFileURL
);
135 void ScAnnontationObj::tearDown()
137 closeDocument(mxComponent
);
138 CalcUnoApiTest::tearDown();
141 CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj
);
143 } // namespace sc_apitest
145 CPPUNIT_PLUGIN_IMPLEMENT();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */