24
|
1 |
// Copyright (c) 2007-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 |
#ifndef CMOCKSYENGINE_H
|
|
17 |
#define CMOCKSYENGINE_H
|
|
18 |
|
|
19 |
#include <e32def.h>
|
|
20 |
#include <e32base.h>
|
|
21 |
class CRotatingStrBuf;
|
|
22 |
|
|
23 |
#define KMaxLogLineSize 255
|
|
24 |
|
|
25 |
/**
|
|
26 |
Listener to CMockSYEngine events
|
|
27 |
*/
|
|
28 |
class MMockSYEngineListener
|
|
29 |
{
|
|
30 |
public:
|
|
31 |
enum TNotificationType
|
|
32 |
{
|
|
33 |
EHandlingTerminated, //< all messages are handled
|
|
34 |
EFailure, //< receive message doesn't correspond to the expected one
|
|
35 |
};
|
|
36 |
|
|
37 |
virtual void Notify(TNotificationType aNotification) =0;
|
|
38 |
};
|
|
39 |
|
|
40 |
|
|
41 |
/**
|
|
42 |
Abstract class for command data
|
|
43 |
*/
|
|
44 |
class MMockSyEngineData
|
|
45 |
{
|
|
46 |
public:
|
|
47 |
/**
|
|
48 |
Comparator: compare the data with it packaged version from an Event
|
|
49 |
*/
|
|
50 |
virtual TBool operator ==(const TDesC8& aData) const =0;
|
|
51 |
};
|
|
52 |
|
|
53 |
|
|
54 |
/**
|
|
55 |
Abstract class for the logger
|
|
56 |
*/
|
|
57 |
|
|
58 |
/**
|
|
59 |
Mock SY engine base class
|
|
60 |
*/
|
|
61 |
class CMockSYEngine : public CBase
|
|
62 |
{
|
|
63 |
public:
|
|
64 |
IMPORT_C virtual ~CMockSYEngine();
|
|
65 |
|
|
66 |
public:
|
|
67 |
/**
|
|
68 |
Called by the SY, handle received command by verifing that is the expected command
|
|
69 |
and queuing the conresponding completions
|
|
70 |
Return KErrCorrupt it it's not the expected command
|
|
71 |
*/
|
|
72 |
IMPORT_C TInt ExecuteCommandL(TInt aCmdId, MMockSyEngineData& aData);
|
|
73 |
/**
|
|
74 |
Check data or not depending on the aCheckData
|
|
75 |
*/
|
|
76 |
IMPORT_C TInt ExecuteCommandL(TInt aCmdId, MMockSyEngineData& aData, TBool aCheckData);
|
|
77 |
|
|
78 |
public:
|
|
79 |
inline void SessionClosed();
|
|
80 |
inline void QueueEpectedCallL(TInt aCmdId, TInt aErrorCode, TBool aLeave, HBufC8* aData);
|
|
81 |
inline void QueueReturnCallL(TInt aCmdId, TInt aErrorCode, TInt aDelay, HBufC8* aData);
|
|
82 |
HBufC* GetNextLogLine();
|
|
83 |
|
|
84 |
inline TBool HasWaitingEvents() const;
|
|
85 |
inline TBool HasPendingEvents() const;
|
|
86 |
inline TBool HasFailure() const;
|
|
87 |
IMPORT_C void CheckAndUpdateTransId(TUint8 aTransId, TInt aCommandId);
|
|
88 |
|
|
89 |
public: // listener API
|
|
90 |
void AddListenerL(MMockSYEngineListener& aListener);
|
|
91 |
void RemoveListener(MMockSYEngineListener& aListener);
|
|
92 |
TInt PauseCompletion();
|
|
93 |
TInt ResumeCompletion();
|
|
94 |
|
|
95 |
protected:
|
|
96 |
IMPORT_C virtual void ConstructL();
|
|
97 |
IMPORT_C CMockSYEngine();
|
|
98 |
|
|
99 |
protected:
|
|
100 |
/**
|
|
101 |
A LTSY event.
|
|
102 |
It can be a message as received from the LTSY or a completion to send to CTSY
|
|
103 |
*/
|
|
104 |
class TMockSYEvent
|
|
105 |
{
|
|
106 |
public:
|
|
107 |
enum TEventType
|
|
108 |
{
|
|
109 |
EMessage,
|
|
110 |
ECompletion
|
|
111 |
};
|
|
112 |
TEventType iEventType; //< Event type
|
|
113 |
TInt iCmdId; //< expected cmdId or cmdId to complete
|
|
114 |
TInt iResultCode; //< Message or completion result code
|
|
115 |
TBool iLeave; //< If True, leave with iResultCode error
|
|
116 |
TInt iDelay; //< for completion: delay before sending the completion
|
|
117 |
RBuf8 iData; //< Message or completion data
|
|
118 |
public:
|
|
119 |
TDblQueLink iWaitingEventQueLink; //< Link for the waiting event queue
|
|
120 |
TDeltaQueLink iPendingEventQueLink; //< Link for the pending event queue
|
|
121 |
};
|
|
122 |
|
|
123 |
protected:
|
|
124 |
/**
|
|
125 |
Complete aEvent. Subclass must implement this function and complete the
|
|
126 |
SY request
|
|
127 |
*/
|
|
128 |
virtual void DoCompleteEventL(const TMockSYEvent& aEvent) =0;
|
|
129 |
/**
|
|
130 |
Queue an event.
|
|
131 |
*/
|
|
132 |
IMPORT_C virtual void DoQueueEventL(TMockSYEvent::TEventType aType, TInt aCmdId, HBufC8* aData,
|
|
133 |
TInt aResultCode, TBool aLeave, TInt aDelay);
|
|
134 |
/**
|
|
135 |
Returns if MockSY can ignore a given unexpected IPC error.
|
|
136 |
*/
|
|
137 |
IMPORT_C virtual TBool CanIgnoreUnexpectedIpc(TInt aCmdId);
|
|
138 |
|
|
139 |
private:
|
|
140 |
TDblQue<TMockSYEvent> iWaitingEventQue;
|
|
141 |
TDeltaQue<TMockSYEvent> iPendingEventQue;
|
|
142 |
TBool iFailure;
|
|
143 |
|
|
144 |
CPeriodic* iTimer;
|
|
145 |
|
|
146 |
RPointerArray<MMockSYEngineListener> iListeners;
|
|
147 |
|
|
148 |
private:
|
|
149 |
void DoTimerCallbackL();
|
|
150 |
|
|
151 |
protected:
|
|
152 |
IMPORT_C virtual void Failure();
|
|
153 |
IMPORT_C virtual void Reset();
|
|
154 |
|
|
155 |
private: // listener API
|
|
156 |
void NotifyListeners(MMockSYEngineListener::TNotificationType aNotification);
|
|
157 |
|
|
158 |
protected: // logging: can be override to log specific informations
|
|
159 |
IMPORT_C virtual void LogRequest(TInt aCmdId, const MMockSyEngineData& aData,TInt aResultCode);
|
|
160 |
IMPORT_C virtual void LogCompletion(TInt aCmdId, const TDesC8& aData,TInt aResultCode);
|
|
161 |
IMPORT_C virtual void LogExpectError(TInt aCmdId, const MMockSyEngineData& aData,TInt aExpectedCmd,const TDesC8& aExpectedData, TBool aIsErrorIgnored=EFalse);
|
|
162 |
IMPORT_C virtual void Log(const TDesC& aDesc);
|
|
163 |
|
|
164 |
private: // static timer callback
|
|
165 |
CRotatingStrBuf* iRotatingLog;
|
|
166 |
static TInt TimerCallbackL(TAny* aPtr);
|
|
167 |
TBool iPaused;
|
|
168 |
};
|
|
169 |
|
|
170 |
|
|
171 |
// inlines
|
|
172 |
inline void CMockSYEngine::QueueEpectedCallL(TInt aCmdId, TInt aErrorCode, TBool aLeave, HBufC8* aData)
|
|
173 |
{
|
|
174 |
DoQueueEventL(TMockSYEvent::EMessage, aCmdId, aData, aErrorCode, aLeave, 0);
|
|
175 |
}
|
|
176 |
|
|
177 |
inline void CMockSYEngine::QueueReturnCallL(TInt aCmdId, TInt aErrorCode, TInt aDelay, HBufC8* aData)
|
|
178 |
{
|
|
179 |
DoQueueEventL(TMockSYEvent::ECompletion, aCmdId, aData, aErrorCode, EFalse, aDelay);
|
|
180 |
}
|
|
181 |
|
|
182 |
inline TBool CMockSYEngine::HasWaitingEvents() const
|
|
183 |
{
|
|
184 |
return !iWaitingEventQue.IsEmpty();
|
|
185 |
}
|
|
186 |
|
|
187 |
inline TBool CMockSYEngine::HasPendingEvents() const
|
|
188 |
{
|
|
189 |
return !iPendingEventQue.IsEmpty();
|
|
190 |
}
|
|
191 |
|
|
192 |
inline TBool CMockSYEngine::HasFailure() const
|
|
193 |
{
|
|
194 |
return iFailure;
|
|
195 |
}
|
|
196 |
|
|
197 |
/**
|
|
198 |
Called when the session using this engine is closed
|
|
199 |
*/
|
|
200 |
inline void CMockSYEngine::SessionClosed()
|
|
201 |
{
|
|
202 |
iFailure = EFalse;
|
|
203 |
Reset();
|
|
204 |
}
|
|
205 |
|
|
206 |
#endif
|