aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/integration/usb-manager-test.cpp31
-rw-r--r--tests/unit/adbd-client-test.cpp2
-rw-r--r--tests/unit/usb-snap-test.cpp34
-rw-r--r--tests/utils/qt-fixture.h58
4 files changed, 69 insertions, 56 deletions
diff --git a/tests/integration/usb-manager-test.cpp b/tests/integration/usb-manager-test.cpp
index 82c170e..21fdc97 100644
--- a/tests/integration/usb-manager-test.cpp
+++ b/tests/integration/usb-manager-test.cpp
@@ -20,10 +20,7 @@
#define QT_NO_KEYWORDS
#include <tests/utils/adbd-server.h>
-#include <tests/utils/dbus-types.h>
-#include <tests/utils/glib-fixture.h>
-#include <tests/utils/gtest-qt-print-helpers.h>
-#include <tests/utils/qdbus-helpers.h>
+#include <tests/utils/qt-fixture.h>
#include <src/dbus-names.h>
#include <src/usb-manager.h>
@@ -32,12 +29,6 @@
#include <libqtdbustest/QProcessDBusService.h>
#include <libqtdbusmock/DBusMock.h>
-#include <glib.h>
-
-#include <gtest/gtest.h>
-
-#include <QSignalSpy>
-
#include <fstream>
#include <sstream>
#include <vector>
@@ -46,26 +37,15 @@
****
***/
-#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
-{\
- while (signalSpy.size() < signalsExpected)\
- {\
- ASSERT_TRUE(signalSpy.wait());\
- }\
- ASSERT_EQ(signalsExpected, signalSpy.size());\
-}
-
-class UsbManagerFixture: public GlibFixture
+class UsbManagerFixture: public QtFixture
{
- using super = GlibFixture;
+ using super = QtFixture;
public:
UsbManagerFixture():
dbusMock{dbusTestRunner}
{
- DBusTypes::registerMetaTypes();
-
dbusTestRunner.startServices();
}
@@ -76,7 +56,7 @@ protected:
static void file_deleter (std::string* s)
{
fprintf(stderr, "remove \"%s\"\n", s->c_str());
- remove(s->c_str());
+ g_remove(s->c_str());
delete s;
}
@@ -102,7 +82,6 @@ protected:
QtDBusTest::DBusTestRunner dbusTestRunner;
QtDBusMock::DBusMock dbusMock;
- QtDBusTest::DBusServicePtr indicator;
std::shared_ptr<std::string> m_tmpdir;
};
@@ -126,7 +105,7 @@ TEST_F(UsbManagerFixture, Allow)
auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path);
// wait for the notification to show up, confirm it looks right
- WAIT_FOR_SIGNALS(notificationsSpy, 1);
+ wait_for_signals(notificationsSpy, 1);
{
QVariantList const& call(notificationsSpy.at(0));
EXPECT_EQ("Notify", call.at(0));
diff --git a/tests/unit/adbd-client-test.cpp b/tests/unit/adbd-client-test.cpp
index c00c07a..754f76c 100644
--- a/tests/unit/adbd-client-test.cpp
+++ b/tests/unit/adbd-client-test.cpp
@@ -32,7 +32,7 @@ protected:
static void file_deleter (std::string* s)
{
fprintf(stderr, "remove \"%s\"\n", s->c_str());
- remove(s->c_str());
+ g_remove(s->c_str());
delete s;
}
diff --git a/tests/unit/usb-snap-test.cpp b/tests/unit/usb-snap-test.cpp
index dc17696..663f9e6 100644
--- a/tests/unit/usb-snap-test.cpp
+++ b/tests/unit/usb-snap-test.cpp
@@ -18,47 +18,24 @@
*/
#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 <tests/utils/qt-fixture.h>
#include <src/dbus-names.h>
#include <src/usb-snap.h>
-#include <glib.h>
-
#include <libqtdbustest/DBusTestRunner.h>
#include <libqtdbustest/QProcessDBusService.h>
#include <libqtdbusmock/DBusMock.h>
-#include <QSignalSpy>
-
-#include <gtest/gtest.h>
-
-using namespace QtDBusTest;
-using namespace QtDBusMock;
-
-#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
-{\
- while (signalSpy.size() < signalsExpected)\
- {\
- ASSERT_TRUE(signalSpy.wait());\
- }\
- ASSERT_EQ(signalsExpected, signalSpy.size());\
-}
-
-class UsbSnapFixture: public GlibFixture
+class UsbSnapFixture: public QtFixture
{
- using super = GlibFixture;
+ using super = QtFixture;
public:
UsbSnapFixture():
dbusMock{dbusTestRunner}
{
- DBusTypes::registerMetaTypes();
-
dbusTestRunner.startServices();
}
@@ -84,7 +61,6 @@ protected:
QtDBusTest::DBusTestRunner dbusTestRunner;
QtDBusMock::DBusMock dbusMock;
- QtDBusTest::DBusServicePtr indicator;
};
TEST_F(UsbSnapFixture, TestRoundTrip)
@@ -119,7 +95,7 @@ TEST_F(UsbSnapFixture, TestRoundTrip)
});
// test that UsbSnap creates a fdo notification
- WAIT_FOR_SIGNALS(notificationsSpy, 1);
+ wait_for_signals(notificationsSpy, 1);
{
QVariantList const& call(notificationsSpy.at(0));
EXPECT_EQ("Notify", call.at(0));
@@ -157,7 +133,7 @@ TEST_F(UsbSnapFixture, TestRoundTrip)
// confirm that the snap dtor cleans up the notification
snap.reset();
- WAIT_FOR_SIGNALS(notificationsSpy, 1);
+ wait_for_signals(notificationsSpy, 1);
{
QVariantList const& call(notificationsSpy.at(0));
EXPECT_EQ("CloseNotification", call.at(0));
diff --git a/tests/utils/qt-fixture.h b/tests/utils/qt-fixture.h
new file mode 100644
index 0000000..321d56e
--- /dev/null
+++ b/tests/utils/qt-fixture.h
@@ -0,0 +1,58 @@
+/*
+ * 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/qdbus-helpers.h>
+#include <tests/utils/glib-fixture.h>
+#include <tests/utils/gtest-qt-print-helpers.h>
+
+#include <gtest/gtest.h>
+
+#include <QSignalSpy>
+
+class QtFixture: public GlibFixture
+{
+ using super = GlibFixture;
+
+public:
+
+ QtFixture()
+ {
+ DBusTypes::registerMetaTypes();
+ }
+
+ ~QtFixture() =default;
+
+protected:
+
+ void wait_for_signals(QSignalSpy& signalSpy, int signalsExpected)
+ {
+ while (signalSpy.size() < signalsExpected)
+ {
+ ASSERT_TRUE(signalSpy.wait());
+ }
+
+ ASSERT_EQ(signalsExpected, signalSpy.size());
+ }
+};
+