|
1 /* |
|
2 * Copyright (c) 2006 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: Test support file tool |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CPRFWTESTFILETOOL_H |
|
20 #define CPRFWTESTFILETOOL_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <ximpbase.h> |
|
24 |
|
25 class CXIMPApiEventBase; |
|
26 class CXIMPTestFileSrvMsg; |
|
27 class MXIMPTestFileObserver; |
|
28 |
|
29 /** |
|
30 * File support for tests. |
|
31 * Support functions for externalizing a class to a known directory and |
|
32 * retrieving the classes. |
|
33 * |
|
34 * This is a sort of "pseudo-IPC" from the test protocol (ecom plugin) |
|
35 * to EUnit test code. A server could also be used, but this is faster |
|
36 * to do and simpler. |
|
37 * |
|
38 * @since S60 v4.0 |
|
39 */ |
|
40 class CXIMPTestFileTool : public CBase |
|
41 { |
|
42 public: |
|
43 |
|
44 IMPORT_C static CXIMPTestFileTool* NewL( TUint32 aUid, const TDesC16& aInstanceId ); |
|
45 IMPORT_C static CXIMPTestFileTool* NewL( TUint32 aUid, TInt aInstanceIdAsNum ); |
|
46 virtual ~CXIMPTestFileTool(); |
|
47 |
|
48 private: |
|
49 |
|
50 CXIMPTestFileTool( TUint32 aUid ); |
|
51 void ConstructL( const TDesC16& aInstanceId ); |
|
52 void ConstructL( TInt aInstanceIdAsNum ); |
|
53 |
|
54 public: |
|
55 |
|
56 /** |
|
57 * Clean all files from the filetool directory. |
|
58 * Remove also the directory itself. |
|
59 * Removes EVERYTHING from ALL DIRECTORIES used |
|
60 * by filetool!!! So don't call it everytime, only once |
|
61 * upon test case startup. |
|
62 */ |
|
63 IMPORT_C static void CleanAllL(); |
|
64 |
|
65 /** |
|
66 * Prepares for writing only the directory used by this |
|
67 * filetool instance |
|
68 */ |
|
69 IMPORT_C void PrepareL(); |
|
70 |
|
71 /** |
|
72 * Store the object to file. |
|
73 * The given descriptor is externalized as given, |
|
74 * with the length of the descriptor written first, |
|
75 * as a 32-bit TUint: |
|
76 * <length of descriptor 32-bit><descriptor data> |
|
77 * @param aExternalizedObject The externalized object |
|
78 */ |
|
79 IMPORT_C void PluginStoreL( const TDesC8& aExternalizedObject ); |
|
80 |
|
81 /** |
|
82 * Restore a stored object from file. |
|
83 * Ownership is transferred! |
|
84 * @param aObjIndex The index for the object |
|
85 */ |
|
86 IMPORT_C CXIMPApiEventBase* PluginRestoreLC( TInt aObjIndex ); |
|
87 |
|
88 /** |
|
89 * Store the object to file. (SERVER MESSAGE) |
|
90 * The given descriptor is externalized as given, |
|
91 * with the length of the descriptor written first, |
|
92 * as a 32-bit TUint: |
|
93 * <length of descriptor 32-bit><descriptor data> |
|
94 * @param aExternalizedObject The externalized object |
|
95 */ |
|
96 IMPORT_C void SrvMsgStoreL( CXIMPTestFileSrvMsg* aSrvMsg ); |
|
97 |
|
98 /** |
|
99 * Restore a stored object from file. (SERVER MESSAGE) |
|
100 * Ownership is transferred! |
|
101 * @param aIndex The index for the object |
|
102 */ |
|
103 IMPORT_C CXIMPTestFileSrvMsg* SrvMsgRestoreLC( TInt aIndex ); |
|
104 |
|
105 /** |
|
106 * Return the number of objects currently stored in the directory. |
|
107 */ |
|
108 IMPORT_C TInt NumObjectsL(); |
|
109 |
|
110 /** |
|
111 * Return the number of objects depicting server-originated |
|
112 * message currently stored in the directory. |
|
113 */ |
|
114 IMPORT_C TInt NumSrvMsgL(); |
|
115 |
|
116 /** |
|
117 * @return Instance id |
|
118 */ |
|
119 IMPORT_C const TDesC16& InstanceId() const; |
|
120 |
|
121 private: |
|
122 |
|
123 /** |
|
124 * @return The directory name (with backslash) |
|
125 * (E.g. "C:/temp/prfw/1234/0/SrvMsg/") |
|
126 */ |
|
127 HBufC* GetDirNameAndBackslashLC( |
|
128 const TDesC& aTemplate ); |
|
129 |
|
130 /** |
|
131 * @return Wildcard for file deletion |
|
132 * (E.g. "C:/temp/prfw/1234/0/SrvMsg/file*.prfw") |
|
133 * @param aDirTemplate The directory template for the wildcard |
|
134 */ |
|
135 HBufC* GetWildcardLC( |
|
136 const TDesC& aDirTemplate ); |
|
137 |
|
138 /** |
|
139 * Get the full file name, properly expanded. |
|
140 * @param aDirTemplate The template for the dirs |
|
141 * @param aObjIndex The object index |
|
142 */ |
|
143 HBufC* GetFileNameLC( |
|
144 const TDesC& aDirTemplate, |
|
145 TInt aObjIndex ); |
|
146 |
|
147 /** |
|
148 * @return Length of the given number as if it were a string. |
|
149 * @param aNum The number |
|
150 */ |
|
151 TInt NumLenInChars( TInt aNum ); |
|
152 |
|
153 /** |
|
154 * @return Listing of the directory |
|
155 * @param aTemplate The wildcard template for the files |
|
156 */ |
|
157 CDir* GetDirListL( const TDesC& aTemplate ); |
|
158 |
|
159 /** |
|
160 * Common helper for NumObjects methods. |
|
161 */ |
|
162 TInt DoNumObjectsL( const TDesC& aTemplate ); |
|
163 |
|
164 /** |
|
165 * |
|
166 */ |
|
167 static TInt Process( TAny* aMyself ); |
|
168 void DoProcessL(); |
|
169 |
|
170 public: |
|
171 |
|
172 /** |
|
173 * Observer registration |
|
174 */ |
|
175 void RegisterObserverL( MXIMPTestFileObserver* aObserver ); |
|
176 void UnregisterObserver( MXIMPTestFileObserver* aObserver ); |
|
177 |
|
178 |
|
179 private: // data |
|
180 |
|
181 TUint32 iUid; // protocoluid |
|
182 HBufC16* iInstance; // the global instance id |
|
183 |
|
184 TInt iObjIndex; // object index for created objects |
|
185 TInt iSrvObjIndex; // object index for created srvmsg objects |
|
186 RFs iFs; |
|
187 |
|
188 |
|
189 /** |
|
190 * Monitor on when there is observers. |
|
191 * Call HandleL for observers for every new file. |
|
192 */ |
|
193 RPointerArray< MXIMPTestFileObserver > iObservers; |
|
194 |
|
195 // timer |
|
196 CPeriodic* iTimer; |
|
197 }; |
|
198 |
|
199 #endif // CPRFWTESTFILETOOL_H |