1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/sheet/xsheetannotation.hxx>
13 #include <com/sun/star/beans/XPropertySet.hpp>
14 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
15 #include <com/sun/star/sheet/XSpreadsheet.hpp>
17 #include <com/sun/star/table/CellAddress.hpp>
18 #include <com/sun/star/table/XCell.hpp>
20 #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
23 using namespace css::uno
;
25 namespace sc_apitest
{
27 #define NUMBER_OF_TESTS 5
29 class ScAnnontationObj
: public CalcUnoApiTest
, apitest::XSheetAnnotation
34 virtual void setUp() SAL_OVERRIDE
;
35 virtual void tearDown() SAL_OVERRIDE
;
37 virtual uno::Reference
< uno::XInterface
> init() SAL_OVERRIDE
;
38 virtual uno::Reference
< sheet::XSheetAnnotation
> getAnnotation(table::CellAddress
&) SAL_OVERRIDE
;
40 CPPUNIT_TEST_SUITE(ScAnnontationObj
);
41 CPPUNIT_TEST(testGetPosition
);
42 CPPUNIT_TEST(testGetAuthor
);
43 CPPUNIT_TEST(testGetDate
);
44 CPPUNIT_TEST(testGetIsVisible
);
45 CPPUNIT_TEST(testSetIsVisible
);
46 CPPUNIT_TEST_SUITE_END();
49 static sal_Int32 nTest
;
50 static uno::Reference
< lang::XComponent
> mxComponent
;
53 sal_Int32
ScAnnontationObj::nTest
= 0;
54 uno::Reference
< lang::XComponent
> ScAnnontationObj::mxComponent
;
56 ScAnnontationObj::ScAnnontationObj()
57 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
61 uno::Reference
< sheet::XSheetAnnotation
> ScAnnontationObj::getAnnotation(table::CellAddress
& xCellAddress
)
64 uno::Reference
< sheet::XSpreadsheetDocument
> xDoc(mxComponent
, UNO_QUERY_THROW
);
65 uno::Reference
< container::XIndexAccess
> xIndex (xDoc
->getSheets(), UNO_QUERY_THROW
);
66 uno::Reference
< sheet::XSpreadsheet
> xSheet( xIndex
->getByIndex(xCellAddress
.Sheet
), UNO_QUERY_THROW
);
69 uno::Reference
< table::XCell
> xCell( xSheet
->getCellByPosition(xCellAddress
.Column
, xCellAddress
.Row
), UNO_QUERY_THROW
);
71 // get the annotation from cell
72 uno::Reference
< sheet::XSheetAnnotationAnchor
> xAnnotationAnchor(xCell
, UNO_QUERY_THROW
);
73 uno::Reference
< sheet::XSheetAnnotation
> xSheetAnnotation( xAnnotationAnchor
->getAnnotation(), UNO_QUERY_THROW
);
75 CPPUNIT_ASSERT(xSheetAnnotation
.is());
77 return xSheetAnnotation
;
80 uno::Reference
< uno::XInterface
> ScAnnontationObj::init()
85 createFileURL(OUString("ScAnnotationObj.ods"), aFileURL
);
87 mxComponent
= loadFromDesktop(aFileURL
);
88 CPPUNIT_ASSERT_MESSAGE("Component not loaded",mxComponent
.is());
90 // tested annotation is in sheet 0 cell C2
91 table::CellAddress xCellAddress
;
92 xCellAddress
.Sheet
= 0;
94 xCellAddress
.Column
= 2;
96 return getAnnotation(xCellAddress
);
99 void ScAnnontationObj::setUp()
102 CalcUnoApiTest::setUp();
105 void ScAnnontationObj::tearDown()
107 if (nTest
== NUMBER_OF_TESTS
)
109 closeDocument(mxComponent
);
113 CalcUnoApiTest::tearDown();
116 CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj
);
120 CPPUNIT_PLUGIN_IMPLEMENT();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */