|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QtTest> |
|
43 #include <QtNetwork/qnetworkrequest.h> |
|
44 |
|
45 #include <qmediacontent.h> |
|
46 |
|
47 QT_USE_NAMESPACE |
|
48 class tst_QMediaContent : public QObject |
|
49 { |
|
50 Q_OBJECT |
|
51 |
|
52 private slots: |
|
53 void testNull(); |
|
54 void testUrlCtor(); |
|
55 void testRequestCtor(); |
|
56 void testResourceCtor(); |
|
57 void testResourceListCtor(); |
|
58 void testCopy(); |
|
59 void testAssignment(); |
|
60 void testEquality(); |
|
61 void testResources(); |
|
62 }; |
|
63 |
|
64 void tst_QMediaContent::testNull() |
|
65 { |
|
66 QMediaContent media; |
|
67 |
|
68 QCOMPARE(media.isNull(), true); |
|
69 QCOMPARE(media.canonicalUrl(), QUrl()); |
|
70 QCOMPARE(media.canonicalResource(), QMediaResource()); |
|
71 QCOMPARE(media.resources(), QMediaResourceList()); |
|
72 } |
|
73 |
|
74 void tst_QMediaContent::testUrlCtor() |
|
75 { |
|
76 QMediaContent media(QUrl("http://example.com/movie.mov")); |
|
77 |
|
78 QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); |
|
79 QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); |
|
80 } |
|
81 |
|
82 void tst_QMediaContent::testRequestCtor() |
|
83 { |
|
84 QNetworkRequest request(QUrl("http://example.com/movie.mov")); |
|
85 request.setAttribute(QNetworkRequest::User, QVariant(1234)); |
|
86 |
|
87 QMediaContent media(request); |
|
88 |
|
89 QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); |
|
90 QCOMPARE(media.canonicalResource().request(), request); |
|
91 QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); |
|
92 } |
|
93 |
|
94 void tst_QMediaContent::testResourceCtor() |
|
95 { |
|
96 QMediaContent media(QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
97 |
|
98 QCOMPARE(media.canonicalResource(), QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
99 } |
|
100 |
|
101 void tst_QMediaContent::testResourceListCtor() |
|
102 { |
|
103 QMediaResourceList resourceList; |
|
104 resourceList << QMediaResource(QUrl("http://example.com/movie.mov")); |
|
105 |
|
106 QMediaContent media(resourceList); |
|
107 |
|
108 QCOMPARE(media.canonicalUrl(), QUrl("http://example.com/movie.mov")); |
|
109 QCOMPARE(media.canonicalResource().url(), QUrl("http://example.com/movie.mov")); |
|
110 } |
|
111 |
|
112 void tst_QMediaContent::testCopy() |
|
113 { |
|
114 QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
115 QMediaContent media2(media1); |
|
116 |
|
117 QVERIFY(media1 == media2); |
|
118 } |
|
119 |
|
120 void tst_QMediaContent::testAssignment() |
|
121 { |
|
122 QMediaContent media1(QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
123 QMediaContent media2; |
|
124 QMediaContent media3; |
|
125 |
|
126 media2 = media1; |
|
127 QVERIFY(media2 == media1); |
|
128 |
|
129 media2 = media3; |
|
130 QVERIFY(media2 == media3); |
|
131 } |
|
132 |
|
133 void tst_QMediaContent::testEquality() |
|
134 { |
|
135 QMediaContent media1; |
|
136 QMediaContent media2; |
|
137 QMediaContent media3(QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
138 QMediaContent media4(QMediaResource(QUrl("http://example.com/movie.mov"))); |
|
139 QMediaContent media5(QMediaResource(QUrl("file:///some/where/over/the/rainbow.mp3"))); |
|
140 |
|
141 // null == null |
|
142 QCOMPARE(media1 == media2, true); |
|
143 QCOMPARE(media1 != media2, false); |
|
144 |
|
145 // null != something |
|
146 QCOMPARE(media1 == media3, false); |
|
147 QCOMPARE(media1 != media3, true); |
|
148 |
|
149 // equiv |
|
150 QCOMPARE(media3 == media4, true); |
|
151 QCOMPARE(media3 != media4, false); |
|
152 |
|
153 // not equiv |
|
154 QCOMPARE(media4 == media5, false); |
|
155 QCOMPARE(media4 != media5, true); |
|
156 } |
|
157 |
|
158 void tst_QMediaContent::testResources() |
|
159 { |
|
160 QMediaResourceList resourceList; |
|
161 |
|
162 resourceList << QMediaResource(QUrl("http://example.com/movie-main.mov")); |
|
163 resourceList << QMediaResource(QUrl("http://example.com/movie-big.mov")); |
|
164 QMediaContent media(resourceList); |
|
165 |
|
166 QMediaResourceList res = media.resources(); |
|
167 QCOMPARE(res.size(), 2); |
|
168 QCOMPARE(res[0], QMediaResource(QUrl("http://example.com/movie-main.mov"))); |
|
169 QCOMPARE(res[1], QMediaResource(QUrl("http://example.com/movie-big.mov"))); |
|
170 } |
|
171 |
|
172 QTEST_MAIN(tst_QMediaContent) |
|
173 |
|
174 #include "tst_qmediacontent.moc" |