|
1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @test |
|
21 @internalComponent - Internal Symbian test code |
|
22 */ |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <e32math.h> |
|
26 |
|
27 #include "appfwk_test_utils.h" |
|
28 |
|
29 |
|
30 |
|
31 const TUid KServerUid3 = {0x10009FBD}; |
|
32 |
|
33 |
|
34 /** |
|
35 Start the server process. Simultaneous launching of two such processes should be detected when the second one attempts to |
|
36 create the server object, failing with KErrAlreadyExists. |
|
37 */ |
|
38 static TInt StartServer() |
|
39 { |
|
40 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
41 RProcess server; |
|
42 TInt r = server.Create(KTestServerImg,KNullDesC,serverUid); |
|
43 if (r!=KErrNone) |
|
44 { |
|
45 return r; |
|
46 } |
|
47 |
|
48 TRequestStatus stat; |
|
49 server.Rendezvous(stat); |
|
50 if (stat!=KRequestPending) |
|
51 { |
|
52 server.Kill(0); |
|
53 } |
|
54 else |
|
55 { |
|
56 server.Resume(); |
|
57 } |
|
58 |
|
59 // wait for start or death |
|
60 User::WaitForRequest(stat); |
|
61 server.Close(); |
|
62 |
|
63 return stat.Int(); |
|
64 } |
|
65 |
|
66 |
|
67 /** |
|
68 Connect to the server, attempting to start it if necessary |
|
69 */ |
|
70 EXPORT_C TInt RSmlTestUtils::Connect() |
|
71 { |
|
72 TInt retry=2; |
|
73 for (;;) |
|
74 { |
|
75 TInt r=CreateSession(KTestServerName,TVersion(0,0,0),1); |
|
76 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
77 { |
|
78 return r; |
|
79 } |
|
80 if (--retry==0) |
|
81 { |
|
82 return r; |
|
83 } |
|
84 r=StartServer(); |
|
85 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
86 { |
|
87 return r; |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 |
|
93 EXPORT_C void RSmlTestUtils::SetDevIdL(const TDesC8& aDevId) |
|
94 { |
|
95 TIpcArgs args(&aDevId); |
|
96 User::LeaveIfError(SendReceive(EChangeDevId,args)); |
|
97 } |
|
98 |
|
99 |
|
100 EXPORT_C void RSmlTestUtils::GetDevIdL(TDes8& aDevId) |
|
101 { |
|
102 TIpcArgs args(&aDevId); |
|
103 User::LeaveIfError(SendReceive(EGetDevId, args)); |
|
104 } |
|
105 |
|
106 |
|
107 EXPORT_C TInt RSmlTestUtils::WipeDataStoreL(TWipeItems aItemsToClean) |
|
108 { |
|
109 TPckgBuf<TWipeItems> temp(aItemsToClean); |
|
110 TIpcArgs args(&temp); |
|
111 User::LeaveIfError(SendReceive(EWipeDataStore, args)); |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 |
|
116 EXPORT_C TInt RSmlTestUtils::RenameDirectoryL(const TDesC16& aSrc,const TDesC16& aDest) |
|
117 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
118 TIpcArgs args(&aSrc,&aDest); |
|
119 TInt ret = SendReceive(ERenameDir, args); |
|
120 return ret; |
|
121 } |
|
122 |
|
123 |
|
124 EXPORT_C TInt RSmlTestUtils::CreateDirectoryL(const TDesC& aPath) |
|
125 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
126 TIpcArgs args(&aPath); |
|
127 TInt ret = SendReceive(ECreateDir, args); |
|
128 return ret; |
|
129 } |
|
130 |
|
131 |
|
132 EXPORT_C TInt RSmlTestUtils::DeleteDirectoryL(const TDesC& aPath) |
|
133 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
134 TIpcArgs args(&aPath); |
|
135 TInt ret = SendReceive(EDeleteDir, args); |
|
136 return ret; |
|
137 } |
|
138 |
|
139 |
|
140 EXPORT_C TInt RSmlTestUtils::CreateFileL(const TDesC& aPath) |
|
141 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
142 TIpcArgs args(&aPath); |
|
143 TInt ret = SendReceive(ECreateFile, args); |
|
144 return ret; |
|
145 } |
|
146 |
|
147 |
|
148 EXPORT_C TInt RSmlTestUtils::DeleteFileL(const TDesC& aPath) |
|
149 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
150 TIpcArgs args(&aPath); |
|
151 TInt ret = SendReceive(EDeleteFile, args); |
|
152 return ret; |
|
153 } |
|
154 |
|
155 |
|
156 EXPORT_C TInt RSmlTestUtils::DeleteFileUsingWildcardL(const TDesC& aPath) |
|
157 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
158 TIpcArgs args(&aPath); |
|
159 TInt ret = SendReceive(EDeleteFileUsingWildcard, args); |
|
160 return ret; |
|
161 } |
|
162 |
|
163 |
|
164 EXPORT_C TInt RSmlTestUtils::CopyFileL(const TDesC& aSrc,const TDesC& aDest) |
|
165 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
166 TIpcArgs args(&aSrc,&aDest); |
|
167 TInt ret = SendReceive(ECopyFile, args); |
|
168 return ret; |
|
169 } |
|
170 |
|
171 // lint warning stating that aTime could be a const reference, |
|
172 // but since this is derived from product code, it cannot be |
|
173 // changed here, and hence the warning is suppressed |
|
174 //lint -efunc(1746,RSmlTestUtils::SetHomeTimeL) |
|
175 EXPORT_C void RSmlTestUtils::SetHomeTimeL(const TTime aTime) |
|
176 { |
|
177 TPckgBuf<TTime> temp(aTime); |
|
178 TIpcArgs args(&temp); |
|
179 User::LeaveIfError(SendReceive(ESetHomeTime, args)); |
|
180 } |
|
181 |
|
182 |
|
183 EXPORT_C TInt RSmlTestUtils::ReplaceFileL(const TDesC& aName,TUint aFileMode) |
|
184 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
185 TPckgBuf<TUint> temp(aFileMode); |
|
186 TIpcArgs args(&aName,&temp); |
|
187 TInt ret = SendReceive(EReplaceFile, args); |
|
188 return ret; |
|
189 } |
|
190 |
|
191 |
|
192 EXPORT_C TInt RSmlTestUtils::IsFilePresent(const TDesC& aName, TBool &aPresent) |
|
193 { |
|
194 TPckgBuf<TBool> present(aPresent); |
|
195 TIpcArgs args(&aName,&present); |
|
196 TInt ret = SendReceive(EIsFilePresent, args); |
|
197 aPresent = present(); |
|
198 return ret; |
|
199 } |
|
200 |
|
201 |
|
202 EXPORT_C TInt RSmlTestUtils::SetReadOnly(const TDesC& aName,TUint aSetAttMask) |
|
203 { |
|
204 TPckgBuf<TUint> temp(aSetAttMask); |
|
205 TIpcArgs args(&aName,&temp); |
|
206 TInt ret = SendReceive(ESetReadOnly,args); |
|
207 return ret; |
|
208 } |
|
209 |
|
210 |
|
211 EXPORT_C TInt RSmlTestUtils::GetAtt( const TDesC& aName, TUint& aAttValue ) |
|
212 { |
|
213 TPckgBuf<TUint> attPckg( aAttValue ); |
|
214 TIpcArgs args( &aName, &attPckg ); |
|
215 TInt ret = SendReceive( EGetAttributes, args ); |
|
216 aAttValue = attPckg(); |
|
217 return ret; |
|
218 } |
|
219 |
|
220 |
|
221 EXPORT_C TInt RSmlTestUtils::SetAtt( const TDesC &aName, TUint aSetAttMask, TUint aClearAttMask ) |
|
222 { |
|
223 TIpcArgs args( &aName, &aSetAttMask, &aClearAttMask ); |
|
224 TInt ret = SendReceive( ESetAttributes, args ); |
|
225 return ret; |
|
226 } |
|
227 |
|
228 |
|
229 EXPORT_C TInt RSmlTestUtils::CopyDirectoryL(const TDesC& aSource,const TDesC& aTarget) |
|
230 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
231 TIpcArgs args(&aSource,&aTarget); |
|
232 TInt ret = SendReceive(ECopyDirectory, args); |
|
233 return ret; |
|
234 } |
|
235 |
|
236 |
|
237 EXPORT_C TInt RSmlTestUtils::ChangeFilePermissionL(const TDesC& aPath) |
|
238 { // this implementation of this method does not leave but further derived implementations may if they choose |
|
239 TIpcArgs args(&aPath); |
|
240 TInt ret = SendReceive(EChangeFilePermission, args); |
|
241 return ret; |
|
242 } |