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>
36 #include <cppunit/TestAssert.h>
43 void XDocumentAuditing::dispatch(
const uno::Reference<frame::XFrame>& xFrame,
44 const uno::Sequence<beans::PropertyValue>& rArguments)
46 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
47 uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext),
49 CPPUNIT_ASSERT(xDispatchHelper.is());
51 uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, UNO_QUERY_THROW);
52 CPPUNIT_ASSERT(xDispatchProvider.is());
54 xDispatchHelper->executeDispatch(xDispatchProvider,
".uno:AutoRefreshArrows",
"", 0,
58 bool XDocumentAuditing::hasRightAmountOfShapes(
const uno::Reference<drawing::XDrawPage>& xDrawPage,
59 sal_Int32 nElementCount, sal_Int32 nShapes)
61 const sal_Int32
nCount = xDrawPage->getCount();
62 if (nCount != nElementCount + nShapes)
68 for (sal_Int32
i = nElementCount;
i < nCount;
i++)
70 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(
i), UNO_QUERY_THROW);
78 void XDocumentAuditing::testRefreshArrows()
80 uno::Reference<sheet::XDocumentAuditing> xDocumentAuditing(
init(), UNO_QUERY_THROW);
82 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xDocumentAuditing, UNO_QUERY_THROW);
83 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
84 uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW);
85 uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(0), UNO_QUERY_THROW);
86 uno::Reference<sheet::XSpreadsheet> xSheet2(xIA->getByIndex(1), UNO_QUERY_THROW);
88 uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDocumentAuditing, UNO_QUERY_THROW);
89 uno::Reference<drawing::XDrawPage> xDrawPage(xDPS->getDrawPages()->getByIndex(1),
92 sal_Int32 nDrawPageElementCount = 0;
93 if (xDrawPage->hasElements())
94 nDrawPageElementCount = xDrawPage->getCount();
96 uno::Sequence<beans::PropertyValue> aPropertyValue(1);
99 aPropertyValue[0].Name =
"AutoRefreshArrows";
100 aPropertyValue[0].
Value = aValue;
101 uno::Reference<frame::XModel>
xModel(xDocumentAuditing, UNO_QUERY_THROW);
102 dispatch(xModel->getCurrentController()->getFrame(), aPropertyValue);
104 xSheet1->getCellByPosition(6, 6)->setValue(9);
105 uno::Reference<container::XNamed> xNA1(xSheet1, UNO_QUERY_THROW);
106 OUString sSheet1Name = xNA1->getName();
108 xSheet2->getCellByPosition(6, 6)->setValue(16);
109 xSheet2->getCellByPosition(6, 7)->setFormula(
"= SQRT(G7)");
111 uno::Reference<sheet::XSheetAuditing> xSheetAuditing(xSheet2, UNO_QUERY_THROW);
112 xSheetAuditing->showPrecedents(table::CellAddress(1, 6, 7));
113 bool bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
114 CPPUNIT_ASSERT_MESSAGE(
"Wrong amount of shapes on page", bResult);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1);
118 xSheet2->getCellByPosition(6, 7)->setFormula(
"= SQRT(" + sSheet1Name +
".G7)");
119 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1);
121 bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
122 CPPUNIT_ASSERT_MESSAGE(
"Wrong amount of shapes on page", bResult);
125 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arrow has been refreshed", Position0.X, Position1.X);
126 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Arrow has been refreshed", Position0.Y, Position1.Y);
128 xDocumentAuditing->refreshArrows();
130 bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1);
131 CPPUNIT_ASSERT_MESSAGE(
"Wrong amount of shapes on page", bResult);
134 CPPUNIT_ASSERT_MESSAGE(
"Arrow has not been refreshed",
135 Position1.X != Position2.X || Position1.Y != Position2.Y);
geometry::RealPoint2D m_Position
FILE * init(int, char **)
Reference< XModel > xModel