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 
11 #include <cppuhelper/implbase.hxx>
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 
22 using namespace css;
23 
24 namespace apitest
25 {
26 namespace
27 {
28 class MockedChartDataChangeEventListener
29  : public ::cppu::WeakImplHelper<chart::XChartDataChangeEventListener>
30 {
31 public:
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 
47 void XChartData::testGetNotANumber()
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 
55 void XChartData::testIsNotANumber()
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 
63 void XChartData::testChartDataChangeEventListener()
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  aData[0][0] += 1.0;
79  xCDD->setData(aData);
80  CPPUNIT_ASSERT(pListener0->m_bListenerCalled);
81  CPPUNIT_ASSERT(pListener1->m_bListenerCalled);
82 
83  pListener0->m_bListenerCalled = false;
84  pListener1->m_bListenerCalled = false;
85 
86  xCD->removeChartDataChangeEventListener(
87  uno::Reference<chart::XChartDataChangeEventListener>(pListener1));
88  aData[0][0] += 1.0;
89  xCDD->setData(aData);
90  CPPUNIT_ASSERT(pListener0->m_bListenerCalled);
91  CPPUNIT_ASSERT(!pListener1->m_bListenerCalled);
92 }
93 
94 } // namespace apitest
95 
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
constexpr OUStringLiteral aData
FILE * init(int, char **)
bool m_bListenerCalled
Definition: xchartdata.cxx:37