LibreOffice Module test (master) 1
xsheetauditing.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
11
12#include <com/sun/star/beans/XPropertySet.hpp>
13#include <com/sun/star/drawing/XDrawPage.hpp>
14#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
15#include <com/sun/star/sheet/XSheetAuditing.hpp>
16#include <com/sun/star/sheet/XSpreadsheet.hpp>
17#include <com/sun/star/sheet/ValidationType.hpp>
18#include <com/sun/star/table/CellAddress.hpp>
19#include <com/sun/star/table/XCell.hpp>
20#include <com/sun/star/text/XText.hpp>
21#include <com/sun/star/uno/Any.hxx>
22#include <com/sun/star/uno/Reference.hxx>
23
24#include <cppunit/TestAssert.h>
25
26using namespace css;
27using namespace css::uno;
28
29namespace apitest
30{
32{
33 uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);
34
35 uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
36 uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
37 const sal_Int32 nElements = xDrawPage->getCount();
38
39 xAuditing->showDependents(table::CellAddress(0, 8, 6));
40 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showDependents()", nElements + 1,
41 xDrawPage->getCount());
42
43 xAuditing->hideDependents(table::CellAddress(0, 8, 6));
44 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to hideDependents()", nElements, xDrawPage->getCount());
45}
46
48{
49 uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);
50
51 uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
52 uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
53 const sal_Int32 nElements = xDrawPage->getCount();
54
55 xAuditing->showPrecedents(table::CellAddress(0, 8, 6));
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements + 2,
57 xDrawPage->getCount());
58
59 xAuditing->hidePrecedents(table::CellAddress(0, 8, 6));
60 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements, xDrawPage->getCount());
61}
62
64{
65 uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);
66
67 uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
68 uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
69 const sal_Int32 nElements = xDrawPage->getCount();
70
71 xAuditing->showPrecedents(table::CellAddress(0, 8, 6));
72 xAuditing->showDependents(table::CellAddress(0, 8, 6));
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set arrows", nElements + 3, xDrawPage->getCount());
74
75 xAuditing->clearArrows();
76 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to clear arrows", nElements, xDrawPage->getCount());
77}
78
80{
81 uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);
82
83 uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
84 uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
85 const sal_Int32 nElements = xDrawPage->getCount();
86
87 uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW);
88 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6);
89 xCell->setValue(-9);
90 xCell->setFormula("=SQRT(" + OUStringChar(static_cast<char>('A' + 7)) + OUString::number(7)
91 + ")");
92
93 uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW);
94 CPPUNIT_ASSERT_EQUAL_MESSAGE("No error code", OUString("Err:522"), xText->getString());
95
96 xAuditing->showErrors(table::CellAddress(0, 7, 6));
97 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show errors", nElements + 1, xDrawPage->getCount());
98}
99
101{
102 uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);
103
104 uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
105 uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
106 const sal_Int32 nElements = xDrawPage->getCount();
107
108 uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW);
109 uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6);
110 xCell->setValue(2.5);
111
112 uno::Reference<beans::XPropertySet> xPropSet(xCell, UNO_QUERY_THROW);
113 uno::Any aValidation = xPropSet->getPropertyValue("Validation");
114 uno::Reference<beans::XPropertySet> xValidation(aValidation, UNO_QUERY_THROW);
115 uno::Any aAny;
116
117 aAny <<= sheet::ValidationType_WHOLE;
118 xValidation->setPropertyValue("Type", aAny);
119 aAny <<= xValidation;
120 xPropSet->setPropertyValue("Validation", aAny);
121 xAuditing->showInvalid();
122 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (WHOLE)", nElements + 1,
123 xDrawPage->getCount());
124
125 xAuditing->clearArrows();
126
127 aAny <<= sheet::ValidationType_ANY;
128 xValidation->setPropertyValue("Type", aAny);
129 aAny <<= xValidation;
130 xPropSet->setPropertyValue("Validation", aAny);
131
132 xAuditing->showInvalid();
133 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (ANY)", nElements, xDrawPage->getCount());
134}
135}
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
sal_Int32 nElements