diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-07-18 19:51:56 +0200 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2012-07-18 19:51:56 +0200 |
| commit | 492c087bc3cf6397fe657456399f15d0bc4e1087 (patch) | |
| tree | 5709833bdaad937053abc5f0874d4cda9167ed26 | |
| parent | d5f94ca359f3c423de530351ffa4e4a1e762865d (diff) | |
Mock GVolume too.
(bzr r2507.1.6)
| -rw-r--r-- | launcher/AbstractVolumeMonitorWrapper.h | 61 | ||||
| -rw-r--r-- | launcher/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | launcher/DeviceLauncherSection.cpp | 2 | ||||
| -rw-r--r-- | launcher/DeviceLauncherSection.h | 6 | ||||
| -rw-r--r-- | launcher/LauncherController.cpp | 3 | ||||
| -rw-r--r-- | launcher/VolumeMonitorWrapper.h | 22 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | tests/gmockvolume.c | 177 | ||||
| -rw-r--r-- | tests/gmockvolume.h | 53 | ||||
| -rw-r--r-- | tests/test_device_launcher_section.cpp | 36 |
10 files changed, 332 insertions, 30 deletions
diff --git a/launcher/AbstractVolumeMonitorWrapper.h b/launcher/AbstractVolumeMonitorWrapper.h new file mode 100644 index 000000000..878787119 --- /dev/null +++ b/launcher/AbstractVolumeMonitorWrapper.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 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: Andrea Azzarone <andrea.azzarone@canonical.com> + */ + +#ifndef UNITYSHELL_ABSTRACT_VOLUME_MONITOR_WRAPPER_H +#define UNITYSHELL_ABSTRACT_VOLUME_MONITOR_WRAPPER_H + +#include <list> +#include <memory> + +#include <gio/gio.h> +#include <sigc++/signal.h> +#include <sigc++/trackable.h> + +#include <UnityCore/GLibWrapper.h> +#include <UnityCore/GLibSignal.h> + +namespace unity +{ +namespace launcher +{ + +class AbstractVolumeMonitorWrapper : public sigc::trackable +{ +public: + typedef std::shared_ptr<AbstractVolumeMonitorWrapper> Ptr; + typedef std::list<glib::Object<GVolume>> VolumeList; + + AbstractVolumeMonitorWrapper() = default; + virtual ~AbstractVolumeMonitorWrapper() = default; + + // Makes VolumeMonitorWrapper uncopyable + AbstractVolumeMonitorWrapper(AbstractVolumeMonitorWrapper const&) = delete; + AbstractVolumeMonitorWrapper& operator=(AbstractVolumeMonitorWrapper const&) = delete; + + virtual VolumeList GetVolumes() = 0; + + // Signals + sigc::signal<void, glib::Object<GVolume> const&> volume_added; + sigc::signal<void, glib::Object<GVolume> const&> volume_removed; +}; + +} // namespace launcher +} // namespace unity + +#endif // UNITYSHELL_ABSTRACT_VOLUME_MONITOR_WRAPPER_H + diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index ceefbdb0e..bea64c94b 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -72,7 +72,6 @@ set (LAUNCHER_SOURCES SpacerLauncherIcon.cpp Tooltip.cpp TrashLauncherIcon.cpp - VolumeMonitorWrapper.cpp ) add_library (launcher-lib STATIC ${LAUNCHER_SOURCES}) diff --git a/launcher/DeviceLauncherSection.cpp b/launcher/DeviceLauncherSection.cpp index 93fcd8a12..5fa8cbf36 100644 --- a/launcher/DeviceLauncherSection.cpp +++ b/launcher/DeviceLauncherSection.cpp @@ -24,7 +24,7 @@ namespace unity namespace launcher { -DeviceLauncherSection::DeviceLauncherSection(VolumeMonitorWrapper::Ptr volume_monitor) +DeviceLauncherSection::DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor) : monitor_(volume_monitor) { monitor_->volume_added.connect(sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded)); diff --git a/launcher/DeviceLauncherSection.h b/launcher/DeviceLauncherSection.h index 95661b2a3..249939068 100644 --- a/launcher/DeviceLauncherSection.h +++ b/launcher/DeviceLauncherSection.h @@ -25,7 +25,7 @@ #include <UnityCore/GLibSource.h> #include "DeviceLauncherIcon.h" -#include "VolumeMonitorWrapper.h" +#include "AbstractVolumeMonitorWrapper.h" namespace unity { @@ -35,7 +35,7 @@ namespace launcher class DeviceLauncherSection : public sigc::trackable { public: - DeviceLauncherSection(VolumeMonitorWrapper::Ptr volume_monitor); + DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor); sigc::signal<void, AbstractLauncherIcon::Ptr> IconAdded; @@ -45,7 +45,7 @@ private: void OnVolumeRemoved(glib::Object<GVolume> const& volume); std::map<GVolume*, DeviceLauncherIcon::Ptr> map_; - VolumeMonitorWrapper::Ptr monitor_; + AbstractVolumeMonitorWrapper::Ptr monitor_; glib::Idle device_populate_idle_; }; diff --git a/launcher/LauncherController.cpp b/launcher/LauncherController.cpp index c8c77c241..d3ce15f70 100644 --- a/launcher/LauncherController.cpp +++ b/launcher/LauncherController.cpp @@ -41,6 +41,7 @@ #include "AbstractLauncherIcon.h" #include "SoftwareCenterLauncherIcon.h" #include "LauncherModel.h" +#include "VolumeMonitorWrapper.h" #include "unity-shared/WindowManager.h" #include "TrashLauncherIcon.h" #include "BFBLauncherIcon.h" @@ -175,7 +176,7 @@ public: nux::ObjectPtr<Launcher> launcher_; nux::ObjectPtr<Launcher> keyboard_launcher_; int sort_priority_; - VolumeMonitorWrapper::Ptr volume_monitor_; + AbstractVolumeMonitorWrapper::Ptr volume_monitor_; DeviceLauncherSection device_section_; LauncherEntryRemoteModel remote_model_; AbstractLauncherIcon::Ptr expo_icon_; diff --git a/launcher/VolumeMonitorWrapper.h b/launcher/VolumeMonitorWrapper.h index 02835efc5..383bf80da 100644 --- a/launcher/VolumeMonitorWrapper.h +++ b/launcher/VolumeMonitorWrapper.h @@ -19,39 +19,23 @@ #ifndef UNITYSHELL_VOLUME_MONITOR_WRAPPER_H #define UNITYSHELL_VOLUME_MONITOR_WRAPPER_H -#include <list> -#include <memory> - -#include <gio/gio.h> -#include <sigc++/signal.h> -#include <sigc++/trackable.h> - #include <UnityCore/GLibWrapper.h> #include <UnityCore/GLibSignal.h> +#include "AbstractVolumeMonitorWrapper.h" + namespace unity { namespace launcher { -class VolumeMonitorWrapper : public sigc::trackable +class VolumeMonitorWrapper : public AbstractVolumeMonitorWrapper { public: - typedef std::shared_ptr<VolumeMonitorWrapper> Ptr; - typedef std::list<glib::Object<GVolume>> VolumeList; - VolumeMonitorWrapper(); - // Makes VolumeMonitorWrapper uncopyable - VolumeMonitorWrapper(VolumeMonitorWrapper const&) = delete; - VolumeMonitorWrapper& operator=(VolumeMonitorWrapper const&) = delete; - VolumeList GetVolumes(); - // Signals - sigc::signal<void, glib::Object<GVolume> const&> volume_added; - sigc::signal<void, glib::Object<GVolume> const&> volume_removed; - private: void OnVolumeAdded(GVolumeMonitor* monitor, GVolume* volume); void OnVolumeRemoved(GVolumeMonitor* monitor, GVolume* volume); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9a108e4ee..c29d422f2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -219,6 +219,7 @@ if (GTEST_SRC_DIR AND test_single_monitor_launcher_icon.cpp test_switcher_controller.cpp test_switcher_model.cpp + gmockvolume.c ${CMAKE_SOURCE_DIR}/dash/AbstractPlacesGroup.cpp ${CMAKE_SOURCE_DIR}/dash/DashViewPrivate.cpp ${CMAKE_SOURCE_DIR}/dash/LensViewPrivate.cpp diff --git a/tests/gmockvolume.c b/tests/gmockvolume.c new file mode 100644 index 000000000..0ade02e9d --- /dev/null +++ b/tests/gmockvolume.c @@ -0,0 +1,177 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2012 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> + * + */ + +#include <glib.h> + +#include "gmockvolume.h" + +static void g_mock_volume_volume_iface_init (GVolumeIface *iface); + +#define g_mock_volume_get_type _g_mock_volume_get_type +G_DEFINE_TYPE_WITH_CODE (GMockVolume, g_mock_volume, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_VOLUME, + g_mock_volume_volume_iface_init)) + +static void +g_mock_volume_finalize (GObject *object) +{ + G_OBJECT_CLASS (g_mock_volume_parent_class)->finalize (object); +} + +static void +g_mock_volume_class_init (GMockVolumeClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = g_mock_volume_finalize; +} + +static void +g_mock_volume_init (GMockVolume *mock_volume) +{ +} + +GMockVolume * +_g_mock_volume_new () +{ + GMockVolume *volume; + + volume = g_object_new (G_TYPE_MOCK_VOLUME, NULL); + + return volume; +} + +static char * +g_mock_volume_get_name (GVolume *volume) +{ + return g_strdup (""); +} + +static GIcon * +g_mock_volume_get_icon (GVolume *volume) +{ + return g_icon_new_for_string("", NULL); +} + +static char * +g_mock_volume_get_uuid (GVolume *volume) +{ + return NULL; +} + +static GDrive * +g_mock_volume_get_drive (GVolume *volume) +{ + return NULL; +} + +static GMount * +g_mock_volume_get_mount (GVolume *volume) +{ + return NULL; +} + +static gboolean +g_mock_volume_can_mount (GVolume *volume) +{ + return TRUE; +} + +static gboolean +g_mock_volume_can_eject (GVolume *volume) +{ + return FALSE; +} + +static gboolean +g_mock_volume_should_automount (GVolume *volume) +{ + return TRUE; +} + +static void +g_mock_volume_mount (GVolume *volume, + GMountMountFlags flags, + GMountOperation *mount_operation, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ +} + +static gboolean +g_mock_volume_mount_finish (GVolume *volume, + GAsyncResult *result, + GError **error) +{ + return TRUE; +} + +static void +g_mock_volume_eject (GVolume *volume, + GMountUnmountFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ +} + +static gboolean +g_mock_volume_eject_finish (GVolume *volume, + GAsyncResult *result, + GError **error) +{ + return TRUE; +} + +static gchar * +g_mock_volume_get_identifier (GVolume *volume, + const gchar *kind) +{ + return NULL; +} + +static gchar ** +g_mock_volume_enumerate_identifiers (GVolume *volume) +{ + return NULL; +} + +static void +g_mock_volume_volume_iface_init (GVolumeIface *iface) +{ + iface->get_name = g_mock_volume_get_name; + iface->get_icon = g_mock_volume_get_icon; + iface->get_uuid = g_mock_volume_get_uuid; + iface->get_drive = g_mock_volume_get_drive; + iface->get_mount = g_mock_volume_get_mount; + iface->can_mount = g_mock_volume_can_mount; + iface->can_eject = g_mock_volume_can_eject; + iface->should_automount = g_mock_volume_should_automount; + iface->mount_fn = g_mock_volume_mount; + iface->mount_finish = g_mock_volume_mount_finish; + iface->eject = g_mock_volume_eject; + iface->eject_finish = g_mock_volume_eject_finish; + iface->get_identifier = g_mock_volume_get_identifier; + iface->enumerate_identifiers = g_mock_volume_enumerate_identifiers; +} + diff --git a/tests/gmockvolume.h b/tests/gmockvolume.h new file mode 100644 index 000000000..2038b0f36 --- /dev/null +++ b/tests/gmockvolume.h @@ -0,0 +1,53 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2012 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> + * + */ + +#ifndef UNITYSHELL_G_MOCK_VOLUME_H +#define UNITYSHELL_G_MOCK_VOLUME_H + +#include <gio/gio.h> + +G_BEGIN_DECLS + +#define G_TYPE_MOCK_VOLUME (_g_mock_volume_get_type ()) +#define G_MOCK_VOLUME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_MOCK_VOLUME, GMockVolume)) +#define G_MOCK_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_MOCK_VOLUME, GMockVolumeClass)) +#define G_IS_MOCK_VOLUME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_MOCK_VOLUME)) +#define G_IS_MOCK_VOLUME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_MOCK_VOLUME)) + +typedef struct _GMockVolume GMockVolume; +typedef struct _GMockVolumeClass GMockVolumeClass; + +struct _GMockVolume { + GObject parent; +}; + +struct _GMockVolumeClass { + GObjectClass parent_class; +}; + +GType _g_mock_volume_get_type (void) G_GNUC_CONST; +GMockVolume * _g_mock_volume_new (); + +G_END_DECLS + +#endif // UNITYSHELL_G_MOCK_VOLUME_H + diff --git a/tests/test_device_launcher_section.cpp b/tests/test_device_launcher_section.cpp index 040e5b390..69df40c2a 100644 --- a/tests/test_device_launcher_section.cpp +++ b/tests/test_device_launcher_section.cpp @@ -24,10 +24,11 @@ using namespace testing; #include "DeviceLauncherSection.h" -#include "VolumeMonitorWrapper.h" +#include "AbstractVolumeMonitorWrapper.h" using namespace unity; using namespace unity::launcher; +#include "gmockvolume.h" #include "test_utils.h" namespace @@ -48,11 +49,36 @@ public: bool icon_added; }; +class MockVolumeMonitorWrapper : public AbstractVolumeMonitorWrapper +{ +public: + typedef std::shared_ptr<MockVolumeMonitorWrapper> Ptr; + + MockVolumeMonitorWrapper() + : volume1(G_VOLUME(_g_mock_volume_new())) + , volume2(G_VOLUME(_g_mock_volume_new())) + { + } + + VolumeList GetVolumes() + { + VolumeList ret; + + ret.push_back(volume1); + ret.push_back(volume2); + + return ret; + } + + glib::Object<GVolume> volume1; + glib::Object<GVolume> volume2; +}; + class TestDeviceLauncherSection : public Test { public: TestDeviceLauncherSection() - : monitor_(new VolumeMonitorWrapper) + : monitor_(new MockVolumeMonitorWrapper) , section_(monitor_) {} @@ -62,7 +88,7 @@ public: Utils::WaitForTimeoutMSec(1500); } - VolumeMonitorWrapper::Ptr monitor_; + MockVolumeMonitorWrapper::Ptr monitor_; DeviceLauncherSection section_; }; @@ -73,8 +99,8 @@ TEST_F(TestDeviceLauncherSection, TestNoDuplicates) section_.IconAdded.connect(sigc::mem_fun(*listener, &EventListener::OnIconAdded)); // Emit the signal volume_added for each volume. - for (auto volume : monitor_->GetVolumes()) - monitor_->volume_added.emit(volume); + monitor_->volume_added.emit(monitor_->volume1); + monitor_->volume_added.emit(monitor_->volume2); Utils::WaitForTimeoutMSec(500); |
