First public contribution.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // This file contains the definitions for
15 // the transition classes for testing the
16 // CExampleInterface class.
22 #include "TestUtilities.h" // For __FILE__LINE__
23 #include "Interface.h"
24 #include "MagicTransitions.h"
27 // __________________________________________________________________________
28 CExampleInterface_UnitTestContext::CExampleInterface_UnitTestContext(CDataLogger& aDataLogger,
29 MStateAccessor& aAccessor,
30 MTransitionObserver& aObserver)
31 : CUnitTestContext(aDataLogger, aAccessor, aObserver), iExampleInterface(NULL)
36 CExampleInterface_UnitTestContext::~CExampleInterface_UnitTestContext()
38 iListImplThread.Close();
39 delete iExampleInterface;
40 delete iSecondExampleInterface;
41 iImplementations.ResetAndDestroy();
44 //Define the transition ids for all the transitions of the CExampleInterface class
45 _LIT(KInterfaceNewLTransitionName, "CExampleInterfaceNewLTransition");
46 _LIT(KInterfaceNewWPLTransitionName, "CExampleInterfaceNewWPLTransition");
47 _LIT(KInterfaceNewResolveLTransitionName, "CExampleInterfaceNewResolveLTransition");
48 _LIT(KInterfaceDoubleNewLTransitionName, "CExampleInterfaceDoubleNewLTransition");
49 _LIT(KInterfaceDestroyTransitionName, "CExampleInterfaceDestroyTransition");
50 _LIT(KInterfaceDtorTransitionName, "CExampleInterfaceDtorTransition");
51 _LIT(KInterfaceDoubleDtorTransitionName, "CExampleInterfaceDoubleDtorTransition");
52 _LIT(KInterfaceListImplementationsLTransitionName, "CExampleInterfaceListImplementationsLTransition");
53 _LIT(KInterfacePersistLTransitionName, "CExampleInterfacePersistLTransition");
54 _LIT(KInterfaceAsynchCreateTransitionName, "CExampleInterfaceAsynchCreateTransition");
55 _LIT(KInterfaceDoMethodLTransitionName, "CExampleInterfaceDoMethodLTransition");
56 _LIT(KInterfaceFireAndForgetTransitionName, "CExampleInterfaceFireAndForgetTransition");
57 _LIT(KInterfaceListImplementationsLNewThreadTransitionName, "CExampleInterfaceListImplementationsLNewThreadTransition");
59 // For each class method implement a transition class...
60 // __________________________________________________________________________
62 CExampleInterfaceNewLTransition::CExampleInterfaceNewLTransition(CUnitTestContext& aUTContext,
63 TTransitionValidator& aValidator)
64 : CTransitionType(KInterfaceNewLTransitionName, aUTContext, aValidator)
68 void CExampleInterfaceNewLTransition::TransitMethodL()
70 _LIT(KExampleInterfaceNewLTransitMethod, "CExampleInterface::NewL transition");
71 Context().DataLogger().LogInformation(KExampleInterfaceNewLTransitMethod);
73 // Call the NewL method
74 Context().iExampleInterface = CExampleInterface::NewL();
78 inline CExampleInterface_UnitTestContext& CExampleInterfaceNewLTransition::Context()
80 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
83 // __________________________________________________________________________
84 CExampleInterfaceNewWPLTransition::CExampleInterfaceNewWPLTransition(CUnitTestContext& aUTContext,
85 TTransitionValidator& aValidator)
86 : CTransitionType(KInterfaceNewWPLTransitionName, aUTContext, aValidator)
90 void CExampleInterfaceNewWPLTransition::TransitMethodL()
92 // Call the NewL method which requires parameters
93 const TInt KTestId = 0xBDE;
94 _LIT(KTestIdDes,"0xBDE");
95 Context().iExampleInterface = CExampleInterface::NewL(KTestId,KTestIdDes());
98 inline CExampleInterface_UnitTestContext& CExampleInterfaceNewWPLTransition::Context()
100 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
103 // __________________________________________________________________________
104 CExampleInterfaceNewResolveLTransition::CExampleInterfaceNewResolveLTransition(CUnitTestContext& aUTContext,
105 TTransitionValidator& aValidator)
106 : CTransitionType(KInterfaceNewResolveLTransitionName, aUTContext, aValidator)
110 void CExampleInterfaceNewResolveLTransition::TransitMethodL()
112 // Call the NewL method which requires parameters
113 _LIT8(KTestResolveType,"text/*");
114 Context().iExampleInterface = CExampleInterface::NewL(KTestResolveType);
117 inline CExampleInterface_UnitTestContext& CExampleInterfaceNewResolveLTransition::Context()
119 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
122 // __________________________________________________________________________
124 CExampleInterfaceDoubleNewLTransition::CExampleInterfaceDoubleNewLTransition(CUnitTestContext& aUTContext,
125 TTransitionValidator& aValidator)
126 : CTransitionType(KInterfaceDoubleNewLTransitionName, aUTContext, aValidator)
130 void CExampleInterfaceDoubleNewLTransition::TransitMethodL()
132 _LIT(KExampleInterfaceNewLTransitMethod, "CExampleInterface::NewL transition");
133 Context().DataLogger().LogInformation(KExampleInterfaceNewLTransitMethod);
135 CExampleInterface* objectTwo = CExampleInterface::NewL();
136 CleanupStack::PushL(objectTwo);
137 Context().iExampleInterface = CExampleInterface::NewL();
138 Context().iSecondExampleInterface = objectTwo;
139 CleanupStack::Pop(objectTwo);
143 inline CExampleInterface_UnitTestContext& CExampleInterfaceDoubleNewLTransition::Context()
145 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
148 // __________________________________________________________________________
150 inline CExampleInterfaceDtorTransition::CExampleInterfaceDtorTransition(CUnitTestContext& aUTContext,
151 TTransitionValidator& aValidator)
152 : CTransitionType(KInterfaceDtorTransitionName, aUTContext, aValidator)
156 inline void CExampleInterfaceDtorTransition::TransitMethodL()
158 // Call the d'tor method
159 delete Context().iExampleInterface;
160 Context().iExampleInterface = NULL;
161 REComSession::FinalClose();
165 inline CExampleInterface_UnitTestContext& CExampleInterfaceDtorTransition::Context()
167 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
170 // __________________________________________________________________________
172 inline CExampleInterfaceDoubleDtorTransition::CExampleInterfaceDoubleDtorTransition(CUnitTestContext& aUTContext,
173 TTransitionValidator& aValidator)
174 : CTransitionType(KInterfaceDoubleDtorTransitionName, aUTContext, aValidator)
178 inline void CExampleInterfaceDoubleDtorTransition::TransitMethodL()
180 // Call the d'tor method
181 delete Context().iExampleInterface;
182 Context().iExampleInterface = NULL;
183 delete Context().iSecondExampleInterface;
184 Context().iSecondExampleInterface = NULL;
188 inline CExampleInterface_UnitTestContext& CExampleInterfaceDoubleDtorTransition::Context()
190 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
193 // __________________________________________________________________________
194 //Leaving method call
195 inline CExampleInterfaceDoMethodLTransition::CExampleInterfaceDoMethodLTransition(CUnitTestContext& aUTContext,
196 TTransitionValidator& aValidator)
197 : CTransitionType(KInterfaceDoMethodLTransitionName, aUTContext, aValidator)
201 inline void CExampleInterfaceDoMethodLTransition::TransitMethodL()
203 // Call the DoMethodL method
204 Context().iExampleInterface->DoMethodL();
208 inline CExampleInterface_UnitTestContext& CExampleInterfaceDoMethodLTransition::Context()
210 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
213 // __________________________________________________________________________
214 //ListImplementationsL method call
215 CExampleInterfaceListImplementationsLTransition::CExampleInterfaceListImplementationsLTransition(CUnitTestContext& aUTContext,
216 TTransitionValidator& aValidator)
217 : CTransitionType(KInterfaceListImplementationsLTransitionName, aUTContext, aValidator)
221 void CExampleInterfaceListImplementationsLTransition::TransitMethodL()
223 // Call the ListImplementationsL method
224 CExampleInterface::ListImplementationsL(Context().iImplementations);
228 inline CExampleInterface_UnitTestContext& CExampleInterfaceListImplementationsLTransition::Context()
230 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
233 // __________________________________________________________________________
234 //ListAllImplementationsL method call
235 CExampleInterfaceListAllImplementationsLTransition::CExampleInterfaceListAllImplementationsLTransition(CUnitTestContext& aUTContext,
236 TTransitionValidator& aValidator)
237 : CTransitionType(KInterfaceListImplementationsLTransitionName, aUTContext, aValidator)
241 void CExampleInterfaceListAllImplementationsLTransition::TransitMethodL()
243 // Call the ListImplementationsL method
244 CExampleInterface::ListAllImplementationsL(Context().iImplementations);
248 inline CExampleInterface_UnitTestContext& CExampleInterfaceListAllImplementationsLTransition::Context()
250 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);
253 // __________________________________________________________________________
254 //ListAllImplementationsL method call
255 CExampleInterfaceListImplementationsLNewThreadTransition::CExampleInterfaceListImplementationsLNewThreadTransition(CUnitTestContext& aUTContext,
256 TTransitionValidator& aValidator)
257 : CTransitionType(KInterfaceListImplementationsLNewThreadTransitionName, aUTContext, aValidator)
261 void CExampleInterfaceListImplementationsLNewThreadTransition::TransitMethodL()
263 // Start the new thread which will call the ListImplementationsL method
264 Context().iListImplThread.Resume();
266 // Stay here until that thread returns
267 TExitType exit = EExitPending;
268 while( exit == EExitPending)
270 exit = Context().iListImplThread.ExitType();
275 inline CExampleInterface_UnitTestContext& CExampleInterfaceListImplementationsLNewThreadTransition::Context()
277 return REINTERPRET_CAST(CExampleInterface_UnitTestContext&,iUTContext);