|
1 // Copyright (c) 2006-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 CFAKEINPUTSTREAM_H |
|
17 #define CFAKEINPUTSTREAM_H |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <test/tefunit.h> |
|
21 #include "minputstream.h" |
|
22 #include "minputstreamobserver.h" |
|
23 |
|
24 typedef RArray<TPtrC8> RArrayPtrC8; |
|
25 |
|
26 /** |
|
27 Observer interface that notifies interested unit tests when CFakeInputStream |
|
28 has finished delivering the data it has been given to deliver. |
|
29 This gives unit test the opportunity to perform tasks (such as Canceling a request) |
|
30 before all the data has been delivered. |
|
31 A unit test can initially give CFakeInputStream a partial set of data |
|
32 (e.g. not containing the tagged response) |
|
33 and then give it the remainder of the data (e.g. containing the tagged response) |
|
34 upon notification of this observer interface. |
|
35 @internalTechnology |
|
36 @prototype |
|
37 */ |
|
38 class MFakeInputStreamIsEmptyObserver |
|
39 { |
|
40 public: |
|
41 /** |
|
42 This method is called by CFakeInputStream when it has delivered all the data in iInputStrings. |
|
43 @param aInputStrings update this array with more data to deliver. |
|
44 */ |
|
45 virtual void OnInputStreamIsEmptyL() =0; |
|
46 }; |
|
47 |
|
48 /** |
|
49 A dummy input stream object. |
|
50 The owner of this object can set up a sequence of data to send to the observer via SetInputStrings. |
|
51 Each item in the iInputStrings array will be sent to the observer in a single call to its |
|
52 ReceivedDataIndL() method. The next string in the array will not be sent until ReadReq() has |
|
53 been called by the observer to indicate that the previous string has been consumed. |
|
54 @internalTechnology |
|
55 @prototype |
|
56 */ |
|
57 class CFakeInputStream : public CActive |
|
58 , public MInputStream |
|
59 { |
|
60 public: |
|
61 static CFakeInputStream* NewL(CTestExecuteLogger& aLogger); |
|
62 ~CFakeInputStream(); |
|
63 |
|
64 void NotifyWhenStreamIsEmpty(MFakeInputStreamIsEmptyObserver& aStreamIsEmptyObserver); |
|
65 |
|
66 void AppendInputStringL(const TDesC8& aString); |
|
67 void ResetInputStrings(); |
|
68 |
|
69 protected: |
|
70 // Implement MInputStream |
|
71 void Bind(MInputStreamObserver& aInputStreamObserver, TInt aLogId); |
|
72 void ReadReq(TInt aIdleTime = 0); |
|
73 void CancelReadReq(); |
|
74 TBool IsReading(); |
|
75 |
|
76 void CompleteSelf(TInt aError); |
|
77 |
|
78 // Implements CActive |
|
79 void RunL(); |
|
80 void DoCancel(); |
|
81 |
|
82 inline CTestExecuteLogger& Logger() { return iLogger; } |
|
83 |
|
84 private: |
|
85 CFakeInputStream(CTestExecuteLogger& aLogger); |
|
86 |
|
87 private: |
|
88 CTestExecuteLogger& iLogger; |
|
89 MInputStreamObserver* iInputStreamObserver; |
|
90 |
|
91 MFakeInputStreamIsEmptyObserver* iStreamIsEmptyObserver; |
|
92 |
|
93 RArrayPtrC8 iInputStrings; |
|
94 TInt iNextInputString; |
|
95 |
|
96 TBool iIsReading; |
|
97 }; |
|
98 |
|
99 #endif // CFAKEINPUTSTREAM_H |