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 10 : 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 2 : CPPUNIT_TEST_SUITE(ScAnnontationObj);
41 1 : CPPUNIT_TEST(testGetPosition);
42 1 : CPPUNIT_TEST(testGetAuthor);
43 1 : CPPUNIT_TEST(testGetDate);
44 1 : CPPUNIT_TEST(testGetIsVisible);
45 1 : CPPUNIT_TEST(testSetIsVisible);
46 5 : 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 1 : uno::Reference< lang::XComponent > ScAnnontationObj::mxComponent;
55 :
56 5 : ScAnnontationObj::ScAnnontationObj()
57 5 : : CalcUnoApiTest("/sc/qa/extras/testdocuments")
58 : {
59 5 : }
60 :
61 5 : uno::Reference< sheet::XSheetAnnotation> ScAnnontationObj::getAnnotation(table::CellAddress& xCellAddress)
62 : {
63 : // get the sheet
64 5 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(mxComponent, UNO_QUERY_THROW);
65 10 : uno::Reference< container::XIndexAccess > xIndex (xDoc->getSheets(), UNO_QUERY_THROW);
66 10 : uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex(xCellAddress.Sheet), UNO_QUERY_THROW);
67 :
68 : // get the cell
69 10 : uno::Reference< table::XCell > xCell( xSheet->getCellByPosition(xCellAddress.Column, xCellAddress.Row), UNO_QUERY_THROW);
70 :
71 : // get the annotation from cell
72 10 : uno::Reference< sheet::XSheetAnnotationAnchor > xAnnotationAnchor(xCell, UNO_QUERY_THROW);
73 5 : uno::Reference< sheet::XSheetAnnotation > xSheetAnnotation( xAnnotationAnchor->getAnnotation(), UNO_QUERY_THROW);
74 :
75 5 : CPPUNIT_ASSERT(xSheetAnnotation.is());
76 :
77 10 : return xSheetAnnotation;
78 : }
79 :
80 5 : uno::Reference< uno::XInterface > ScAnnontationObj::init()
81 : {
82 :
83 : // get the test file
84 5 : OUString aFileURL;
85 5 : createFileURL(OUString("ScAnnotationObj.ods"), aFileURL);
86 5 : if(!mxComponent.is())
87 1 : mxComponent = loadFromDesktop(aFileURL);
88 5 : CPPUNIT_ASSERT_MESSAGE("Component not loaded",mxComponent.is());
89 :
90 : // tested annotation is in sheet 0 cell C2
91 5 : table::CellAddress xCellAddress;
92 5 : xCellAddress.Sheet = 0;
93 5 : xCellAddress.Row = 1;
94 5 : xCellAddress.Column = 2;
95 :
96 5 : return getAnnotation(xCellAddress);
97 : }
98 :
99 5 : void ScAnnontationObj::setUp()
100 : {
101 5 : nTest++;
102 5 : CalcUnoApiTest::setUp();
103 5 : }
104 :
105 5 : void ScAnnontationObj::tearDown()
106 : {
107 5 : if (nTest == NUMBER_OF_TESTS)
108 : {
109 1 : closeDocument(mxComponent);
110 1 : mxComponent.clear();
111 : }
112 :
113 5 : CalcUnoApiTest::tearDown();
114 5 : }
115 :
116 1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnontationObj);
117 :
118 : }
119 :
120 4 : CPPUNIT_PLUGIN_IMPLEMENT();
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|