LibreOffice Module test (master) 1
xdocumentauditing.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/awt/Point.hpp>
13#include <com/sun/star/beans/PropertyValue.hpp>
14#include <com/sun/star/container/XIndexAccess.hpp>
15#include <com/sun/star/container/XNamed.hpp>
16#include <com/sun/star/drawing/XDrawPage.hpp>
17#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
18#include <com/sun/star/drawing/XShape.hpp>
19#include <com/sun/star/frame/DispatchHelper.hpp>
20#include <com/sun/star/frame/XDispatchHelper.hpp>
21#include <com/sun/star/frame/XDispatchProvider.hpp>
22#include <com/sun/star/frame/XFrame.hpp>
23#include <com/sun/star/frame/XModel.hpp>
24#include <com/sun/star/sheet/XDocumentAuditing.hpp>
25#include <com/sun/star/sheet/XSheetAuditing.hpp>
26#include <com/sun/star/sheet/XSpreadsheet.hpp>
27#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
28#include <com/sun/star/sheet/XSpreadsheets.hpp>
29#include <com/sun/star/table/CellAddress.hpp>
30#include <com/sun/star/uno/Reference.hxx>
31#include <com/sun/star/uno/Sequence.hxx>
32#include <com/sun/star/uno/XComponentContext.hpp>
33
36
37#include <cppunit/TestAssert.h>
38
39using namespace com::sun::star;
40using namespace com::sun::star::uno;
41
42namespace apitest
43{
44void XDocumentAuditing::dispatch(const uno::Reference<frame::XFrame>& xFrame,
45 const uno::Sequence<beans::PropertyValue>& rArguments)
46{
47 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
48 uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext),
49 UNO_SET_THROW);
50 CPPUNIT_ASSERT(xDispatchHelper.is());
51
52 uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, UNO_QUERY_THROW);
53 CPPUNIT_ASSERT(xDispatchProvider.is());
54
55 xDispatchHelper->executeDispatch(xDispatchProvider, ".uno:AutoRefreshArrows", "", 0,
56 rArguments);
57}
58
59bool XDocumentAuditing::hasRightAmountOfShapes(const uno::Reference<drawing::XDrawPage>& xDrawPage,
60 sal_Int32 nElementCount, sal_Int32 nShapes)
61{
62 const sal_Int32 nCount = xDrawPage->getCount();
63 if (nCount != nElementCount + nShapes)
64 return false;
65 else
66 {
67 if (nShapes >= 0)
68 {
69 for (sal_Int32 i = nElementCount; i < nCount; i++)
70 {
71 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(i), UNO_QUERY_THROW);
72 m_Position = xShape->getPosition();
73 }
74 }
75 }
76 return true;
77}
78
80{
81 uno::Reference<sheet::XDocumentAuditing> xDocumentAuditing(init(), UNO_QUERY_THROW);
82
83 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xDocumentAuditing, UNO_QUERY_THROW);
84 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
85 uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW);
86 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(0), UNO_QUERY_THROW);
87 uno::Reference<sheet::XSpreadsheet> xSheet2(xIA->getByIndex(1), UNO_QUERY_THROW);
88
89 uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDocumentAuditing, UNO_QUERY_THROW);
90 uno::Reference<drawing::XDrawPage> xDrawPage(xDPS->getDrawPages()->getByIndex(1),
91 UNO_QUERY_THROW);
92
93 sal_Int32 nDrawPageElementCount = 0;
94 if (xDrawPage->hasElements())
95 nDrawPageElementCount = xDrawPage->getCount();
96
97 uno::Sequence<beans::PropertyValue> aPropertyValue{ comphelper::makePropertyValue(
98 "AutoRefreshArrows", false) };
99 uno::Reference<frame::XModel> xModel(xDocumentAuditing, UNO_QUERY_THROW);
100 dispatch(xModel->getCurrentController()->getFrame(), aPropertyValue);
101
102 xSheet1->getCellByPosition(6, 6)->setValue(9);
103 uno::Reference<container::XNamed> xNA1(xSheet1, UNO_QUERY_THROW);
104 OUString sSheet1Name = xNA1->getName();
105
106 xSheet2->getCellByPosition(6, 6)->setValue(16);
107 xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(G7)");
108
109 uno::Reference<sheet::XSheetAuditing> xSheetAuditing(xSheet2, UNO_QUERY_THROW);
110 xSheetAuditing->showPrecedents(table::CellAddress(1, 6, 7));
111 bool bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
112 CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult);
113 awt::Point Position0 = m_Position;
114
115 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1);
116 xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(" + sSheet1Name + ".G7)");
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1);
118
119 bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
120 CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult);
121 awt::Point Position1 = m_Position;
122
123 CPPUNIT_ASSERT_EQUAL_MESSAGE("Arrow has been refreshed", Position0.X, Position1.X);
124 CPPUNIT_ASSERT_EQUAL_MESSAGE("Arrow has been refreshed", Position0.Y, Position1.Y);
125
126 xDocumentAuditing->refreshArrows();
127
128 bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
129 CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult);
130 awt::Point Position2 = m_Position;
131
132 CPPUNIT_ASSERT_MESSAGE("Arrow has not been refreshed",
133 Position1.X != Position2.X || Position1.Y != Position2.Y);
134}
135} // namespace apitest
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
static void dispatch(const css::uno::Reference< css::frame::XFrame > &xFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments)
bool hasRightAmountOfShapes(const css::uno::Reference< css::drawing::XDrawPage > &xDrawPage, sal_Int32 nElementCount, sal_Int32 nShapes)
int nCount
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
int i
Reference< XFrame > xFrame
Reference< XModel > xModel