2
* Copyright © 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include <location/serializing_bus.h>
20
#include <location/runtime.h>
22
#include <gmock/gmock.h>
26
struct IndexedEvent : public location::Event
28
IndexedEvent(std::size_t idx) : idx{idx}
32
Event::Type type() const override
34
return Event::Type{Event::Type::first_user_defined_type};
40
struct MockEventReceiver : public location::Event::Receiver
42
MOCK_METHOD1(on_new_event, void(const location::Event&));
46
TEST(SerializingBus, ctor_and_dtor_work_for_valid_runtime)
48
auto sb = location::SerializingBus::create(location::Runtime::create());
51
TEST(SerializingBus, dispatches_events_serially)
53
using namespace ::testing;
55
auto rt = location::Runtime::create();
56
auto sb = location::SerializingBus::create(rt);
57
auto receiver = std::make_shared<NiceMock<MockEventReceiver>>();
61
auto verifier = [&last](const location::Event& e)
63
const IndexedEvent& indexed_event = dynamic_cast<const IndexedEvent&>(e);
64
EXPECT_EQ(1, indexed_event.idx - last);
65
last = indexed_event.idx;
68
ON_CALL(*receiver, on_new_event(_)).WillByDefault(Invoke(verifier));
70
sb->subscribe(receiver);
74
for (std::size_t idx = 1; idx <= 100000; idx++)
75
sb->dispatch(std::make_shared<IndexedEvent>(idx));
77
while (last != 100000) {}