summaryrefslogtreecommitdiff
path: root/test/source/sheet/xsheetauditing.cxx
blob: 82ffbf5c53321df5ddec5ae3d0af556bd9c4e0ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <test/sheet/xsheetauditing.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/sheet/XSheetAuditing.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/ValidationType.hpp>
#include <com/sun/star/table/CellAddress.hpp>
#include <com/sun/star/table/XCell.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>

#include <cppunit/extensions/HelperMacros.h>

using namespace css;
using namespace css::uno;

namespace apitest
{
void XSheetAuditing::testShowHideDependents()
{
    uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);

    uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
    uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
    const sal_Int32 nElements = xDrawPage->getCount();

    xAuditing->showDependents(table::CellAddress(0, 8, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showDependents()", nElements + 1,
                                 xDrawPage->getCount());

    xAuditing->hideDependents(table::CellAddress(0, 8, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to hideDependents()", nElements, xDrawPage->getCount());
}

void XSheetAuditing::testShowHidePrecedents()
{
    uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);

    uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
    uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
    const sal_Int32 nElements = xDrawPage->getCount();

    xAuditing->showPrecedents(table::CellAddress(0, 8, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements + 2,
                                 xDrawPage->getCount());

    xAuditing->hidePrecedents(table::CellAddress(0, 8, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements, xDrawPage->getCount());
}

void XSheetAuditing::testClearArrows()
{
    uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);

    uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
    uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
    const sal_Int32 nElements = xDrawPage->getCount();

    xAuditing->showPrecedents(table::CellAddress(0, 8, 6));
    xAuditing->showDependents(table::CellAddress(0, 8, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set arrows", nElements + 3, xDrawPage->getCount());

    xAuditing->clearArrows();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to clear arrows", nElements, xDrawPage->getCount());
}

void XSheetAuditing::testShowErrors()
{
    uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);

    uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
    uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
    const sal_Int32 nElements = xDrawPage->getCount();

    uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW);
    uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6);
    xCell->setValue(-9);
    xCell->setFormula("=SQRT(" + OUStringChar(static_cast<char>('A' + 7)) + OUString::number(7)
                      + ")");

    uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("No error code", OUString("Err:522"), xText->getString());

    xAuditing->showErrors(table::CellAddress(0, 7, 6));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show errors", nElements + 1, xDrawPage->getCount());
}

void XSheetAuditing::testShowInvalid()
{
    uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW);

    uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW);
    uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage();
    const sal_Int32 nElements = xDrawPage->getCount();

    uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW);
    uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6);
    xCell->setValue(2.5);

    uno::Reference<beans::XPropertySet> xPropSet(xCell, UNO_QUERY_THROW);
    uno::Any aValidation = xPropSet->getPropertyValue("Validation");
    uno::Reference<beans::XPropertySet> xValidation(aValidation, UNO_QUERY_THROW);
    uno::Any aAny;

    aAny <<= sheet::ValidationType_WHOLE;
    xValidation->setPropertyValue("Type", aAny);
    aAny <<= xValidation;
    xPropSet->setPropertyValue("Validation", aAny);
    xAuditing->showInvalid();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (WHOLE)", nElements + 1,
                                 xDrawPage->getCount());

    xAuditing->clearArrows();

    aAny <<= sheet::ValidationType_ANY;
    xValidation->setPropertyValue("Type", aAny);
    aAny <<= xValidation;
    xPropSet->setPropertyValue("Validation", aAny);

    xAuditing->showInvalid();
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (ANY)", nElements, xDrawPage->getCount());
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */