|
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 "TestHarness.h" |
|
19 #include <s32mem.h> |
|
20 #include "clientsession.h" |
|
21 |
|
22 TEST_GROUP(TestCertificatesManager) |
|
23 { |
|
24 RClientSession iSession; |
|
25 |
|
26 TEST_SETUP() |
|
27 { |
|
28 } |
|
29 |
|
30 TEST_TEARDOWN() |
|
31 { |
|
32 } |
|
33 }; |
|
34 |
|
35 TEST(TestCertificatesManager, TestCertificatesManagerL) |
|
36 { |
|
37 // initializations |
|
38 TRequestStatus status; |
|
39 _LIT(KServerName, "!SystemAMS.SecurityAdmin"); |
|
40 _LIT(KDummy, "dummy"); |
|
41 TPckgBuf<TUint32> count; |
|
42 HBufC8* buffer = NULL; |
|
43 CBufFlat* info = NULL; |
|
44 // connect |
|
45 CHECK(iSession.Connect(KServerName) == KErrNone); |
|
46 iSession.Count(status, KDummy, count); |
|
47 User::WaitForRequest(status); |
|
48 CHECK(status.Int() == KErrNone && count() != 0); |
|
49 // info |
|
50 buffer = HBufC8::NewL(4096); |
|
51 CleanupStack::PushL(buffer); |
|
52 TPtr8 ptr = buffer->Des(); |
|
53 iSession.Info(status, KDummy, ptr); |
|
54 User::WaitForRequest(status); |
|
55 CHECK(status.Int() == KErrNone); |
|
56 info = CBufFlat::NewL(ptr.Length()); |
|
57 CleanupStack::PushL(info); |
|
58 info->SetReserveL(ptr.Length()); |
|
59 info->InsertL(0, ptr); |
|
60 RBufReadStream reader(*info, 0); |
|
61 TInt cnt = reader.ReadUint32L(); |
|
62 CHECK(cnt > 0); |
|
63 for (int i=0; i<cnt; i++) |
|
64 { |
|
65 TInt id = reader.ReadUint32L(); |
|
66 TInt flags = reader.ReadUint32L(); |
|
67 TInt length = reader.ReadUint32L(); |
|
68 HBufC8* cert = HBufC8::NewL(4096); |
|
69 CleanupStack::PushL(cert); |
|
70 TPtr8 certPtr = cert->Des(); |
|
71 iSession.Certificate(status, id, certPtr); |
|
72 User::WaitForRequest(status); |
|
73 CHECK(length > 0 && certPtr.Length() == length); |
|
74 CleanupStack::PopAndDestroy(cert); |
|
75 iSession.Disable(status, id); |
|
76 User::WaitForRequest(status); |
|
77 CHECK(status.Int() == KErrNone || status.Int() == KErrArgument); |
|
78 iSession.Delete(status, id); |
|
79 User::WaitForRequest(status); |
|
80 CHECK(status.Int() == KErrNone || status.Int() == KErrArgument); |
|
81 iSession.Enable(status, id); |
|
82 User::WaitForRequest(status); |
|
83 CHECK(status.Int() == KErrNone || status.Int() == KErrArgument); |
|
84 } |
|
85 HBufC8* tmpCert = HBufC8::NewL(4096); |
|
86 CleanupStack::PushL(tmpCert); |
|
87 TPtr8 tmpCertPtr = tmpCert->Des(); |
|
88 iSession.Certificate(status, -1, tmpCertPtr); |
|
89 User::WaitForRequest(status); |
|
90 CHECK(status.Int() == KErrNotFound); |
|
91 CleanupStack::PopAndDestroy(tmpCert); |
|
92 CleanupStack::PopAndDestroy(info); |
|
93 CleanupStack::PopAndDestroy(buffer); |
|
94 } |