nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / unit / test_ScChartListenerCollection.cxx
blob67f2f045c7bffaa90d690c6dfa6031eec14ad858
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <test/bootstrapfixture.hxx>
12 #include <address.hxx>
13 #include <chartlis.hxx>
14 #include <scdll.hxx>
16 namespace
18 const ScRange RANGE_1(10, 10, 0, 19, 10, 0);
19 const ScRange RANGE_2(20, 10, 0, 29, 10, 0);
21 const ScRange RANGE_INTERSECTING_1_AND_2(10, 10, 0, 29, 10, 0);
23 class ChartListenerCollectionTest : public test::BootstrapFixture
25 public:
26 virtual void setUp() override
28 BootstrapFixture::setUp();
30 ScDLL::Init();
33 private:
34 void ListenerGetsNotifiedWhenItsRangeIsSetDirty();
35 void ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes();
36 void ListenerDoesNotGetNotifiedWhenListeningStops();
37 void ListenerStopsListeningForAllRanges();
38 void ListenersStopListeningIndependently();
40 CPPUNIT_TEST_SUITE(ChartListenerCollectionTest);
42 CPPUNIT_TEST(ListenerGetsNotifiedWhenItsRangeIsSetDirty);
43 CPPUNIT_TEST(ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes);
44 CPPUNIT_TEST(ListenerDoesNotGetNotifiedWhenListeningStops);
45 CPPUNIT_TEST(ListenerStopsListeningForAllRanges);
46 CPPUNIT_TEST(ListenersStopListeningIndependently);
48 CPPUNIT_TEST_SUITE_END();
51 struct MockedHiddenRangeListener : public ScChartHiddenRangeListener
53 unsigned mNotifyCount;
54 MockedHiddenRangeListener()
55 : mNotifyCount(0)
59 void notify() override { mNotifyCount++; }
62 void ChartListenerCollectionTest::ListenerGetsNotifiedWhenItsRangeIsSetDirty()
64 MockedHiddenRangeListener listener;
65 ScDocument aDoc;
66 ScChartListenerCollection sut(aDoc);
68 sut.StartListeningHiddenRange(RANGE_1, &listener);
69 sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
71 CPPUNIT_ASSERT_EQUAL(1u, listener.mNotifyCount);
74 void ChartListenerCollectionTest::ListenerGetsNotifiedTwiceWhenRegisteredTwoTimes()
76 MockedHiddenRangeListener listener;
77 ScDocument aDoc;
78 ScChartListenerCollection sut(aDoc);
80 sut.StartListeningHiddenRange(RANGE_1, &listener);
81 sut.StartListeningHiddenRange(RANGE_2, &listener);
82 sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
84 CPPUNIT_ASSERT_EQUAL(2u, listener.mNotifyCount);
87 void ChartListenerCollectionTest::ListenerDoesNotGetNotifiedWhenListeningStops()
89 MockedHiddenRangeListener listener;
90 ScDocument aDoc;
91 ScChartListenerCollection sut(aDoc);
92 sut.StartListeningHiddenRange(RANGE_1, &listener);
94 sut.EndListeningHiddenRange(&listener);
95 sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
97 CPPUNIT_ASSERT_EQUAL(0u, listener.mNotifyCount);
100 void ChartListenerCollectionTest::ListenerStopsListeningForAllRanges()
102 MockedHiddenRangeListener listener;
103 ScDocument aDoc;
104 ScChartListenerCollection sut(aDoc);
105 sut.StartListeningHiddenRange(RANGE_1, &listener);
106 sut.StartListeningHiddenRange(RANGE_2, &listener);
108 sut.EndListeningHiddenRange(&listener);
109 sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
111 CPPUNIT_ASSERT_EQUAL(0u, listener.mNotifyCount);
114 void ChartListenerCollectionTest::ListenersStopListeningIndependently()
116 MockedHiddenRangeListener listener1;
117 MockedHiddenRangeListener listener2;
118 ScDocument aDoc;
120 ScChartListenerCollection sut(aDoc);
121 sut.StartListeningHiddenRange(RANGE_1, &listener1);
122 sut.StartListeningHiddenRange(RANGE_2, &listener2);
124 sut.EndListeningHiddenRange(&listener1);
125 sut.SetRangeDirty(RANGE_INTERSECTING_1_AND_2);
127 CPPUNIT_ASSERT_EQUAL(0u, listener1.mNotifyCount);
128 CPPUNIT_ASSERT_EQUAL(1u, listener2.mNotifyCount);
132 CPPUNIT_TEST_SUITE_REGISTRATION(ChartListenerCollectionTest);
134 CPPUNIT_PLUGIN_IMPLEMENT();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */