0
|
1 |
// Copyright (c) 1996-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_multin.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test multiple inheritance with and without virtual bases.
|
|
17 |
// API Information:
|
|
18 |
// N/A
|
|
19 |
// Details:
|
|
20 |
// - Test multiple inheritance with virtual bases. Using a virtual
|
|
21 |
// base class, copy one or more strings from the "producer" object
|
|
22 |
// to the "consumer" object. Verify that results are as expected.
|
|
23 |
// - Test multiple inheritance without virtual bases. Using a non-
|
|
24 |
// virtual base class, copy one or more strings from the "producer"
|
|
25 |
// object to the "consumer" object. Verify that results are as expected.
|
|
26 |
// Platforms/Drives/Compatibility:
|
|
27 |
// All.
|
|
28 |
// Assumptions/Requirement/Pre-requisites:
|
|
29 |
// Failures and causes:
|
|
30 |
// Base Port information:
|
|
31 |
//
|
|
32 |
//
|
|
33 |
|
|
34 |
#include "t_multin.h"
|
|
35 |
|
|
36 |
LOCAL_D RTest test(_L("T_MULTIN"));
|
|
37 |
|
|
38 |
void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2)
|
|
39 |
{
|
|
40 |
#if defined(__TRACE__)
|
|
41 |
test.Printf(_L("MConsumer::Consume(s,s)\n"));
|
|
42 |
//test.Getch();
|
|
43 |
#endif
|
|
44 |
TBuf<0x100> b;b.Format(_L("%S%S"),&aStr1,&aStr2);Consume(b);
|
|
45 |
}
|
|
46 |
|
|
47 |
void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
|
|
48 |
{
|
|
49 |
#if defined(__TRACE__)
|
|
50 |
test.Printf(_L("MConsumer::Consume(s,s,s)\n"));
|
|
51 |
//test.Getch();
|
|
52 |
#endif
|
|
53 |
TBuf<0x100> b;b.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);Consume(b);
|
|
54 |
}
|
|
55 |
|
|
56 |
void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
|
|
57 |
{
|
|
58 |
#if defined(__TRACE__)
|
|
59 |
test.Printf(_L("MConsumer::Consume(s,s,s,s)\n"));
|
|
60 |
//test.Getch();
|
|
61 |
#endif
|
|
62 |
TBuf<0x100> b;b.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);Consume(b);
|
|
63 |
}
|
|
64 |
|
|
65 |
TPtrC MPipe::Produce()
|
|
66 |
{
|
|
67 |
#if defined(__TRACE__)
|
|
68 |
test.Printf(_L("MPipe::Produce\n"));
|
|
69 |
//test.Getch();
|
|
70 |
#endif
|
|
71 |
return(iBuf);
|
|
72 |
}
|
|
73 |
|
|
74 |
void MPipe::Consume(const TDesC& aStr)
|
|
75 |
{
|
|
76 |
#if defined(__TRACE__)
|
|
77 |
test.Printf(_L("MPipe::Consume(s)\n"));
|
|
78 |
//test.Getch();
|
|
79 |
#endif
|
|
80 |
#if defined(__TRACE__)
|
|
81 |
{
|
|
82 |
TInt l=*(TInt*)&aStr;
|
|
83 |
TInt t=l>>28;
|
|
84 |
l&=0xfffffff;
|
|
85 |
test.Printf(_L("aStr type=%d,aStr length=%d\n"),t,l);
|
|
86 |
//
|
|
87 |
TText* p=NULL;
|
|
88 |
switch (t)
|
|
89 |
{
|
|
90 |
case 0:
|
|
91 |
p=(TText*)((TInt*)&aStr+1);
|
|
92 |
break;
|
|
93 |
case 1:
|
|
94 |
p=*(TText**)((TInt*)&aStr+1);
|
|
95 |
break;
|
|
96 |
case 2:
|
|
97 |
p=*(TText**)((TInt*)&aStr+2);
|
|
98 |
break;
|
|
99 |
case 3:
|
|
100 |
p=(TText*)((TInt*)&aStr+2);
|
|
101 |
break;
|
|
102 |
case 4:
|
|
103 |
p=(TText*)(*(TInt**)((TInt*)&aStr+2)+1);
|
|
104 |
break;
|
|
105 |
}
|
|
106 |
//
|
|
107 |
test.Printf(_L("aStr=\"%.3s...\"\n"),p);
|
|
108 |
}
|
|
109 |
//test.Getch();
|
|
110 |
#endif
|
|
111 |
#if defined(__TRACE__)
|
|
112 |
{
|
|
113 |
TInt l=*(TInt*)&iBuf;
|
|
114 |
TInt t=l>>28;
|
|
115 |
l&=0xfffffff;
|
|
116 |
TInt m=((TInt*)&iBuf)[1];
|
|
117 |
test.Printf(_L("iBuf type=%d,iBuf length=%d,iBuf max length=%d\n"),t,l,m);
|
|
118 |
//
|
|
119 |
TText* p=NULL;
|
|
120 |
switch (t)
|
|
121 |
{
|
|
122 |
case 0:
|
|
123 |
p=(TText*)((TInt*)&iBuf+1);
|
|
124 |
break;
|
|
125 |
case 1:
|
|
126 |
p=*(TText**)((TInt*)&iBuf+1);
|
|
127 |
break;
|
|
128 |
case 2:
|
|
129 |
p=*(TText**)((TInt*)&iBuf+2);
|
|
130 |
break;
|
|
131 |
case 3:
|
|
132 |
p=(TText*)((TInt*)&iBuf+2);
|
|
133 |
break;
|
|
134 |
case 4:
|
|
135 |
p=(TText*)(*(TInt**)((TInt*)&iBuf+2)+1);
|
|
136 |
break;
|
|
137 |
}
|
|
138 |
//
|
|
139 |
test.Printf(_L("iBuf=\"%.3s...\"\n"),p);
|
|
140 |
}
|
|
141 |
//test.Getch();
|
|
142 |
#endif
|
|
143 |
iBuf=aStr;
|
|
144 |
}
|
|
145 |
|
|
146 |
void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2)
|
|
147 |
{
|
|
148 |
#if defined(__TRACE__)
|
|
149 |
test.Printf(_L("MPipe::Consume(s,s)\n"));
|
|
150 |
//test.Getch();
|
|
151 |
#endif
|
|
152 |
iBuf.Format(_L("%S%S"),&aStr1,&aStr2);
|
|
153 |
}
|
|
154 |
|
|
155 |
void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
|
|
156 |
{
|
|
157 |
#if defined(__TRACE__)
|
|
158 |
test.Printf(_L("MPipe::Consume(s,s,s)\n"));
|
|
159 |
//test.Getch();
|
|
160 |
#endif
|
|
161 |
iBuf.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);
|
|
162 |
}
|
|
163 |
|
|
164 |
void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
|
|
165 |
{
|
|
166 |
#if defined(__TRACE__)
|
|
167 |
test.Printf(_L("MPipe::Consume(s,s,s,s)\n"));
|
|
168 |
//test.Getch();
|
|
169 |
#endif
|
|
170 |
iBuf.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);
|
|
171 |
}
|
|
172 |
|
|
173 |
MProducer* TBase::Producer()
|
|
174 |
{
|
|
175 |
#if defined(__TRACE__)
|
|
176 |
test.Printf(_L("TBase::Producer\n"));
|
|
177 |
//test.Getch();
|
|
178 |
#endif
|
|
179 |
switch(Species())
|
|
180 |
{
|
|
181 |
case EProducer:
|
|
182 |
return((TProducer*)this);
|
|
183 |
case EPipe:
|
|
184 |
return((TPipe*)this);
|
|
185 |
default:
|
|
186 |
return(NULL);
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
MConsumer* TBase::Consumer()
|
|
191 |
{
|
|
192 |
#if defined(__TRACE__)
|
|
193 |
test.Printf(_L("TBase::Consumer\n"));
|
|
194 |
//test.Getch();
|
|
195 |
#endif
|
|
196 |
switch(Species())
|
|
197 |
{
|
|
198 |
case EConsumer:
|
|
199 |
return((TConsumer*)this);
|
|
200 |
case EPipe:
|
|
201 |
return((TPipe*)this);
|
|
202 |
default:
|
|
203 |
return(NULL);
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
TPtrC TProducer::Produce()
|
|
208 |
{
|
|
209 |
#if defined(__TRACE__)
|
|
210 |
test.Printf(_L("TProducer::Produce\n"));
|
|
211 |
//test.Getch();
|
|
212 |
#endif
|
|
213 |
return(_L("*"));
|
|
214 |
}
|
|
215 |
|
|
216 |
TSpecies TProducer::Species() const
|
|
217 |
{
|
|
218 |
#if defined(__TRACE__)
|
|
219 |
test.Printf(_L("TProducer::Species\n"));
|
|
220 |
//test.Getch();
|
|
221 |
#endif
|
|
222 |
return(EProducer);
|
|
223 |
}
|
|
224 |
|
|
225 |
TSpecies TConsumer::Species() const
|
|
226 |
{
|
|
227 |
#if defined(__TRACE__)
|
|
228 |
test.Printf(_L("TConsumer::Species\n"));
|
|
229 |
//test.Getch();
|
|
230 |
#endif
|
|
231 |
return(EConsumer);
|
|
232 |
}
|
|
233 |
|
|
234 |
void TConsumer::Consume(const TDesC& aStr)
|
|
235 |
{
|
|
236 |
#if defined(__TRACE__)
|
|
237 |
test.Printf(_L("TConsumer::Consume\n"));
|
|
238 |
//test.Getch();
|
|
239 |
#endif
|
|
240 |
test.Printf(_L("Consumed: %S\n"),&aStr);
|
|
241 |
}
|
|
242 |
|
|
243 |
TSpecies TPipe::Species() const
|
|
244 |
{
|
|
245 |
#if defined(__TRACE__)
|
|
246 |
test.Printf(_L("TPipe::Species\n"));
|
|
247 |
//test.Getch();
|
|
248 |
#endif
|
|
249 |
return(EPipe);
|
|
250 |
}
|
|
251 |
|
|
252 |
TSpecies TVirProducer::Species() const
|
|
253 |
{
|
|
254 |
#if defined(__TRACE__)
|
|
255 |
test.Printf(_L("TVirProducer::Species\n"));
|
|
256 |
//test.Getch();
|
|
257 |
#endif
|
|
258 |
return(EVirtual);
|
|
259 |
}
|
|
260 |
|
|
261 |
TPtrC TVirProducer::Produce()
|
|
262 |
{
|
|
263 |
#if defined(__TRACE__)
|
|
264 |
test.Printf(_L("TVirProducer::Produce\n"));
|
|
265 |
//test.Getch();
|
|
266 |
#endif
|
|
267 |
return(_L("*"));
|
|
268 |
}
|
|
269 |
|
|
270 |
TSpecies TVirConsumer::Species() const
|
|
271 |
{
|
|
272 |
#if defined(__TRACE__)
|
|
273 |
test.Printf(_L("TVirConsumer::Species\n"));
|
|
274 |
//test.Getch();
|
|
275 |
#endif
|
|
276 |
return(EVirtual);
|
|
277 |
};
|
|
278 |
|
|
279 |
MConsumer* TVirConsumer::Consumer()
|
|
280 |
{
|
|
281 |
#if defined(__TRACE__)
|
|
282 |
test.Printf(_L("TVirConsumer::Consumer\n"));
|
|
283 |
//test.Getch();
|
|
284 |
#endif
|
|
285 |
return(this);
|
|
286 |
}
|
|
287 |
|
|
288 |
void TVirConsumer::Consume(const TDesC& aStr)
|
|
289 |
{
|
|
290 |
#if defined(__TRACE__)
|
|
291 |
test.Printf(_L("TVirConsumer::Consume\n"));
|
|
292 |
//test.Getch();
|
|
293 |
#endif
|
|
294 |
test.Printf(_L("Consumed: %S\n"),&aStr);
|
|
295 |
}
|
|
296 |
|
|
297 |
TSpecies TVirPipe::Species() const
|
|
298 |
{
|
|
299 |
#if defined(__TRACE__)
|
|
300 |
test.Printf(_L("TVirPipe::Species\n"));
|
|
301 |
//test.Getch();
|
|
302 |
#endif
|
|
303 |
return(EVirtual);
|
|
304 |
};
|
|
305 |
|
|
306 |
MProducer* TVirPipe::Producer()
|
|
307 |
{
|
|
308 |
#if defined(__TRACE__)
|
|
309 |
test.Printf(_L("TVirPipe::Producer\n"));
|
|
310 |
//test.Getch();
|
|
311 |
#endif
|
|
312 |
return(this);
|
|
313 |
}
|
|
314 |
|
|
315 |
MConsumer* TVirPipe::Consumer()
|
|
316 |
{
|
|
317 |
#if defined(__TRACE__)
|
|
318 |
test.Printf(_L("TVirPipe::Consumer\n"));
|
|
319 |
//test.Getch();
|
|
320 |
#endif
|
|
321 |
return(this);
|
|
322 |
}
|
|
323 |
|
|
324 |
TPtrC TVirPipe::Produce()
|
|
325 |
{
|
|
326 |
#if defined(__TRACE__)
|
|
327 |
test.Printf(_L("TVirPipe::Produce\n"));
|
|
328 |
//test.Getch();
|
|
329 |
#endif
|
|
330 |
return(iBuf);
|
|
331 |
}
|
|
332 |
|
|
333 |
void TVirPipe::Consume(const TDesC& aStr)
|
|
334 |
{
|
|
335 |
#if defined(__TRACE__)
|
|
336 |
test.Printf(_L("TVirPipe::Consume(s)\n"));
|
|
337 |
//test.Getch();
|
|
338 |
#endif
|
|
339 |
iBuf=aStr;
|
|
340 |
}
|
|
341 |
|
|
342 |
void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2)
|
|
343 |
{
|
|
344 |
#if defined(__TRACE__)
|
|
345 |
test.Printf(_L("TVirPipe::Consume(s,s)\n"));
|
|
346 |
//test.Getch();
|
|
347 |
#endif
|
|
348 |
iBuf.Format(_L("%S%S"),&aStr1,&aStr2);
|
|
349 |
}
|
|
350 |
|
|
351 |
void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
|
|
352 |
{
|
|
353 |
#if defined(__TRACE__)
|
|
354 |
test.Printf(_L("TVirPipe::Consume(s,s,s)\n"));
|
|
355 |
//test.Getch();
|
|
356 |
#endif
|
|
357 |
iBuf.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);
|
|
358 |
}
|
|
359 |
|
|
360 |
void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
|
|
361 |
{
|
|
362 |
#if defined(__TRACE__)
|
|
363 |
test.Printf(_L("TVirPipe::Consume(s,s,s,s)\n"));
|
|
364 |
//test.Getch();
|
|
365 |
#endif
|
|
366 |
iBuf.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);
|
|
367 |
}
|
|
368 |
|
|
369 |
LOCAL_C MProducer& Producer(TBase& aBase)
|
|
370 |
{
|
|
371 |
#if defined(__TRACE__)
|
|
372 |
test.Printf(_L("Producer(TBase&)\n"));
|
|
373 |
//test.Getch();
|
|
374 |
#endif
|
|
375 |
MProducer* prod=aBase.Producer();
|
|
376 |
test(prod!=NULL);
|
|
377 |
return(*prod);
|
|
378 |
}
|
|
379 |
|
|
380 |
LOCAL_C MConsumer& Consumer(TBase& aBase)
|
|
381 |
{
|
|
382 |
#if defined(__TRACE__)
|
|
383 |
test.Printf(_L("Consumer(TBase&)\n"));
|
|
384 |
//test.Getch();
|
|
385 |
#endif
|
|
386 |
MConsumer* cons=aBase.Consumer();
|
|
387 |
test(cons!=NULL);
|
|
388 |
return(*cons);
|
|
389 |
}
|
|
390 |
|
|
391 |
LOCAL_C void testCopy1(MConsumer& aConsumer,MProducer& aProducer)
|
|
392 |
//
|
|
393 |
// Copy a string from the producer to the consumer.
|
|
394 |
//
|
|
395 |
{
|
|
396 |
|
|
397 |
#if defined(__TRACE__)
|
|
398 |
test.Printf(_L("testCopy1()\n"));
|
|
399 |
//test.Getch();
|
|
400 |
#endif
|
|
401 |
aConsumer.Consume(aProducer.Produce());
|
|
402 |
}
|
|
403 |
|
|
404 |
LOCAL_C void testCopy2(MConsumer& aConsumer,MProducer& aProducer)
|
|
405 |
//
|
|
406 |
// Copy two strings from the producer to the consumer.
|
|
407 |
//
|
|
408 |
{
|
|
409 |
|
|
410 |
#if defined(__TRACE__)
|
|
411 |
test.Printf(_L("testCopy2()\n"));
|
|
412 |
//test.Getch();
|
|
413 |
#endif
|
|
414 |
TPtrC s1=aProducer.Produce();
|
|
415 |
TPtrC s2=aProducer.Produce();
|
|
416 |
aConsumer.Consume(s1,s2);
|
|
417 |
}
|
|
418 |
|
|
419 |
LOCAL_C void testCopy3(MConsumer& aConsumer,MProducer& aProducer)
|
|
420 |
//
|
|
421 |
// Copy three strings from the producer to the consumer.
|
|
422 |
//
|
|
423 |
{
|
|
424 |
|
|
425 |
#if defined(__TRACE__)
|
|
426 |
test.Printf(_L("testCopy3()\n"));
|
|
427 |
//test.Getch();
|
|
428 |
#endif
|
|
429 |
TPtrC s1=aProducer.Produce();
|
|
430 |
TPtrC s2=aProducer.Produce();
|
|
431 |
TPtrC s3=aProducer.Produce();
|
|
432 |
aConsumer.Consume(s1,s2,s3);
|
|
433 |
}
|
|
434 |
|
|
435 |
LOCAL_C void testCopy4(MConsumer& aConsumer,MProducer& aProducer)
|
|
436 |
//
|
|
437 |
// Copy four strings from the producer to the consumer.
|
|
438 |
//
|
|
439 |
{
|
|
440 |
|
|
441 |
#if defined(__TRACE__)
|
|
442 |
test.Printf(_L("testCopy4()\n"));
|
|
443 |
//test.Getch();
|
|
444 |
#endif
|
|
445 |
TPtrC s1=aProducer.Produce();
|
|
446 |
TPtrC s2=aProducer.Produce();
|
|
447 |
TPtrC s3=aProducer.Produce();
|
|
448 |
TPtrC s4=aProducer.Produce();
|
|
449 |
aConsumer.Consume(s1,s2,s3,s4);
|
|
450 |
}
|
|
451 |
|
|
452 |
LOCAL_C void testMulti()
|
|
453 |
//
|
|
454 |
// Test multiple inheritance without virtual bases.
|
|
455 |
//
|
|
456 |
{
|
|
457 |
|
|
458 |
#if defined(__TRACE__)
|
|
459 |
test.Printf(_L("testMulti()\n"));
|
|
460 |
//test.Getch();
|
|
461 |
#endif
|
|
462 |
test.Next(_L("without virtual base classes"));
|
|
463 |
//
|
|
464 |
TProducer prod;
|
|
465 |
TConsumer cons;
|
|
466 |
TPipe pipe;
|
|
467 |
testCopy1(Consumer(pipe),Producer(prod));
|
|
468 |
testCopy2(Consumer(cons),Producer(pipe));
|
|
469 |
//
|
|
470 |
testCopy3(Consumer(pipe),Producer(prod));
|
|
471 |
testCopy4(Consumer(cons),Producer(pipe));
|
|
472 |
//
|
|
473 |
testCopy4(Consumer(pipe),Producer(prod));
|
|
474 |
testCopy3(Consumer(cons),Producer(pipe));
|
|
475 |
//
|
|
476 |
testCopy2(Consumer(pipe),Producer(prod));
|
|
477 |
testCopy1(Consumer(cons),Producer(pipe));
|
|
478 |
}
|
|
479 |
|
|
480 |
LOCAL_C void testVirt()
|
|
481 |
//
|
|
482 |
// Test multiple inheritance with virtual bases.
|
|
483 |
//
|
|
484 |
{
|
|
485 |
|
|
486 |
#if defined(__TRACE__)
|
|
487 |
test.Printf(_L("testVirt()\n"));
|
|
488 |
//test.Getch();
|
|
489 |
#endif
|
|
490 |
test.Next(_L("with virtual base classes"));
|
|
491 |
//
|
|
492 |
TVirProducer prod;
|
|
493 |
TVirConsumer cons;
|
|
494 |
TVirPipe pipe;
|
|
495 |
testCopy1(Consumer(pipe),Producer(prod));
|
|
496 |
testCopy2(Consumer(cons),Producer(pipe));
|
|
497 |
//
|
|
498 |
testCopy3(Consumer(pipe),Producer(prod));
|
|
499 |
testCopy4(Consumer(cons),Producer(pipe));
|
|
500 |
//
|
|
501 |
testCopy4(Consumer(pipe),Producer(prod));
|
|
502 |
testCopy3(Consumer(cons),Producer(pipe));
|
|
503 |
//
|
|
504 |
testCopy2(Consumer(pipe),Producer(prod));
|
|
505 |
testCopy1(Consumer(cons),Producer(pipe));
|
|
506 |
}
|
|
507 |
|
|
508 |
GLDEF_C TInt E32Main()
|
|
509 |
//
|
|
510 |
// Test the multiple inheritance implementation.
|
|
511 |
//
|
|
512 |
{
|
|
513 |
#if defined(__TRACE__)
|
|
514 |
test.Printf(_L("E32Main()\n"));
|
|
515 |
//test.Getch();
|
|
516 |
#endif
|
|
517 |
test.Title();
|
|
518 |
//
|
|
519 |
test.Start(_L("Multiple Inheritance"));
|
|
520 |
testMulti();
|
|
521 |
//
|
|
522 |
testVirt();
|
|
523 |
//
|
|
524 |
test.End();
|
|
525 |
test.Close();
|
|
526 |
return(KErrNone);
|
|
527 |
}
|
|
528 |
|