|
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <s32mem.h> |
|
17 #include "sendas2test.h" |
|
18 |
|
19 RTest test(_L("SendAs2 Arrays")); |
|
20 |
|
21 // |
|
22 |
|
23 LOCAL_C void TestSendAsAccountsL() |
|
24 { |
|
25 CSendAsAccounts* accounts = CSendAsAccounts::NewL(); |
|
26 CleanupStack::PushL(accounts); |
|
27 |
|
28 // test adding |
|
29 test(accounts->Count()==0); |
|
30 accounts->AppendAccountL(_L("SendAsMtm1"), 0xaaaaaaaa); |
|
31 test(accounts->Count()==1); |
|
32 accounts->AppendAccountL(_L("SendAsMtm2"), 0x55555555); |
|
33 test(accounts->Count()==2); |
|
34 accounts->AppendAccountL(_L("SendAsMtm3"), 0x11111111); |
|
35 test(accounts->Count()==3); |
|
36 accounts->AppendAccountL(_L("SendAsMtm4"), 0x22222222); |
|
37 test(accounts->Count()==4); |
|
38 |
|
39 // test Account() member |
|
40 test(accounts->Account(0) == 0xaaaaaaaa); |
|
41 test(accounts->Account(1) == 0x55555555); |
|
42 test(accounts->Account(2) == 0x11111111); |
|
43 test(accounts->Account(3) == 0x22222222); |
|
44 |
|
45 // test Reset() member |
|
46 accounts->Reset(); |
|
47 test(accounts->Count()==0); |
|
48 |
|
49 // repopulate |
|
50 accounts->AppendAccountL(_L("SendAsMtm1"), 0xaaaaaaaa); |
|
51 accounts->AppendAccountL(_L("SendAsMtm2"), 0x55555555); |
|
52 accounts->AppendAccountL(_L("SendAsMtm3"), 0x11111111); |
|
53 accounts->AppendAccountL(_L("SendAsMtm4"), 0x22222222); |
|
54 |
|
55 // test AccountNames() member |
|
56 test(accounts->AccountNames().MdcaPoint(0)==_L("SendAsMtm1")); |
|
57 test(accounts->AccountNames().MdcaPoint(1)==_L("SendAsMtm2")); |
|
58 test(accounts->AccountNames().MdcaPoint(2)==_L("SendAsMtm3")); |
|
59 test(accounts->AccountNames().MdcaPoint(3)==_L("SendAsMtm4")); |
|
60 |
|
61 // test SetMessageType() / GetMessageType() |
|
62 TUid testUid = TUid::Uid(0x5a5a5a5a); |
|
63 accounts->SetMessageType(testUid); |
|
64 test(accounts->MessageType() == testUid); |
|
65 |
|
66 // test RemoveAccount() member |
|
67 accounts->RemoveAccount(1); |
|
68 test(accounts->Count() == 3); |
|
69 test(accounts->AccountNames().MdcaPoint(0) == _L("SendAsMtm1")); |
|
70 test(accounts->AccountNames().MdcaPoint(1) == _L("SendAsMtm3")); |
|
71 accounts->RemoveAccount(0); |
|
72 test(accounts->AccountNames().MdcaPoint(0) == _L("SendAsMtm3")); |
|
73 accounts->RemoveAccount(1); |
|
74 test(accounts->AccountNames().MdcaPoint(0) == _L("SendAsMtm3")); |
|
75 accounts->RemoveAccount(0); |
|
76 test(accounts->Count() == 0); |
|
77 accounts->Reset(); |
|
78 |
|
79 // repopulate |
|
80 accounts->AppendAccountL(_L("SendAsMtm1"), 0xaaaaaaaa); |
|
81 accounts->AppendAccountL(_L("SendAsMtm2"), 0x55555555); |
|
82 accounts->AppendAccountL(_L("SendAsMtm3"), 0x11111111); |
|
83 accounts->AppendAccountL(_L("SendAsMtm4"), 0x22222222); |
|
84 accounts->SetMessageType(testUid); |
|
85 |
|
86 // test name lookup by account id |
|
87 test(accounts->NameFromAccountL(0xaaaaaaaa) == _L("SendAsMtm1")); |
|
88 test(accounts->NameFromAccountL(0x55555555) == _L("SendAsMtm2")); |
|
89 test(accounts->NameFromAccountL(0x11111111) == _L("SendAsMtm3")); |
|
90 test(accounts->NameFromAccountL(0x22222222) == _L("SendAsMtm4")); |
|
91 // test non-existent entry |
|
92 TRAPD(err1, accounts->NameFromAccountL(0x12121212)); |
|
93 test(err1 == KErrNotFound); |
|
94 |
|
95 // test account id lookup by name |
|
96 test(accounts->AccountFromNameL(_L("SendAsMtm1")) == 0xaaaaaaaa); |
|
97 test(accounts->AccountFromNameL(_L("SendAsMtm2")) == 0x55555555); |
|
98 test(accounts->AccountFromNameL(_L("SendAsMtm3")) == 0x11111111); |
|
99 test(accounts->AccountFromNameL(_L("SendAsMtm4")) == 0x22222222); |
|
100 // test unknowns |
|
101 TRAPD(err2, accounts->AccountFromNameL(_L("Not there"))); |
|
102 test(err2 == KErrNotFound); |
|
103 |
|
104 // test Size() member |
|
105 TInt size = accounts->Size(); |
|
106 test(size == 122); |
|
107 HBufC8* accBuf = HBufC8::NewLC(size); |
|
108 TPtr8 ptr(accBuf->Des()); |
|
109 |
|
110 // test ExternalizeL() member |
|
111 RDesWriteStream writeStream(ptr); |
|
112 CleanupClosePushL(writeStream); |
|
113 accounts->ExternalizeL(writeStream); |
|
114 writeStream.CommitL(); |
|
115 CleanupStack::PopAndDestroy(&writeStream); |
|
116 |
|
117 CSendAsAccounts* accounts2 = CSendAsAccounts::NewL(); |
|
118 CleanupStack::PushL(accounts2); |
|
119 |
|
120 // test InternalizeL() member |
|
121 RDesReadStream readStream(*accBuf); |
|
122 CleanupClosePushL(readStream); |
|
123 accounts2->InternalizeL(readStream); |
|
124 CleanupStack::PopAndDestroy(&readStream); |
|
125 |
|
126 // compare |
|
127 test(accounts->Size() == accounts2->Size()); |
|
128 test(accounts->AccountNames().MdcaPoint(0) == accounts2->AccountNames().MdcaPoint(0)); |
|
129 test(accounts->AccountNames().MdcaPoint(1) == accounts2->AccountNames().MdcaPoint(1)); |
|
130 test(accounts->AccountNames().MdcaPoint(2) == accounts2->AccountNames().MdcaPoint(2)); |
|
131 test(accounts->AccountNames().MdcaPoint(3) == accounts2->AccountNames().MdcaPoint(3)); |
|
132 test(accounts->Account(0) == accounts2->Account(0)); |
|
133 test(accounts->Account(1) == accounts2->Account(1)); |
|
134 test(accounts->Account(2) == accounts2->Account(2)); |
|
135 test(accounts->Account(3) == accounts2->Account(3)); |
|
136 test(accounts->MessageType() == accounts2->MessageType()); |
|
137 CleanupStack::PopAndDestroy(accounts2); |
|
138 |
|
139 // clean up |
|
140 CleanupStack::PopAndDestroy(2, accounts); // accounts, accBuf |
|
141 } |
|
142 |
|
143 LOCAL_C void TestSendAsMessageTypesL() |
|
144 { |
|
145 CSendAsMessageTypes* msgtypes = CSendAsMessageTypes::NewL(); |
|
146 CleanupStack::PushL(msgtypes); |
|
147 |
|
148 // test adding |
|
149 test(msgtypes->Count()==0); |
|
150 msgtypes->AppendMessageTypeL(_L("SendAsMtm1"), TUid::Uid(0xaaaaaaaa)); |
|
151 test(msgtypes->Count()==1); |
|
152 msgtypes->AppendMessageTypeL(_L("SendAsMtm2"), TUid::Uid(0x55555555)); |
|
153 test(msgtypes->Count()==2); |
|
154 msgtypes->AppendMessageTypeL(_L("SendAsMtm3"), TUid::Uid(0x11111111)); |
|
155 test(msgtypes->Count()==3); |
|
156 msgtypes->AppendMessageTypeL(_L("SendAsMtm4"), TUid::Uid(0x22222222)); |
|
157 test(msgtypes->Count()==4); |
|
158 |
|
159 // test Account() member |
|
160 test(msgtypes->MessageTypeUid(0) == TUid::Uid(0xaaaaaaaa)); |
|
161 test(msgtypes->MessageTypeUid(1) == TUid::Uid(0x55555555)); |
|
162 test(msgtypes->MessageTypeUid(2) == TUid::Uid(0x11111111)); |
|
163 test(msgtypes->MessageTypeUid(3) == TUid::Uid(0x22222222)); |
|
164 |
|
165 // test Reset() member |
|
166 msgtypes->Reset(); |
|
167 test(msgtypes->Count()==0); |
|
168 |
|
169 // repopulate |
|
170 msgtypes->AppendMessageTypeL(_L("SendAsMtm1"), TUid::Uid(0xaaaaaaaa)); |
|
171 msgtypes->AppendMessageTypeL(_L("SendAsMtm2"), TUid::Uid(0x55555555)); |
|
172 msgtypes->AppendMessageTypeL(_L("SendAsMtm3"), TUid::Uid(0x11111111)); |
|
173 msgtypes->AppendMessageTypeL(_L("SendAsMtm4"), TUid::Uid(0x22222222)); |
|
174 |
|
175 // test AccountNames() member |
|
176 test(msgtypes->AvailableMessageTypes().MdcaPoint(0)==_L("SendAsMtm1")); |
|
177 test(msgtypes->AvailableMessageTypes().MdcaPoint(1)==_L("SendAsMtm2")); |
|
178 test(msgtypes->AvailableMessageTypes().MdcaPoint(2)==_L("SendAsMtm3")); |
|
179 test(msgtypes->AvailableMessageTypes().MdcaPoint(3)==_L("SendAsMtm4")); |
|
180 |
|
181 // test RemoveAccount() member |
|
182 msgtypes->RemoveMessageType(1); |
|
183 test(msgtypes->Count() == 3); |
|
184 test(msgtypes->AvailableMessageTypes().MdcaPoint(0) == _L("SendAsMtm1")); |
|
185 test(msgtypes->AvailableMessageTypes().MdcaPoint(1) == _L("SendAsMtm3")); |
|
186 msgtypes->RemoveMessageType(0); |
|
187 test(msgtypes->AvailableMessageTypes().MdcaPoint(0) == _L("SendAsMtm3")); |
|
188 msgtypes->RemoveMessageType(1); |
|
189 test(msgtypes->AvailableMessageTypes().MdcaPoint(0) == _L("SendAsMtm3")); |
|
190 msgtypes->RemoveMessageType(0); |
|
191 test(msgtypes->Count() == 0); |
|
192 msgtypes->Reset(); |
|
193 |
|
194 // repopulate |
|
195 msgtypes->AppendMessageTypeL(_L("SendAsMtm1"), TUid::Uid(0xaaaaaaaa)); |
|
196 msgtypes->AppendMessageTypeL(_L("SendAsMtm2"), TUid::Uid(0x55555555)); |
|
197 msgtypes->AppendMessageTypeL(_L("SendAsMtm3"), TUid::Uid(0x11111111)); |
|
198 msgtypes->AppendMessageTypeL(_L("SendAsMtm4"), TUid::Uid(0x22222222)); |
|
199 |
|
200 // test name lookup by mtm uid |
|
201 test(msgtypes->NameFromUidL(TUid::Uid(0xaaaaaaaa)) == _L("SendAsMtm1")); |
|
202 test(msgtypes->NameFromUidL(TUid::Uid(0x55555555)) == _L("SendAsMtm2")); |
|
203 test(msgtypes->NameFromUidL(TUid::Uid(0x11111111)) == _L("SendAsMtm3")); |
|
204 test(msgtypes->NameFromUidL(TUid::Uid(0x22222222)) == _L("SendAsMtm4")); |
|
205 // test non-existent entry |
|
206 TRAPD(err1, msgtypes->NameFromUidL(TUid::Uid(0x21212121))); |
|
207 test(err1 == KErrNotFound); |
|
208 |
|
209 // test mtm uid lookup by name |
|
210 test(msgtypes->UidFromNameL(_L("SendAsMtm1")) == TUid::Uid(0xaaaaaaaa)); |
|
211 test(msgtypes->UidFromNameL(_L("SendAsMtm2")) == TUid::Uid(0x55555555)); |
|
212 test(msgtypes->UidFromNameL(_L("SendAsMtm3")) == TUid::Uid(0x11111111)); |
|
213 test(msgtypes->UidFromNameL(_L("SendAsMtm4")) == TUid::Uid(0x22222222)); |
|
214 // test non-existent entry |
|
215 TRAPD(err2, msgtypes->UidFromNameL(_L("not there"))); |
|
216 test(err2 == KErrNotFound); |
|
217 |
|
218 // test Size() member |
|
219 TInt size = msgtypes->Size(); |
|
220 test(size == 118); |
|
221 HBufC8* accBuf = HBufC8::NewLC(size); |
|
222 TPtr8 ptr(accBuf->Des()); |
|
223 |
|
224 // test ExternalizeL() member |
|
225 RDesWriteStream writeStream(ptr); |
|
226 CleanupClosePushL(writeStream); |
|
227 msgtypes->ExternalizeL(writeStream); |
|
228 writeStream.CommitL(); |
|
229 CleanupStack::PopAndDestroy(&writeStream); |
|
230 |
|
231 CSendAsMessageTypes* msgtypes2 = CSendAsMessageTypes::NewL(); |
|
232 CleanupStack::PushL(msgtypes2); |
|
233 |
|
234 // test InternalizeL() member |
|
235 RDesReadStream readStream(*accBuf); |
|
236 CleanupClosePushL(readStream); |
|
237 msgtypes2->InternalizeL(readStream); |
|
238 CleanupStack::PopAndDestroy(&readStream); |
|
239 |
|
240 // compare |
|
241 test(msgtypes->Size() == msgtypes2->Size()); |
|
242 test(msgtypes->AvailableMessageTypes().MdcaPoint(0) == msgtypes2->AvailableMessageTypes().MdcaPoint(0)); |
|
243 test(msgtypes->AvailableMessageTypes().MdcaPoint(1) == msgtypes2->AvailableMessageTypes().MdcaPoint(1)); |
|
244 test(msgtypes->AvailableMessageTypes().MdcaPoint(2) == msgtypes2->AvailableMessageTypes().MdcaPoint(2)); |
|
245 test(msgtypes->AvailableMessageTypes().MdcaPoint(3) == msgtypes2->AvailableMessageTypes().MdcaPoint(3)); |
|
246 test(msgtypes->MessageTypeUid(0) == msgtypes2->MessageTypeUid(0)); |
|
247 test(msgtypes->MessageTypeUid(1) == msgtypes2->MessageTypeUid(1)); |
|
248 test(msgtypes->MessageTypeUid(2) == msgtypes2->MessageTypeUid(2)); |
|
249 test(msgtypes->MessageTypeUid(3) == msgtypes2->MessageTypeUid(3)); |
|
250 CleanupStack::PopAndDestroy(msgtypes2); |
|
251 |
|
252 // clean up |
|
253 CleanupStack::PopAndDestroy(2, msgtypes); // msgtypes, accBuf |
|
254 } |
|
255 |
|
256 GLDEF_C void doTestsL() |
|
257 { |
|
258 theUtils->Start(_L("Accounts")); |
|
259 TestSendAsAccountsL(); // Qualified: No leavescan error |
|
260 theUtils->Complete(); |
|
261 |
|
262 theUtils->Start(_L("Message Types")); |
|
263 TestSendAsMessageTypesL(); // Qualified: No leavescan error |
|
264 theUtils->Complete(); |
|
265 } |