|
1 /* |
|
2 * Copyright (c) 2008-2009 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 the License "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: |
|
15 * TestUtil - client testutils interface implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @test |
|
25 @internalComponent |
|
26 */ |
|
27 |
|
28 #include "testutilsdpclient.h" |
|
29 #include "testutilclientserver.h" |
|
30 |
|
31 static TInt StartTestUtilServer() |
|
32 { |
|
33 const TUidType serverUid(KNullUid, KNullUid, KServerUid3); |
|
34 RProcess server; |
|
35 TInt err = server.Create(KTestUtilServerImg, KNullDesC, serverUid); |
|
36 if (err != KErrNone) |
|
37 { |
|
38 return err; |
|
39 } |
|
40 TRequestStatus stat; |
|
41 server.Rendezvous(stat); |
|
42 if (stat != KRequestPending) |
|
43 { |
|
44 server.Kill(0); // abort startup |
|
45 } |
|
46 else |
|
47 { |
|
48 server.Resume(); // logon OK - start the server |
|
49 } |
|
50 User::WaitForRequest(stat); // wait for start or death |
|
51 // we can't use the 'exit reason' if the server panicked as this |
|
52 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
53 // from KErrNone |
|
54 err = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int(); |
|
55 server.Close(); |
|
56 return err; |
|
57 } |
|
58 |
|
59 EXPORT_C TInt RTestUtilSession::Connect() |
|
60 // |
|
61 // Connect to the server, attempting to start it if necessary |
|
62 // |
|
63 { |
|
64 TInt retry=2; |
|
65 for (;;) |
|
66 { |
|
67 TInt err = CreateSession(KTestUtilServerName, TVersion(0, 0, 0), 2); |
|
68 if (err != KErrNotFound && err != KErrServerTerminated) |
|
69 { |
|
70 return err; |
|
71 } |
|
72 if (--retry==0) |
|
73 { |
|
74 return err; |
|
75 } |
|
76 err = StartTestUtilServer(); |
|
77 if (err != KErrNone && err != KErrAlreadyExists) |
|
78 { |
|
79 return err; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 EXPORT_C TInt RTestUtilSession::Copy(const TDesC& aSourceFile, const TDesC& aDestinationFile) |
|
85 { |
|
86 return SendReceive(ECopy,TIpcArgs(&aSourceFile, &aDestinationFile)); |
|
87 } |
|
88 |
|
89 EXPORT_C TInt RTestUtilSession::Move(const TDesC& aSourceFile, const TDesC& aDestinationFile) |
|
90 { |
|
91 return SendReceive(EMove,TIpcArgs(&aSourceFile, &aDestinationFile)); |
|
92 } |
|
93 |
|
94 EXPORT_C TInt RTestUtilSession::Delete(const TDesC& aFileName) |
|
95 { |
|
96 return SendReceive(EDelete,TIpcArgs(&aFileName)); |
|
97 } |
|
98 |
|
99 EXPORT_C TInt RTestUtilSession::MkDirAll(const TDesC& aFileName) |
|
100 { |
|
101 return SendReceive(EMkDirAll,TIpcArgs(&aFileName)); |
|
102 } |
|
103 |
|
104 EXPORT_C TInt RTestUtilSession::RmDir(const TDesC& aFileName) |
|
105 { |
|
106 return SendReceive(ERmDir,TIpcArgs(&aFileName)); |
|
107 } |
|
108 |
|
109 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName) |
|
110 { |
|
111 return FileExistsL(aFileName, 0); |
|
112 } |
|
113 |
|
114 EXPORT_C TBool RTestUtilSession::FileExistsL(const TDesC& aFileName, TInt aMsecTimeout) |
|
115 { |
|
116 TBool fileExists; |
|
117 TPckg<TBool> exists(fileExists); |
|
118 User::LeaveIfError(SendReceive(EFileExists,TIpcArgs(&aFileName, aMsecTimeout, &exists))); |
|
119 return fileExists; |
|
120 } |
|
121 EXPORT_C TInt RTestUtilSession::FormatDrive(TInt aDrive, TBool aFormatFatTableOnly) |
|
122 { |
|
123 return SendReceive(EFormat,TIpcArgs(aDrive, aFormatFatTableOnly)); |
|
124 } |
|
125 EXPORT_C TInt RTestUtilSession::MountDrive(TInt aDrive) |
|
126 { |
|
127 return SendReceive(EMount,TIpcArgs(aDrive)); |
|
128 } |
|
129 EXPORT_C TInt RTestUtilSession::UnMountDrive(TInt aDrive) |
|
130 { |
|
131 return SendReceive(EUnMount,TIpcArgs(aDrive)); |
|
132 } |
|
133 |
|
134 EXPORT_C TInt RTestUtilSession::Lock(const TDesC& aFileName) |
|
135 { |
|
136 return SendReceive(ELock,TIpcArgs(&aFileName)); |
|
137 } |
|
138 |
|
139 EXPORT_C TInt RTestUtilSession::Unlock(const TDesC& aFileName) |
|
140 { |
|
141 return SendReceive(EUnlock,TIpcArgs(&aFileName)); |
|
142 } |
|
143 |
|
144 EXPORT_C TInt RTestUtilSession::SetReadOnly(const TDesC& aFileName, TInt aSetReadOnly) |
|
145 { |
|
146 return SendReceive(ESetReadOnly,TIpcArgs(&aFileName, aSetReadOnly)); |
|
147 } |
|
148 EXPORT_C TInt RTestUtilSession::GetFileHandle(const TDesC& aFileName, RFile &aRFile) |
|
149 { |
|
150 TPckgBuf<TInt> fh; |
|
151 TInt fsh = SendReceive(EGetFileHandle, TIpcArgs(&aFileName, &fh)); |
|
152 if(fsh < 0) |
|
153 { |
|
154 return fsh; |
|
155 } |
|
156 return aRFile.AdoptFromServer(fsh, fh()); |
|
157 } |
|
158 EXPORT_C void RTestUtilSession::WatchFile(const TDesC& aFileName, TRequestStatus& aStatus) |
|
159 { |
|
160 aStatus=KRequestPending; |
|
161 SendReceive(EWatchFile, TIpcArgs(&aFileName), aStatus); |
|
162 } |
|
163 EXPORT_C void RTestUtilSession::WatchFileCancelL() |
|
164 { |
|
165 User::LeaveIfError(SendReceive(EWatchFileCancel)); |
|
166 } |
|
167 EXPORT_C TInt RTestUtilSession::GetNumFilesL(const TDesC& aDirName) |
|
168 { |
|
169 TInt numFiles; |
|
170 TPckg<TInt> getNum(numFiles); |
|
171 |
|
172 User::LeaveIfError(SendReceive(EGetNumFiles, TIpcArgs(&aDirName, &getNum))); |
|
173 |
|
174 return numFiles; |
|
175 } |
|
176 |
|
177 // End of file |