summaryrefslogtreecommitdiff
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2012-07-17 22:57:46 +0200
committerAndrea Azzarone <azzaronea@gmail.com>2012-07-17 22:57:46 +0200
commit8d358515294c51f42983519bc8c49a5f818a2318 (patch)
tree736e7dc3c79c9079dd7348e8939e3c010c4aa500
parent63f18a1d6350430734a1cf3f2fc899ad27beabc4 (diff)
Add unit test.
(bzr r2507.1.3)
-rw-r--r--launcher/AbstractVolumeMonitorWrapper.h53
-rw-r--r--launcher/DeviceLauncherSection.cpp3
-rw-r--r--launcher/DeviceLauncherSection.h9
-rw-r--r--launcher/LauncherController.cpp1
-rw-r--r--launcher/VolumeMonitorWrapper.h17
-rw-r--r--tests/CMakeLists.txt5
-rw-r--r--tests/test_device_launcher_section.cpp85
7 files changed, 110 insertions, 63 deletions
diff --git a/launcher/AbstractVolumeMonitorWrapper.h b/launcher/AbstractVolumeMonitorWrapper.h
deleted file mode 100644
index 8e8341ddc..000000000
--- a/launcher/AbstractVolumeMonitorWrapper.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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>
-
-namespace unity
-{
-namespace launcher
-{
-
-class AbstractVolumeMonitorWrapper : public sigc::trackable
-{
-public:
- typedef std::shared_ptr<AbstractVolumeMonitorWrapper> Ptr;
-
- virtual ~AbstractVolumeMonitorWrapper() = default;
-
- virtual std::list<glib::Object<GVolume>> 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/DeviceLauncherSection.cpp b/launcher/DeviceLauncherSection.cpp
index c3408138a..570894180 100644
--- a/launcher/DeviceLauncherSection.cpp
+++ b/launcher/DeviceLauncherSection.cpp
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
+ * Andrea Azzarone <andrea.azzarone@canonical.com>
*/
#include "DeviceLauncherSection.h"
@@ -23,7 +24,7 @@ namespace unity
namespace launcher
{
-DeviceLauncherSection::DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor)
+DeviceLauncherSection::DeviceLauncherSection(VolumeMonitorWrapper::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 dd11e6acc..361390ca3 100644
--- a/launcher/DeviceLauncherSection.h
+++ b/launcher/DeviceLauncherSection.h
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
+ * Andrea Azzarone <andrea.azzarone@canonical.com>
*/
#ifndef _DEVICE_LAUNCHER_SECTION_H_
@@ -24,7 +25,7 @@
#include <UnityCore/GLibSource.h>
#include "DeviceLauncherIcon.h"
-#include "AbstractVolumeMonitorWrapper.h"
+#include "VolumeMonitorWrapper.h"
class Launcher;
class LauncherIcon;
@@ -37,19 +38,17 @@ namespace launcher
class DeviceLauncherSection : public sigc::trackable
{
public:
- DeviceLauncherSection(AbstractVolumeMonitorWrapper::Ptr volume_monitor);
+ DeviceLauncherSection(VolumeMonitorWrapper::Ptr volume_monitor);
sigc::signal<void, AbstractLauncherIcon::Ptr> IconAdded;
private:
void PopulateEntries();
-
void OnVolumeAdded(glib::Object<GVolume> const& volume);
void OnVolumeRemoved(glib::Object<GVolume> const& volume);
-private:
std::map<GVolume*, DeviceLauncherIcon*> map_;
- AbstractVolumeMonitorWrapper::Ptr monitor_;
+ VolumeMonitorWrapper::Ptr monitor_;
glib::Idle device_populate_idle_;
};
diff --git a/launcher/LauncherController.cpp b/launcher/LauncherController.cpp
index 8e153bef0..c8c77c241 100644
--- a/launcher/LauncherController.cpp
+++ b/launcher/LauncherController.cpp
@@ -41,7 +41,6 @@
#include "AbstractLauncherIcon.h"
#include "SoftwareCenterLauncherIcon.h"
#include "LauncherModel.h"
-#include "VolumeMonitorWrapper.h"
#include "unity-shared/WindowManager.h"
#include "TrashLauncherIcon.h"
#include "BFBLauncherIcon.h"
diff --git a/launcher/VolumeMonitorWrapper.h b/launcher/VolumeMonitorWrapper.h
index ed37f6514..867736e5d 100644
--- a/launcher/VolumeMonitorWrapper.h
+++ b/launcher/VolumeMonitorWrapper.h
@@ -19,24 +19,35 @@
#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 <UnityCore/GLibSource.h>
-#include "AbstractVolumeMonitorWrapper.h"
-
namespace unity
{
namespace launcher
{
-class VolumeMonitorWrapper : public AbstractVolumeMonitorWrapper
+class VolumeMonitorWrapper : public sigc::trackable
{
public:
+ typedef std::shared_ptr<VolumeMonitorWrapper> Ptr;
+
VolumeMonitorWrapper();
std::list<glib::Object<GVolume>> 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 526ec0cb3..9a108e4ee 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -209,6 +209,7 @@ if (GTEST_SRC_DIR AND
test_texture_cache.cpp
test_main.cpp
test_launcher.cpp
+ test_device_launcher_section.cpp
test_lensview_impl.cpp
test_icon_loader.cpp
test_im_text_entry.cpp
@@ -236,6 +237,9 @@ if (GTEST_SRC_DIR AND
${CMAKE_SOURCE_DIR}/launcher/CairoBaseWindow.cpp
${CMAKE_SOURCE_DIR}/launcher/DNDCollectionWindow.cpp
${CMAKE_SOURCE_DIR}/launcher/Decaymulator.cpp
+ ${CMAKE_SOURCE_DIR}/launcher/DeviceLauncherIcon.cpp
+ ${CMAKE_SOURCE_DIR}/launcher/DeviceLauncherSection.cpp
+ ${CMAKE_SOURCE_DIR}/launcher/DevicesSettings.cpp
${CMAKE_SOURCE_DIR}/launcher/DndData.cpp
${CMAKE_SOURCE_DIR}/launcher/FavoriteStore.cpp
${CMAKE_SOURCE_DIR}/launcher/FavoriteStoreGSettings.cpp
@@ -265,6 +269,7 @@ if (GTEST_SRC_DIR AND
${CMAKE_SOURCE_DIR}/launcher/SwitcherModel.cpp
${CMAKE_SOURCE_DIR}/launcher/SwitcherView.cpp
${CMAKE_SOURCE_DIR}/launcher/Tooltip.cpp
+ ${CMAKE_SOURCE_DIR}/launcher/VolumeMonitorWrapper.cpp
${CMAKE_SOURCE_DIR}/unity-shared/Animator.cpp
${CMAKE_SOURCE_DIR}/unity-shared/BackgroundEffectHelper.cpp
${CMAKE_SOURCE_DIR}/unity-shared/DashStyle.cpp
diff --git a/tests/test_device_launcher_section.cpp b/tests/test_device_launcher_section.cpp
new file mode 100644
index 000000000..040e5b390
--- /dev/null
+++ b/tests/test_device_launcher_section.cpp
@@ -0,0 +1,85 @@
+// -*- 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 <gmock/gmock.h>
+using namespace testing;
+
+#include "DeviceLauncherSection.h"
+#include "VolumeMonitorWrapper.h"
+using namespace unity;
+using namespace unity::launcher;
+
+#include "test_utils.h"
+
+namespace
+{
+
+class EventListener
+{
+public:
+ EventListener()
+ : icon_added(false)
+ {}
+
+ void OnIconAdded(AbstractLauncherIcon::Ptr icon)
+ {
+ icon_added = true;
+ }
+
+ bool icon_added;
+};
+
+class TestDeviceLauncherSection : public Test
+{
+public:
+ TestDeviceLauncherSection()
+ : monitor_(new VolumeMonitorWrapper)
+ , section_(monitor_)
+ {}
+
+ void SetUp()
+ {
+ // Make sure PopulateEntries is called.
+ Utils::WaitForTimeoutMSec(1500);
+ }
+
+ VolumeMonitorWrapper::Ptr monitor_;
+ DeviceLauncherSection section_;
+};
+
+
+TEST_F(TestDeviceLauncherSection, TestNoDuplicates)
+{
+ std::shared_ptr<EventListener> listener(new EventListener);
+ 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);
+
+ Utils::WaitForTimeoutMSec(500);
+
+ EXPECT_EQ(listener->icon_added, false);
+}
+
+}
+