on xenial help sign in
Added some basic tests for preview bindings.
commitf9664327af34002215d52a22127ad35193885d29 authorPawel Stolowski <pawel.stolowski@canonical.com> dateFri 28 Jun 2013, 16:01 (13 years ago) parent0bfbf81
11 files changed+197−12
plugins/Unity/applicationpreview.h+1−1 plugins/Unity/moviepreview.cpp+1−1 plugins/Unity/moviepreview.h+1−1 plugins/Unity/musicpreview.cpp+3 plugins/Unity/musicpreview.h+2−4 plugins/Unity/preview.cpp+1−2 plugins/Unity/preview.h+3−3 tests/plugins/CMakeLists.txt+1 tests/plugins/Unity/CMakeLists.txt+38 tests/plugins/Unity/previewbindingstest.cpp+112 tests/plugins/Unity/previewbindingstest.h+34
plugins/Unity/applicationpreview.h+1−1
@@ -30,7 +30,7 @@
3030// libunity-core
3131#include <UnityCore/ApplicationPreview.h>
3232
33−class ApplicationPreview: public Preview
33+class Q_DECL_EXPORT ApplicationPreview: public Preview
3434{
3535 Q_OBJECT
3636
plugins/Unity/moviepreview.cpp+1−1
@@ -58,7 +58,7 @@ unsigned int MoviePreview::numRatings() const
5858 }
5959 return 0;
6060}
61−
61+
6262void MoviePreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
6363{
6464 m_unityMoviePreview = std::dynamic_pointer_cast<unity::dash::MoviePreview>(unityPreview);
plugins/Unity/moviepreview.h+1−1
@@ -30,7 +30,7 @@
3030// libunity-core
3131#include <UnityCore/MoviePreview.h>
3232
33−class MoviePreview: public Preview
33+class Q_DECL_EXPORT MoviePreview: public Preview
3434{
3535 Q_OBJECT
3636
plugins/Unity/musicpreview.cpp+3
@@ -20,6 +20,9 @@
2020#include "musicpreview.h"
2121#include <QDebug>
2222
23+// dee-qt
24+#include "deelistmodel.h"
25+
2326MusicPreview::MusicPreview(QObject *parent):
2427 Preview(parent),
2528 m_unityMusicPreview(nullptr)
plugins/Unity/musicpreview.h+2−4
@@ -30,11 +30,9 @@
3030// libunity-core
3131#include <UnityCore/MusicPreview.h>
3232
33+class DeeListModel;
3334
34−// dee-qt
35−#include "deelistmodel.h"
36−
37−class MusicPreview: public Preview
35+class Q_DECL_EXPORT MusicPreview: public Preview
3836{
3937 Q_OBJECT
4038
plugins/Unity/preview.cpp+1−2
@@ -152,7 +152,7 @@ Preview* Preview::newFromUnityPreview(unity::dash::Preview::Ptr unityPreview)
152152 qWarning() << "Unknown preview type: " << typeid(*unityPreview).name();
153153 preview = new GenericPreview();
154154 }
155−
155+
156156 preview->Preview::setUnityPreview(unityPreview);
157157 preview->setUnityPreview(unityPreview);
158158
@@ -182,4 +182,3 @@ void Preview::execute(const QString& actionId, const QHash<QString, QVariant>& h
182182 qWarning() << "Preview not set";
183183 }
184184}
185−
plugins/Unity/preview.h+3−3
@@ -31,10 +31,10 @@
3131// local
3232#include "previewaction.h"
3333
34−class Preview : public QObject
34+class Q_DECL_EXPORT Preview : public QObject
3535{
3636 Q_OBJECT
37−
37+
3838 Q_PROPERTY(QString rendererName READ rendererName NOTIFY rendererNameChanged)
3939 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
4040 Q_PROPERTY(QString subtitle READ subtitle NOTIFY subtitleChanged)
@@ -43,7 +43,7 @@ class Preview : public QObject
4343 Q_PROPERTY(QVariant infoHints READ infoHints NOTIFY infoHintsChanged)
4444 Q_PROPERTY(QString image READ image NOTIFY imageChanged)
4545 Q_PROPERTY(QString imageSourceUri READ imageSourceUri NOTIFY imageSourceUriChanged)
46−
46+
4747public:
4848 explicit Preview(QObject *parent = 0);
4949 static Preview* newFromUnityPreview(unity::dash::Preview::Ptr unityPreview);
tests/plugins/CMakeLists.txt+1
@@ -1,2 +1,3 @@
11add_subdirectory(Utils)
22add_subdirectory(Ubuntu)
3+add_subdirectory(Unity)
tests/plugins/Unity/CMakeLists.txtnew file+38
@@ -0,0 +1,38 @@
1+pkg_check_modules(UNITYCORE REQUIRED unity-core-6.0)
2+pkg_check_modules(LIBUNITYPROTO REQUIRED unity-protocol-private)
3+
4+include_directories(
5+ ${Unity-qml_SOURCE_DIR}
6+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../plugins/Unity
7+ ${CMAKE_CURRENT_BINARY_DIR}
8+ ${LIBUNITYPROTO_INCLUDE_DIRS}
9+ ${UNITYCORE_INCLUDE_DIRS}
10+ )
11+
12+macro(run_tests)
13+ set(_test_list "")
14+ foreach(_test ${ARGN})
15+ set(testCommand
16+ ${CMAKE_CURRENT_BINARY_DIR}/${_test}Exec
17+ -o ${CMAKE_BINARY_DIR}/${_test}.xml,xunitxml
18+ -o -,txt)
19+ add_test(NAME test${CLASSNAME}${_test} COMMAND ${testCommand})
20+ add_custom_target(${_test} ${testCommand})
21+ add_executable(${_test}Exec ${_test}.cpp previewbindingstest.cpp)
22+ qt5_use_modules(${_test}Exec Test Core Qml)
23+ set_tests_properties(test${CLASSNAME}${_test}
24+ PROPERTIES ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/plugins/Unity:${LIBUNITYPROTO_LIBRARY_DIRS})
25+
26+ target_link_libraries(${_test}Exec
27+ Unity-qml
28+ ${UNITYCORE_LDFLAGS}
29+ ${LIBUNITYPROTO_LDFLAGS}
30+ )
31+
32+ set(_test_list "${_test_list};${_test}")
33+ endforeach()
34+endmacro(run_tests)
35+
36+run_tests(
37+ previewbindingstest
38+ )
tests/plugins/Unity/previewbindingstest.cppnew file+112
@@ -0,0 +1,112 @@
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+#include <QSignalSpy>
20+#include <QDebug>
21+
22+#include <UnityCore/GenericPreview.h>
23+#include <UnityCore/GLibWrapper.h>
24+#include <unity-protocol.h>
25+
26+#include "preview.h"
27+#include "applicationpreview.h"
28+#include "moviepreview.h"
29+#include "musicpreview.h"
30+
31+void PreviewBindingsTest::initTestCase()
32+{
33+}
34+
35+void PreviewBindingsTest::testGenericPreview()
36+{
37+ auto raw_preview = (GObject *)unity_protocol_generic_preview_new();
38+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Metallica");
39+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Ride The Lightning");
40+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
41+ unity::glib::Object<GObject> gen_prv(raw_preview);
42+
43+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
44+ auto prv = Preview::newFromUnityPreview(core_prv);
45+
46+ QCOMPARE(prv != nullptr, true);
47+ QCOMPARE(prv->title(), QString("Metallica"));
48+ QCOMPARE(prv->subtitle(), QString("Ride The Lightning"));
49+ QCOMPARE(prv->description(), QString("Lorem ipsum dolor sit amet"));
50+}
51+
52+void PreviewBindingsTest::testApplicationPreview()
53+{
54+ auto raw_preview = (GObject *)unity_protocol_application_preview_new();
55+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Firefox");
56+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Web Browser");
57+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
58+ unity_protocol_application_preview_set_license(UNITY_PROTOCOL_APPLICATION_PREVIEW(raw_preview), "GPL");
59+ unity::glib::Object<GObject> gen_prv(raw_preview);
60+
61+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
62+ auto prv = Preview::newFromUnityPreview(core_prv);
63+ auto app_prv = dynamic_cast<ApplicationPreview*>(prv);
64+
65+ QCOMPARE(app_prv != nullptr, true);
66+ QCOMPARE(app_prv->title(), QString("Firefox"));
67+ QCOMPARE(app_prv->subtitle(), QString("Web Browser"));
68+ QCOMPARE(app_prv->description(), QString("Lorem ipsum dolor sit amet"));
69+ QCOMPARE(app_prv->license(), QString("GPL"));
70+}
71+
72+void PreviewBindingsTest::testMoviePreview()
73+{
74+ auto raw_preview = (GObject *)unity_protocol_movie_preview_new();
75+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Blade Runner");
76+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Ridley Scott");
77+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
78+ unity_protocol_movie_preview_set_year(UNITY_PROTOCOL_MOVIE_PREVIEW(raw_preview), "1982");
79+ unity::glib::Object<GObject> gen_prv(raw_preview);
80+
81+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
82+ auto prv = Preview::newFromUnityPreview(core_prv);
83+ auto movie_prv = dynamic_cast<MoviePreview*>(prv);
84+
85+ QCOMPARE(movie_prv != nullptr, true);
86+ QCOMPARE(movie_prv->title(), QString("Blade Runner"));
87+ QCOMPARE(movie_prv->subtitle(), QString("Ridley Scott"));
88+ QCOMPARE(movie_prv->description(), QString("Lorem ipsum dolor sit amet"));
89+ QCOMPARE(movie_prv->year(), QString("1982"));
90+}
91+
92+void PreviewBindingsTest::testMusicPreview()
93+{
94+ auto raw_preview = (GObject *)unity_protocol_music_preview_new();
95+ unity_protocol_preview_set_title(UNITY_PROTOCOL_PREVIEW(raw_preview), "Metallica");
96+ unity_protocol_preview_set_subtitle(UNITY_PROTOCOL_PREVIEW(raw_preview), "Death Magnetic");
97+ unity_protocol_preview_set_description(UNITY_PROTOCOL_PREVIEW(raw_preview), "Lorem ipsum dolor sit amet");
98+ unity::glib::Object<GObject> gen_prv(raw_preview);
99+
100+ auto core_prv = unity::dash::Preview::PreviewForProtocolObject(gen_prv);
101+ auto prv = Preview::newFromUnityPreview(core_prv);
102+ auto music_prv = dynamic_cast<MusicPreview*>(prv);
103+
104+ QCOMPARE(music_prv != nullptr, true);
105+ QCOMPARE(music_prv->title(), QString("Metallica"));
106+ QCOMPARE(music_prv->subtitle(), QString("Death Magnetic"));
107+ QCOMPARE(music_prv->description(), QString("Lorem ipsum dolor sit amet"));
108+}
109+
110+QTEST_MAIN(PreviewBindingsTest)
111+
112+#include "previewbindingstest.moc"
tests/plugins/Unity/previewbindingstest.hnew file+34
@@ -0,0 +1,34 @@
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+#ifndef PREVIEWBINDINGSTEST_H
18+#define PREVIEWBINDINGSTEST_H
19+
20+#include <QObject>
21+
22+class PreviewBindingsTest : public QObject
23+{
24+ Q_OBJECT
25+
26+ private Q_SLOTS:
27+ void initTestCase();
28+ void testGenericPreview();
29+ void testApplicationPreview();
30+ void testMoviePreview();
31+ void testMusicPreview();
32+};
33+
34+#endif