1 /* |
|
2 * Copyright (c) 2005-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 * Example CTestStep derived implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file WriteStringStep.cpp |
|
23 */ |
|
24 #include "testmacrosstep.h" |
|
25 #include "te_regsteptestsuitedefs.h" |
|
26 |
|
27 _LIT(KMacro, "Macro"); |
|
28 _LIT(KInitState, "InitState"); |
|
29 _LIT(KParameter, "Parameter"); |
|
30 _LIT(KParameter2, "Parameter2"); |
|
31 _LIT(KParameter3, "Parameter3"); |
|
32 _LIT(KExpectedResult, "ExpectedResult"); |
|
33 |
|
34 _LIT(KTest, "TEST&TESTE"); |
|
35 _LIT(KTest1, "TEST1&TESTE1"); |
|
36 //_LIT(KTestE, "TESTE"); |
|
37 //_LIT(KTestE1, "TESTE1"); |
|
38 _LIT(KTestCheckL, "TEST_CHECKL"); |
|
39 |
|
40 _LIT(KPositive, "positive"); |
|
41 _LIT(KNegative, "negative"); |
|
42 |
|
43 #define POS_NEG_SEL (parameter?&KPositive():&KNegative()) |
|
44 |
|
45 |
|
46 CTestMacrosTestStep::~CTestMacrosTestStep() |
|
47 /** |
|
48 * Destructor |
|
49 */ |
|
50 { |
|
51 } |
|
52 |
|
53 CTestMacrosTestStep::CTestMacrosTestStep() |
|
54 /** |
|
55 * Constructor |
|
56 */ |
|
57 { |
|
58 SetTestStepName(KMacrosTestStep); |
|
59 } |
|
60 |
|
61 TVerdict CTestMacrosTestStep::doTestStepPreambleL() |
|
62 /** |
|
63 * @return - TVerdict code |
|
64 * Override of base class virtual |
|
65 */ |
|
66 { |
|
67 // There is no initiation work so set this result to pass. |
|
68 SetTestStepResult(EPass); |
|
69 return TestStepResult(); |
|
70 } |
|
71 |
|
72 |
|
73 TVerdict CTestMacrosTestStep::doTestStepL() |
|
74 /** |
|
75 * @return - TVerdict code |
|
76 * Override of base class pure virtual |
|
77 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
78 * not leave. That being the case, the current test result value will be EPass. |
|
79 */ |
|
80 { |
|
81 TPtrC macro; |
|
82 GetStringFromConfig(ConfigSection(), KMacro, macro); |
|
83 if (macro == KTest) |
|
84 { |
|
85 TBool parameter; |
|
86 TInt parameter2; |
|
87 TInt expectedResult; |
|
88 GetBoolFromConfig(ConfigSection(), KParameter, parameter); |
|
89 GetIntFromConfig(ConfigSection(), KParameter2, parameter2); |
|
90 GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult); |
|
91 _LIT(KStartInfo, "Start to run %S test of macros TEST(E) & TEST(E)L"); |
|
92 INFO_PRINTF2(KStartInfo, POS_NEG_SEL); |
|
93 TEST(parameter); |
|
94 TESTE(parameter, parameter2); |
|
95 if (expectedResult != TestStepResult()) |
|
96 { |
|
97 ERR_PRINTF2(_L("The %S test of macro TEST(E) test is failed!"), POS_NEG_SEL); |
|
98 SetTestStepResult(EFail); |
|
99 } |
|
100 else |
|
101 { |
|
102 SetTestStepResult(EPass); |
|
103 INFO_PRINTF3(_L("The %S test of macro TEST(E) is passed. Start to run %S test of macro TEST(E)L"), POS_NEG_SEL, POS_NEG_SEL); |
|
104 |
|
105 TRAPD(err, TESTL(parameter)); |
|
106 TRAPD(err1, TESTEL(parameter, parameter2)); |
|
107 if ((expectedResult==EPass && KErrNone!=err) || (expectedResult==EFail && TEST_ERROR_CODE!=err && parameter2!=err1)) |
|
108 { |
|
109 ERR_PRINTF2(_L("The %S test of macro TEST(E)L test is failed!"), POS_NEG_SEL); |
|
110 SetTestStepResult(EFail); |
|
111 } |
|
112 else |
|
113 { |
|
114 INFO_PRINTF2(_L("The %S test of macro TEST(E)L is passed."), POS_NEG_SEL); |
|
115 SetTestStepResult(EPass); |
|
116 } |
|
117 } |
|
118 } |
|
119 else if (macro == KTest1) |
|
120 { |
|
121 TBool parameter; |
|
122 TBool parameter2; |
|
123 TInt parameter3; |
|
124 TInt initState; |
|
125 TInt expectedResult; |
|
126 GetBoolFromConfig(ConfigSection(), KParameter, parameter); |
|
127 GetBoolFromConfig(ConfigSection(), KParameter2, parameter2); |
|
128 GetIntFromConfig(ConfigSection(), KParameter3, parameter3); |
|
129 GetIntFromConfig(ConfigSection(), KInitState, initState); |
|
130 GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult); |
|
131 SetTestStepResult((TVerdict)initState); |
|
132 _LIT(KStartInfo, "Start to run %S test of macros TEST(E)1 & TEST(E)1L"); |
|
133 INFO_PRINTF2(KStartInfo, POS_NEG_SEL); |
|
134 TEST1(parameter, parameter2); |
|
135 TESTE1(parameter, parameter3, parameter2); |
|
136 if (expectedResult != TestStepResult()) |
|
137 { |
|
138 ERR_PRINTF1(_L("Macro TEST(E)1 test failed!")); |
|
139 SetTestStepResult(EFail); |
|
140 } |
|
141 else |
|
142 { |
|
143 SetTestStepResult(EPass); |
|
144 INFO_PRINTF3(_L("The %S test of macro TEST(E)1 has passed. Start to run %S test of macro TEST(E)1L"), POS_NEG_SEL, POS_NEG_SEL); |
|
145 |
|
146 TRAPD(err, TEST1L(parameter, parameter2)); |
|
147 TRAP_IGNORE(TESTE1L(parameter, parameter3, parameter2)); |
|
148 if ((expectedResult==EPass && KErrNone!=err) || ((expectedResult==EFail) && (parameter && ((TEST_ERROR_CODE==err)||(parameter3==err))) || (!parameter && TEST_ERROR_CODE!=err && parameter3!=err))) |
|
149 { |
|
150 ERR_PRINTF1(_L("Macro TEST(E)1L test failed!")); |
|
151 SetTestStepResult(EFail); |
|
152 } |
|
153 else |
|
154 { |
|
155 INFO_PRINTF2(_L("The %S test of macro TEST(E)1L has passed."), POS_NEG_SEL); |
|
156 SetTestStepResult(EPass); |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 else if (macro == KTestCheckL) |
|
162 { |
|
163 TInt parameter; |
|
164 TInt parameter1; |
|
165 TPtrC parameter2; |
|
166 TInt expectedResult; |
|
167 GetIntFromConfig(ConfigSection(), KParameter, parameter1); |
|
168 GetStringFromConfig(ConfigSection(), KParameter2, parameter2); |
|
169 GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult); |
|
170 |
|
171 parameter = (parameter1==expectedResult); |
|
172 INFO_PRINTF3(_L("Start %S test of macro %S"), POS_NEG_SEL, &KTestCheckL()); |
|
173 |
|
174 TRAPD(err, TEST_CHECKL(parameter1, expectedResult, parameter2)); |
|
175 _LIT(KPassInfo, "This test should be passed!"); |
|
176 _LIT(KFailInfo, "This test should be failed!"); |
|
177 if ((KErrNone==err && parameter2==KPassInfo()) || (parameter1==err && parameter2==KFailInfo())) |
|
178 { |
|
179 INFO_PRINTF2(_L("The macro %S test is passed!"), &KTestCheckL()); |
|
180 SetTestStepResult(EPass); |
|
181 } |
|
182 else |
|
183 { |
|
184 ERR_PRINTF2(_L("The macro %S test is failed!"), &KTestCheckL()); |
|
185 SetTestStepResult(EFail); |
|
186 } |
|
187 } |
|
188 else |
|
189 { |
|
190 WARN_PRINTF2(_L("Unrecognized Marco %S"), macro); |
|
191 } |
|
192 |
|
193 return TestStepResult(); |
|
194 } |
|
195 |
|
196 |
|
197 |
|
198 TVerdict CTestMacrosTestStep::doTestStepPostambleL() |
|
199 /** |
|
200 * @return - TVerdict code |
|
201 * Override of base class virtual |
|
202 */ |
|
203 { |
|
204 return TestStepResult(); |
|
205 } |
|