2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
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>
20
#include <biometry/runtime.h>
21
#include <biometry/dbus/codec.h>
23
#include <core/dbus/fixture.h>
24
#include <core/dbus/macros.h>
25
#include <core/dbus/message.h>
26
#include <core/dbus/object.h>
28
#include <core/posix/fork.h>
29
#include <core/posix/signal.h>
31
#include <core/dbus/asio/executor.h>
33
#include <gmock/gmock.h>
35
#include "did_finish_successfully.h"
36
#include "echo_service.h"
40
struct VerifyingEchoService : public testing::EchoService
44
static biometry::Application application()
46
return biometry::Application{"JustSomeDummyApplication"};
49
static biometry::Progress progress()
51
biometry::Progress result;
52
result.percent = biometry::Percent::from_raw_value(0.42);
56
static biometry::Point point()
58
return biometry::Point{42, 42};
61
static biometry::Rectangle rectangle()
63
return {point(), point()};
66
static biometry::Reason reason()
68
return biometry::Reason{"because we are testing"};
71
static biometry::User user()
73
return biometry::User::current();
76
static biometry::Variant::None none()
78
return biometry::Variant::None{};
81
static biometry::Variant variant()
83
return biometry::Variant::v(
85
biometry::Variant::b(true),
86
biometry::Variant::i(42),
87
biometry::Variant::d(42.),
88
biometry::Variant::r(Reference::rectangle()),
89
biometry::Variant::s("42"),
92
biometry::Variant::b(true),
93
biometry::Variant::i(42),
94
biometry::Variant::d(42.),
95
biometry::Variant::r(Reference::rectangle()),
96
biometry::Variant::s("42")
101
static biometry::Void void_()
103
return biometry::Void{};
107
void application(const biometry::Application& value)
109
EXPECT_EQ(Reference::application(), value);
112
void progress(const biometry::Progress& value)
114
EXPECT_EQ(Reference::progress(), value);
117
void point(const biometry::Point& value)
119
EXPECT_EQ(Reference::point(), value);
122
void rectangle(const biometry::Rectangle& value)
124
EXPECT_EQ(Reference::rectangle(), value);
127
void reason(const biometry::Reason& value)
129
EXPECT_EQ(Reference::reason(), value);
132
void user(const biometry::User& value)
134
EXPECT_EQ(Reference::user(), value);
137
void none(const biometry::Variant::None& value)
139
EXPECT_EQ(Reference::none(), value);
142
void variant(const biometry::Variant& value)
144
EXPECT_EQ(Reference::variant(), value);
147
void void_(const biometry::Void& value)
149
EXPECT_EQ(Reference::void_(), value);
154
struct DbusCodec : public core::dbus::testing::Fixture
158
TEST_F(DbusCodec, encoding_and_decoding_works_for_relevant_types)
162
auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term});
163
trap->signal_raised().connect([trap](core::posix::Signal)
168
auto bus = session_bus();
169
bus->install_executor(core::dbus::asio::make_executor(bus));
171
std::thread t{[bus]() { bus->run(); }};
173
auto impl = std::make_shared<VerifyingEchoService>();
174
auto sk = std::make_shared<testing::SkeletonEchoService>(bus,
175
core::dbus::Service::add_service(bus, testing::EchoService::name())
176
->add_object_for_path(testing::EchoService::path()),
186
return Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
191
auto bus = session_bus();
192
bus->install_executor(core::dbus::asio::make_executor(bus));
194
std::thread t{[bus]() { bus->run(); }};
196
auto st = std::make_shared<testing::StubEchoService>(core::dbus::Service::use_service(bus, testing::EchoService::name())->object_for_path(testing::EchoService::path()));
198
EXPECT_NO_THROW(st->application(VerifyingEchoService::Reference::application()));
199
EXPECT_NO_THROW(st->progress(VerifyingEchoService::Reference::progress()));
200
EXPECT_NO_THROW(st->point(VerifyingEchoService::Reference::point()));
201
EXPECT_NO_THROW(st->rectangle(VerifyingEchoService::Reference::rectangle()));
202
EXPECT_NO_THROW(st->reason(VerifyingEchoService::Reference::reason()));
203
EXPECT_NO_THROW(st->user(VerifyingEchoService::Reference::user()));
204
EXPECT_NO_THROW(st->none(VerifyingEchoService::Reference::none()));
205
EXPECT_NO_THROW(st->variant(VerifyingEchoService::Reference::variant()));
206
EXPECT_NO_THROW(st->void_(VerifyingEchoService::Reference::void_()));
208
bus->stop(); if (t.joinable()) t.join();
210
return Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
213
auto skp = core::posix::fork(sk, core::posix::StandardStream::empty);
214
std::this_thread::sleep_for(std::chrono::milliseconds{500});
215
auto stp = core::posix::fork(st, core::posix::StandardStream::empty);
217
EXPECT_TRUE(testing::did_finish_successfully(stp.wait_for(core::posix::wait::Flags::untraced)));
218
EXPECT_NO_THROW(skp.send_signal_or_throw(core::posix::Signal::sig_term));
219
EXPECT_TRUE(testing::did_finish_successfully(skp.wait_for(core::posix::wait::Flags::untraced)));