~ps-jenkins/unity-scopes-shell/ubuntu-rtm-14.09-proposed

« back to all changes in this revision

Viewing changes to tests/previewbindingstest.cpp

  • Committer: Michal Hruby
  • Date: 2013-11-07 17:48:16 UTC
  • Revision ID: michal.mhr@gmail.com-20131107174816-w1vqq6juarrawx23
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011, 2013 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 */
 
16
 
 
17
#include "previewbindingstest.h"
 
18
#include <QTest>
 
19
 
 
20
#include <UnityCore/Preview.h>
 
21
#include <UnityCore/GLibWrapper.h>
 
22
#include <UnityCore/Variant.h>
 
23
#include <unity-protocol.h>
 
24
 
 
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"
 
32
 
 
33
#include <glib.h>
 
34
#include <glib-object.h>
 
35
 
 
36
void PreviewBindingsTest::initTestCase()
 
37
{
 
38
}
 
39
 
 
40
void PreviewBindingsTest::testGenericPreview()
 
41
{
 
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);
 
51
 
 
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;
 
65
 
 
66
    auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
 
67
    corePrv->preview_result = localResult;
 
68
 
 
69
    auto prv = Preview::newFromUnityPreview(corePrv);
 
70
 
 
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"));
 
75
 
 
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"));
 
83
 
 
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"));
 
93
 
 
94
    g_object_unref(icon);
 
95
    g_object_unref(iconFile);
 
96
}
 
97
 
 
98
void PreviewBindingsTest::testApplicationPreview()
 
99
{
 
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);
 
108
 
 
109
    auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
 
110
    auto prv = Preview::newFromUnityPreview(corePrv);
 
111
    auto appPrv = dynamic_cast<ApplicationPreview*>(prv);
 
112
 
 
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));
 
120
}
 
121
 
 
122
void PreviewBindingsTest::testMoviePreview()
 
123
{
 
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);
 
130
 
 
131
    auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
 
132
    auto prv = Preview::newFromUnityPreview(corePrv);
 
133
    auto moviePrv = dynamic_cast<MoviePreview*>(prv);
 
134
 
 
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"));
 
140
}
 
141
 
 
142
void PreviewBindingsTest::testMusicPreview()
 
143
{
 
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);
 
149
 
 
150
    auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
 
151
    auto prv = Preview::newFromUnityPreview(corePrv);
 
152
    auto musicPrv = dynamic_cast<MusicPreview*>(prv);
 
153
 
 
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"));
 
158
}
 
159
 
 
160
void PreviewBindingsTest::testSocialPreview()
 
161
{
 
162
    GFile *iconFile = g_file_new_for_path("/foo.png");
 
163
    GIcon *icon =  g_file_icon_new(iconFile);
 
164
 
 
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);
 
171
 
 
172
    auto corePrv = unity::dash::Preview::PreviewForProtocolObject(genPrv);
 
173
    auto prv = Preview::newFromUnityPreview(corePrv);
 
174
    auto socialPrv = dynamic_cast<SocialPreview*>(prv);
 
175
 
 
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"));
 
180
 
 
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"));
 
189
 
 
190
    g_object_unref(icon);
 
191
    g_object_unref(iconFile);
 
192
}
 
193
 
 
194
QTEST_MAIN(PreviewBindingsTest)