|
1 // Copyright (c) 2002-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 "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 // e32test\system\testprocess.h |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef __TESTPROCESS_H__ |
|
19 #define __TESTPROCESS_H__ |
|
20 |
|
21 class RTestProcess : public RProcess |
|
22 { |
|
23 public: |
|
24 void Create(TUint32 aCapability,TTestProcessFunctions aFunction,TInt aArg1=-1,TInt aArg2=-1); |
|
25 void Create(TTestProcessFunctions aFunction,TInt aArg1=-1,TInt aArg2=-1); |
|
26 void Run(); |
|
27 static TUint iInstanceCount; |
|
28 }; |
|
29 |
|
30 TUint RTestProcess::iInstanceCount = 0; |
|
31 |
|
32 void RTestProcess::Create(TUint32 aCapability,TTestProcessFunctions aFunction,TInt aArg1,TInt aArg2) |
|
33 { |
|
34 TFileName source=RProcess().FileName(); |
|
35 |
|
36 TFileName destination; |
|
37 _LIT(KTempPath,"c:\\system\\bin\\"); |
|
38 _LIT(KTempPathSysBin,"c:\\sys\\bin\\"); |
|
39 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) |
|
40 destination = KTempPathSysBin; |
|
41 else |
|
42 destination = KTempPath; |
|
43 destination.Append(source.Mid(source.LocateReverse('\\')+1)); |
|
44 destination.SetLength(source.Locate('.')); |
|
45 destination.Append((TText)'-'); |
|
46 destination.AppendNum(++iInstanceCount,EHex); |
|
47 _LIT(KDotExe,".exe"); |
|
48 destination.Append(KDotExe); |
|
49 |
|
50 TInt r; |
|
51 TBuf<128> b; |
|
52 b.Zero(); |
|
53 #ifdef __WINS__ |
|
54 if(source[0]=='z' || source[0]=='Z') |
|
55 { |
|
56 b.Append(source.Mid(source.LocateReverse('\\')+1)); |
|
57 } |
|
58 else |
|
59 #endif |
|
60 b.Append(source); |
|
61 b.Append(' '); |
|
62 b.AppendNum((TUint)aCapability,EHex); |
|
63 b.Append(' '); |
|
64 b.Append(destination); |
|
65 RProcess p; |
|
66 _LIT(KSetcapExe,"setcap.exe"); |
|
67 r = p.Create(KSetcapExe,b); |
|
68 test(r==KErrNone); |
|
69 TRequestStatus s; |
|
70 p.Logon(s); |
|
71 p.Resume(); |
|
72 User::WaitForRequest(s); |
|
73 test(s==KErrNone); |
|
74 test(p.ExitType()==EExitKill); |
|
75 |
|
76 if(aArg1==-1) |
|
77 aArg1 = RProcess().Id(); |
|
78 TBuf<512> commandLine; |
|
79 commandLine.AppendNum((TInt)aFunction); |
|
80 commandLine.Append(_L(" ")); |
|
81 commandLine.AppendNum(aArg1); |
|
82 commandLine.Append(_L(" ")); |
|
83 commandLine.AppendNum(aArg2); |
|
84 r = RProcess::Create(destination,commandLine); |
|
85 test(r==KErrNone); |
|
86 SetJustInTime(EFalse); |
|
87 } |
|
88 |
|
89 void RTestProcess::Create(TTestProcessFunctions aFunction,TInt aArg1,TInt aArg2) |
|
90 { |
|
91 if(aArg1==-1) |
|
92 aArg1 = RProcess().Id(); |
|
93 TBuf<512> commandLine; |
|
94 commandLine.Num((TInt)aFunction); |
|
95 commandLine.Append(_L(" ")); |
|
96 commandLine.AppendNum(aArg1); |
|
97 commandLine.Append(_L(" ")); |
|
98 commandLine.AppendNum(aArg2); |
|
99 TInt r = RProcess::Create(RProcess().FileName(),commandLine); |
|
100 test(r==KErrNone); |
|
101 SetJustInTime(EFalse); |
|
102 } |
|
103 |
|
104 void RTestProcess::Run() |
|
105 { |
|
106 TRequestStatus s; |
|
107 Logon(s); |
|
108 Resume(); |
|
109 User::WaitForRequest(s); |
|
110 test(s==KErrNone); |
|
111 test(ExitType()==EExitKill); |
|
112 CLOSE_AND_WAIT(*this); |
|
113 } |
|
114 |
|
115 #endif |