|
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 * |
|
16 */ |
|
17 |
|
18 #include "T_DataRSdp.h" |
|
19 |
|
20 /*@{*/ |
|
21 |
|
22 //Parameters |
|
23 _LIT(KExpected, "expected"); |
|
24 _LIT(KVersionName, "name"); |
|
25 _LIT(KVersionBuild, "build"); |
|
26 _LIT(KVersionMajor, "major"); |
|
27 _LIT(KVersionMinor, "minor"); |
|
28 |
|
29 //Commands |
|
30 _LIT(KCmdConstructor, "Constructor"); |
|
31 _LIT(KCmdConnect, "Connect"); |
|
32 _LIT(KCmdClose, "Close"); |
|
33 _LIT(KCmdVersion, "Version"); |
|
34 _LIT(KCmdResourceCountMarkStart, "ResourceCountMarkStart"); |
|
35 _LIT(KCmdResourceCountMarkEnd, "ResourceCountMarkEnd"); |
|
36 _LIT(KCmdResourceCount, "ResourceCount"); |
|
37 /*@}*/ |
|
38 |
|
39 ////////////////////////////////////////////////////////////////////// |
|
40 // Construction/Destruction |
|
41 ////////////////////////////////////////////////////////////////////// |
|
42 |
|
43 CT_DataRSdp* CT_DataRSdp::NewL() |
|
44 { |
|
45 CT_DataRSdp* ret=new (ELeave) CT_DataRSdp(); |
|
46 CleanupStack::PushL(ret); |
|
47 ret->ConstructL(); |
|
48 CleanupStack::Pop(ret); |
|
49 return ret; |
|
50 } |
|
51 |
|
52 CT_DataRSdp::CT_DataRSdp() |
|
53 : iRsdp(NULL) |
|
54 { |
|
55 } |
|
56 |
|
57 void CT_DataRSdp::ConstructL() |
|
58 { |
|
59 } |
|
60 |
|
61 CT_DataRSdp::~CT_DataRSdp() |
|
62 { |
|
63 DestroyData(); |
|
64 } |
|
65 |
|
66 void CT_DataRSdp::SetObjectL(TAny* aAny) |
|
67 { |
|
68 DestroyData(); |
|
69 iRsdp = static_cast<RSdp*> (aAny); |
|
70 } |
|
71 |
|
72 void CT_DataRSdp::DisownObjectL() |
|
73 { |
|
74 iRsdp = NULL; |
|
75 } |
|
76 |
|
77 void CT_DataRSdp::DestroyData() |
|
78 { |
|
79 delete iRsdp; |
|
80 iRsdp=NULL; |
|
81 } |
|
82 |
|
83 inline TCleanupOperation CT_DataRSdp::CleanupOperation() |
|
84 { |
|
85 return CleanupOperation; |
|
86 } |
|
87 |
|
88 void CT_DataRSdp::CleanupOperation(TAny* aAny) |
|
89 { |
|
90 RSdp* sdp=static_cast<RSdp*>(aAny); |
|
91 delete sdp; |
|
92 } |
|
93 |
|
94 /** |
|
95 test script command entry point |
|
96 @internalAll |
|
97 @return ETrue if syncronous command otherwise EFalse |
|
98 @param aParam1 descriptor containing the command value |
|
99 @param aParam2 descriptor containing the command parameter |
|
100 @pre N/A |
|
101 @post N/A |
|
102 */ |
|
103 TBool CT_DataRSdp::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
104 { |
|
105 TBool ret=ETrue; |
|
106 |
|
107 if ( aCommand==KCmdConstructor ) |
|
108 { |
|
109 DoCmdConstructor(); |
|
110 } |
|
111 else if( aCommand==KCmdConnect ) |
|
112 { |
|
113 DoCmdConnect(); |
|
114 } |
|
115 else if( aCommand==KCmdClose ) |
|
116 { |
|
117 DoCmdClose(); |
|
118 } |
|
119 else if( aCommand==KCmdVersion ) |
|
120 { |
|
121 DoCmdVersion(aSection); |
|
122 } |
|
123 else if( aCommand==KCmdResourceCountMarkStart ) |
|
124 { |
|
125 DoCmdResourceCountMarkStart(); |
|
126 } |
|
127 else if( aCommand==KCmdResourceCountMarkEnd ) |
|
128 { |
|
129 DoCmdResourceCountMarkEnd(); |
|
130 } |
|
131 else if( aCommand==KCmdResourceCount ) |
|
132 { |
|
133 DoCmdResourceCount(aSection); |
|
134 } |
|
135 else |
|
136 { |
|
137 ret=EFalse; |
|
138 } |
|
139 |
|
140 return ret; |
|
141 } |
|
142 |
|
143 |
|
144 void CT_DataRSdp::DoCmdConstructor() |
|
145 { |
|
146 DestroyData(); |
|
147 |
|
148 TRAPD(err, iRsdp = new (ELeave) RSdp()); |
|
149 if(err != KErrNone) |
|
150 { |
|
151 ERR_PRINTF2(_L("**** RSdp Constructor failed with error %d"), err); |
|
152 SetError(err); |
|
153 } |
|
154 } |
|
155 |
|
156 void CT_DataRSdp::DoCmdConnect() |
|
157 { |
|
158 TInt err = iRsdp->Connect(); |
|
159 if(err != KErrNone) |
|
160 { |
|
161 ERR_PRINTF2(_L("**** RSdp Connect failed with error %d"), err); |
|
162 SetError(err); |
|
163 } |
|
164 } |
|
165 |
|
166 void CT_DataRSdp::DoCmdClose() |
|
167 { |
|
168 iRsdp->Close(); |
|
169 } |
|
170 |
|
171 void CT_DataRSdp::DoCmdVersion(const TDesC& aSection) |
|
172 { |
|
173 TVersion version=iRsdp->Version(); |
|
174 TVersionName versionName = version.Name(); |
|
175 |
|
176 INFO_PRINTF1(_L("Version name :")); |
|
177 INFO_PRINTF1(versionName); |
|
178 INFO_PRINTF2(_L("Version build : %d"), (TInt)version.iBuild); |
|
179 INFO_PRINTF2(_L("Version major : %d"), (TInt)version.iMajor); |
|
180 INFO_PRINTF2(_L("Version minor : %d"), (TInt)version.iMinor); |
|
181 |
|
182 TPtrC name; |
|
183 if ( GetStringFromConfig(aSection, KVersionName(), name) ) |
|
184 { |
|
185 if ( name != versionName ) |
|
186 { |
|
187 ERR_PRINTF1(_L("Name does not match expected name")); |
|
188 SetBlockResult(EFail); |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 ERR_PRINTF2(_L("Missing expected value %S"), &KVersionName()); |
|
194 SetBlockResult(EFail); |
|
195 } |
|
196 |
|
197 /* |
|
198 The following expected values are optional since the version name already includes these info. |
|
199 */ |
|
200 TInt intTemp; |
|
201 if ( GetIntFromConfig(aSection, KVersionBuild(), intTemp) ) |
|
202 { |
|
203 if ( intTemp != version.iBuild ) |
|
204 { |
|
205 ERR_PRINTF1(_L("Build does not match expected build")); |
|
206 SetBlockResult(EFail); |
|
207 } |
|
208 } |
|
209 |
|
210 if ( GetIntFromConfig(aSection, KVersionMajor(), intTemp) ) |
|
211 { |
|
212 if ( intTemp != version.iMajor ) |
|
213 { |
|
214 ERR_PRINTF1(_L("Major does not match expected major")); |
|
215 SetBlockResult(EFail); |
|
216 } |
|
217 } |
|
218 |
|
219 if ( GetIntFromConfig(aSection, KVersionMinor(), intTemp) ) |
|
220 { |
|
221 if ( intTemp != version.iMinor ) |
|
222 { |
|
223 ERR_PRINTF1(_L("Minor does not match expected minor")); |
|
224 SetBlockResult(EFail); |
|
225 } |
|
226 } |
|
227 |
|
228 if (versionName == _L("") && version.iBuild == 0) |
|
229 { |
|
230 ERR_PRINTF1(_L("Some version fields are not set!")); |
|
231 SetBlockResult(EFail); |
|
232 } |
|
233 |
|
234 if (version.iMajor == 0 && version.iMinor == 0) |
|
235 { |
|
236 ERR_PRINTF1(_L("Some version fields are not set!")); |
|
237 SetBlockResult(EFail); |
|
238 } |
|
239 } |
|
240 |
|
241 void CT_DataRSdp::DoCmdResourceCountMarkStart() |
|
242 { |
|
243 iRsdp->ResourceCountMarkStart(); |
|
244 } |
|
245 |
|
246 void CT_DataRSdp::DoCmdResourceCountMarkEnd() |
|
247 { |
|
248 iRsdp->ResourceCountMarkEnd(); |
|
249 } |
|
250 |
|
251 void CT_DataRSdp::DoCmdResourceCount(const TDesC& aSection) |
|
252 { |
|
253 TInt actual=iRsdp->ResourceCount(); |
|
254 INFO_PRINTF2(_L("RSdp::ResourceCount = %d"), actual); |
|
255 |
|
256 TInt expected; |
|
257 if ( GetIntFromConfig(aSection, KExpected(), expected) ) |
|
258 { |
|
259 if ( actual!=expected ) |
|
260 { |
|
261 ERR_PRINTF1(_L("ResourceCount is not as expected!")); |
|
262 SetBlockResult(EFail); |
|
263 } |
|
264 } |
|
265 } |