|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #include <QtTest/QtTest> |
|
18 #include "tsstorage.h" |
|
19 #include "t_tsstorage.h" |
|
20 #include "t_tsmodel.h" |
|
21 |
|
22 const int KBigSet(100); |
|
23 |
|
24 void T_TsStorage::testItemDataChanged() |
|
25 { |
|
26 CTsStorage* storage(0); |
|
27 T_TsModel emptyProvider(0), |
|
28 bigSetProvider(KBigSet); |
|
29 RPointerArray<MTsModel>providers; |
|
30 CleanupClosePushL(providers); |
|
31 |
|
32 //storage has no data providers |
|
33 mNotifications = 0; |
|
34 storage = CTsStorage::NewL(providers.Array()); |
|
35 storage->dataChanged(bigSetProvider.itemL(0)); |
|
36 QVERIFY(0 == mNotifications);//storage has no observers |
|
37 verifyProviders(*storage, providers.Array()); |
|
38 storage->setObserver(this); |
|
39 storage->dataChanged(bigSetProvider.itemL(0)); |
|
40 QVERIFY(1 == mNotifications);//storage has observers |
|
41 verifyProviders(*storage, providers.Array()); |
|
42 delete storage; |
|
43 |
|
44 providers.Append(&emptyProvider); |
|
45 providers.Append(&bigSetProvider); |
|
46 |
|
47 //storage has some |
|
48 mNotifications = 0; |
|
49 storage = CTsStorage::NewL(providers.Array()); |
|
50 storage->dataChanged(bigSetProvider.itemL(0)); |
|
51 QVERIFY(0 == mNotifications);//storage has no observers |
|
52 verifyProviders(*storage, providers.Array()); |
|
53 storage->setObserver(this); |
|
54 storage->dataChanged(bigSetProvider.itemL(0)); |
|
55 QVERIFY(1 == mNotifications);//storage has observers |
|
56 verifyProviders(*storage, providers.Array()); |
|
57 delete storage; |
|
58 CleanupStack::PopAndDestroy(&providers); |
|
59 } |
|
60 |
|
61 void T_TsStorage::testModelDataChanged() |
|
62 { |
|
63 CTsStorage* storage(0); |
|
64 T_TsModel emptyProvider(0), |
|
65 bigSetProvider(KBigSet); |
|
66 RPointerArray<MTsModel>providers; |
|
67 CleanupClosePushL(providers); |
|
68 |
|
69 //storage has no data providers |
|
70 mNotifications = 0; |
|
71 storage = CTsStorage::NewL(providers.Array()); |
|
72 storage->dataChanged(emptyProvider); |
|
73 QVERIFY(0 == mNotifications);//storage has no observers |
|
74 verifyProviders(*storage, providers.Array()); |
|
75 storage->setObserver(this); |
|
76 storage->dataChanged(emptyProvider); |
|
77 QVERIFY(1 == mNotifications);//storage has observers |
|
78 verifyProviders(*storage, providers.Array()); |
|
79 delete storage; |
|
80 |
|
81 providers.Append(&emptyProvider); |
|
82 providers.Append(&bigSetProvider); |
|
83 |
|
84 //storage has some |
|
85 mNotifications = 0; |
|
86 storage = CTsStorage::NewL(providers.Array()); |
|
87 storage->dataChanged(emptyProvider); |
|
88 QVERIFY(0 == mNotifications);//storage has no observers |
|
89 verifyProviders(*storage, providers.Array()); |
|
90 storage->setObserver(this); |
|
91 storage->dataChanged(emptyProvider); |
|
92 QVERIFY(1 == mNotifications);//storage has observers |
|
93 verifyProviders(*storage, providers.Array()); |
|
94 delete storage; |
|
95 CleanupStack::PopAndDestroy(&providers); |
|
96 } |
|
97 |
|
98 void T_TsStorage::verifyProviders(const MTsModel &set, const TArray<MTsModel*>& providers) |
|
99 { |
|
100 int sum(0); |
|
101 for (int iter(0); iter < providers.Count(); ++iter) { |
|
102 sum += (providers[iter])->count(); |
|
103 QVERIFY(set.count() >= (providers[iter])->count()); |
|
104 QVERIFY(EFalse != isSubset(set, *(providers[iter]))); |
|
105 } |
|
106 QVERIFY(set.count() == sum); |
|
107 } |
|
108 |
|
109 TBool T_TsStorage::isSubset(const MTsModel &set, const MTsModel& subset) const |
|
110 { |
|
111 bool isOk = true; |
|
112 for (int i(0); i < subset.count() && isOk; ++i) { |
|
113 isOk = false; |
|
114 for(int k(0); k < set.count() && !isOk; ++k){ |
|
115 set.itemL(k).launchL(); |
|
116 set.itemL(k).closeL(); |
|
117 isOk = (subset.itemL(i).keyL() == set.itemL(k).keyL()) && |
|
118 (subset.itemL(i).timestampL() == set.itemL(k).timestampL()) && |
|
119 (subset.itemL(i).iconHandleL() == set.itemL(k).iconHandleL()) && |
|
120 (subset.itemL(i).isActiveL() == set.itemL(k).isActiveL()) && |
|
121 (subset.itemL(i).isClosableL() == set.itemL(k).isClosableL()) && |
|
122 (0 == subset.itemL(i).displayNameL().Compare(set.itemL(k).displayNameL())); |
|
123 } |
|
124 } |
|
125 return isOk ? ETrue : EFalse; |
|
126 } |
|
127 |
|
128 QTEST_MAIN(T_TsStorage) |