aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRatchanan Srirattanamet <ratchanan@ubports.com>2023-12-14 04:13:48 +0700
committerRatchanan Srirattanamet <ratchanan@ubports.com>2023-12-14 04:13:48 +0700
commitfce2bb770d17a0f9487fd490eecf6c074c7a7273 (patch)
tree25b11b8df7f75bc4a6166e9323de92a1d3585c2c
parent32f4db850f34668bf3c66e86f009bcb3a8c8374e (diff)
downloadayatana-indicator-display-fce2bb770d17a0f9487fd490eecf6c074c7a7273.tar.gz
ayatana-indicator-display-fce2bb770d17a0f9487fd490eecf6c074c7a7273.tar.bz2
ayatana-indicator-display-fce2bb770d17a0f9487fd490eecf6c074c7a7273.zip
tests: remove no longer needed parts
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/unit/CMakeLists.txt10
-rw-r--r--tests/utils/CMakeLists.txt16
-rw-r--r--tests/utils/adbd-server.h148
-rw-r--r--tests/utils/dbus-types.h42
-rw-r--r--tests/utils/gtest-print-helpers.h18
-rw-r--r--tests/utils/gtest-qt-print-helpers.h45
-rw-r--r--tests/utils/mock-greeter.h32
-rw-r--r--tests/utils/mock-greeter.py41
-rw-r--r--tests/utils/mock-usb-monitor.h32
-rw-r--r--tests/utils/qmain.cpp61
-rw-r--r--tests/utils/qt-fixture.h74
12 files changed, 0 insertions, 520 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 0619a51..3ce7fa3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -32,7 +32,6 @@ add_test(cppcheck cppcheck --enable=all -USCHEMA_DIR --error-exitcode=2 --inline
if (ENABLE_LOMIRI_FEATURES)
add_subdirectory (unit)
- add_subdirectory (utils)
endif ()
set(COVERAGE_TEST_TARGETS
diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt
index 14f4d9e..d24aa70 100644
--- a/tests/unit/CMakeLists.txt
+++ b/tests/unit/CMakeLists.txt
@@ -33,22 +33,12 @@ set(SERVICE_LINK_LIBRARIES
${SERVICE_LIB}
${SERVICE_DEPS_LIBRARIES}
)
-set(QT_LINK_LIBRARIES
- test-utils
- Qt5::Core
- Qt5::Test
- Qt5::DBus
-)
set(TEST_LINK_LIBRARIES
${TEST_DEPS_LIBRARIES}
${GTEST_LIBRARIES}
${GMOCK_LIBRARIES}
)
-add_definitions(
- -DGREETER_TEMPLATE="${CMAKE_SOURCE_DIR}/tests/utils/mock-greeter.py"
-)
-
function(add_test_by_name name)
set(TEST_NAME ${name})
set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE)
diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt
deleted file mode 100644
index cec97ef..0000000
--- a/tests/utils/CMakeLists.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-include_directories(
- ${CMAKE_CURRENT_BINARY_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}
-)
-
-add_library(
- test-utils
- STATIC
- qmain.cpp
-)
-
-target_link_libraries(
- test-utils
- Qt5::Core
- Qt5::DBus
-)
diff --git a/tests/utils/adbd-server.h b/tests/utils/adbd-server.h
deleted file mode 100644
index 585380f..0000000
--- a/tests/utils/adbd-server.h
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 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 warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- */
-
-#include <gio/gio.h>
-#include <gio/gunixsocketaddress.h>
-
-#include <string>
-#include <thread>
-#include <vector>
-
-
-/**
- * A Mock ADBD server.
- *
- * Binds to a local domain socket, sends public key requests across it,
- * and reads back the client's responses.
- */
-class GAdbdServer
-{
-public:
-
- GAdbdServer(const std::string& socket_path,
- const std::vector<std::string>& requests):
- m_requests{requests},
- m_server_socket{create_server_socket(socket_path)},
- m_cancellable{g_cancellable_new()},
- m_worker_thread{&GAdbdServer::worker_func, this}
- {
- }
-
- ~GAdbdServer()
- {
- // tell the worker thread to stop whatever it's doing and exit.
- 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;
- std::vector<std::string> m_responses;
-
-private:
-
- void worker_func() // runs in worker thread
- {
- auto requests = m_requests;
-
- while (!g_cancellable_is_cancelled(m_cancellable) && !requests.empty())
- {
- // wait for a client connection
- g_message("GAdbdServer::Impl::worker_func() calling g_socket_accept()");
- 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);
- g_clear_error(&error);
- break;
- }
-
- // pop the next request off the stack
- auto request = requests.front();
-
- // send the request
- g_message("GAdbdServer::Impl::worker_func() sending req [%s]", request.c_str());
- g_socket_send(client_socket,
- request.c_str(),
- request.size(),
- m_cancellable,
- &error);
- if (error != nullptr) {
- if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_message("GAdbdServer: Error sending request: %s", error->message);
- g_clear_error(&error);
- g_clear_object(&client_socket);
- break;
- }
-
- // read the response
- g_message("GAdbdServer::Impl::worker_func() reading response");
- char buf[4096];
- const auto n_bytes = g_socket_receive(client_socket,
- buf,
- sizeof(buf),
- m_cancellable,
- &error);
- if (error != nullptr) {
- if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_message("GAdbdServer: Error reading response: %s", error->message);
- g_clear_error(&error);
- g_clear_object(&client_socket);
- continue;
- }
- const std::string response(buf, std::string::size_type(n_bytes));
- g_message("server read %d bytes, got response: '%s'", int(n_bytes), response.c_str());
- if (!response.empty()) {
- m_responses.push_back(response);
- requests.erase(requests.begin());
- }
-
- // cleanup
- g_clear_object(&client_socket);
- }
- }
-
- // bind to a local domain socket
- static GSocket* create_server_socket(const std::string& socket_path)
- {
- GError* error {};
- auto socket = g_socket_new(G_SOCKET_FAMILY_UNIX,
- G_SOCKET_TYPE_STREAM,
- G_SOCKET_PROTOCOL_DEFAULT,
- &error);
- g_assert_no_error(error);
- auto address = g_unix_socket_address_new (socket_path.c_str());
- g_socket_bind (socket, address, false, &error);
- g_assert_no_error (error);
- g_clear_object (&address);
-
- g_socket_listen (socket, &error);
- g_assert_no_error (error);
-
- return socket;
- }
-
- GSocket* m_server_socket {};
- GCancellable* m_cancellable {};
- std::thread m_worker_thread;
-};
-
-
diff --git a/tests/utils/dbus-types.h b/tests/utils/dbus-types.h
deleted file mode 100644
index 3b3a02d..0000000
--- a/tests/utils/dbus-types.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2013-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 warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Author: Pete Woods <pete.woods@canonical.com>
- */
-
-#pragma once
-
-#include <QDBusMetaType>
-#include <QtCore>
-#include <QString>
-#include <QVariantMap>
-
-typedef QMap<QString, QVariantMap> QVariantDictMap;
-Q_DECLARE_METATYPE(QVariantDictMap)
-
-typedef QMap<QString, QString> QStringMap;
-Q_DECLARE_METATYPE(QStringMap)
-
-namespace DBusTypes
-{
- inline void registerMetaTypes()
- {
- qRegisterMetaType<QVariantDictMap>("QVariantDictMap");
- qRegisterMetaType<QStringMap>("QStringMap");
-
- qDBusRegisterMetaType<QVariantDictMap>();
- qDBusRegisterMetaType<QStringMap>();
- }
-}
diff --git a/tests/utils/gtest-print-helpers.h b/tests/utils/gtest-print-helpers.h
deleted file mode 100644
index 60f42b4..0000000
--- a/tests/utils/gtest-print-helpers.h
+++ /dev/null
@@ -1,18 +0,0 @@
-
-#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/gtest-qt-print-helpers.h b/tests/utils/gtest-qt-print-helpers.h
deleted file mode 100644
index 7a0897e..0000000
--- a/tests/utils/gtest-qt-print-helpers.h
+++ /dev/null
@@ -1,45 +0,0 @@
-
-#pragma once
-
-#include <QDBusObjectPath>
-#include <QString>
-#include <QStringList>
-#include <QVariant>
-
-inline QString qVariantToString(const QVariant& variant) {
- QString output;
- QDebug dbg(&output);
- dbg << variant;
- return output;
-}
-
-inline void PrintTo(const QVariant& variant, std::ostream* os) {
- QString output;
- QDebug dbg(&output);
- dbg << variant;
-
- *os << "QVariant(" << output.toStdString() << ")";
-}
-
-inline void PrintTo(const QString& s, std::ostream* os) {
- *os << "\"" << s.toStdString() << "\"";
-}
-
-inline void PrintTo(const QStringList& list, std::ostream* os) {
- QString output;
- QDebug dbg(&output);
- dbg << list;
-
- *os << "QStringList(" << output.toStdString() << ")";
-}
-
-inline void PrintTo(const QList<QDBusObjectPath>& list, std::ostream* os) {
- QString output;
- for (const auto& path: list)
- {
- output.append("\"" + path.path() + "\",");
- }
-
- *os << "QList<QDBusObjectPath>(" << output.toStdString() << ")";
-}
-
diff --git a/tests/utils/mock-greeter.h b/tests/utils/mock-greeter.h
deleted file mode 100644
index 5015087..0000000
--- a/tests/utils/mock-greeter.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 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 warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- */
-
-#pragma once
-
-#include <src/greeter.h>
-
-class MockGreeter: public Greeter
-{
-public:
- MockGreeter() =default;
- virtual ~MockGreeter() =default;
- core::Property<Greeter::State>& state() override {return m_state;}
- core::Property<Greeter::State> m_state {State::INACTIVE};
-};
-
diff --git a/tests/utils/mock-greeter.py b/tests/utils/mock-greeter.py
deleted file mode 100644
index dc48a6d..0000000
--- a/tests/utils/mock-greeter.py
+++ /dev/null
@@ -1,41 +0,0 @@
-'''desktop 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 = 'org.ayatana.Greeter'
-MAIN_OBJ = '/'
-MAIN_IFACE = 'org.ayatana.Greeter'
-SYSTEM_BUS = False
-
-
-def load(mock, parameters):
- mock.AddMethods(
- MAIN_IFACE, [
- ('HideGreeter', '', '', 'self.Set("org.ayatana.Greeter", "IsActive", False)'),
- ('ShowGreeter', '', '', 'self.Set("org.ayatana.Greeter", "IsActive", True)')
- ]
- )
- mock.AddProperties(
- MAIN_IFACE,
- dbus.Dictionary({
- 'IsActive': parameters.get('IsActive', False),
- }, signature='sv')
- )
-
diff --git a/tests/utils/mock-usb-monitor.h b/tests/utils/mock-usb-monitor.h
deleted file mode 100644
index 92b89db..0000000
--- a/tests/utils/mock-usb-monitor.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 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 warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- */
-
-#pragma once
-
-#include <src/usb-monitor.h>
-
-class MockUsbMonitor: public UsbMonitor
-{
-public:
- MockUsbMonitor() =default;
- virtual ~MockUsbMonitor() =default;
- core::Signal<const std::string&>& on_usb_disconnected() override {return m_on_usb_disconnected;}
- core::Signal<const std::string&> m_on_usb_disconnected;
-};
-
diff --git a/tests/utils/qmain.cpp b/tests/utils/qmain.cpp
deleted file mode 100644
index 58b1125..0000000
--- a/tests/utils/qmain.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright © 2014 Canonical Ltd.
- *
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU Lesser 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Authors:
- * Pete Woods <pete.woods@canonical.com>
- */
-
-//#include <config.h>
-
-#include <QCoreApplication>
-#include <QTimer>
-#include <gtest/gtest.h>
-#include <libintl.h>
-
-#include <libqtdbusmock/DBusMock.h>
-
-using namespace QtDBusMock;
-
-class Runner: public QObject
-{
- Q_OBJECT
-public Q_SLOTS:
- void run()
- {
- QCoreApplication::exit(RUN_ALL_TESTS());
- }
-};
-
-int main(int argc, char **argv)
-{
- qputenv("LANG", "C.UTF-8");
- unsetenv("LC_ALL");
-
- // boilerplate i18n
- setlocale(LC_ALL, "");
- bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
- textdomain(GETTEXT_PACKAGE);
-
- QCoreApplication application(argc, argv);
- DBusMock::registerMetaTypes();
- ::testing::InitGoogleTest(&argc, argv);
-
- Runner runner;
- QTimer::singleShot(0, &runner, SLOT(run()));
-
- return application.exec();
-}
-
-#include "qmain.moc"
diff --git a/tests/utils/qt-fixture.h b/tests/utils/qt-fixture.h
deleted file mode 100644
index 95b9b14..0000000
--- a/tests/utils/qt-fixture.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 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 warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.
- *
- * Authors:
- * Charles Kerr <charles.kerr@canonical.com>
- */
-
-#pragma once
-
-#define QT_NO_KEYWORDS
-
-#include <tests/utils/dbus-types.h>
-#include <tests/utils/glib-fixture.h>
-#include <tests/utils/gtest-qt-print-helpers.h>
-
-#include <gtest/gtest.h>
-
-#include <QDBusArgument>
-#include <QVariant>
-#include <QSignalSpy>
-
-#define wait_for_signals(signalSpy,signalsExpected) \
-{ \
- while (signalSpy.size() < signalsExpected) \
- { \
- ASSERT_TRUE(signalSpy.wait()); \
- } \
- \
- ASSERT_EQ(signalsExpected, signalSpy.size()); \
-}
-
-class QtFixture: public GlibFixture
-{
- using super = GlibFixture;
-
-public:
-
- QtFixture()
- {
- DBusTypes::registerMetaTypes();
- }
-
- ~QtFixture() =default;
-
-protected:
-
- bool qDBusArgumentToMap(QVariant const& variant, QVariantMap& map)
- {
- if (variant.canConvert<QDBusArgument>())
- {
- QDBusArgument value(variant.value<QDBusArgument>());
- if (value.currentType() == QDBusArgument::MapType)
- {
- value >> map;
- return true;
- }
- }
-
- return false;
- }
-};
-