|
1 /* |
|
2 * Copyright (c) 1998-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 the License "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 |
|
19 #include "ValidateTest.h" |
|
20 #include "t_input.h" |
|
21 |
|
22 _LIT(KFilenameStart, "<filename>"); |
|
23 _LIT(KExpectedKeyIDStart, "<expectedkeyid>"); |
|
24 _LIT(KResultStart, "<result>"); |
|
25 |
|
26 CTestAction* CValidateTest::NewL(RFs& aFs, CConsoleBase& aConsole, |
|
27 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
28 { |
|
29 CTestAction* self = CValidateTest::NewLC(aFs, aConsole, aOut, aTestActionSpec); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 CTestAction* CValidateTest::NewLC(RFs& aFs, CConsoleBase& aConsole, |
|
35 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
36 { |
|
37 CValidateTest* self = new(ELeave) CValidateTest(aFs, aConsole, aOut); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(aTestActionSpec); |
|
40 return self; |
|
41 } |
|
42 |
|
43 |
|
44 CValidateTest::CValidateTest(RFs& aFs, |
|
45 CConsoleBase& aConsole, |
|
46 Output& aOut) |
|
47 : CTestAction(aConsole, aOut), iFs(aFs) |
|
48 { |
|
49 } |
|
50 |
|
51 void CValidateTest::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
52 { |
|
53 CTestAction::ConstructL(aTestActionSpec); |
|
54 TInt pos=0, resultPos=0; |
|
55 HBufC* aBody = HBufC::NewLC(aTestActionSpec.iActionBody.Length()); |
|
56 |
|
57 aBody->Des().Copy(aTestActionSpec.iActionBody); |
|
58 // creates the test chan validation object |
|
59 TPtrC ioFilename = Input::ParseElement(*aBody, KFilenameStart, pos); |
|
60 iFilename.Copy(ioFilename); |
|
61 TPtrC ioKeyId = Input::ParseElement(*aBody, KExpectedKeyIDStart, pos); |
|
62 |
|
63 if(ioKeyId.Length() == 40) |
|
64 { |
|
65 iResultKeyID.SetLength(iResultKeyID.MaxLength()); |
|
66 for(TInt byte =0; byte < 40; byte+=2) |
|
67 { |
|
68 TUint8 firstHalfOfOutput = ConvertByteA2H(static_cast<TInt8>(ioKeyId[byte])); |
|
69 TUint8 secondHalfOfOutput = ConvertByteA2H(static_cast<TInt8>(ioKeyId[byte+1])); |
|
70 iResultKeyID[resultPos] = static_cast<TInt8>((firstHalfOfOutput << 4)|secondHalfOfOutput); |
|
71 resultPos++; |
|
72 }; |
|
73 } |
|
74 TPtrC ioResult = Input::ParseElement(*aBody, KResultStart, pos); |
|
75 |
|
76 if(ioResult.CompareF(_L("Valid"))==0) |
|
77 iValid = ETrue; |
|
78 else |
|
79 iValid = EFalse; |
|
80 |
|
81 CleanupStack::PopAndDestroy(aBody); |
|
82 } |
|
83 |
|
84 CValidateTest::~CValidateTest() |
|
85 { |
|
86 } |
|
87 |
|
88 TUint8 CValidateTest::ConvertByteA2H(TUint8 aInput) |
|
89 { |
|
90 TUint8 output=0; |
|
91 if ((aInput > 0x29) && (aInput < 0x3a)) |
|
92 { |
|
93 output = static_cast<TInt8>(aInput-0x30); |
|
94 } |
|
95 if ((aInput > 0x40) && (aInput < 0x47)) |
|
96 { |
|
97 output = static_cast<TInt8>(aInput-0x37); |
|
98 } |
|
99 return output; |
|
100 } |
|
101 |
|
102 |
|
103 void CValidateTest::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
104 { |
|
105 TRequestStatus* status = &aStatus; |
|
106 User::RequestComplete(status, KErrNone); |
|
107 iActionState = EAction; |
|
108 } |
|
109 |
|
110 void CValidateTest::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
111 { |
|
112 TRequestStatus* status = &aStatus; |
|
113 User::RequestComplete(status, KErrNone); |
|
114 iFinished = ETrue; |
|
115 } |
|
116 |
|
117 void CValidateTest::PerformAction(TRequestStatus& aStatus) |
|
118 { |
|
119 CX509Certificate* cert = NULL; |
|
120 TInt err; |
|
121 TFileName filename(iFilename); |
|
122 |
|
123 HBufC8* buf=NULL; |
|
124 TRAP(err, buf = Input::ReadFileL(filename, iFs)); |
|
125 |
|
126 if (err == KErrNotFound) |
|
127 { |
|
128 iResult = EFalse; |
|
129 iFinished = ETrue; |
|
130 SetScriptError(EFileNotFound, iFilename); |
|
131 TRequestStatus* status = &aStatus; |
|
132 iActionState = EPostrequisite; |
|
133 User::RequestComplete(status, KErrNone); |
|
134 return; |
|
135 } |
|
136 else if (err != KErrNone) |
|
137 User::Leave(err); |
|
138 |
|
139 CleanupStack::PushL(buf); |
|
140 cert = CX509Certificate::NewLC(buf->Des()); |
|
141 |
|
142 TKeyIdentifier id = cert->KeyIdentifierL(); |
|
143 CleanupStack::PopAndDestroy(2); // buf & cert |
|
144 |
|
145 iConsole.Printf(_L("Validating file ")); |
|
146 iConsole.Printf(iFilename); |
|
147 iOut.writeString(_L("Validating file ")); |
|
148 iOut.writeString(iFilename); |
|
149 |
|
150 if(id == iResultKeyID) |
|
151 { |
|
152 iConsole.Printf(_L(" Match ")); |
|
153 iOut.writeString(_L(" Match ")); |
|
154 if(iValid) |
|
155 iResult = ETrue; |
|
156 else |
|
157 iResult = EFalse; |
|
158 } |
|
159 else |
|
160 { |
|
161 iConsole.Printf(_L(" No Match ")); |
|
162 iOut.writeString(_L(" No Match ")); |
|
163 if(!iValid) |
|
164 iResult = ETrue; |
|
165 else |
|
166 iResult = EFalse; |
|
167 } |
|
168 if(iResult) |
|
169 { |
|
170 iConsole.Printf(_L(" Success\n")); |
|
171 iOut.writeString(_L(" Success")); |
|
172 iOut.writeNewLine(); |
|
173 } |
|
174 else |
|
175 { |
|
176 iConsole.Printf(_L(" Failed\n")); |
|
177 iOut.writeString(_L(" Failed")); |
|
178 iOut.writeNewLine(); |
|
179 }; |
|
180 |
|
181 TRequestStatus* status = &aStatus; |
|
182 iActionState = EPostrequisite; |
|
183 User::RequestComplete(status, KErrNone); |
|
184 } |
|
185 |
|
186 |
|
187 void CValidateTest::DoReportAction() |
|
188 { |
|
189 } |
|
190 |
|
191 void CValidateTest::DoCheckResult(TInt /*aError*/) |
|
192 { |
|
193 } |