aboutsummaryrefslogtreecommitdiff
path: root/tests/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils')
-rw-r--r--tests/utils/adbd-server.h20
-rw-r--r--tests/utils/gtest-print-helpers.h18
-rw-r--r--tests/utils/mock-greeter.h4
-rw-r--r--tests/utils/mock-unity-greeter.py41
4 files changed, 70 insertions, 13 deletions
diff --git a/tests/utils/adbd-server.h b/tests/utils/adbd-server.h
index b574622..585380f 100644
--- a/tests/utils/adbd-server.h
+++ b/tests/utils/adbd-server.h
@@ -38,7 +38,7 @@ public:
GAdbdServer(const std::string& socket_path,
const std::vector<std::string>& requests):
m_requests{requests},
- m_socket_path{socket_path},
+ m_server_socket{create_server_socket(socket_path)},
m_cancellable{g_cancellable_new()},
m_worker_thread{&GAdbdServer::worker_func, this}
{
@@ -50,6 +50,7 @@ public:
g_cancellable_cancel(m_cancellable);
m_worker_thread.join();
g_clear_object(&m_cancellable);
+ g_clear_object(&m_server_socket);
}
const std::vector<std::string> m_requests;
@@ -59,18 +60,14 @@ private:
void worker_func() // runs in worker thread
{
- auto server_socket = create_server_socket(m_socket_path);
auto requests = m_requests;
- GError* error {};
- g_socket_listen (server_socket, &error);
- g_assert_no_error (error);
-
while (!g_cancellable_is_cancelled(m_cancellable) && !requests.empty())
{
// wait for a client connection
g_message("GAdbdServer::Impl::worker_func() calling g_socket_accept()");
- auto client_socket = g_socket_accept(server_socket, m_cancellable, &error);
+ GError* error {};
+ auto client_socket = g_socket_accept(m_server_socket, m_cancellable, &error);
if (error != nullptr) {
if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_message("GAdbdServer: Error accepting socket connection: %s", error->message);
@@ -121,8 +118,6 @@ private:
// cleanup
g_clear_object(&client_socket);
}
-
- g_clear_object(&server_socket);
}
// bind to a local domain socket
@@ -139,11 +134,14 @@ private:
g_assert_no_error (error);
g_clear_object (&address);
+ g_socket_listen (socket, &error);
+ g_assert_no_error (error);
+
return socket;
}
- const std::string m_socket_path;
- GCancellable* m_cancellable = nullptr;
+ GSocket* m_server_socket {};
+ GCancellable* m_cancellable {};
std::thread m_worker_thread;
};
diff --git a/tests/utils/gtest-print-helpers.h b/tests/utils/gtest-print-helpers.h
new file mode 100644
index 0000000..60f42b4
--- /dev/null
+++ b/tests/utils/gtest-print-helpers.h
@@ -0,0 +1,18 @@
+
+#pragma once
+
+#include <src/greeter.h>
+
+inline void PrintTo(const Greeter::State& state, std::ostream* os) {
+ switch(state) {
+ case Greeter::State::ACTIVE: *os << "Active"; break;
+ case Greeter::State::INACTIVE: *os << "Inactive"; break;
+ case Greeter::State::UNAVAILABLE: *os << "Unavailable"; break;
+ }
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Greeter::State& state) {
+ PrintTo(state, &os);
+ return os;
+}
+
diff --git a/tests/utils/mock-greeter.h b/tests/utils/mock-greeter.h
index 5ac85a0..5015087 100644
--- a/tests/utils/mock-greeter.h
+++ b/tests/utils/mock-greeter.h
@@ -26,7 +26,7 @@ class MockGreeter: public Greeter
public:
MockGreeter() =default;
virtual ~MockGreeter() =default;
- core::Property<bool>& is_active() override {return m_is_active;}
- core::Property<bool> m_is_active {false};
+ core::Property<Greeter::State>& state() override {return m_state;}
+ core::Property<Greeter::State> m_state {State::INACTIVE};
};
diff --git a/tests/utils/mock-unity-greeter.py b/tests/utils/mock-unity-greeter.py
new file mode 100644
index 0000000..70fb791
--- /dev/null
+++ b/tests/utils/mock-unity-greeter.py
@@ -0,0 +1,41 @@
+'''unity greeter mock template
+
+Very basic template that just mocks the greeter is-active flag
+'''
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option) any
+# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text
+# of the license.
+
+__author__ = 'Charles Kerr'
+__email__ = 'charles.kerr@canonical.com'
+__copyright__ = '(c) 2016 Canonical Ltd.'
+__license__ = 'LGPL 3+'
+
+import dbus
+import os
+
+from dbusmock import MOCK_IFACE, mockobject
+
+BUS_NAME = 'com.canonical.UnityGreeter'
+MAIN_OBJ = '/'
+MAIN_IFACE = 'com.canonical.UnityGreeter'
+SYSTEM_BUS = False
+
+
+def load(mock, parameters):
+ mock.AddMethods(
+ MAIN_IFACE, [
+ ('HideGreeter', '', '', 'self.Set("com.canonical.UnityGreeter", "IsActive", False)'),
+ ('ShowGreeter', '', '', 'self.Set("com.canonical.UnityGreeter", "IsActive", True)')
+ ]
+ )
+ mock.AddProperties(
+ MAIN_IFACE,
+ dbus.Dictionary({
+ 'IsActive': parameters.get('IsActive', False),
+ }, signature='sv')
+ )
+