LibreOffice Module test (master) 1
xrefreshable.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/lang/EventObject.hpp>
13#include <com/sun/star/util/XRefreshListener.hpp>
14#include <com/sun/star/util/XRefreshable.hpp>
15
16#include <com/sun/star/uno/Reference.hxx>
17
19#include <rtl/ref.hxx>
20
21#include <cppunit/TestAssert.h>
22
23using namespace com::sun::star;
24using namespace com::sun::star::uno;
25
26namespace apitest
27{
28namespace
29{
30class MockedRefreshListener : public ::cppu::WeakImplHelper<util::XRefreshListener>
31{
32public:
33 MockedRefreshListener()
34 : m_bListenerCalled(false)
35 {
36 }
37
39 virtual void SAL_CALL refreshed(const lang::EventObject& /* xEvent */) override
40 {
41 m_bListenerCalled = true;
42 }
43 virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {}
44};
45}
46
48{
49 uno::Reference<util::XRefreshable> xRefreshable(init(), uno::UNO_QUERY_THROW);
50
51 rtl::Reference<MockedRefreshListener> xListener = new MockedRefreshListener();
52 xRefreshable->addRefreshListener(uno::Reference<util::XRefreshListener>(xListener));
53
54 xRefreshable->refresh();
55 CPPUNIT_ASSERT(xListener->m_bListenerCalled);
56
57 xListener->m_bListenerCalled = false;
58 xRefreshable->removeRefreshListener(uno::Reference<util::XRefreshListener>(xListener));
59 xRefreshable->refresh();
60 CPPUNIT_ASSERT(!xListener->m_bListenerCalled);
61}
62
63} // namespace apitest
64/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
bool m_bListenerCalled