aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/usb-manager-test.cpp44
-rw-r--r--tests/unit/usb-snap-test.cpp1
-rw-r--r--tests/utils/mock-usb-monitor.h32
-rw-r--r--tests/utils/qdbus-helpers.h21
-rw-r--r--tests/utils/qt-fixture.h18
5 files changed, 90 insertions, 26 deletions
diff --git a/tests/integration/usb-manager-test.cpp b/tests/integration/usb-manager-test.cpp
index 21fdc97..19c0401 100644
--- a/tests/integration/usb-manager-test.cpp
+++ b/tests/integration/usb-manager-test.cpp
@@ -17,10 +17,9 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#define QT_NO_KEYWORDS
-
#include <tests/utils/adbd-server.h>
#include <tests/utils/qt-fixture.h>
+#include <tests/utils/mock-usb-monitor.h>
#include <src/dbus-names.h>
#include <src/usb-manager.h>
@@ -64,6 +63,8 @@ protected:
{
super::SetUp();
+ m_usb_monitor.reset(new MockUsbMonitor{});
+
char tmpl[] = {"usb-manager-test-XXXXXX"};
m_tmpdir.reset(new std::string{g_mkdtemp(tmpl)}, file_deleter);
g_message("using tmpdir '%s'", m_tmpdir->c_str());
@@ -83,6 +84,7 @@ protected:
QtDBusTest::DBusTestRunner dbusTestRunner;
QtDBusMock::DBusMock dbusMock;
std::shared_ptr<std::string> m_tmpdir;
+ std::shared_ptr<MockUsbMonitor> m_usb_monitor;
};
TEST_F(UsbManagerFixture, Allow)
@@ -102,7 +104,7 @@ TEST_F(UsbManagerFixture, Allow)
auto adbd_server = std::make_shared<GAdbdServer>(*socket_path, std::vector<std::string>{"PK"+public_key});
// set up a UsbManager to process the request
- auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path);
+ auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path, m_usb_monitor);
// wait for the notification to show up, confirm it looks right
wait_for_signals(notificationsSpy, 1);
@@ -151,3 +153,39 @@ TEST_F(UsbManagerFixture, Allow)
ASSERT_EQ(1, lines.size());
EXPECT_EQ(public_key, lines[0]);
}
+
+TEST_F(UsbManagerFixture, Cancel)
+{
+ const std::shared_ptr<std::string> socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter};
+ const std::shared_ptr<std::string> public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter};
+
+ // add a signal spy to listen to the notification daemon
+ QSignalSpy notificationsSpy(
+ &notificationsMockInterface(),
+ SIGNAL(MethodCalled(const QString &, const QVariantList &))
+ );
+
+ // start a mock AdbdServer ready to submit a request
+ const std::string public_key {"public_key"};
+ auto adbd_server = std::make_shared<GAdbdServer>(*socket_path, std::vector<std::string>{"PK"+public_key});
+
+ // set up a UsbManager to process the request
+ auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path, m_usb_monitor);
+
+ // wait for a notification to show up
+ wait_for_signals(notificationsSpy, 1);
+ EXPECT_EQ("Notify", notificationsSpy.at(0).at(0));
+ notificationsSpy.clear();
+
+ // wait for UsbSnap to receive dbusmock's response to the Notify request.
+ // there's no event to key off of for this, so just wait for a moment
+ wait_msec();
+
+ // disconnect the USB before the user has a chance to allow/deny
+ m_usb_monitor->m_on_usb_disconnected("android0");
+
+ // confirm that we requested the notification to be pulled down
+ wait_for_signals(notificationsSpy, 1);
+ EXPECT_EQ("CloseNotification", notificationsSpy.at(0).at(0));
+ notificationsSpy.clear();
+}
diff --git a/tests/unit/usb-snap-test.cpp b/tests/unit/usb-snap-test.cpp
index 663f9e6..40de94a 100644
--- a/tests/unit/usb-snap-test.cpp
+++ b/tests/unit/usb-snap-test.cpp
@@ -17,7 +17,6 @@
* Charles Kerr <charles.kerr@canonical.com>
*/
-#define QT_NO_KEYWORDS
#include <tests/utils/qt-fixture.h>
#include <src/dbus-names.h>
diff --git a/tests/utils/mock-usb-monitor.h b/tests/utils/mock-usb-monitor.h
new file mode 100644
index 0000000..92b89db
--- /dev/null
+++ b/tests/utils/mock-usb-monitor.h
@@ -0,0 +1,32 @@
+/*
+ * 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/qdbus-helpers.h b/tests/utils/qdbus-helpers.h
deleted file mode 100644
index f873e23..0000000
--- a/tests/utils/qdbus-helpers.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#define QT_NO_KEYWORDS
-#include <QDBusArgument>
-#include <QVariant>
-
-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;
-}
-
diff --git a/tests/utils/qt-fixture.h b/tests/utils/qt-fixture.h
index 321d56e..0f5722b 100644
--- a/tests/utils/qt-fixture.h
+++ b/tests/utils/qt-fixture.h
@@ -22,12 +22,13 @@
#define QT_NO_KEYWORDS
#include <tests/utils/dbus-types.h>
-#include <tests/utils/qdbus-helpers.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>
class QtFixture: public GlibFixture
@@ -54,5 +55,20 @@ protected:
ASSERT_EQ(signalsExpected, signalSpy.size());
}
+
+ 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;
+ }
};