|
1 /* |
|
2 * Copyright (c) 2001-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 * Implementation for testing implicit tagging |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "testimplicittag.h" |
|
21 #include "tasn1normaltest.h" |
|
22 #include <asn1enc.h> |
|
23 #include <asn1dec.h> |
|
24 |
|
25 #include <e32cons.h> |
|
26 |
|
27 _LIT(KUniversalClass, "Universal"); |
|
28 _LIT(KApplicationSpecific, "ApplicationSpecific"); |
|
29 _LIT(KContextSpecific, "ContextSpecific"); |
|
30 _LIT(KPrivate, "Private"); |
|
31 |
|
32 CTestImplicitTag* CTestImplicitTag::NewL(CASN1NormalTest &aASN1Action) |
|
33 { |
|
34 CTestImplicitTag* test = new (ELeave) CTestImplicitTag(aASN1Action); |
|
35 return test; |
|
36 } |
|
37 |
|
38 CTestImplicitTag::CTestImplicitTag(CASN1NormalTest &aASN1Action) : CTestBase(aASN1Action) |
|
39 { |
|
40 }; |
|
41 |
|
42 |
|
43 void CTestImplicitTag::GetName(TDes& aBuf) |
|
44 { |
|
45 aBuf.Copy(_L("Test Implicit Tagging")); |
|
46 } |
|
47 |
|
48 void CTestImplicitTag::FillParameterArray(void) |
|
49 { |
|
50 iParameters->Append(CTestParameter::EString); |
|
51 iParameters->Append(CTestParameter::EInt); |
|
52 } |
|
53 |
|
54 |
|
55 TBool CTestImplicitTag::PerformTest(CConsoleBase& aConsole, const TASN1Class& aClass, const TUint &aTest, const TInt &aTestNumber, const TInt &aTotalTests) |
|
56 { |
|
57 CASN1EncBase* encoder = CASN1EncSequence::NewLC(); |
|
58 encoder->SetTag(aTest, aClass); |
|
59 |
|
60 // Prepare a buffer |
|
61 TInt totalLength = encoder->LengthDER(); |
|
62 HBufC8* buf = HBufC8::NewMaxLC(totalLength); |
|
63 TPtr8 tBuf = buf->Des(); |
|
64 |
|
65 // Write into the buffer |
|
66 TUint writeLength = 0; |
|
67 encoder->WriteDERL(tBuf, writeLength); |
|
68 |
|
69 // Read the buffer |
|
70 TASN1DecGeneric decoder(tBuf); |
|
71 decoder.InitL(); |
|
72 |
|
73 TTagType readTag = decoder.Tag(); |
|
74 TASN1Class readClass = decoder.Class(); |
|
75 |
|
76 // Check tag + class read OK |
|
77 if (readTag != aTest || readClass != aClass) |
|
78 { |
|
79 aConsole.Write(_L("Implicitly tagged object mis-read")); |
|
80 OutputEncodingL(aConsole, tBuf); |
|
81 iASN1Action.ReportProgressL(KErrASN1EncodingError, aTestNumber, aTotalTests); |
|
82 CleanupStack::PopAndDestroy(2); // buf, encoder |
|
83 return(EFalse); |
|
84 } |
|
85 else |
|
86 { |
|
87 iASN1Action.ReportProgressL(KErrNone, aTestNumber, aTotalTests); |
|
88 CleanupStack::PopAndDestroy(2); // buf, encoder |
|
89 return(ETrue); |
|
90 } |
|
91 } |
|
92 |
|
93 TBool CTestImplicitTag::PerformTestsL(CConsoleBase& aConsole) |
|
94 { |
|
95 CTestParameter* test; |
|
96 TInt totalTests, currentTest=0; |
|
97 TASN1Class classE; |
|
98 |
|
99 if(!CountTests(totalTests)) return(EFalse); |
|
100 |
|
101 for(TInt pos = 0; pos < iValues->Count(); pos++) |
|
102 { |
|
103 test = (*iValues)[pos]; |
|
104 if(test->GetType() == CTestParameter::EString) |
|
105 { |
|
106 CStringTestParameter *testString = REINTERPRET_CAST(CStringTestParameter*, test); |
|
107 TBuf<128> value; |
|
108 |
|
109 testString->GetValue(value); |
|
110 |
|
111 if(value == KUniversalClass) |
|
112 classE = EUniversal; |
|
113 else if(value == KApplicationSpecific) |
|
114 classE = EApplicationSpecific; |
|
115 else if(value == KPrivate) |
|
116 classE = EPrivate; |
|
117 else if(value == KContextSpecific) |
|
118 classE = EContextSpecific; |
|
119 else |
|
120 return(EFalse); |
|
121 } |
|
122 else |
|
123 return(EFalse); |
|
124 |
|
125 pos++; |
|
126 test = (*iValues)[pos]; |
|
127 |
|
128 switch(test->GetType()) |
|
129 { |
|
130 case CTestParameter::EInt : |
|
131 { |
|
132 CIntTestParameter *rangeInt = REINTERPRET_CAST(CIntTestParameter*, test); |
|
133 |
|
134 if(PerformTest(aConsole, classE, rangeInt->Value(), currentTest, totalTests)) |
|
135 return(EFalse); |
|
136 currentTest++; |
|
137 break; |
|
138 } |
|
139 case CTestParameter::EIntRange : |
|
140 { |
|
141 CIntRangeTestParameter *rangeInt = REINTERPRET_CAST(CIntRangeTestParameter*, test); |
|
142 |
|
143 for(TInt test = rangeInt->Start(); test <= rangeInt->Finish(); test++) |
|
144 { |
|
145 if(!PerformTest(aConsole, classE, test, currentTest, totalTests)) |
|
146 return(EFalse); |
|
147 currentTest++; |
|
148 } |
|
149 break; |
|
150 } |
|
151 default: |
|
152 return EFalse; |
|
153 } |
|
154 } |
|
155 iASN1Action.ReportProgressL(KErrNone, totalTests, totalTests); |
|
156 return(ETrue); |
|
157 } |