summaryrefslogtreecommitdiff
path: root/tests
diff options
authorTed Gould <ted@gould.cx>2016-07-20 17:55:32 +0200
committerTed Gould <ted@gould.cx>2016-07-20 17:55:32 +0200
commitd6450929f648572bec5dbfbb334f5325e64d3938 (patch)
tree9810414b751e8173cdba39d8bb1bbd3f3e8ed487 /tests
parent0794e1e677ab54bd46c6e64cd6c2f34d11c74971 (diff)
Setup a test for the systemd wrapper
(bzr r4153.9.8)
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/test_systemd_wrapper.cpp110
2 files changed, 111 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
+*
+* Authored by: Ted Gould <ted@canonical.com>
+*/
+
+#include <gtest/gtest.h>
+using namespace testing;
+
+#include "unity-shared/SystemdWrapper.h"
+
+#include <UnityCore/GLibDBusServer.h>
+#include <UnityCore/Variant.h>
+
+#include "test_utils.h"
+
+namespace
+{
+
+const std::string SYSTEMD =
+R"(<node>
+ <interface name="org.freedesktop.systemd1.Manager">
+ <method name="StartUnit">
+ <arg name="name" type="s" direction="in" />
+ <arg name="mode" type="s" direction="in" />
+ <arg name="job" type="o" direction="out" />
+ </method>
+ <method name="StopUnit">
+ <arg name="name" type="s" direction="in" />
+ <arg name="mode" type="s" direction="in" />
+ <arg name="job" type="o" direction="out" />
+ </method>
+ </interface>
+</node>)";
+
+struct MockSystemdWrapper : unity::SystemdWrapper {
+ MockSystemdWrapper()
+ : SystemdWrapper(SystemdWrapper::TestMode())
+ {}
+};
+
+struct TestSystemdWrapper : public Test
+{
+ TestSystemdWrapper()
+ {
+ systemd_server_ = std::make_shared<unity::glib::DBusServer>("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);
+}
+
+}