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