|
1 // Copyright (c) 2002-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 // |
|
15 |
|
16 |
|
17 #include "ObexTestUtils.h" |
|
18 // System includes |
|
19 #include <msvids.h> |
|
20 #include <msvuids.h> |
|
21 #include <mtclbase.h> // CBaseMtm |
|
22 #include <mtsr.h> // CBaseServerMtm |
|
23 #include <btmsgtypeuid.h> // KUidMsgTypeBt |
|
24 #include <irmsgtypeuid.h> // KUidMsgTypeIr |
|
25 // User includes |
|
26 |
|
27 _LIT(KObexTestPanicLiteral, "Obex Test"); // literal for panic |
|
28 |
|
29 |
|
30 CObexTestUtils* CObexTestUtils::NewL(RTest& aTest, TUint aCreationFlags) |
|
31 { |
|
32 CObexTestUtils* self = NewLC(aTest, aCreationFlags); |
|
33 CleanupStack::Pop(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CObexTestUtils* CObexTestUtils::NewLC(RTest& aTest, TUint aCreationFlags) |
|
38 { |
|
39 CObexTestUtils* self = new (ELeave) CObexTestUtils(aTest); |
|
40 CleanupStack::PushL(self); |
|
41 self->ConstructL(aCreationFlags); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CObexTestUtils::CObexTestUtils(RTest& aTest) : |
|
46 CMsvTestUtils(aTest), |
|
47 iBTServiceId(KMsvUnknownServiceIndexEntryId), |
|
48 iIRServiceId(KMsvUnknownServiceIndexEntryId), |
|
49 iCurrentMtm(KUidMsvNullEntry) |
|
50 { |
|
51 // StartC32(); //TODO:- required? |
|
52 } |
|
53 |
|
54 void CObexTestUtils::ConstructL(TUint aCreationFlags) |
|
55 { |
|
56 CMsvTestUtils::ConstructL(aCreationFlags); |
|
57 } |
|
58 |
|
59 CObexTestUtils::~CObexTestUtils() |
|
60 { |
|
61 delete iBTClientMtm; |
|
62 delete iBTServerMtm; |
|
63 delete iIRClientMtm; |
|
64 delete iIRServerMtm; |
|
65 } |
|
66 |
|
67 const CBaseMtm& CObexTestUtils::GetCurrentObexClientMtm() const |
|
68 { |
|
69 __ASSERT_ALWAYS( iCurrentMtm != KUidMsvNullEntry, User::Panic(KObexTestPanicLiteral, KErrNotReady) ); |
|
70 return (iCurrentMtm == KUidMsgTypeBt) ? *iBTClientMtm : *iIRClientMtm; |
|
71 } |
|
72 |
|
73 CBaseMtm& CObexTestUtils::GetCurrentObexClientMtm() |
|
74 { |
|
75 __ASSERT_ALWAYS( iCurrentMtm != KUidMsvNullEntry, User::Panic(KObexTestPanicLiteral, KErrNotReady) ); |
|
76 return (iCurrentMtm == KUidMsgTypeBt) ? *iBTClientMtm : *iIRClientMtm; |
|
77 } |
|
78 |
|
79 const CBaseServerMtm& CObexTestUtils::GetCurrentObexServerMtm() const |
|
80 { |
|
81 __ASSERT_ALWAYS( iCurrentMtm != KUidMsvNullEntry, User::Panic(KObexTestPanicLiteral, KErrNotReady) ); |
|
82 return (iCurrentMtm == KUidMsgTypeBt) ? *iBTServerMtm : *iIRServerMtm; |
|
83 } |
|
84 |
|
85 CBaseServerMtm& CObexTestUtils::GetCurrentObexServerMtm() |
|
86 { |
|
87 __ASSERT_ALWAYS( iCurrentMtm != KUidMsvNullEntry, User::Panic(KObexTestPanicLiteral, KErrNotReady) ); |
|
88 return (iCurrentMtm == KUidMsgTypeBt) ? *iBTServerMtm : *iIRServerMtm; |
|
89 } |
|
90 |
|
91 TMsvId CObexTestUtils::GetCurrentServiceId() const |
|
92 { |
|
93 __ASSERT_ALWAYS( iCurrentMtm != KUidMsvNullEntry, User::Panic(KObexTestPanicLiteral, KErrNotReady) ); |
|
94 return (iCurrentMtm == KUidMsgTypeBt) ? iBTServiceId : iIRServiceId; |
|
95 } |
|
96 |
|
97 void CObexTestUtils::InstantiateClientMtmsL() |
|
98 { |
|
99 InstantiateBTClientMtmL(); |
|
100 InstantiateIRClientMtmL(); |
|
101 } |
|
102 |
|
103 void CObexTestUtils::InstantiateServerMtmsL() |
|
104 { |
|
105 InstantiateBTServerMtmL(); |
|
106 InstantiateIRServerMtmL(); |
|
107 } |
|
108 |
|
109 void CObexTestUtils::InstantiateBTClientMtmL() |
|
110 { |
|
111 delete iBTClientMtm; |
|
112 iBTClientMtm = NULL; |
|
113 iBTClientMtm = InstantiateClientMtmL(KUidMsgTypeBt, iBTServiceId); |
|
114 } |
|
115 |
|
116 void CObexTestUtils::InstantiateBTServerMtmL() |
|
117 { |
|
118 delete iBTServerMtm; |
|
119 iBTServerMtm = NULL; |
|
120 iBTServerMtm = InstantiateServerMtmL(KUidMsgTypeBt, iBTServiceId); |
|
121 } |
|
122 |
|
123 void CObexTestUtils::InstantiateIRClientMtmL() |
|
124 { |
|
125 delete iIRClientMtm; |
|
126 iIRClientMtm = NULL; |
|
127 iIRClientMtm = InstantiateClientMtmL(KUidMsgTypeIrUID, iIRServiceId); |
|
128 } |
|
129 |
|
130 void CObexTestUtils::InstantiateIRServerMtmL() |
|
131 { |
|
132 delete iIRServerMtm; |
|
133 iIRServerMtm = NULL; |
|
134 iIRServerMtm = InstantiateServerMtmL(KUidMsgTypeIrUID, iIRServiceId); |
|
135 } |
|
136 |
|
137 void CObexTestUtils::DeleteServicesL() |
|
138 { |
|
139 DeleteServiceL(KUidMsgTypeBt); |
|
140 DeleteServiceL(KUidMsgTypeIrUID); |
|
141 } |
|
142 |
|
143 void CObexTestUtils::CreateServicesL() |
|
144 { |
|
145 iBTServiceId = CreateObexServiceL(KUidMsgTypeBt); |
|
146 iIRServiceId = CreateObexServiceL(KUidMsgTypeIrUID); |
|
147 } |
|
148 |
|
149 void CObexTestUtils::FindExistingServicesL() |
|
150 { |
|
151 TInt err = KErrNone; |
|
152 |
|
153 TRAP(err, ServiceIdL(KUidMsgTypeBt, iBTServiceId)); |
|
154 |
|
155 if (err != KErrNone) |
|
156 { |
|
157 _LIT(KBTEntryNotFound, "Bluetooth Service Entry Not Found\n"); |
|
158 Printf(KBTEntryNotFound); |
|
159 } |
|
160 |
|
161 TRAP(err, ServiceIdL(KUidMsgTypeIrUID, iIRServiceId)); |
|
162 |
|
163 if (err != KErrNone) |
|
164 { |
|
165 _LIT(KIREntryNotFound, "Ir Service Entry Not Found\n"); |
|
166 Printf(KIREntryNotFound); |
|
167 } |
|
168 } |
|
169 |
|
170 void CObexTestUtils::CreateServerMtmRegsL() |
|
171 { |
|
172 User::Leave(KErrNotSupported); |
|
173 } |
|
174 |
|
175 void CObexTestUtils::InstallMtmGroupsL() |
|
176 { |
|
177 if(iMsvSession) |
|
178 { |
|
179 User::LeaveIfError(iMsvSession->InstallMtmGroup(_L("z:\\system\\libs\\BTMTM.RSC"))); |
|
180 User::LeaveIfError(iMsvSession->InstallMtmGroup(_L("z:\\system\\libs\\IRMTM.RSC"))); |
|
181 } |
|
182 else |
|
183 WriteComment(_L("can't install mtms as there's no session\n")); |
|
184 } |
|
185 |
|
186 TMsvId CObexTestUtils::CreateObexServiceL(TUid aMsgType) |
|
187 { |
|
188 __ASSERT_ALWAYS( aMsgType == KUidMsgTypeBt || aMsgType == KUidMsgTypeIrUID, Panic(KErrArgument) ); |
|
189 |
|
190 TInt err = KErrNone; |
|
191 TMsvId serviceId = 0; |
|
192 |
|
193 //Get the first service entry for the message type |
|
194 TRAP(err, ServiceIdL(aMsgType, serviceId)); |
|
195 |
|
196 //Create a new service entry if one doesn't exist. Otherwise, use the existing one |
|
197 if (err != KErrNone) |
|
198 { |
|
199 _LIT(KCreatingServiceEntry, "Creating New Service Entry.\n"); |
|
200 Printf(KCreatingServiceEntry); |
|
201 serviceId = CreateServiceL(aMsgType); |
|
202 } |
|
203 else |
|
204 { |
|
205 _LIT(KUsingExistingServiceEntry, "Using Existing Service Entry.\n"); |
|
206 Printf(KUsingExistingServiceEntry); |
|
207 } |
|
208 |
|
209 //set the service Id attribute for the particular message type |
|
210 TMsvId& id = (aMsgType == KUidMsgTypeBt ? iBTServiceId : iIRServiceId); |
|
211 id = serviceId; |
|
212 |
|
213 return serviceId; |
|
214 } |
|
215 |
|
216 |
|
217 void CObexTestUtils::Reset() |
|
218 { |
|
219 delete iBTClientMtm; |
|
220 iBTClientMtm = NULL; |
|
221 delete iBTServerMtm; |
|
222 iBTServerMtm = NULL; |
|
223 delete iIRClientMtm; |
|
224 iIRClientMtm = NULL; |
|
225 delete iIRServerMtm; |
|
226 iIRServerMtm = NULL; |
|
227 |
|
228 CMsvTestUtils::Reset(); |
|
229 } |
|
230 |
|
231 void CObexTestUtils::Panic(TInt aPanic) |
|
232 { |
|
233 User::Panic(KObexTestPanicLiteral, aPanic); |
|
234 } |
|
235 |
|
236 |
|
237 TUid CObexTestUtils::CurrentObexMtm() const |
|
238 { |
|
239 return iCurrentMtm; |
|
240 } |
|
241 |
|
242 TBool CObexTestUtils::SelectObexMtmL(TUid aMsgType) |
|
243 { |
|
244 __ASSERT_ALWAYS( aMsgType == KUidMsgTypeBt || aMsgType == KUidMsgTypeIrUID, Panic(KErrArgument) ); |
|
245 |
|
246 if (!iClientMtmRegistry) |
|
247 { |
|
248 iClientMtmRegistry = CClientMtmRegistry::NewL(*iMsvSession); |
|
249 } |
|
250 |
|
251 TBool present = iClientMtmRegistry->IsPresent(aMsgType); |
|
252 |
|
253 if(present) |
|
254 iCurrentMtm = aMsgType; |
|
255 |
|
256 return present; |
|
257 } |
|
258 |
|
259 |
|
260 void CObexTestUtils::RegisterIRMtmL() |
|
261 { |
|
262 if(iMsvSession) |
|
263 { |
|
264 User::LeaveIfError(iMsvSession->InstallMtmGroup(_L("z:\\resource\\messaging\\mtm\\IRMTM.RSC"))); |
|
265 } |
|
266 else |
|
267 WriteComment(_L("can't install IR Mtm as there's no session\n")); |
|
268 } |
|
269 |
|
270 void CObexTestUtils::RegisterBTMtmL() |
|
271 { |
|
272 if(iMsvSession) |
|
273 { |
|
274 User::LeaveIfError(iMsvSession->InstallMtmGroup(_L("z:\\resource\\messaging\\mtm\\BTMTM.RSC"))); |
|
275 } |
|
276 else |
|
277 WriteComment(_L("can't install BT Mtm as there's no session\n")); |
|
278 } |
|
279 |
|
280 void CObexTestUtils::UnRegisterIRMtmL() |
|
281 { |
|
282 if(iMsvSession) |
|
283 { |
|
284 User::LeaveIfError(iMsvSession->DeInstallMtmGroup(_L("z:\\system\\libs\\IRMTM.RSC"))); |
|
285 } |
|
286 else |
|
287 WriteComment(_L("can't deinstall IR Mtm as there's no session\n")); |
|
288 } |
|
289 |
|
290 void CObexTestUtils::UnRegisterBTMtmL() |
|
291 { |
|
292 if(iMsvSession) |
|
293 { |
|
294 User::LeaveIfError(iMsvSession->DeInstallMtmGroup(_L("z:\\system\\libs\\BTMTM.RSC"))); |
|
295 } |
|
296 else |
|
297 WriteComment(_L("can't deinstall BT Mtm as there's no session\n")); |
|
298 } |