2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file test_event_support.cpp
18 * @author Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19 * @author Pawel Sikorski (p.sikorski@samsung.com)
21 * @brief This file contains test for event support
24 #include <dpl/test/test_runner.h>
25 #include <dpl/generic_event.h>
26 #include <dpl/event/event_listener.h>
27 #include <dpl/event/event_support.h>
28 #include <dpl/application.h>
29 #include <dpl/event/controller.h>
30 #include <dpl/fast_delegate.h>
31 #include <dpl/log/log.h>
33 DECLARE_GENERIC_EVENT_0(TestEvent)
35 class TestListener : public DPL::Event::EventListener<TestEvent>
38 explicit TestListener() : m_dummyVar(0) { }
39 void OnEventReceived(const TestEvent &)
43 int GetDummyVar() const
56 class TestEventSupport :
57 public DPL::Event::EventSupport<TestEvent>
62 EmitEvent(TestEvent());
66 DECLARE_GENERIC_EVENT_0(QuitEvent)
68 class QuitController :
69 public DPL::Event::Controller<DPL::TypeListDecl<QuitEvent>::Type>,
70 public DPL::ApplicationExt
73 QuitController() : DPL::ApplicationExt(1, NULL, "test-app")
79 virtual void OnEventReceived(const QuitEvent &)
86 Name: EventSupport_DestroyBeforeProcessing
87 Description: tests if remoign listener is full successfull
88 Expected: dummy var should be affected by explicit call of ZeroDummyVar(),
89 but no by emitting event after removing listener
91 RUNNER_TEST(EventSupport_DestroyBeforeProcessing)
93 QuitController quitter;
94 quitter.PostTimedEvent(QuitEvent(), 1.0);
96 TestListener eventListener;
98 TestEventSupport eventSupport;
99 eventSupport.AddListener(&eventListener);
100 eventSupport.TestEmitEvent();
101 eventSupport.RemoveListener(&eventListener);
103 eventListener.ZeroDummyVar();
106 RUNNER_ASSERT(eventListener.GetDummyVar() == 0);
111 void OnDelegateTest(const int &k);
113 void OnDelegateTest(const int &k)
115 LogInfo("Got delegate call");
119 class DelegateTestSupport :
120 public DPL::Event::EventSupport<int>
130 Name: EventSupport_BindDelegate
131 Description: tests if event support derived class successfully propagates
132 event to registered listener
133 Expected: value of event should be passed to listener
135 RUNNER_TEST(EventSupport_BindDelegate)
139 DelegateTestSupport support;
140 support.AddListener(&OnDelegateTest);
142 QuitController quitter;
143 quitter.PostTimedEvent(QuitEvent(), 1.0);
149 support.RemoveListener(&OnDelegateTest);
151 RUNNER_ASSERT(g_delegateTest == 7);