LibreOffice Module test (master) 1
xchartdata.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
12#include <rtl/ref.hxx>
13
14#include <com/sun/star/chart/ChartDataChangeEvent.hpp>
15#include <com/sun/star/chart/XChartData.hpp>
16#include <com/sun/star/chart/XChartDataArray.hpp>
17#include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
18#include <com/sun/star/lang/EventObject.hpp>
19
20#include <cppunit/TestAssert.h>
21
22using namespace css;
23
24namespace apitest
25{
26namespace
27{
28class MockedChartDataChangeEventListener
29 : public ::cppu::WeakImplHelper<chart::XChartDataChangeEventListener>
30{
31public:
32 MockedChartDataChangeEventListener()
33 : m_bListenerCalled(false)
34 {
35 }
36
38 virtual void SAL_CALL chartDataChanged(const chart::ChartDataChangeEvent& /* rEvent */) override
39 {
40 m_bListenerCalled = true;
41 }
42
43 virtual void SAL_CALL disposing(const lang::EventObject& /* xEvent */) override {}
44};
45}
46
48{
49 uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW);
50 const double fNaN = xCD->getNotANumber();
51
52 CPPUNIT_ASSERT(fNaN != 1.0);
53}
54
56{
57 uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW);
58 const double fNaN = xCD->getNotANumber();
59 CPPUNIT_ASSERT(xCD->isNotANumber(fNaN));
60 CPPUNIT_ASSERT(!xCD->isNotANumber(fNaN + 1.0));
61}
62
64{
65 uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW);
66
68 = new MockedChartDataChangeEventListener();
69 xCD->addChartDataChangeEventListener(
70 uno::Reference<chart::XChartDataChangeEventListener>(pListener0));
72 = new MockedChartDataChangeEventListener();
73 xCD->addChartDataChangeEventListener(
74 uno::Reference<chart::XChartDataChangeEventListener>(pListener1));
75
76 uno::Reference<chart::XChartDataArray> xCDD(xCD, uno::UNO_QUERY_THROW);
77 uno::Sequence<uno::Sequence<double>> aData = xCDD->getData();
78 auto& rFirstCell = aData.getArray()[0].getArray()[0];
79 rFirstCell += 1.0;
80 xCDD->setData(aData);
81 CPPUNIT_ASSERT(pListener0->m_bListenerCalled);
82 CPPUNIT_ASSERT(pListener1->m_bListenerCalled);
83
84 pListener0->m_bListenerCalled = false;
85 pListener1->m_bListenerCalled = false;
86
87 xCD->removeChartDataChangeEventListener(
88 uno::Reference<chart::XChartDataChangeEventListener>(pListener1));
89 rFirstCell += 1.0;
90 xCDD->setData(aData);
91 CPPUNIT_ASSERT(pListener0->m_bListenerCalled);
92 CPPUNIT_ASSERT(!pListener1->m_bListenerCalled);
93}
94
95} // namespace apitest
96
97/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void testChartDataChangeEventListener()
Definition: xchartdata.cxx:63
virtual css::uno::Reference< css::uno::XInterface > init()=0
constexpr OUStringLiteral aData
bool m_bListenerCalled
Definition: xchartdata.cxx:37