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