From d6450929f648572bec5dbfbb334f5325e64d3938 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 20 Jul 2016 17:55:32 +0200 Subject: Setup a test for the systemd wrapper (bzr r4153.9.8) --- tests/CMakeLists.txt | 1 + tests/test_systemd_wrapper.cpp | 110 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/test_systemd_wrapper.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 17ea9b758..d1f58d33c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -286,6 +286,7 @@ if (ENABLE_X_SUPPORT) test_switcher_controller_class.cpp test_switcher_model.cpp test_switcher_view.cpp + test_systemd_wrapper.cpp test_tabiterator.cpp test_texture_cache.cpp test_text_input.cpp diff --git a/tests/test_systemd_wrapper.cpp b/tests/test_systemd_wrapper.cpp new file mode 100644 index 000000000..30d5f9f76 --- /dev/null +++ b/tests/test_systemd_wrapper.cpp @@ -0,0 +1,110 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (c) 2016 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Authored by: Ted Gould +*/ + +#include +using namespace testing; + +#include "unity-shared/SystemdWrapper.h" + +#include +#include + +#include "test_utils.h" + +namespace +{ + +const std::string SYSTEMD = +R"( + + + + + + + + + + + + +)"; + +struct MockSystemdWrapper : unity::SystemdWrapper { + MockSystemdWrapper() + : SystemdWrapper(SystemdWrapper::TestMode()) + {} +}; + +struct TestSystemdWrapper : public Test +{ + TestSystemdWrapper() + { + systemd_server_ = std::make_shared("com.canonical.Unity.Test.Systemd"); + systemd_server_->AddObjects(SYSTEMD, "/org/freedesktop/systemd1"); + + Utils::WaitUntilMSec([this] { return systemd_server_->IsConnected(); }); + } + + unity::glib::DBusServer::Ptr systemd_server_; + MockSystemdWrapper systemd_wrapper_; +}; + + +TEST_F(TestSystemdWrapper, Start) +{ + bool start_sent = false; + + systemd_server_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* { + if (method == "StartUnit") + { + start_sent = true; + + std::string event_name = glib::Variant(g_variant_get_child_value(par, 0)).GetString(); + EXPECT_EQ("unity-screen-locked", event_name); + } + + return nullptr; + }); + + systemd_wrapper_.Start("unity-screen-locked"); + Utils::WaitUntil(start_sent); +} + +TEST_F(TestSystemdWrapper, Stop) +{ + bool stop_sent = false; + + systemd_server_->GetObjects().front()->SetMethodsCallsHandler([&] (std::string const& method, GVariant* par) -> GVariant* { + if (method == "StopUnit") + { + stop_sent = true; + + std::string event_name = glib::Variant(g_variant_get_child_value(par, 0)).GetString(); + EXPECT_EQ("unity-screen-locked", event_name); + } + + return nullptr; + }); + + systemd_wrapper_.Stop("unity-screen-locked"); + Utils::WaitUntil(stop_sent); +} + +} -- cgit v1.2.3