|
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 |
|
18 #include <stdio.h> |
|
19 #include <string> |
|
20 #include <memory> |
|
21 #include <unistd.h> |
|
22 #include <e32cmn.h> |
|
23 #include <e32des8.h> |
|
24 |
|
25 #include "TestHarness.h" |
|
26 #include "javauid.h" |
|
27 #include "javasymbianoslayer.h" |
|
28 |
|
29 using namespace std; |
|
30 using namespace java::util; |
|
31 |
|
32 TEST_GROUP(UidTests) |
|
33 { |
|
34 TEST_SETUP() |
|
35 { |
|
36 } |
|
37 |
|
38 TEST_TEARDOWN() |
|
39 { |
|
40 } |
|
41 }; |
|
42 |
|
43 // |
|
44 // TEST CASE 1 |
|
45 // This test verifies that angle bracket version from the UID [12345678] is managed properly. |
|
46 // |
|
47 TEST(UidTests,uidtoTuidTests1) |
|
48 { |
|
49 printf("+uidtoTuidTests1\n"); |
|
50 |
|
51 try |
|
52 { |
|
53 //# 1 |
|
54 //Maximum value of the uid. |
|
55 { |
|
56 java::util::Uid myUid(L"[EFFFFFFF]"); |
|
57 TUid tUid; |
|
58 TInt err = uidToTUid(myUid,tUid); |
|
59 CHECK(KErrNone == err); |
|
60 CHECK(4026531839 == tUid.iUid); |
|
61 } |
|
62 |
|
63 //# 2 |
|
64 { |
|
65 java::util::Uid myUid(L" [efffffff] "); |
|
66 TUid tUid; |
|
67 TInt err = uidToTUid(myUid,tUid); |
|
68 CHECK(KErrNone == err); |
|
69 CHECK(4026531839 == tUid.iUid); |
|
70 } |
|
71 |
|
72 //# 3 |
|
73 { |
|
74 java::util::Uid myUid(L"\t[EFFFFFFF]\n"); |
|
75 TUid tUid; |
|
76 TInt err = uidToTUid(myUid,tUid); |
|
77 CHECK(KErrNone == err); |
|
78 CHECK(4026531839 == tUid.iUid); |
|
79 } |
|
80 |
|
81 //# 4 |
|
82 { |
|
83 java::util::Uid myUid(L" [00000000] "); |
|
84 TUid tUid; |
|
85 TInt err = uidToTUid(myUid,tUid); |
|
86 CHECK(KErrNone == err); |
|
87 CHECK(0 == tUid.iUid); |
|
88 } |
|
89 |
|
90 //Error cases. |
|
91 |
|
92 //# 5 |
|
93 { |
|
94 java::util::Uid myUid(L" [000t0000] "); |
|
95 TUid tUid; |
|
96 TInt err = uidToTUid(myUid,tUid); |
|
97 CHECK(KErrArgument == err); |
|
98 } |
|
99 |
|
100 //# 6 |
|
101 //More than 8 digits. |
|
102 { |
|
103 java::util::Uid myUid(L"[EFFFFFFFF]"); |
|
104 TUid tUid; |
|
105 TInt err = uidToTUid(myUid,tUid); |
|
106 CHECK(KErrArgument == err); |
|
107 } |
|
108 |
|
109 //# 7 |
|
110 //Less than 8 digits. |
|
111 { |
|
112 java::util::Uid myUid(L"[EFFFFFF]"); |
|
113 TUid tUid; |
|
114 TInt err = uidToTUid(myUid,tUid); |
|
115 CHECK(KErrArgument == err); |
|
116 } |
|
117 |
|
118 //# 8 |
|
119 //Empty string. |
|
120 { |
|
121 java::util::Uid myUid(L""); |
|
122 TUid tUid; |
|
123 TInt err = uidToTUid(myUid,tUid); |
|
124 CHECK(KErrArgument == err); |
|
125 } |
|
126 |
|
127 //# 9 |
|
128 //Unsupported brackets. |
|
129 { |
|
130 java::util::Uid myUid(L"(EFFFFFFF)"); |
|
131 TUid tUid; |
|
132 TInt err = uidToTUid(myUid,tUid); |
|
133 CHECK(KErrArgument == err); |
|
134 } |
|
135 |
|
136 printf("-uidtoTuidTests1\n"); |
|
137 } |
|
138 catch (...) |
|
139 { |
|
140 printf("uidtoTuidTests1() Unexpected exception caught"); |
|
141 CHECK(false); |
|
142 } |
|
143 } |
|
144 |
|
145 // |
|
146 // TEST CASE 2 |
|
147 // This test verifies that "0x123456ab" version from the UID is managed properly. |
|
148 // |
|
149 TEST(UidTests,uidtoTuidTests2) |
|
150 { |
|
151 printf("+uidtoTuidTests2\n"); |
|
152 |
|
153 try |
|
154 { |
|
155 //# 1 |
|
156 //Maximum value of the uid. |
|
157 { |
|
158 java::util::Uid myUid(L"0xEFFFFFFF"); |
|
159 TUid tUid; |
|
160 TInt err = uidToTUid(myUid,tUid); |
|
161 CHECK(KErrNone == err); |
|
162 CHECK(4026531839 == tUid.iUid); |
|
163 } |
|
164 |
|
165 //# 2 |
|
166 { |
|
167 java::util::Uid myUid(L" 0xEFFFFFFF "); |
|
168 TUid tUid; |
|
169 TInt err = uidToTUid(myUid,tUid); |
|
170 CHECK(KErrNone == err); |
|
171 CHECK(4026531839 == tUid.iUid); |
|
172 } |
|
173 |
|
174 //# 3 |
|
175 { |
|
176 java::util::Uid myUid(L"\n 0xEFFFFFFF \t"); |
|
177 TUid tUid; |
|
178 TInt err = uidToTUid(myUid,tUid); |
|
179 CHECK(KErrNone == err); |
|
180 CHECK(4026531839 == tUid.iUid); |
|
181 } |
|
182 |
|
183 //# 4 |
|
184 { |
|
185 java::util::Uid myUid(L" 0x00000000 "); |
|
186 TUid tUid; |
|
187 TInt err = uidToTUid(myUid,tUid); |
|
188 CHECK(KErrNone == err); |
|
189 CHECK(0 == tUid.iUid); |
|
190 } |
|
191 |
|
192 //Error cases. |
|
193 |
|
194 //# 5 |
|
195 { |
|
196 java::util::Uid myUid(L"0x000t0000"); |
|
197 TUid tUid; |
|
198 TInt err = uidToTUid(myUid,tUid); |
|
199 CHECK(KErrArgument == err); |
|
200 } |
|
201 |
|
202 //# 6 |
|
203 //More than 8 digits. |
|
204 { |
|
205 java::util::Uid myUid(L"0xEFFFFFFFF"); |
|
206 TUid tUid; |
|
207 TInt err = uidToTUid(myUid,tUid); |
|
208 CHECK(KErrArgument == err); |
|
209 } |
|
210 |
|
211 //# 7 |
|
212 //Less than 8 digits. |
|
213 { |
|
214 java::util::Uid myUid(L"0xEFFFFFF"); |
|
215 TUid tUid; |
|
216 TInt err = uidToTUid(myUid,tUid); |
|
217 CHECK(KErrArgument == err); |
|
218 } |
|
219 |
|
220 printf("-uidtoTuidTests2\n"); |
|
221 } |
|
222 catch (...) |
|
223 { |
|
224 printf("uidtoTuidTests2() Unexpected exception caught"); |
|
225 CHECK(false); |
|
226 } |
|
227 } |
|
228 |
|
229 // |
|
230 // TEST CASE 3 |
|
231 // This test verifies that "123456ab" version from the UID is managed properly. |
|
232 // |
|
233 TEST(UidTests,uidtoTuidTests3) |
|
234 { |
|
235 printf("+uidtoTuidTests3\n"); |
|
236 |
|
237 try |
|
238 { |
|
239 //# 1 |
|
240 //Maximum value of the uid. |
|
241 { |
|
242 java::util::Uid myUid(L"EFFFFFFF"); |
|
243 TUid tUid; |
|
244 TInt err = uidToTUid(myUid,tUid); |
|
245 CHECK(KErrNone == err); |
|
246 CHECK(4026531839 == tUid.iUid); |
|
247 } |
|
248 |
|
249 //# 2 |
|
250 { |
|
251 java::util::Uid myUid(L" EFFFFFFF "); |
|
252 TUid tUid; |
|
253 TInt err = uidToTUid(myUid,tUid); |
|
254 CHECK(KErrNone == err); |
|
255 CHECK(4026531839 == tUid.iUid); |
|
256 } |
|
257 |
|
258 //# 3 |
|
259 { |
|
260 java::util::Uid myUid(L"\n EFFFFFFF \t"); |
|
261 TUid tUid; |
|
262 TInt err = uidToTUid(myUid,tUid); |
|
263 CHECK(KErrNone == err); |
|
264 CHECK(4026531839 == tUid.iUid); |
|
265 } |
|
266 |
|
267 //# 4 |
|
268 { |
|
269 java::util::Uid myUid(L" 00000000 "); |
|
270 TUid tUid; |
|
271 TInt err = uidToTUid(myUid,tUid); |
|
272 CHECK(KErrNone == err); |
|
273 CHECK(0 == tUid.iUid); |
|
274 } |
|
275 |
|
276 //Error cases. |
|
277 |
|
278 //# 5 |
|
279 { |
|
280 java::util::Uid myUid(L"000t0000"); |
|
281 TUid tUid; |
|
282 TInt err = uidToTUid(myUid,tUid); |
|
283 CHECK(KErrArgument == err); |
|
284 } |
|
285 |
|
286 //# 6 |
|
287 //More than 8 digits. |
|
288 { |
|
289 java::util::Uid myUid(L"EFFFFFFFF"); |
|
290 TUid tUid; |
|
291 TInt err = uidToTUid(myUid,tUid); |
|
292 CHECK(KErrArgument == err); |
|
293 } |
|
294 |
|
295 //# 7 |
|
296 //Less than 8 digits. |
|
297 { |
|
298 java::util::Uid myUid(L"EFFFFFF"); |
|
299 TUid tUid; |
|
300 TInt err = uidToTUid(myUid,tUid); |
|
301 CHECK(KErrArgument == err); |
|
302 } |
|
303 |
|
304 printf("-uidtoTuidTests3\n"); |
|
305 } |
|
306 catch (...) |
|
307 { |
|
308 printf("uidtoTuidTests3() Unexpected exception caught"); |
|
309 CHECK(false); |
|
310 } |
|
311 } |
|
312 |
|
313 // |
|
314 // TEST CASE 4 |
|
315 // Tests for TUidToUid(const TUid& aId,java::util::Uid& aOutUid) method. |
|
316 // |
|
317 TEST(UidTests,tuidToUidTests1) |
|
318 { |
|
319 printf("+tuidToUidTests1\n"); |
|
320 |
|
321 try |
|
322 { |
|
323 //# 1 |
|
324 { |
|
325 TUid tuid = TUid::Uid(4026531839); |
|
326 Uid retUid; |
|
327 retUid = TUidToUid(tuid,retUid); |
|
328 CHECK(false == retUid.isEmpty()); |
|
329 std::wstring tmpStr(retUid.toString()); |
|
330 std::string tmpStr2(tmpStr.begin(),tmpStr.end()); |
|
331 CHECK(0 == retUid.toString().compare(L"[efffffff]")); |
|
332 } |
|
333 |
|
334 //# 2 |
|
335 { |
|
336 TUid tuid = TUid::Uid(0); |
|
337 Uid retUid; |
|
338 retUid = TUidToUid(tuid,retUid); |
|
339 CHECK(true == retUid.isEmpty()); |
|
340 std::wstring tmpStr(retUid.toString()); |
|
341 std::string tmpStr2(tmpStr.begin(),tmpStr.end()); |
|
342 CHECK(0 == retUid.toString().compare(L"")); |
|
343 } |
|
344 |
|
345 //# 3 |
|
346 //Null constructed TUid. |
|
347 { |
|
348 TUid tuid = TUid::Null(); |
|
349 Uid retUid; |
|
350 retUid = TUidToUid(tuid,retUid); |
|
351 CHECK(true == retUid.isEmpty()); |
|
352 } |
|
353 |
|
354 printf("-tuidToUidTests1\n"); |
|
355 } |
|
356 catch (...) |
|
357 { |
|
358 printf("tuidToUidTests1() Unexpected exception caught"); |
|
359 CHECK(false); |
|
360 } |
|
361 } |
|
362 |