sl@0
|
1 |
// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\system\t_env.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32std_private.h>
|
sl@0
|
20 |
#include <e32test.h>
|
sl@0
|
21 |
#include <e32panic.h>
|
sl@0
|
22 |
#include <e32msgqueue.h>
|
sl@0
|
23 |
#include <f32file.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
LOCAL_D RTest test(_L("T_ENV_CHILD"));
|
sl@0
|
26 |
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
GLDEF_C TInt E32Main()
|
sl@0
|
30 |
{
|
sl@0
|
31 |
|
sl@0
|
32 |
test.Title();
|
sl@0
|
33 |
test.Start(_L("Environment"));
|
sl@0
|
34 |
|
sl@0
|
35 |
//parameter slot 1 contains a message queue of TInts which contain control messages
|
sl@0
|
36 |
//parameter slot 2 contains a message queue of TInts
|
sl@0
|
37 |
//parameter slot 3 is a mutex
|
sl@0
|
38 |
//parameter slot 4 is a semaphore
|
sl@0
|
39 |
//parameter slot 5 is a chunk
|
sl@0
|
40 |
|
sl@0
|
41 |
RMsgQueue<TInt> controlQueue;
|
sl@0
|
42 |
TInt err = controlQueue.Open(1, EOwnerProcess);
|
sl@0
|
43 |
test(err==KErrNone);
|
sl@0
|
44 |
|
sl@0
|
45 |
TInt t = 0;
|
sl@0
|
46 |
controlQueue.ReceiveBlocking(t);
|
sl@0
|
47 |
switch (t)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
case 0:
|
sl@0
|
50 |
{
|
sl@0
|
51 |
// out of range test
|
sl@0
|
52 |
User::SetJustInTime(EFalse);
|
sl@0
|
53 |
RMsgQueue<TInt> intQueue;
|
sl@0
|
54 |
intQueue.Open(-1); //should panic
|
sl@0
|
55 |
break;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
|
sl@0
|
58 |
case 1:
|
sl@0
|
59 |
{
|
sl@0
|
60 |
// out of range test
|
sl@0
|
61 |
User::SetJustInTime(EFalse);
|
sl@0
|
62 |
RMsgQueue<TInt> intQueue;
|
sl@0
|
63 |
intQueue.Open(4545); //should panic
|
sl@0
|
64 |
break;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
case 2:
|
sl@0
|
68 |
{
|
sl@0
|
69 |
//attempt to read slot which is empty
|
sl@0
|
70 |
RMsgQueue<TInt> intQueue;
|
sl@0
|
71 |
TInt ret = intQueue.Open(15); //15 is empty
|
sl@0
|
72 |
test(ret == KErrNotFound);
|
sl@0
|
73 |
break;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
case 3:
|
sl@0
|
77 |
//attempt to open incorrect handle type
|
sl@0
|
78 |
{
|
sl@0
|
79 |
RMutex mutex;
|
sl@0
|
80 |
TInt ret = mutex.Open(2); //2 is a TInt queue
|
sl@0
|
81 |
test(ret == KErrArgument);
|
sl@0
|
82 |
break;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
case 4:
|
sl@0
|
85 |
|
sl@0
|
86 |
{
|
sl@0
|
87 |
//test passing a mutex (slot 3)
|
sl@0
|
88 |
RMutex mutex;
|
sl@0
|
89 |
mutex.Open(3, EOwnerThread);
|
sl@0
|
90 |
TFullName name = mutex.FullName();
|
sl@0
|
91 |
TInt ret = name.CompareF(_L("testmutex"));
|
sl@0
|
92 |
test (ret == KErrNone);
|
sl@0
|
93 |
mutex.Close();
|
sl@0
|
94 |
break;
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
case 5:
|
sl@0
|
98 |
{
|
sl@0
|
99 |
//test passing a semaphore (slot 4)
|
sl@0
|
100 |
RSemaphore sem;
|
sl@0
|
101 |
sem.Open(4, EOwnerThread);
|
sl@0
|
102 |
TFullName name = sem.FullName();
|
sl@0
|
103 |
TInt ret = name.CompareF(_L("testsemaphore"));
|
sl@0
|
104 |
test (ret == KErrNone);
|
sl@0
|
105 |
sem.Close();
|
sl@0
|
106 |
break;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
case 6:
|
sl@0
|
110 |
{
|
sl@0
|
111 |
//test file handle (slots 7=session 8=file)
|
sl@0
|
112 |
_LIT8(KTestData,"test data");
|
sl@0
|
113 |
RFs session;
|
sl@0
|
114 |
session.Open(7);
|
sl@0
|
115 |
RFile file;
|
sl@0
|
116 |
TInt handle;
|
sl@0
|
117 |
TInt len = User::ParameterLength(8);
|
sl@0
|
118 |
test (len == 4);
|
sl@0
|
119 |
TInt ret = User::GetTIntParameter(8, handle);
|
sl@0
|
120 |
test(ret == KErrNone);
|
sl@0
|
121 |
file.Adopt(session, handle);
|
sl@0
|
122 |
TBuf8<100> rbuf;
|
sl@0
|
123 |
ret = file.Read(0, rbuf);
|
sl@0
|
124 |
test(ret == KErrNone);
|
sl@0
|
125 |
file.Close();
|
sl@0
|
126 |
ret = rbuf.CompareF(KTestData);
|
sl@0
|
127 |
test(ret == KErrNone);
|
sl@0
|
128 |
|
sl@0
|
129 |
session.Close();
|
sl@0
|
130 |
break;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
case 7:
|
sl@0
|
134 |
{
|
sl@0
|
135 |
//test a chunk in slot 5
|
sl@0
|
136 |
RChunk chunk;
|
sl@0
|
137 |
TInt ret = chunk.Open(5, EOwnerThread);
|
sl@0
|
138 |
test (ret == KErrNone);
|
sl@0
|
139 |
TFullName name = chunk.FullName();
|
sl@0
|
140 |
ret = name.CompareF(_L("testchunk"));
|
sl@0
|
141 |
test (ret == KErrNone);
|
sl@0
|
142 |
chunk.Close();
|
sl@0
|
143 |
|
sl@0
|
144 |
break;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
case 8:
|
sl@0
|
147 |
{
|
sl@0
|
148 |
//test passing a 16 bit descriptor // slot 15
|
sl@0
|
149 |
//_L("16 bit text"
|
sl@0
|
150 |
TBuf16<40> buf;
|
sl@0
|
151 |
TInt len = User::ParameterLength(15);
|
sl@0
|
152 |
TInt ret = User::GetDesParameter(15, buf);
|
sl@0
|
153 |
test (ret == KErrNone);
|
sl@0
|
154 |
test(buf.Length() == len/2);
|
sl@0
|
155 |
ret = buf.CompareF(_L("16 bit text"));
|
sl@0
|
156 |
test (ret == KErrNone);
|
sl@0
|
157 |
|
sl@0
|
158 |
break;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
case 9:
|
sl@0
|
161 |
{
|
sl@0
|
162 |
//test passing a 8 bit descriptor // slot 15
|
sl@0
|
163 |
TBuf8<40> buf;
|
sl@0
|
164 |
TInt len = User::ParameterLength(15);
|
sl@0
|
165 |
TInt ret = User::GetDesParameter(15, buf);
|
sl@0
|
166 |
test (ret == KErrNone);
|
sl@0
|
167 |
test (len == buf.Length());
|
sl@0
|
168 |
ret = buf.CompareF(_L8("8 bit text"));
|
sl@0
|
169 |
test (ret == KErrNone);
|
sl@0
|
170 |
break;
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
case 10:
|
sl@0
|
174 |
{
|
sl@0
|
175 |
User::SetJustInTime(EFalse);
|
sl@0
|
176 |
TPtr8 bad((TUint8*)0xfeed, 20);
|
sl@0
|
177 |
User::GetDesParameter(15, bad);
|
sl@0
|
178 |
break;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
case 11:
|
sl@0
|
182 |
{
|
sl@0
|
183 |
//test passing zero length data
|
sl@0
|
184 |
TBuf8<40> buf;
|
sl@0
|
185 |
TInt len = User::ParameterLength(15);
|
sl@0
|
186 |
TInt ret = User::GetDesParameter(15, buf);
|
sl@0
|
187 |
test (ret == KErrNone);
|
sl@0
|
188 |
test (len == buf.Length());
|
sl@0
|
189 |
test (len == 0);
|
sl@0
|
190 |
break;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
case 12:
|
sl@0
|
194 |
{
|
sl@0
|
195 |
//test getting command line, will be zero at the moment as just a reserved slot
|
sl@0
|
196 |
TBuf8<40> buf;
|
sl@0
|
197 |
TInt len = User::ParameterLength(0);
|
sl@0
|
198 |
TInt ret = User::GetDesParameter(0, buf);
|
sl@0
|
199 |
test (ret == KErrNone);
|
sl@0
|
200 |
test (len == buf.Length());
|
sl@0
|
201 |
test (len == 0);
|
sl@0
|
202 |
break;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
default:
|
sl@0
|
206 |
test(0);
|
sl@0
|
207 |
break;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
controlQueue.Close();
|
sl@0
|
211 |
test.End();
|
sl@0
|
212 |
return 0;
|
sl@0
|
213 |
}
|