|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Upnp Command Handlers. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // CLASS HEADER |
|
22 #include "t_glxcommandhandlercopytohomenetwork.h" |
|
23 |
|
24 // EXTERNAL INCLUDES |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 #include <digia/eunit/eunitdecorators.h> |
|
27 |
|
28 #include <glxcommandhandlers.hrh> |
|
29 #include <mglxmedialist.h> |
|
30 #include <upnpshowcommand.h> |
|
31 |
|
32 // INTERNAL INCLUDES |
|
33 #include "glxupnprenderer.h" |
|
34 #include <upnpcopycommand.h> |
|
35 #include <glxattributeretriever.h> |
|
36 |
|
37 TInt GlxAttributeRetriever::RetrieveL(const MGlxFetchContext& /*aContext*/, |
|
38 MGlxMediaList& /*aList*/, TBool /*aShowDialog*/) |
|
39 { |
|
40 return KErrNone; |
|
41 } |
|
42 |
|
43 TBool CUpnpCopyCommand::gUpnpCopyCommandEnabled = EFalse; |
|
44 |
|
45 class _CGlxTestMediaList: public CBase, public MGlxMediaList |
|
46 { |
|
47 public: |
|
48 ~_CGlxTestMediaList() |
|
49 { |
|
50 iItems.Close(); |
|
51 iMedia.ResetAndDestroy(); |
|
52 iSelectedItems.Close(); |
|
53 } |
|
54 |
|
55 virtual void Close() |
|
56 { |
|
57 }; |
|
58 virtual TGlxMediaListId Id() const |
|
59 { |
|
60 return KGlxIdNone; |
|
61 } |
|
62 |
|
63 virtual TInt Count(NGlxListDefs::TCountType /*aType*/) const |
|
64 { |
|
65 return iItems.Count(); |
|
66 } |
|
67 |
|
68 virtual TInt FocusIndex() const |
|
69 { |
|
70 return iFocusIndex; |
|
71 } |
|
72 |
|
73 virtual void SetFocusL(NGlxListDefs::TFocusSetType /*aType*/, TInt aValue) |
|
74 { |
|
75 iFocusIndex = aValue; |
|
76 } |
|
77 |
|
78 virtual const TGlxMedia& Item(TInt aIndex) const |
|
79 { |
|
80 return iItems[aIndex]; |
|
81 } |
|
82 |
|
83 virtual TInt Index(const TGlxIdSpaceId& /* aIdSpaceId */, const TGlxMediaId& aId) const |
|
84 { |
|
85 TInt count = iItems.Count(); |
|
86 for (TInt i = 0; i < count; i++) |
|
87 { |
|
88 if (iItems[i].Id() == aId) |
|
89 { |
|
90 return i; |
|
91 } |
|
92 } |
|
93 return KErrNotFound; |
|
94 } |
|
95 |
|
96 virtual void AddMediaListObserverL(MGlxMediaListObserver* /*aObserver*/) |
|
97 { |
|
98 } |
|
99 |
|
100 virtual void RemoveMediaListObserver(MGlxMediaListObserver* /*aObserver*/) |
|
101 { |
|
102 } |
|
103 |
|
104 virtual void AddContextL(const MGlxFetchContext* /*aContext*/, TInt /*aPriority*/) |
|
105 { |
|
106 } |
|
107 |
|
108 virtual void RemoveContext(const MGlxFetchContext* /*aContext*/) |
|
109 { |
|
110 } |
|
111 |
|
112 virtual MMPXCollection& Collection() const |
|
113 { |
|
114 // we know that this method is not called in our tests, this is just to make the code compile |
|
115 MMPXCollection* empty = NULL; |
|
116 return *empty; |
|
117 } |
|
118 |
|
119 virtual TBool IsSelected(TInt aIndex) const |
|
120 { |
|
121 TInt idx = iSelectedItems.Find(aIndex); |
|
122 return (idx != KErrNotFound); |
|
123 } |
|
124 |
|
125 virtual void SetSelectedL(TInt aIndex, TBool aSelected) |
|
126 { |
|
127 if (aSelected) |
|
128 { |
|
129 iSelectedItems.InsertInOrder(aIndex); |
|
130 } |
|
131 else |
|
132 { |
|
133 iSelectedItems.Remove(iSelectedItems.Find(aIndex)); |
|
134 } |
|
135 } |
|
136 |
|
137 virtual const TArray<TInt> Selection() const |
|
138 { |
|
139 return iSelectedItems.Array(); |
|
140 } |
|
141 |
|
142 virtual void CommandL(CMPXCommand& /*aCommand*/) |
|
143 { |
|
144 } |
|
145 |
|
146 virtual void CancelCommand() |
|
147 { |
|
148 } |
|
149 |
|
150 virtual void SetFilterL(CMPXFilter* /*aFilter*/) |
|
151 { |
|
152 } |
|
153 |
|
154 virtual CMPXFilter* Filter() const |
|
155 { |
|
156 return NULL; |
|
157 } |
|
158 |
|
159 virtual TGlxIdSpaceId IdSpaceId(TInt /*aIndex*/) const |
|
160 { |
|
161 return KGlxIdNone; |
|
162 } |
|
163 |
|
164 void AppendL(TInt aId, TBool aCreateMedia) |
|
165 { |
|
166 if (aCreateMedia) |
|
167 { |
|
168 CGlxMedia* media = new (ELeave) CGlxMedia(TGlxMediaId(aId)); |
|
169 CleanupStack::PushL(media); |
|
170 iMedia.AppendL(media); |
|
171 CleanupStack::Pop(media); |
|
172 iItems.AppendL(TGlxMedia(TGlxMediaId(aId), media)); |
|
173 } |
|
174 else |
|
175 { |
|
176 iItems.AppendL(TGlxMedia(TGlxMediaId(aId))); |
|
177 } |
|
178 } |
|
179 |
|
180 CGlxMedia* MediaObj(TInt aIndex) const |
|
181 { |
|
182 return const_cast<CGlxMedia*>(static_cast<const CGlxMedia*>(iItems[aIndex].Properties())); |
|
183 } |
|
184 |
|
185 CMPXCollectionPath* PathLC(NGlxListDefs::TPathType /*aType*/) const |
|
186 { |
|
187 return NULL; |
|
188 } |
|
189 |
|
190 TInt SelectionCount() const |
|
191 { |
|
192 return iSelectedItems.Count(); |
|
193 } |
|
194 |
|
195 TInt SelectedItemIndex(TInt /*aSelectionIndex*/) const |
|
196 { |
|
197 return 0; |
|
198 } |
|
199 |
|
200 TBool IsPopulated() const |
|
201 { |
|
202 return ETrue; |
|
203 } |
|
204 |
|
205 void AddStaticItemL( CGlxMedia* /*aStaticItem*/, |
|
206 NGlxListDefs::TInsertionPosition /*aTargetPosition*/ ) {}; |
|
207 |
|
208 void RemoveStaticItem(const TGlxMediaId& /*aItemId*/) {}; |
|
209 |
|
210 void SetStaticItemsEnabled( TBool aEnabled ) { iStaticItemsEnabled = aEnabled; }; |
|
211 |
|
212 TBool IsStaticItemsEnabled() const { return iStaticItemsEnabled; }; |
|
213 |
|
214 void SetFocusInitialPosition(NGlxListDefs::TFocusInitialPosition aFocusInitialPosition){}; |
|
215 |
|
216 void ResetFocus(){}; |
|
217 |
|
218 void SetVisibleWindowIndexL( TInt aIndex ){}; |
|
219 TInt VisibleWindowIndex() const {}; |
|
220 void CancelPreviousRequests() {}; |
|
221 RArray<TGlxMedia> iItems; |
|
222 RPointerArray<CGlxMedia> iMedia; |
|
223 RArray<TInt> iSelectedItems; |
|
224 TInt iFocusIndex; |
|
225 TBool iStaticItemsEnabled; |
|
226 }; |
|
227 |
|
228 // CONSTRUCTION |
|
229 t_cglxcommandhandlercopytohomenetwork* t_cglxcommandhandlercopytohomenetwork::NewL() |
|
230 { |
|
231 t_cglxcommandhandlercopytohomenetwork* self = t_cglxcommandhandlercopytohomenetwork::NewLC(); |
|
232 CleanupStack::Pop(); |
|
233 return self; |
|
234 } |
|
235 |
|
236 t_cglxcommandhandlercopytohomenetwork* t_cglxcommandhandlercopytohomenetwork::NewLC() |
|
237 { |
|
238 t_cglxcommandhandlercopytohomenetwork* self = new( ELeave ) t_cglxcommandhandlercopytohomenetwork(); |
|
239 CleanupStack::PushL( self ); |
|
240 self->ConstructL(); |
|
241 return self; |
|
242 } |
|
243 |
|
244 |
|
245 // Destructor (virtual by CBase) |
|
246 t_cglxcommandhandlercopytohomenetwork::~t_cglxcommandhandlercopytohomenetwork() |
|
247 { |
|
248 } |
|
249 |
|
250 // Default constructor |
|
251 t_cglxcommandhandlercopytohomenetwork::t_cglxcommandhandlercopytohomenetwork() |
|
252 { |
|
253 } |
|
254 |
|
255 // Second phase construct |
|
256 void t_cglxcommandhandlercopytohomenetwork::ConstructL() |
|
257 { |
|
258 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
259 // It generates the test case table. |
|
260 CEUnitTestSuiteClass::ConstructL(); |
|
261 } |
|
262 |
|
263 |
|
264 //Create the media List |
|
265 |
|
266 MGlxMediaList& t_cglxcommandhandlercopytohomenetwork::MediaList() |
|
267 { |
|
268 CMPXCollectionPath* path = CMPXCollectionPath :: NewL(); |
|
269 CleanupStack::PushL(path); |
|
270 |
|
271 iList = MGlxMediaList::InstanceL(*path,TGlxHierarchyId(NULL),NULL); |
|
272 CleanupStack::PopAndDestroy(path); |
|
273 |
|
274 return *iList; |
|
275 } |
|
276 |
|
277 // Medialist created |
|
278 void t_cglxcommandhandlercopytohomenetwork::SetupL( ) |
|
279 { |
|
280 iList = NULL; |
|
281 iCommandHandlerCopyToHomeNetwork = NULL; |
|
282 //create the medialist |
|
283 // MediaList(); |
|
284 // iCommandHandlerCopyToHomeNetwork = CGlxCommandHandlerCopyToHomeNetwork :: NewL(*this); |
|
285 iList = new (ELeave) _CGlxTestMediaList; |
|
286 iCommandHandlerCopyToHomeNetwork = new (ELeave) CGlxCommandHandlerCopyToHomeNetwork(*this); |
|
287 } |
|
288 |
|
289 //Tear down |
|
290 void t_cglxcommandhandlercopytohomenetwork::Teardown( ) |
|
291 { |
|
292 EUNIT_PRINT(_L("before teardown")); |
|
293 |
|
294 delete iCommandHandlerCopyToHomeNetwork; |
|
295 |
|
296 if(iList) |
|
297 { |
|
298 delete iList; |
|
299 } |
|
300 EUNIT_PRINT(_L("After teardown")); |
|
301 } |
|
302 |
|
303 |
|
304 void t_cglxcommandhandlercopytohomenetwork::T_AddCopyToHomeNetworkCommandL_L() |
|
305 { |
|
306 /// @bug:minor:kihoikka:release5.5: 1/02/2008: you could have a different setup if you dont always want the instance created |
|
307 delete iCommandHandlerCopyToHomeNetwork; // we don't want to use the iCommandHandlerCopyToHomeNetwork instance created by SetupL because ConstructL will have been called |
|
308 iCommandHandlerCopyToHomeNetwork = NULL; |
|
309 iCommandHandlerCopyToHomeNetwork = new (ELeave) CGlxCommandHandlerCopyToHomeNetwork(*this); // We don't want to call ConstructL() |
|
310 EUNIT_ASSERT_EQUALS_DESC(iCommandHandlerCopyToHomeNetwork->iCommandInfoArray.Count(), 0, "command info array count it not zero prior to calling AddCopyToHomeNetworkCommandL"); |
|
311 iCommandHandlerCopyToHomeNetwork->AddCopyToHomeNetworkCommandL(); |
|
312 EUNIT_ASSERT_EQUALS_DESC(iCommandHandlerCopyToHomeNetwork->iCommandInfoArray.Count(), 1, "command info array count it not 1 after calling AddCopyToHomeNetworkCommandL"); |
|
313 CGlxMediaListCommandHandler::TCommandInfo& commandInfo = iCommandHandlerCopyToHomeNetwork->iCommandInfoArray[0]; |
|
314 |
|
315 EUNIT_ASSERT_EQUALS_DESC(commandInfo.iCommandId, EGlxCopyToHomeNetwork, "command id is not EGlxCopyToHomeNetwork"); |
|
316 EUNIT_ASSERT_EQUALS_DESC(commandInfo.iMinSelectionLength, 1, "command min selection length is not 1"); |
|
317 EUNIT_ASSERT_EQUALS_DESC(commandInfo.iDisallowDRM, ETrue, "Disalow DRM is not true"); |
|
318 } |
|
319 |
|
320 |
|
321 void t_cglxcommandhandlercopytohomenetwork::T_DoExecuteL_L() |
|
322 { |
|
323 EUNIT_ASSERT_EQUALS_DESC(ETrue, iCommandHandlerCopyToHomeNetwork->DoExecuteL(EGlxCopyToHomeNetwork, *iList), "EGlxCopyToHomeNetwork was not consumed"); |
|
324 EUNIT_ASSERT_EQUALS_DESC(EFalse, iCommandHandlerCopyToHomeNetwork->DoExecuteL(0, *iList), "unknown command was consumed"); |
|
325 } |
|
326 |
|
327 void t_cglxcommandhandlercopytohomenetwork::T_DoIsDisabled_L() |
|
328 { |
|
329 CUpnpCopyCommand::gUpnpCopyCommandEnabled = ETrue; |
|
330 EUNIT_ASSERT_EQUALS_DESC(ETrue, iCommandHandlerCopyToHomeNetwork->DoIsDisabled(0, *iList), "unknown command is enabled") |
|
331 EUNIT_ASSERT_EQUALS_DESC(EFalse, iCommandHandlerCopyToHomeNetwork->DoIsDisabled(EGlxCopyToHomeNetwork, *iList), "EGlxCopyToHomeNetwork command is disabled"); |
|
332 CUpnpCopyCommand::gUpnpCopyCommandEnabled = EFalse; |
|
333 EUNIT_ASSERT_EQUALS_DESC(ETrue, iCommandHandlerCopyToHomeNetwork->DoIsDisabled(0, *iList), "unknown command is enabled") |
|
334 EUNIT_ASSERT_EQUALS_DESC(ETrue, iCommandHandlerCopyToHomeNetwork->DoIsDisabled(EGlxCopyToHomeNetwork, *iList), "EGlxCopyToHomeNetwork command is enabled"); |
|
335 } |
|
336 |
|
337 |
|
338 // TEST TABLE |
|
339 EUNIT_BEGIN_TEST_TABLE( |
|
340 t_cglxcommandhandlercopytohomenetwork, |
|
341 "Unit tests for CGlxCommandHandlerCopyToHomeNetwork", |
|
342 "UNIT" ) |
|
343 |
|
344 EUNIT_TEST( |
|
345 "AddCopyToHomeNetworkCommandL", |
|
346 "CGlxCommandHandlerCopyToHomeNetwork", |
|
347 "T_AddCopyToHomeNetworkCommandL_L", |
|
348 "UNIT", |
|
349 SetupL, T_AddCopyToHomeNetworkCommandL_L, Teardown) |
|
350 |
|
351 |
|
352 EUNIT_TEST( |
|
353 "DoExecuteL", |
|
354 "CGlxCommandHandlerCopyToHomeNetwork", |
|
355 "T_DoExecuteL_L", |
|
356 "UNIT", |
|
357 SetupL, T_DoExecuteL_L, Teardown) |
|
358 |
|
359 EUNIT_TEST( |
|
360 "DoIsDisabled", |
|
361 "CGlxCommandHandlerCopyToHomeNetwork", |
|
362 "T_DoIsDisabled_L", |
|
363 "UNIT", |
|
364 SetupL, T_DoIsDisabled_L, Teardown) |
|
365 |
|
366 EUNIT_END_TEST_TABLE |
|
367 |
|
368 // END OF FILE |
|
369 |