Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <test/calc_unoapi_test.hxx>
11 : #include <test/sheet/xsheetannotation.hxx>
12 :
13 : #include <com/sun/star/beans/XPropertySet.hpp>
14 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
15 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
16 :
17 : #include <com/sun/star/table/CellAddress.hpp>
18 : #include <com/sun/star/table/XCell.hpp>
19 :
20 : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
21 :
22 : using namespace css;
23 : using namespace css::uno;
24 :
25 : namespace sc_apitest {
26 :
27 : #define NUMBER_OF_TESTS 5
28 :
29 20 : class ScAnnontationObj : public CalcUnoApiTest, apitest::XSheetAnnotation
30 : {
31 : public:
32 : ScAnnontationObj();
33 :
34 : virtual void setUp() SAL_OVERRIDE;
35 : virtual void tearDown() SAL_OVERRIDE;
36 :
37 : virtual uno::Reference< uno::XInterface > init() SAL_OVERRIDE;
38 : virtual uno::Reference< sheet::XSheetAnnotation> getAnnotation(table::CellAddress&) SAL_OVERRIDE;
39 :
40 4 : CPPUNIT_TEST_SUITE(ScAnnontationObj);
41 2 : CPPUNIT_TEST(testGetPosition);
42 2 : CPPUNIT_TEST(testGetAuthor);
43 2 : CPPUNIT_TEST(testGetDate);
44 2 : CPPUNIT_TEST(testGetIsVisible);
45 2 : CPPUNIT_TEST(testSetIsVisible);
46 4 : CPPUNIT_TEST_SUITE_END();
47 : private:
48 :
49 : static sal_Int32 nTest;
50 : static uno::Reference< lang::XComponent > mxComponent;
51 : };
52 :
53 : sal_Int32 ScAnnontationObj::nTest = 0;
54 2 : uno::Reference< lang::XComponent > ScAnnontationObj::mxComponent;
55 :
56 10 : ScAnnontationObj::ScAnnontationObj()
57 10 : : CalcUnoApiTest("/sc/qa/extras/testdocuments")
58 : {
59 10 : }
60 :
61 10 : uno::Reference< sheet::XSheetAnnotation> ScAnnontationObj::getAnnotation(table::CellAddress& xCellAddress)
62 : {
63 : // get the sheet
64 10 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
65 20 : uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW);
66 20 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(xCellAddress.Sheet), UNO_QUERY_THROW);
67 :
68 : // get the cell
69 20 : uno::Reference< table::XCell > xCell( xSheet->getCellByPosition(xCellAddress.Column, xCellAddress.Row), UNO_QUERY_THROW);
70 :
71 : // get the annotation from cell
72 20 : uno::Reference< sheet::XSheetAnnotationAnchor > xAnnotationAnchor(xCell, UNO_QUERY_THROW);
73 10 : uno::Reference< sheet::XSheetAnnotation > xSheetAnnotation( xAnnotationAnchor->getAnnotation(), UNO_QUERY_THROW);
74 :
75 10 : CPPUNIT_ASSERT(xSheetAnnotation.is());
76 :
77 20 : return xSheetAnnotation;
78 : }
79 :
80 10 : uno::Reference< uno::XInterface > ScAnnontationObj::init()
81 : {
82 :
83 : // get the test file
84 10 : OUString aFileURL;
85 10 : createFileURL(OUString("ScAnnotationObj.ods"), aFileURL);
86 10 : if(!mxComponent.is())
87 2 : mxComponent = loadFromDesktop(aFileURL);
88 10 : CPPUNIT_ASSERT_MESSAGE("Component not loaded",mxComponent.is());
89 :
90 : // tested annotation is in sheet 0 cell C2
91 10 : table::CellAddress xCellAddress;
92 10 : xCellAddress.Sheet = 0;
93 10 : xCellAddress.Row = 1;
94 10 : xCellAddress.Column = 2;
95 :
96 10 : return getAnnotation(xCellAddress);
97 : }
98 :
99 10 : void ScAnnontationObj::setUp()
100 : {
101 10 : nTest++;
102 10 : CalcUnoApiTest::setUp();
103 10 : }
104 :
105 10 : void ScAnnontationObj::tearDown()
106 : {
107 10 : if (nTest == NUMBER_OF_TESTS)
108 : {
109 2 : closeDocument(mxComponent);
110 2 : mxComponent.clear();
111 : }
112 :
113 10 : CalcUnoApiTest::tearDown();
114 10 : }
115 :
116 2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj);
117 :
118 : }
119 :
120 8 : CPPUNIT_PLUGIN_IMPLEMENT();
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|