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/text/xtext.hxx>
12 :
13 : #include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp>
14 : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
15 : #include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp>
16 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
17 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
18 : #include <com/sun/star/table/CellAddress.hpp>
19 :
20 : #define NUMBER_OF_TESTS 1
21 :
22 : using namespace css;
23 : using namespace css::uno;
24 :
25 : namespace sc_apitest {
26 :
27 2 : class ScAnnotationShapeObj : public CalcUnoApiTest, apitest::XText
28 : {
29 : public:
30 : ScAnnotationShapeObj();
31 :
32 : virtual void setUp() SAL_OVERRIDE;
33 : virtual void tearDown() SAL_OVERRIDE;
34 : virtual uno::Reference<uno::XInterface> init() SAL_OVERRIDE;
35 : virtual uno::Reference<text::XTextContent> getTextContent() SAL_OVERRIDE;
36 :
37 2 : CPPUNIT_TEST_SUITE(ScAnnotationShapeObj);
38 :
39 : // XText
40 1 : CPPUNIT_TEST(testInsertRemoveTextContent);
41 :
42 5 : CPPUNIT_TEST_SUITE_END();
43 :
44 : private:
45 : static sal_Int32 nTest;
46 : static uno::Reference<lang::XComponent> mxComponent;
47 : static uno::Reference<text::XTextContent> mxField;
48 : };
49 :
50 : sal_Int32 ScAnnotationShapeObj::nTest = 0;
51 1 : uno::Reference<lang::XComponent> ScAnnotationShapeObj::mxComponent;
52 1 : uno::Reference<text::XTextContent> ScAnnotationShapeObj::mxField;
53 :
54 1 : ScAnnotationShapeObj::ScAnnotationShapeObj()
55 1 : : CalcUnoApiTest("sc/qa/extras/testdocuments")
56 : {
57 1 : }
58 :
59 1 : void ScAnnotationShapeObj::setUp()
60 : {
61 1 : ++nTest;
62 1 : CalcUnoApiTest::setUp();
63 1 : }
64 :
65 1 : void ScAnnotationShapeObj::tearDown()
66 : {
67 1 : if (nTest == NUMBER_OF_TESTS)
68 : {
69 1 : mxField.clear();
70 1 : closeDocument(mxComponent);
71 1 : mxComponent.clear();
72 : }
73 :
74 1 : CalcUnoApiTest::tearDown();
75 1 : }
76 :
77 1 : uno::Reference<uno::XInterface> ScAnnotationShapeObj::init()
78 : {
79 1 : if (!mxComponent.is())
80 : // Load an empty document.
81 1 : mxComponent = loadFromDesktop("private:factory/scalc");
82 :
83 1 : uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
84 2 : uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
85 2 : uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW);
86 :
87 : // Use cell A1 for this.
88 :
89 1 : table::CellAddress aNotePos(0, 0, 0);
90 2 : Reference<sheet::XSheetAnnotationsSupplier> xAnnosSupp(xSheet, UNO_QUERY_THROW);
91 2 : Reference<sheet::XSheetAnnotations> xAnnos(xAnnosSupp->getAnnotations(), UNO_SET_THROW);
92 : // non-empty string required by note implementation (real text will be added below)
93 1 : xAnnos->insertNew(aNotePos, OUString(' '));
94 :
95 2 : uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0);
96 2 : uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(xCell, UNO_QUERY_THROW);
97 2 : uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(), UNO_SET_THROW);
98 2 : uno::Reference<text::XSimpleText> xAnnoText(xAnnotation, UNO_QUERY_THROW);
99 1 : xAnnoText->setString("ScAnnotationShapeObj");
100 :
101 2 : uno::Reference<sheet::XSheetAnnotationShapeSupplier> xShapeSupp(xAnnotation, UNO_QUERY_THROW);
102 2 : uno::Reference<drawing::XShape> xShape(xShapeSupp->getAnnotationShape(), UNO_SET_THROW);
103 :
104 2 : return xShape;
105 : }
106 :
107 2 : uno::Reference<text::XTextContent> ScAnnotationShapeObj::getTextContent()
108 : {
109 2 : if (!mxField.is())
110 : {
111 1 : uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW);
112 1 : mxField.set(xSM->createInstance("com.sun.star.text.TextField.DateTime"), UNO_QUERY_THROW);
113 : }
114 2 : return mxField;
115 : }
116 :
117 1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScAnnotationShapeObj);
118 :
119 1 : CPPUNIT_PLUGIN_IMPLEMENT();
120 :
121 3 : }
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|