sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "T_unifiedcertstoreapplications.h"
|
sl@0
|
24 |
#include "t_input.h"
|
sl@0
|
25 |
#include "t_certstoredefs.h"
|
sl@0
|
26 |
#include "t_certstoreout.h"
|
sl@0
|
27 |
#include <ccertattributefilter.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
CTestAction* CUnifiedCertStoreApplications::NewL(RFs& aFs,
|
sl@0
|
30 |
CConsoleBase& aConsole,
|
sl@0
|
31 |
Output& aOut,
|
sl@0
|
32 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
CUnifiedCertStoreApplications* self =
|
sl@0
|
35 |
new(ELeave) CUnifiedCertStoreApplications(aFs, aConsole, aOut);
|
sl@0
|
36 |
CleanupStack::PushL(self);
|
sl@0
|
37 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
38 |
CleanupStack::Pop(self);
|
sl@0
|
39 |
return self;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
CUnifiedCertStoreApplications::~CUnifiedCertStoreApplications()
|
sl@0
|
43 |
{
|
sl@0
|
44 |
iCertInfos.Close();
|
sl@0
|
45 |
iExpectedApplications.Reset();
|
sl@0
|
46 |
delete iFilter;
|
sl@0
|
47 |
iApplications.Close();
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
CUnifiedCertStoreApplications::CUnifiedCertStoreApplications(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
51 |
Output& aOut)
|
sl@0
|
52 |
: CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCert)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void CUnifiedCertStoreApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
CCertStoreTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
59 |
iFilter = CCertAttributeFilter::NewL();
|
sl@0
|
60 |
TInt err = KErrNone;
|
sl@0
|
61 |
TInt pos = 0;
|
sl@0
|
62 |
|
sl@0
|
63 |
TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
|
sl@0
|
64 |
if (err != KErrNone)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
User::Leave(err);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
iCertificateLabel.Copy(pLabel);
|
sl@0
|
69 |
|
sl@0
|
70 |
// Set expected result
|
sl@0
|
71 |
|
sl@0
|
72 |
pos = 0;
|
sl@0
|
73 |
|
sl@0
|
74 |
HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
|
sl@0
|
75 |
TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
|
sl@0
|
76 |
Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
|
sl@0
|
77 |
CleanupStack::PopAndDestroy(result);
|
sl@0
|
78 |
|
sl@0
|
79 |
const TDesC8& uidsString = Input::ParseElement(aTestActionSpec.iActionResult, KUIDStart, KUIDEnd,
|
sl@0
|
80 |
pos, err);
|
sl@0
|
81 |
TLex8 lex(uidsString);
|
sl@0
|
82 |
|
sl@0
|
83 |
err = KErrNone;
|
sl@0
|
84 |
while (err == KErrNone)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
TUid uid;
|
sl@0
|
87 |
err = lex.Val(uid.iUid);
|
sl@0
|
88 |
if (err == KErrNone)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
lex.SkipSpace();
|
sl@0
|
91 |
User::LeaveIfError(iExpectedApplications.Append(uid));
|
sl@0
|
92 |
}
|
sl@0
|
93 |
}
|
sl@0
|
94 |
}
|
sl@0
|
95 |
|
sl@0
|
96 |
void CUnifiedCertStoreApplications::GetApplications(TRequestStatus& aStatus)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
TRequestStatus* status = &aStatus;
|
sl@0
|
99 |
TInt ix = KErrNotFound;
|
sl@0
|
100 |
TInt count = iCertInfos.Count();
|
sl@0
|
101 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
if (iCertInfos[i]->Label() == iCertificateLabel)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
ix = i;
|
sl@0
|
106 |
break;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
}
|
sl@0
|
109 |
if (ix == KErrNotFound)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
User::RequestComplete(status, ix);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
else
|
sl@0
|
114 |
{
|
sl@0
|
115 |
iCertInfoForApplications = iCertInfos[ix];
|
sl@0
|
116 |
CertStore().Applications(*iCertInfoForApplications, iApplications, aStatus);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
void CUnifiedCertStoreApplications::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
switch (iState)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
case EGetCert:
|
sl@0
|
125 |
iState = EGettingApplications;
|
sl@0
|
126 |
//get the certs
|
sl@0
|
127 |
CertStore().List(iCertInfos, *iFilter, aStatus);
|
sl@0
|
128 |
break;
|
sl@0
|
129 |
|
sl@0
|
130 |
case EGettingApplications:
|
sl@0
|
131 |
iState = EFinished;
|
sl@0
|
132 |
//get the certificates associated applications
|
sl@0
|
133 |
GetApplications(aStatus);
|
sl@0
|
134 |
break;
|
sl@0
|
135 |
|
sl@0
|
136 |
case EFinished:
|
sl@0
|
137 |
{
|
sl@0
|
138 |
TRequestStatus* status = &aStatus;
|
sl@0
|
139 |
User::RequestComplete(status, aStatus.Int());
|
sl@0
|
140 |
if (aStatus == iExpectedResult)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
// Check that we have the expected uids
|
sl@0
|
143 |
TInt iEnd = iApplications.Count();
|
sl@0
|
144 |
if (iEnd == iExpectedApplications.Count())
|
sl@0
|
145 |
{
|
sl@0
|
146 |
TInt i = 0;
|
sl@0
|
147 |
for (i = 0; i < iEnd; i++)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
if ((iApplications)[i] != iExpectedApplications[i])
|
sl@0
|
150 |
{
|
sl@0
|
151 |
break;
|
sl@0
|
152 |
}
|
sl@0
|
153 |
}
|
sl@0
|
154 |
if (i == iEnd)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
iResult = ETrue;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
else
|
sl@0
|
159 |
{
|
sl@0
|
160 |
iResult = EFalse;
|
sl@0
|
161 |
}
|
sl@0
|
162 |
}
|
sl@0
|
163 |
else
|
sl@0
|
164 |
{
|
sl@0
|
165 |
iResult = EFalse;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
}
|
sl@0
|
168 |
else
|
sl@0
|
169 |
{
|
sl@0
|
170 |
iResult = EFalse;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
iFinished = ETrue;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
break;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
}
|
sl@0
|
178 |
|
sl@0
|
179 |
void CUnifiedCertStoreApplications::PerformCancel()
|
sl@0
|
180 |
{
|
sl@0
|
181 |
switch (iState)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
case EGettingApplications:
|
sl@0
|
184 |
CertStore().CancelList();
|
sl@0
|
185 |
break;
|
sl@0
|
186 |
|
sl@0
|
187 |
case EFinished:
|
sl@0
|
188 |
CertStore().CancelApplications();
|
sl@0
|
189 |
break;
|
sl@0
|
190 |
|
sl@0
|
191 |
default:
|
sl@0
|
192 |
break;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
void CUnifiedCertStoreApplications::Reset()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
iCertInfos.Close();
|
sl@0
|
199 |
iState = EGetCert;
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
void CUnifiedCertStoreApplications::DoReportAction()
|
sl@0
|
203 |
{
|
sl@0
|
204 |
iOut.writeString(_L("Getting applications..."));
|
sl@0
|
205 |
iOut.writeNewLine();
|
sl@0
|
206 |
iOut.writeString(_L("\tExpected applications :"));
|
sl@0
|
207 |
TInt iEnd = iExpectedApplications.Count();
|
sl@0
|
208 |
for (TInt i = 0; i < iEnd; i++)
|
sl@0
|
209 |
{
|
sl@0
|
210 |
iOut.writeString(_L(" "));
|
sl@0
|
211 |
iOut.writeNum(iExpectedApplications[i].iUid);
|
sl@0
|
212 |
}
|
sl@0
|
213 |
iOut.writeNewLine();
|
sl@0
|
214 |
iOut.writeNewLine();
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
void CUnifiedCertStoreApplications::DoCheckResult(TInt /*aError*/)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
if (iFinished)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
iConsole.Printf(_L("\tApplications : "));
|
sl@0
|
222 |
iOut.writeString(_L("\tApplications : "));
|
sl@0
|
223 |
TInt count = iApplications.Count();
|
sl@0
|
224 |
for (TInt i = 0; i < count; i++)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
iConsole.Printf(_L("%D "), (iApplications)[i]);
|
sl@0
|
227 |
iOut.writeNum((iApplications)[i].iUid);
|
sl@0
|
228 |
iOut.writeString(_L(" "));
|
sl@0
|
229 |
}
|
sl@0
|
230 |
iOut.writeNewLine();
|
sl@0
|
231 |
if (iResult)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
iConsole.Printf(_L("\n\tApplications retrieved successfully\n"));
|
sl@0
|
234 |
iOut.writeString(_L("\tApplications retrieved successfully"));
|
sl@0
|
235 |
iOut.writeNewLine();
|
sl@0
|
236 |
}
|
sl@0
|
237 |
else
|
sl@0
|
238 |
{
|
sl@0
|
239 |
iConsole.Printf(_L("\n\tApplications retrieved failed\n"));
|
sl@0
|
240 |
iOut.writeString(_L("\tApplications retrieved failed"));
|
sl@0
|
241 |
iOut.writeNewLine();
|
sl@0
|
242 |
}
|
sl@0
|
243 |
iOut.writeNewLine();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
}
|