|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Example CTestStep derived implementation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include "TeIniOpenStep.h" |
|
23 |
|
24 //EPOC includes |
|
25 #include <test/testexecutelog.h> |
|
26 #include <es_sock.h> |
|
27 #include <es_ini.h> |
|
28 |
|
29 _LIT(KFileName, "c:\\te_ini.ini"); |
|
30 |
|
31 |
|
32 CTestIniOpenStep::CTestIniOpenStep() : iESockIniData(NULL) |
|
33 /** |
|
34 * Constructor |
|
35 */ |
|
36 { |
|
37 // Call base class method to set up the human readable name for logging |
|
38 SetTestStepName(KOpenIniFile); |
|
39 } |
|
40 |
|
41 CTestIniOpenStep::~CTestIniOpenStep() |
|
42 /** |
|
43 * Destructor |
|
44 */ |
|
45 { |
|
46 delete iESockIniData; |
|
47 iESockIniData = NULL; |
|
48 } |
|
49 |
|
50 |
|
51 TVerdict CTestIniOpenStep::doTestStepL() |
|
52 /** |
|
53 * @return - TVerdict code |
|
54 * Override of base class pure virtual |
|
55 * Demonstrates reading configuration parameters fom an ini iESockIniData section |
|
56 */ |
|
57 { |
|
58 |
|
59 INFO_PRINTF1(_L("In Test Step OpenIniFile")); |
|
60 |
|
61 iESockIniData = CESockIniData::NewL(KFileName); |
|
62 |
|
63 TPtrC result; |
|
64 TPtrC* res = &result; |
|
65 |
|
66 TInt ret1 = 0; |
|
67 |
|
68 // test [SectionOne] VarOne |
|
69 TRAP(ret1, iESockIniData->FindVar(_L("VarOne"),result)); |
|
70 TInt ret2 = result.Compare(_L("FromSectionOne")); |
|
71 if (ret2 != KErrNone) |
|
72 { |
|
73 ERR_PRINTF2(_L("Failed to compare VarOne. Error: %d"), ret2); |
|
74 SetTestStepResult(EFail); |
|
75 return EFail; |
|
76 } |
|
77 else |
|
78 { |
|
79 INFO_PRINTF2(_L("VarOne [RAW] = %S\n\r"), res); |
|
80 } |
|
81 |
|
82 // test [SectionOne] VarOne |
|
83 TRAP(ret1, iESockIniData->FindVar(_L("SectionOne"),_L("VarOne"),result)); |
|
84 ret2 = result.Compare(_L("FromSectionOne")); |
|
85 if (ret2 != KErrNone) |
|
86 { |
|
87 ERR_PRINTF2(_L("Failed to compare [SectionOne] VarOne. Error: %d"), ret2); |
|
88 SetTestStepResult(EFail); |
|
89 return EFail; |
|
90 } |
|
91 else |
|
92 { |
|
93 INFO_PRINTF2(_L("[SectionOne] VarOne = %S\n\r"), res); |
|
94 } |
|
95 |
|
96 // test [SectionOne] VarTwo, which is not existing |
|
97 TBool ret3 = iESockIniData->FindVar(_L("SectionOne"),_L("VarTwo"),result); |
|
98 if (ret3 != EFalse) |
|
99 { |
|
100 ERR_PRINTF1(_L("Failed to compare [SectionOne] VarTwo.")); |
|
101 SetTestStepResult(EFail); |
|
102 return EFail; |
|
103 } |
|
104 else |
|
105 { |
|
106 INFO_PRINTF1(_L("[SectionOne] VarOne NotFound\n\r")); |
|
107 } |
|
108 |
|
109 // test [SectionTwo] VarOne |
|
110 TRAP(ret1, iESockIniData->FindVar(_L("SectionTwo"),_L("VarOne"),result)); |
|
111 ret2 = result.Compare(_L("FromSectionTwo")); |
|
112 if (ret2 != KErrNone) |
|
113 { |
|
114 ERR_PRINTF2(_L("Failed to compare [SectionTwo] VarOne. Error: %d"), ret2); |
|
115 SetTestStepResult(EFail); |
|
116 return EFail; |
|
117 } |
|
118 else |
|
119 { |
|
120 INFO_PRINTF2(_L("[SectionTwo] VarOne = %S\n\r"), res); |
|
121 } |
|
122 |
|
123 // test [SectionThree] VarOne |
|
124 TRAP(ret1, iESockIniData->FindVar(_L("SectionThree"),_L("VarOne"),result)); |
|
125 ret2 = result.Compare(_L("FromSectionThree")); |
|
126 if (ret2 != KErrNone) |
|
127 { |
|
128 ERR_PRINTF2(_L("Failed to compare [SectionThree] VarOne. Error: %d"), ret2); |
|
129 SetTestStepResult(EFail); |
|
130 return EFail; |
|
131 } |
|
132 else |
|
133 { |
|
134 INFO_PRINTF2(_L("[SectionThree] VarOne = %S\n\r"), res); |
|
135 } |
|
136 |
|
137 // test [SectionTwo][SectionThree] |
|
138 TRAP(ret1, iESockIniData->FindVar(_L("SectionTwo"),_L("SectionThree"),result)); |
|
139 ret2 = result.Compare(_L("VarNameSectionThree")); |
|
140 if (ret2 != KErrNone) |
|
141 { |
|
142 ERR_PRINTF2(_L("Failed to compare [SectionTwo] SectionThree. Error: %d"), ret2); |
|
143 SetTestStepResult(EFail); |
|
144 return EFail; |
|
145 } |
|
146 else |
|
147 { |
|
148 INFO_PRINTF2(_L("[SectionTwo] SectionThree = %S\n\r"),res); |
|
149 } |
|
150 |
|
151 |
|
152 // test [SectionOne] sectionNum |
|
153 TInt numResult = 0; |
|
154 TRAP(ret1, iESockIniData->FindVar(_L("SectionOne"),_L("sectionNum"),numResult)); |
|
155 if (numResult != 1) |
|
156 { |
|
157 ERR_PRINTF2(_L("Failed to compare [SectionOne] sectionNum. numResult is: %d"), numResult); |
|
158 SetTestStepResult(EFail); |
|
159 return EFail; |
|
160 } |
|
161 else |
|
162 { |
|
163 INFO_PRINTF2(_L("[SectionOne] sectionNum = %d\n\r"),numResult); |
|
164 } |
|
165 |
|
166 // test [SectionTwo] sectionNum |
|
167 TRAP(ret1, iESockIniData->FindVar(_L("SectionTwo"),_L("sectionNum"),numResult)); |
|
168 if (numResult != 2) |
|
169 { |
|
170 ERR_PRINTF2(_L("Failed to compare [SectionTwo] sectionNum. numResult is: %d"), numResult); |
|
171 SetTestStepResult(EFail); |
|
172 return EFail; |
|
173 } |
|
174 else |
|
175 { |
|
176 INFO_PRINTF2(_L("[SectionTwo] sectionNum = %d\n\r"),numResult); |
|
177 } |
|
178 |
|
179 // test [SectionThree] sectionNum |
|
180 TRAP(ret1, iESockIniData->FindVar(_L("SectionThree"),_L("sectionNum"),numResult)); |
|
181 if (numResult != 3) |
|
182 { |
|
183 ERR_PRINTF2(_L("Failed to compare [SectionThree] sectionNum. numResult is: %d"), numResult); |
|
184 SetTestStepResult(EFail); |
|
185 return EFail; |
|
186 } |
|
187 else |
|
188 { |
|
189 INFO_PRINTF2(_L("[SectionThree] sectionNum = %d\n\r"),numResult); |
|
190 } |
|
191 |
|
192 // test [SectionOne] test1, which is not existing |
|
193 ret3 = iESockIniData->FindVar(_L("SectionOne"),_L("test1"),result); |
|
194 if (ret3 != EFalse) |
|
195 { |
|
196 ERR_PRINTF1(_L("Failed to compare [SectionOne] test1.")); |
|
197 SetTestStepResult(EFail); |
|
198 return EFail; |
|
199 } |
|
200 else |
|
201 { |
|
202 INFO_PRINTF1(_L("[SectionOne] test1 NotFound\n\r")); |
|
203 } |
|
204 |
|
205 // test [SectionOne] test2, which is not existing |
|
206 ret3 = iESockIniData->FindVar(_L("SectionOne"),_L("test2"),result); |
|
207 if (ret3 != EFalse) |
|
208 { |
|
209 ERR_PRINTF1(_L("Failed to compare [SectionOne] test2.")); |
|
210 SetTestStepResult(EFail); |
|
211 return EFail; |
|
212 } |
|
213 else |
|
214 { |
|
215 INFO_PRINTF1(_L("[SectionOne] test2 NotFound\n\r")); |
|
216 } |
|
217 |
|
218 return TestStepResult(); |
|
219 } |
|
220 |
|
221 |
|
222 |