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/sheet/xsheetannotations.hxx>
12 #include <com/sun/star/table/CellAddress.hpp>
13 #include <com/sun/star/container/XIndexAccess.hpp>
14 #include <com/sun/star/sheet/XSheetAnnotation.hpp>
15 #include <com/sun/star/text/XTextRange.hpp>
17 #include "cppunit/extensions/HelperMacros.h"
18 #include <rtl/ustring.hxx>
21 using namespace css::uno
;
25 void XSheetAnnotations::testInsertNew()
27 uno::Reference
< sheet::XSheetAnnotations
> aSheetAnnotations (init(), UNO_QUERY_THROW
);
29 // count before inserting
30 uno::Reference
< container::XIndexAccess
> xAnnotationsIndex (aSheetAnnotations
, UNO_QUERY_THROW
);
31 sal_Int32 nBefore
= xAnnotationsIndex
->getCount();
33 // insert the annotation
34 table::CellAddress
xTargetCellAddress (0,3,4);
35 aSheetAnnotations
->insertNew(xTargetCellAddress
, "an inserted annotation");
37 // count after inserting
38 //uno::Reference< container::XIndexAccess > xAnnotationsIndexAfter (aSheetAnnotations, UNO_QUERY_THROW);
39 sal_Int32 nAfter
= xAnnotationsIndex
->getCount();
41 CPPUNIT_ASSERT_MESSAGE("Annotations index not updated", nAfter
== nBefore
+ 1);
43 // is the position ok ?
44 uno::Reference
< sheet::XSheetAnnotation
> aLastSheetAnnotation (xAnnotationsIndex
->getByIndex(nAfter
-1), UNO_QUERY_THROW
);
45 table::CellAddress xResultCellAddress
= aLastSheetAnnotation
->getPosition();
47 CPPUNIT_ASSERT_MESSAGE("Insert Annotation - Wrong SHEET reference position", xResultCellAddress
.Sheet
== xTargetCellAddress
.Sheet
);
48 CPPUNIT_ASSERT_MESSAGE("Insert Annotation - Wrong COLUMN reference position", xResultCellAddress
.Column
== xTargetCellAddress
.Column
);
49 CPPUNIT_ASSERT_MESSAGE("Insert Annotation - Wrong ROW reference position", xResultCellAddress
.Row
== xTargetCellAddress
.Row
);
52 uno::Reference
< text::XTextRange
> aTextSheetAnnotation(aLastSheetAnnotation
, UNO_QUERY_THROW
);
53 OUString aString
= aTextSheetAnnotation
->getString();
55 CPPUNIT_ASSERT_MESSAGE("Insert Annotation - Wrong string", aString
== "an inserted annotation");
59 void XSheetAnnotations::testRemoveByIndex()
61 uno::Reference
< sheet::XSheetAnnotations
> aSheetAnnotations (init(), UNO_QUERY_THROW
);
63 // insert some annotations
64 table::CellAddress
xTargetCellAddress (0,4,5);
65 aSheetAnnotations
->insertNew(xTargetCellAddress
, "an inserted annotation 1");
66 table::CellAddress
xToBeRemovedCellAddress (0,5,6);
67 aSheetAnnotations
->insertNew(xToBeRemovedCellAddress
, "an inserted annotation 2");
68 table::CellAddress
xOtherCellAddress (0,7,8);
69 aSheetAnnotations
->insertNew(xOtherCellAddress
, "an inserted annotation 3");
71 // count before removing
72 uno::Reference
< container::XIndexAccess
> xAnnotationsIndex (aSheetAnnotations
, UNO_QUERY_THROW
);
73 sal_Int32 nBefore
= xAnnotationsIndex
->getCount();
75 // remove the xToBeRemovedCellAddress
76 aSheetAnnotations
->removeByIndex(nBefore
-2);
78 // count after removing
79 //uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW);
80 sal_Int32 nAfter
= xAnnotationsIndex
->getCount();
82 // the last position should be xOtherCellAddress
83 uno::Reference
< sheet::XSheetAnnotation
> aLastSheetAnnotation (xAnnotationsIndex
->getByIndex(nAfter
-1), UNO_QUERY_THROW
);
84 table::CellAddress xResultCellAddress
= aLastSheetAnnotation
->getPosition();
86 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong SHEET reference position", xResultCellAddress
.Sheet
== xOtherCellAddress
.Sheet
);
87 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong COLUMN reference position", xResultCellAddress
.Column
== xOtherCellAddress
.Column
);
88 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong ROW reference position", xResultCellAddress
.Row
== xOtherCellAddress
.Row
);
91 uno::Reference
< text::XTextRange
> aLastTextSheetAnnotation(aLastSheetAnnotation
, UNO_QUERY_THROW
);
92 OUString aLastString
= aLastTextSheetAnnotation
->getString();
94 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong string", aLastString
== "an inserted annotation 3");
96 // the previous should be xTargetCellAddress
97 uno::Reference
< sheet::XSheetAnnotation
> aPreviousSheetAnnotation (xAnnotationsIndex
->getByIndex(nAfter
-2), UNO_QUERY_THROW
);
98 table::CellAddress xPreviousCellAddress
= aPreviousSheetAnnotation
->getPosition();
100 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong SHEET reference position", xPreviousCellAddress
.Sheet
== xTargetCellAddress
.Sheet
);
101 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong COLUMN reference position", xPreviousCellAddress
.Column
== xTargetCellAddress
.Column
);
102 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong ROW reference position", xPreviousCellAddress
.Row
== xTargetCellAddress
.Row
);
104 // is the string ok ?
105 uno::Reference
< text::XTextRange
> aPreviousTextSheetAnnotation(aPreviousSheetAnnotation
, UNO_QUERY_THROW
);
106 OUString aPreviousString
= aPreviousTextSheetAnnotation
->getString();
108 CPPUNIT_ASSERT_MESSAGE("Remove Annotation - Wrong string", aPreviousString
== "an inserted annotation 1");
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */