diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2012-07-20 00:42:22 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2012-07-20 00:42:22 +0200 |
| commit | 4c48c2677a3ef09e85bd190cc21989feac730cd9 (patch) | |
| tree | 14e780121df4a85a1bee6ddbe829734d7dc0d1ce /tests | |
| parent | b8a9cafe23c547853726489747443d0e75e3911a (diff) | |
| parent | 2258103ed98546a1ed29aa06be5e461781bf5067 (diff) | |
merging with trunk
(bzr r2509.1.26)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | tests/gmockvolume.c | 176 | ||||
| -rw-r--r-- | tests/gmockvolume.h | 53 | ||||
| -rw-r--r-- | tests/test_device_launcher_section.cpp | 111 | ||||
| -rw-r--r-- | tests/test_favorite_store_gsettings.cpp | 2 | ||||
| -rw-r--r-- | tests/test_lens.cpp | 111 | ||||
| -rw-r--r-- | tests/test_previews.cpp | 262 | ||||
| -rw-r--r-- | tests/test_service_lens.c | 50 |
8 files changed, 741 insertions, 30 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ea2bbc5f0..4a05477cf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -148,6 +148,7 @@ if (GTEST_SRC_DIR AND test_home_lens.cpp test_launcher_entry_remote.cpp test_pointer_barrier.cpp + test_previews.cpp test_shortcut_model.cpp test_shortcut_private.cpp test_showdesktop_handler.cpp @@ -209,6 +210,7 @@ if (GTEST_SRC_DIR AND test_dashview_impl.cpp test_edge_barrier_controller.cpp test_launcher.cpp + test_device_launcher_section.cpp test_lensview_impl.cpp test_hud_button.cpp test_hud_controller.cpp @@ -221,6 +223,7 @@ if (GTEST_SRC_DIR AND test_switcher_controller.cpp test_switcher_model.cpp test_texture_cache.cpp + gmockvolume.c ${CMAKE_SOURCE_DIR}/dash/AbstractPlacesGroup.cpp ${CMAKE_SOURCE_DIR}/dash/DashViewPrivate.cpp ${CMAKE_SOURCE_DIR}/dash/LensViewPrivate.cpp @@ -239,6 +242,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/EdgeBarrierController.cpp ${CMAKE_SOURCE_DIR}/launcher/FavoriteStore.cpp diff --git a/tests/gmockvolume.c b/tests/gmockvolume.c new file mode 100644 index 000000000..5ee2d23a1 --- /dev/null +++ b/tests/gmockvolume.c @@ -0,0 +1,176 @@ +// -*- 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); + +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..0c9ee118a --- /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 new file mode 100644 index 000000000..b00bbfc72 --- /dev/null +++ b/tests/test_device_launcher_section.cpp @@ -0,0 +1,111 @@ +// -*- 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 "AbstractVolumeMonitorWrapper.h" +using namespace unity; +using namespace unity::launcher; + +#include "gmockvolume.h" +#include "test_utils.h" + +namespace +{ + +class EventListener +{ +public: + EventListener() + : icon_added(false) + {} + + void OnIconAdded(AbstractLauncherIcon::Ptr icon) + { + icon_added = true; + } + + 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 MockVolumeMonitorWrapper) + , section_(monitor_) + {} + + void SetUp() + { + // Make sure PopulateEntries is called. + Utils::WaitForTimeoutMSec(1500); + } + + MockVolumeMonitorWrapper::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. + monitor_->volume_added.emit(monitor_->volume1); + monitor_->volume_added.emit(monitor_->volume2); + + Utils::WaitForTimeoutMSec(500); + + EXPECT_EQ(listener->icon_added, false); +} + +} + diff --git a/tests/test_favorite_store_gsettings.cpp b/tests/test_favorite_store_gsettings.cpp index 8609d9379..9604dc712 100644 --- a/tests/test_favorite_store_gsettings.cpp +++ b/tests/test_favorite_store_gsettings.cpp @@ -43,7 +43,7 @@ namespace { // Constant const gchar* SCHEMA_DIRECTORY = BUILDDIR"/settings"; const gchar* BASE_STORE_FILE = BUILDDIR"/settings/test-favorite-store-gsettings.store"; -const gchar* BASE_STORE_CONTENTS = "[desktop/unity/launcher]\n" \ +const gchar* BASE_STORE_CONTENTS = "[com/canonical/unity/launcher]\n" \ "favorites=['%s', '%s', '%s']"; const char* base_store_favs[] = { BUILDDIR"/tests/data/ubuntuone-installer.desktop", diff --git a/tests/test_lens.cpp b/tests/test_lens.cpp index 71998e1df..27a4cdd0b 100644 --- a/tests/test_lens.cpp +++ b/tests/test_lens.cpp @@ -6,7 +6,9 @@ #include <UnityCore/GLibWrapper.h> #include <UnityCore/Lens.h> #include <UnityCore/MultiRangeFilter.h> -#include <UnityCore/MusicPreviews.h> +#include <UnityCore/Preview.h> +#include <UnityCore/SeriesPreview.h> +#include <UnityCore/Variant.h> #include <UnityCore/RadioOptionFilter.h> #include <UnityCore/RatingsFilter.h> @@ -52,7 +54,7 @@ public: void WaitForConnected() { bool timeout_reached = false; - guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached); + guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached, 2000); while (!lens_->connected && !timeout_reached) { @@ -68,7 +70,7 @@ public: void WaitForModel(Model<Adaptor>* model, unsigned int n_rows) { bool timeout_reached = false; - guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached); + guint32 timeout_id = Utils::ScheduleTimeout(&timeout_reached, 2000); while (model->count != n_rows && !timeout_reached) { @@ -209,37 +211,102 @@ TEST_F(TestLens, TestActivation) TEST_F(TestLens, TestPreview) { - // FIXME: fix up when unity-core supports current preview protocol - /* std::string uri = PopulateAndGetFirstResultURI(); bool previewed = false; auto preview_cb = [&previewed, &uri] (std::string const& uri_, - Preview::Ptr preview) + Preview::Ptr const& preview) { EXPECT_EQ(uri, uri_); - EXPECT_EQ(preview->renderer_name, "preview-generic"); - - TrackPreview::Ptr track_preview = std::static_pointer_cast<TrackPreview>(preview); - EXPECT_EQ(track_preview->number, (unsigned int)1); - EXPECT_EQ(track_preview->title, "Animus Vox"); - EXPECT_EQ(track_preview->artist, "The Glitch Mob"); - EXPECT_EQ(track_preview->album, "Drink The Sea"); - EXPECT_EQ(track_preview->length, (unsigned int)404); - EXPECT_EQ(track_preview->album_cover, "file://music/the/track"); - EXPECT_EQ(track_preview->primary_action_name, "Play"); - EXPECT_EQ(track_preview->primary_action_icon_hint, ""); - EXPECT_EQ(track_preview->primary_action_uri, "play://music/the/track"); - EXPECT_EQ(track_preview->play_action_uri, "preview://music/the/track"); - EXPECT_EQ(track_preview->pause_action_uri, "pause://music/the/track"); - EXPECT_EQ(track_preview->genres.size(), (unsigned int)1); + EXPECT_EQ(preview->renderer_name, "preview-series"); + + auto series = std::dynamic_pointer_cast<SeriesPreview>(preview); + EXPECT_EQ(series->GetItems().size(), (unsigned)4); + EXPECT_EQ(series->selected_item_index, 2); + + auto child = series->GetChildPreview(); + EXPECT_EQ(child->title, "A preview"); previewed = true; }; + lens_->preview_ready.connect(preview_cb); lens_->Preview(uri); Utils::WaitUntil(previewed); - */ +} + +TEST_F(TestLens, TestPreviewAction) +{ + std::string uri = PopulateAndGetFirstResultURI(); + bool previewed = false; + Preview::Ptr preview; + + auto preview_cb = [&previewed, &uri, &preview] + (std::string const& uri_, + Preview::Ptr const& preview_) + { + EXPECT_EQ(uri, uri_); + EXPECT_EQ(preview_->renderer_name, "preview-series"); + + preview = preview_; + previewed = true; + }; + + lens_->preview_ready.connect(preview_cb); + lens_->Preview(uri); + + Utils::WaitUntil(previewed); + + bool action_executed = false; + auto activated_cb = [&action_executed] (std::string const& uri, + HandledType handled_type, + Lens::Hints const& hints) + { + EXPECT_EQ(handled_type, HandledType::SHOW_DASH); + action_executed = true; + }; + + lens_->activated.connect(activated_cb); + EXPECT_GT(preview->GetActions().size(), (unsigned)0); + auto action = preview->GetActions()[0]; + preview->PerformAction(action->id); + + Utils::WaitUntil(action_executed); +} + +TEST_F(TestLens, TestPreviewSignal) +{ + std::string uri = PopulateAndGetFirstResultURI(); + bool previewed = false; + SeriesPreview::Ptr series_preview; + + auto preview_cb = [&previewed, &uri, &series_preview] + (std::string const& uri_, + Preview::Ptr const& preview) + { + EXPECT_EQ(uri, uri_); + EXPECT_EQ(preview->renderer_name, "preview-series"); + + series_preview = std::dynamic_pointer_cast<SeriesPreview>(preview); + previewed = true; + }; + + lens_->preview_ready.connect(preview_cb); + lens_->Preview(uri); + + Utils::WaitUntil(previewed); + + bool child_changed = false; + auto child_changed_cb = [&child_changed] (Preview::Ptr const& new_child) + { + EXPECT_EQ(new_child->title, "A preview"); + child_changed = true; + }; + + series_preview->child_preview_changed.connect(child_changed_cb); + series_preview->selected_item_index = 1; + + Utils::WaitUntil(child_changed); } TEST_F(TestLens, TestFilterSync) diff --git a/tests/test_previews.cpp b/tests/test_previews.cpp new file mode 100644 index 000000000..a7997b830 --- /dev/null +++ b/tests/test_previews.cpp @@ -0,0 +1,262 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> + */ + +#include <list> +#include <algorithm> +#include <gmock/gmock.h> +#include <gio/gio.h> +#include <UnityCore/Variant.h> +#include <UnityCore/Preview.h> +#include <UnityCore/ApplicationPreview.h> +#include <UnityCore/MoviePreview.h> +#include <UnityCore/MusicPreview.h> +#include <UnityCore/SeriesPreview.h> +#include <unity-protocol.h> + +using namespace std; +using namespace testing; +using namespace unity; +using namespace unity::glib; +using namespace unity::dash; + +namespace +{ + +bool IsVariant(Variant const& variant) +{ + return g_variant_get_type_string(variant) != NULL; +} + +TEST(TestPreviews, DeserializeGeneric) +{ + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); + unity_protocol_preview_set_title(proto_obj, "Title"); + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); + unity_protocol_preview_set_description(proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(proto_obj, icon); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr preview = Preview::PreviewForVariant(v); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-generic"); + EXPECT_EQ(preview->title, "Title"); + EXPECT_EQ(preview->subtitle, "Subtitle"); + EXPECT_EQ(preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); +} + +TEST(TestPreviews, DeserializeGenericWithMeta) +{ + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); + unity_protocol_preview_set_title(proto_obj, "Title"); + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); + unity_protocol_preview_set_description(proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(proto_obj, icon); + unity_protocol_preview_add_action(proto_obj, "action1", "Action #1", NULL, 0); + unity_protocol_preview_add_action(proto_obj, "action2", "Action #2", NULL, 0); + unity_protocol_preview_add_info_hint(proto_obj, "hint1", "Hint 1", NULL, g_variant_new("i", 34)); + unity_protocol_preview_add_info_hint(proto_obj, "hint2", "Hint 2", NULL, g_variant_new("s", "string hint")); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr preview = Preview::PreviewForVariant(v); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-generic"); + EXPECT_EQ(preview->title, "Title"); + EXPECT_EQ(preview->subtitle, "Subtitle"); + EXPECT_EQ(preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); + + auto actions = preview->GetActions(); + auto info_hints = preview->GetInfoHints(); + + EXPECT_EQ(actions.size(), 2); + + auto action1 = actions[0]; + EXPECT_EQ(action1->id, "action1"); + EXPECT_EQ(action1->display_name, "Action #1"); + EXPECT_EQ(action1->icon_hint, ""); + EXPECT_EQ(action1->layout_hint, 0); + + auto action2 = actions[1]; + EXPECT_EQ(action2->id, "action2"); + EXPECT_EQ(action2->display_name, "Action #2"); + EXPECT_EQ(action2->icon_hint, ""); + + EXPECT_EQ(info_hints.size(), 2); + auto hint1 = info_hints[0]; + EXPECT_EQ(hint1->id, "hint1"); + EXPECT_EQ(hint1->display_name, "Hint 1"); + EXPECT_EQ(hint1->icon_hint, ""); + EXPECT_EQ(hint1->value.GetInt(), 34); + auto hint2 = info_hints[1]; + EXPECT_EQ(hint2->id, "hint2"); + EXPECT_EQ(hint2->display_name, "Hint 2"); + EXPECT_EQ(hint2->icon_hint, ""); + EXPECT_EQ(hint2->value.GetString(), "string hint"); +} + +TEST(TestPreviews, DeserializeApplication) +{ + Object<GIcon> icon(g_icon_new_for_string("application", NULL)); + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_application_preview_new())); + unity_protocol_preview_set_title(proto_obj, "Title"); + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); + unity_protocol_preview_set_description(proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(proto_obj, icon); + auto app_proto_obj = glib::object_cast<UnityProtocolApplicationPreview>(proto_obj); + unity_protocol_application_preview_set_last_update(app_proto_obj, "2012/06/13"); + unity_protocol_application_preview_set_copyright(app_proto_obj, "(c) Canonical"); + unity_protocol_application_preview_set_license(app_proto_obj, "GPLv3"); + unity_protocol_application_preview_set_app_icon(app_proto_obj, icon); + unity_protocol_application_preview_set_rating(app_proto_obj, 4.0); + unity_protocol_application_preview_set_num_ratings(app_proto_obj, 12); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr base_preview = Preview::PreviewForVariant(v); + ApplicationPreview::Ptr preview = std::dynamic_pointer_cast<ApplicationPreview>(base_preview); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-application"); + EXPECT_EQ(preview->title, "Title"); + EXPECT_EQ(preview->subtitle, "Subtitle"); + EXPECT_EQ(preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); + EXPECT_EQ(preview->last_update, "2012/06/13"); + EXPECT_EQ(preview->copyright, "(c) Canonical"); + EXPECT_EQ(preview->license, "GPLv3"); + EXPECT_TRUE(g_icon_equal(preview->app_icon(), icon) != FALSE); + EXPECT_EQ(preview->rating, 4.0); + EXPECT_EQ(preview->num_ratings, static_cast<unsigned>(12)); +} + +TEST(TestPreviews, DeserializeMovie) +{ + Object<GIcon> icon(g_icon_new_for_string("movie", NULL)); + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_movie_preview_new())); + unity_protocol_preview_set_title(proto_obj, "Title"); + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); + unity_protocol_preview_set_description(proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(proto_obj, icon); + auto movie_proto_obj = glib::object_cast<UnityProtocolMoviePreview>(proto_obj); + unity_protocol_movie_preview_set_year(movie_proto_obj, "2012"); + unity_protocol_movie_preview_set_rating(movie_proto_obj, 4.0); + unity_protocol_movie_preview_set_num_ratings(movie_proto_obj, 12); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr base_preview = Preview::PreviewForVariant(v); + MoviePreview::Ptr preview = std::dynamic_pointer_cast<MoviePreview>(base_preview); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-movie"); + EXPECT_EQ(preview->title, "Title"); + EXPECT_EQ(preview->subtitle, "Subtitle"); + EXPECT_EQ(preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); + EXPECT_EQ(preview->year, "2012"); + EXPECT_EQ(preview->rating, 4.0); + EXPECT_EQ(preview->num_ratings, static_cast<unsigned int>(12)); +} + +TEST(TestPreviews, DeserializeMusic) +{ + Object<GIcon> icon(g_icon_new_for_string("music", NULL)); + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_music_preview_new())); + unity_protocol_preview_set_title(proto_obj, "Title"); + unity_protocol_preview_set_subtitle(proto_obj, "Subtitle"); + unity_protocol_preview_set_description(proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(proto_obj, icon); + auto music_proto_obj = glib::object_cast<UnityProtocolMusicPreview>(proto_obj); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr base_preview = Preview::PreviewForVariant(v); + MusicPreview::Ptr preview = std::dynamic_pointer_cast<MusicPreview>(base_preview); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-music"); + EXPECT_EQ(preview->title, "Title"); + EXPECT_EQ(preview->subtitle, "Subtitle"); + EXPECT_EQ(preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(preview->image(), icon) != FALSE); +} + +TEST(TestPreviews, DeserializeSeries) +{ + Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_series_preview_new())); + auto series_proto_obj = glib::object_cast<UnityProtocolSeriesPreview>(proto_obj); + unity_protocol_series_preview_add_series_item( + series_proto_obj, "#1", "scheme://path/0", NULL); + unity_protocol_series_preview_add_series_item( + series_proto_obj, "#2", "scheme://path/1", NULL); + unity_protocol_series_preview_set_selected_item(series_proto_obj, 1); + + Object<GIcon> icon(g_icon_new_for_string("accessories", NULL)); + Object<UnityProtocolPreview> child_proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_generic_preview_new())); + unity_protocol_preview_set_title(child_proto_obj, "Title"); + unity_protocol_preview_set_subtitle(child_proto_obj, "Subtitle"); + unity_protocol_preview_set_description(child_proto_obj, "Description"); + unity_protocol_preview_set_thumbnail(child_proto_obj, icon); + + unity_protocol_series_preview_set_child_preview(series_proto_obj, + child_proto_obj); + + Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + EXPECT_TRUE(IsVariant(v)); + + Preview::Ptr base_preview = Preview::PreviewForVariant(v); + SeriesPreview::Ptr preview = std::dynamic_pointer_cast<SeriesPreview>(base_preview); + EXPECT_TRUE(preview != nullptr); + + EXPECT_EQ(preview->renderer_name, "preview-series"); + + auto items = preview->GetItems(); + EXPECT_EQ(items.size(), 2); + + auto item1 = preview->GetItems()[1]; + EXPECT_EQ(item1->uri, "scheme://path/1"); + EXPECT_EQ(item1->title, "#2"); + + auto child_preview = preview->GetChildPreview(); + EXPECT_EQ(child_preview->renderer_name, "preview-generic"); + EXPECT_EQ(child_preview->title, "Title"); + EXPECT_EQ(child_preview->subtitle, "Subtitle"); + EXPECT_EQ(child_preview->description, "Description"); + EXPECT_TRUE(g_icon_equal(child_preview->image(), icon) != FALSE); +} + +} // Namespace diff --git a/tests/test_service_lens.c b/tests/test_service_lens.c index 854c99ec9..7f4dd4485 100644 --- a/tests/test_service_lens.c +++ b/tests/test_service_lens.c @@ -174,7 +174,7 @@ on_search_changed(UnityScope* scope, UnityLensSearch *search, g_free(name); } - g_signal_emit_by_name (search, "finished"); + unity_lens_search_finished (search); } static UnityActivationResponse* @@ -183,15 +183,51 @@ on_activate_uri(UnityScope* scope, const char* uri, ServiceLens* self) return unity_activation_response_new(UNITY_HANDLED_TYPE_HIDE_DASH, ""); } +static UnityActivationResponse* +preview_action_activated(UnityPreviewAction* action, const char* uri) +{ + return unity_activation_response_new(UNITY_HANDLED_TYPE_SHOW_DASH, ""); +} + +static UnityPreview* +generate_child_preview(UnitySeriesPreview* parent, const char* uri) +{ + UnityPreview* preview; + UnityPreviewAction *action; + + gchar* desc = g_strdup_printf("Description for an item with uri %s", uri); + preview = (UnityPreview*) unity_generic_preview_new("A preview", desc, NULL); + action = unity_preview_action_new("child_action_X", "An action", NULL); + unity_preview_add_action(preview, action); + g_signal_connect(action, "activated", + G_CALLBACK(preview_action_activated), NULL); + + g_free(desc); + return preview; +} + static UnityPreview* on_preview_uri(UnityScope* scope, const char* uri, ServiceLens *self) { - return NULL; - // FIXME: update when the new preview types are well defined - /* - return (UnityPreview*)unity_generic_preview_new( - "Animus Vox", "The Glitch Mob - Drink The Sea", NULL); - */ + UnityPreviewAction* action; + UnitySeriesPreview* preview; + UnitySeriesItem* series_items[4]; + + series_items[0] = unity_series_item_new("scheme://item/1", "Item #1", NULL); + series_items[1] = unity_series_item_new("scheme://item/2", "Item #2", NULL); + series_items[2] = unity_series_item_new("scheme://item/3", "Item #3", NULL); + series_items[3] = unity_series_item_new("scheme://item/4", "Item #4", NULL); + + preview = unity_series_preview_new(series_items, 4, "scheme://item/3"); + g_signal_connect(preview, "request-item-preview", + G_CALLBACK(generate_child_preview), NULL); + + action = unity_preview_action_new("series_action_A", "An action", NULL); + unity_preview_add_action(UNITY_PREVIEW(preview), action); + g_signal_connect(action, "activated", + G_CALLBACK(preview_action_activated), NULL); + + return (UnityPreview*) preview; } ServiceLens* |
