2 * Copyright (C) 2011, 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "previewbindingstest.h"
20#include <UnityCore/Preview.h>
21#include <UnityCore/GLibWrapper.h>
22#include <UnityCore/Variant.h>
23#include <unity-protocol.h>
25#include "genericpreview.h"
26#include "applicationpreview.h"
27#include "moviepreview.h"
28#include "musicpreview.h"
29#include "socialpreview.h"
30#include "socialpreviewcomment.h"
31#include "previewaction.h"
34#include <glib-object.h>
36void PreviewBindingsTest::initTestCase()
40void PreviewBindingsTest::testGenericPreview()
42 auto rawPreview = (GObject *)unity_protocol_generic_preview_new();
43 unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Metallica");
44 unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Ride The Lightning");
45 unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
46 GFile *iconFile = g_file_new_for_path("/foo.png");
47 GIcon *icon = g_file_icon_new(iconFile);
48 unity_protocol_preview_add_action(UNITY_PROTOCOL_PREVIEW(rawPreview), "1", "Action1", icon,
49 UNITY_PROTOCOL_LAYOUT_HINT_LEFT);
50 unity::glib::Object<GObject> genPrv(rawPreview);
52 // create local result
53 unity::glib::HintsMap hints;
54 hints["a"] = unity::glib::Variant(g_variant_new_string("b"));
55 unity::dash::LocalResult localResult;
56 localResult.uri = "http://foo";
57 localResult.icon_hint = "xyz";
58 localResult.category_index = 1;
59 localResult.result_type = 2;
60 localResult.mimetype = "abc";
61 localResult.name = "baz";
62 localResult.comment = "qwerty";
63 localResult.dnd_uri = "zzz";
64 localResult.hints = hints;
66 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
67 corePrv->preview_result = localResult;
69 auto prv = Preview::newFromUnityPreview(corePrv);
71 QCOMPARE(prv != nullptr, true);
72 QCOMPARE(prv->title(), QString("Metallica"));
73 QCOMPARE(prv->subtitle(), QString("Ride The Lightning"));
74 QCOMPARE(prv->description(), QString("Lorem ipsum dolor sit amet"));
76 auto actions = prv->actions().value<QList<QObject *>>();
77 QCOMPARE(actions.size(), 1);
78 auto act = dynamic_cast<PreviewAction *>(actions[0]);
79 QVERIFY(act != nullptr);
80 QCOMPARE(act->id(), QString("1"));
81 QCOMPARE(act->displayName(), QString("Action1"));
82 QCOMPARE(act->iconHint(), QString("/foo.png"));
84 Result* res = prv->result().value<Result*>();
85 QCOMPARE(res->uri(), QString("http://foo"));
86 QCOMPARE(res->iconHint(), QString("xyz"));
87 QCOMPARE(res->categoryIndex(), 1u);
88 QCOMPARE(res->resultType(), 2u);
89 QCOMPARE(res->mimeType(), QString("abc"));
90 QCOMPARE(res->title(), QString("baz"));
91 QCOMPARE(res->dndUri(), QString("zzz"));
92 QCOMPARE(res->metadata().toHash()["a"].toString(), QString("b"));
95 g_object_unref(iconFile);
98void PreviewBindingsTest::testApplicationPreview()
100 auto rawPreview = (GObject *)unity_protocol_application_preview_new();
101 unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Firefox");
102 unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Web Browser");
103 unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
104 unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), "GPL");
105 unity_protocol_application_preview_set_rating(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), 0.5f);
106 unity_protocol_application_preview_set_num_ratings(UNITY_PROTOCOL_APPLICATION_PREVIEW(rawPreview), 4);
107 unity::glib::Object<GObject> genPrv(rawPreview);
109 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
110 auto prv = Preview::newFromUnityPreview(corePrv);
111 auto appPrv = dynamic_cast<ApplicationPreview*>(prv);
113 QCOMPARE(appPrv != nullptr, true);
114 QCOMPARE(appPrv->title(), QString("Firefox"));
115 QCOMPARE(appPrv->subtitle(), QString("Web Browser"));
116 QCOMPARE(appPrv->description(), QString("Lorem ipsum dolor sit amet"));
117 QCOMPARE(appPrv->license(), QString("GPL"));
118 QCOMPARE(appPrv->rating(), 0.5f);
119 QCOMPARE(appPrv->numRatings(), unsigned (4));
122void PreviewBindingsTest::testMoviePreview()
124 auto rawPreview = (GObject *)unity_protocol_movie_preview_new();
125 unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Blade Runner");
126 unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Ridley Scott");
127 unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
128 unity_protocol_movie_preview_set_year(UNITY_PROTOCOL_MOVIE_PREVIEW(rawPreview), "1982");
129 unity::glib::Object<GObject> genPrv(rawPreview);
131 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
132 auto prv = Preview::newFromUnityPreview(corePrv);
133 auto moviePrv = dynamic_cast<MoviePreview*>(prv);
135 QCOMPARE(moviePrv != nullptr, true);
136 QCOMPARE(moviePrv->title(), QString("Blade Runner"));
137 QCOMPARE(moviePrv->subtitle(), QString("Ridley Scott"));
138 QCOMPARE(moviePrv->description(), QString("Lorem ipsum dolor sit amet"));
139 QCOMPARE(moviePrv->year(), QString("1982"));
142void PreviewBindingsTest::testMusicPreview()
144 auto rawPreview = (GObject *)unity_protocol_music_preview_new();
145 unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(rawPreview), "Metallica");
146 unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(rawPreview), "Death Magnetic");
147 unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
148 unity::glib::Object<GObject> genPrv(rawPreview);
150 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
151 auto prv = Preview::newFromUnityPreview(corePrv);
152 auto musicPrv = dynamic_cast<MusicPreview*>(prv);
154 QCOMPARE(musicPrv != nullptr, true);
155 QCOMPARE(musicPrv->title(), QString("Metallica"));
156 QCOMPARE(musicPrv->subtitle(), QString("Death Magnetic"));
157 QCOMPARE(musicPrv->description(), QString("Lorem ipsum dolor sit amet"));
160void PreviewBindingsTest::testSocialPreview()
162 GFile *iconFile = g_file_new_for_path("/foo.png");
163 GIcon *icon = g_file_icon_new(iconFile);
165 auto rawPreview = (GObject *)unity_protocol_social_preview_new();
166 unity_protocol_social_preview_set_sender(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "John");
167 unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), icon);
168 unity_protocol_social_preview_set_content(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "Lorem ipsum dolor sit amet");
169 unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(rawPreview), "1", "comment1", "Ubuntu", "2013-07-04 14:10");
170 unity::glib::Object<GObject> genPrv(rawPreview);
172 auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
173 auto prv = Preview::newFromUnityPreview(corePrv);
174 auto socialPrv = dynamic_cast<SocialPreview*>(prv);
176 QCOMPARE(socialPrv != nullptr, true);
177 QCOMPARE(socialPrv->sender(), QString("John"));
178 QCOMPARE(socialPrv->content(), QString("Lorem ipsum dolor sit amet"));
179 QCOMPARE(socialPrv->avatar(), QString("/foo.png"));
181 auto comments = socialPrv->comments().value<QList<QObject *>>();
182 QCOMPARE(comments.size(), 1);
183 auto cmt = dynamic_cast<SocialPreviewComment *>(comments[0]);
184 QVERIFY(cmt != nullptr);
185 QCOMPARE(cmt->id(), QString("1"));
186 QCOMPARE(cmt->displayName(), QString("comment1"));
187 QCOMPARE(cmt->content(), QString("Ubuntu"));
188 QCOMPARE(cmt->time(), QString("2013-07-04 14:10"));
190 g_object_unref(icon);
191 g_object_unref(iconFile);
194QTEST_MAIN(PreviewBindingsTest)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list