os/kernelhwsrv/kerneltest/e32test/system/t_multin.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/system/t_multin.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,528 @@
     1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\system\t_multin.cpp
    1.18 +// Overview:
    1.19 +// Test multiple inheritance with and without virtual bases. 
    1.20 +// API Information:
    1.21 +// N/A
    1.22 +// Details:
    1.23 +// - Test multiple inheritance with virtual bases. Using a virtual
    1.24 +// base class, copy one or more strings from the "producer" object 
    1.25 +// to the "consumer" object. Verify that results are as expected.
    1.26 +// - Test multiple inheritance without virtual bases. Using a non-
    1.27 +// virtual base class, copy one or more strings from the "producer" 
    1.28 +// object to the "consumer" object. Verify that results are as expected.
    1.29 +// Platforms/Drives/Compatibility:
    1.30 +// All.
    1.31 +// Assumptions/Requirement/Pre-requisites:
    1.32 +// Failures and causes:
    1.33 +// Base Port information:
    1.34 +// 
    1.35 +//
    1.36 +
    1.37 +#include "t_multin.h"
    1.38 +
    1.39 +LOCAL_D RTest test(_L("T_MULTIN"));
    1.40 +
    1.41 +void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2)
    1.42 +	{
    1.43 +#if defined(__TRACE__)
    1.44 +	test.Printf(_L("MConsumer::Consume(s,s)\n"));
    1.45 +	//test.Getch();
    1.46 +#endif
    1.47 +	TBuf<0x100> b;b.Format(_L("%S%S"),&aStr1,&aStr2);Consume(b);
    1.48 +	}
    1.49 +
    1.50 +void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
    1.51 +	{
    1.52 +#if defined(__TRACE__)
    1.53 +	test.Printf(_L("MConsumer::Consume(s,s,s)\n"));
    1.54 +	//test.Getch();
    1.55 +#endif
    1.56 +	TBuf<0x100> b;b.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);Consume(b);
    1.57 +	}
    1.58 +
    1.59 +void MConsumer::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
    1.60 +	{
    1.61 +#if defined(__TRACE__)
    1.62 +	test.Printf(_L("MConsumer::Consume(s,s,s,s)\n"));
    1.63 +	//test.Getch();
    1.64 +#endif
    1.65 +	TBuf<0x100> b;b.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);Consume(b);
    1.66 +	}
    1.67 +
    1.68 +TPtrC MPipe::Produce()
    1.69 +	{
    1.70 +#if defined(__TRACE__)
    1.71 +	test.Printf(_L("MPipe::Produce\n"));
    1.72 +	//test.Getch();
    1.73 +#endif
    1.74 +	return(iBuf);
    1.75 +	}
    1.76 +
    1.77 +void MPipe::Consume(const TDesC& aStr)
    1.78 +	{
    1.79 +#if defined(__TRACE__)
    1.80 +	test.Printf(_L("MPipe::Consume(s)\n"));
    1.81 +	//test.Getch();
    1.82 +#endif
    1.83 +#if defined(__TRACE__)
    1.84 +	{
    1.85 +	TInt l=*(TInt*)&aStr;
    1.86 +	TInt t=l>>28;
    1.87 +	l&=0xfffffff;	
    1.88 +	test.Printf(_L("aStr type=%d,aStr length=%d\n"),t,l);
    1.89 +//
    1.90 +	TText* p=NULL;
    1.91 +	switch (t)
    1.92 +		{
    1.93 +	case 0:
    1.94 +		p=(TText*)((TInt*)&aStr+1);
    1.95 +		break;
    1.96 +	case 1:
    1.97 +		p=*(TText**)((TInt*)&aStr+1);
    1.98 +		break;
    1.99 +	case 2:
   1.100 +		p=*(TText**)((TInt*)&aStr+2);
   1.101 +		break;
   1.102 +	case 3:
   1.103 +		p=(TText*)((TInt*)&aStr+2);
   1.104 +		break;
   1.105 +	case 4:
   1.106 +		p=(TText*)(*(TInt**)((TInt*)&aStr+2)+1);
   1.107 +		break;
   1.108 +		}
   1.109 +//
   1.110 +	test.Printf(_L("aStr=\"%.3s...\"\n"),p);
   1.111 +	}
   1.112 +	//test.Getch();
   1.113 +#endif
   1.114 +#if defined(__TRACE__)
   1.115 +	{
   1.116 +	TInt l=*(TInt*)&iBuf;
   1.117 +	TInt t=l>>28;
   1.118 +	l&=0xfffffff;	
   1.119 +	TInt m=((TInt*)&iBuf)[1];
   1.120 +	test.Printf(_L("iBuf type=%d,iBuf length=%d,iBuf max length=%d\n"),t,l,m);
   1.121 +//
   1.122 +	TText* p=NULL;
   1.123 +	switch (t)
   1.124 +		{
   1.125 +	case 0:
   1.126 +		p=(TText*)((TInt*)&iBuf+1);
   1.127 +		break;
   1.128 +	case 1:
   1.129 +		p=*(TText**)((TInt*)&iBuf+1);
   1.130 +		break;
   1.131 +	case 2:
   1.132 +		p=*(TText**)((TInt*)&iBuf+2);
   1.133 +		break;
   1.134 +	case 3:
   1.135 +		p=(TText*)((TInt*)&iBuf+2);
   1.136 +		break;
   1.137 +	case 4:
   1.138 +		p=(TText*)(*(TInt**)((TInt*)&iBuf+2)+1);
   1.139 +		break;
   1.140 +		}
   1.141 +//
   1.142 +	test.Printf(_L("iBuf=\"%.3s...\"\n"),p);
   1.143 +	}
   1.144 +	//test.Getch();
   1.145 +#endif
   1.146 +	iBuf=aStr;
   1.147 +	}
   1.148 +
   1.149 +void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2)
   1.150 +	{
   1.151 +#if defined(__TRACE__)
   1.152 +	test.Printf(_L("MPipe::Consume(s,s)\n"));
   1.153 +	//test.Getch();
   1.154 +#endif
   1.155 +	iBuf.Format(_L("%S%S"),&aStr1,&aStr2);
   1.156 +	}
   1.157 +
   1.158 +void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
   1.159 +	{
   1.160 +#if defined(__TRACE__)
   1.161 +	test.Printf(_L("MPipe::Consume(s,s,s)\n"));
   1.162 +	//test.Getch();
   1.163 +#endif
   1.164 +	iBuf.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);
   1.165 +	}
   1.166 +
   1.167 +void MPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
   1.168 +	{
   1.169 +#if defined(__TRACE__)
   1.170 +	test.Printf(_L("MPipe::Consume(s,s,s,s)\n"));
   1.171 +	//test.Getch();
   1.172 +#endif
   1.173 +	iBuf.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);
   1.174 +	}
   1.175 +
   1.176 +MProducer* TBase::Producer()
   1.177 +	{
   1.178 +#if defined(__TRACE__)
   1.179 +	test.Printf(_L("TBase::Producer\n"));
   1.180 +	//test.Getch();
   1.181 +#endif
   1.182 +	switch(Species())
   1.183 +		{
   1.184 +	case EProducer:
   1.185 +		return((TProducer*)this);
   1.186 +	case EPipe:
   1.187 +		return((TPipe*)this);
   1.188 +	default:
   1.189 +		return(NULL);
   1.190 +		}
   1.191 +	}
   1.192 +
   1.193 +MConsumer* TBase::Consumer()
   1.194 +	{
   1.195 +#if defined(__TRACE__)
   1.196 +	test.Printf(_L("TBase::Consumer\n"));
   1.197 +	//test.Getch();
   1.198 +#endif
   1.199 +	switch(Species())
   1.200 +		{
   1.201 +	case EConsumer:
   1.202 +		return((TConsumer*)this);
   1.203 +	case EPipe:
   1.204 +		return((TPipe*)this);
   1.205 +	default:
   1.206 +		return(NULL);
   1.207 +		}
   1.208 +	}
   1.209 +
   1.210 +TPtrC TProducer::Produce()
   1.211 +	{
   1.212 +#if defined(__TRACE__)
   1.213 +	test.Printf(_L("TProducer::Produce\n"));
   1.214 +	//test.Getch();
   1.215 +#endif
   1.216 +	return(_L("*"));
   1.217 +	}
   1.218 +
   1.219 +TSpecies TProducer::Species() const
   1.220 +	{
   1.221 +#if defined(__TRACE__)
   1.222 +	test.Printf(_L("TProducer::Species\n"));
   1.223 +	//test.Getch();
   1.224 +#endif
   1.225 +	return(EProducer);
   1.226 +	}
   1.227 +
   1.228 +TSpecies TConsumer::Species() const
   1.229 +	{
   1.230 +#if defined(__TRACE__)
   1.231 +	test.Printf(_L("TConsumer::Species\n"));
   1.232 +	//test.Getch();
   1.233 +#endif
   1.234 +	return(EConsumer);
   1.235 +	}
   1.236 +
   1.237 +void TConsumer::Consume(const TDesC& aStr)
   1.238 +	{
   1.239 +#if defined(__TRACE__)
   1.240 +	test.Printf(_L("TConsumer::Consume\n"));
   1.241 +	//test.Getch();
   1.242 +#endif
   1.243 +	test.Printf(_L("Consumed: %S\n"),&aStr);
   1.244 +	}
   1.245 +
   1.246 +TSpecies TPipe::Species() const
   1.247 +	{
   1.248 +#if defined(__TRACE__)
   1.249 +	test.Printf(_L("TPipe::Species\n"));
   1.250 +	//test.Getch();
   1.251 +#endif
   1.252 +	return(EPipe);
   1.253 +	}
   1.254 +
   1.255 +TSpecies TVirProducer::Species() const
   1.256 +	{
   1.257 +#if defined(__TRACE__)
   1.258 +	test.Printf(_L("TVirProducer::Species\n"));
   1.259 +	//test.Getch();
   1.260 +#endif
   1.261 +	return(EVirtual);
   1.262 +	}
   1.263 +
   1.264 +TPtrC TVirProducer::Produce()
   1.265 +	{
   1.266 +#if defined(__TRACE__)
   1.267 +	test.Printf(_L("TVirProducer::Produce\n"));
   1.268 +	//test.Getch();
   1.269 +#endif
   1.270 +	return(_L("*"));
   1.271 +	}
   1.272 +
   1.273 +TSpecies TVirConsumer::Species() const
   1.274 +	{
   1.275 +#if defined(__TRACE__)
   1.276 +	test.Printf(_L("TVirConsumer::Species\n"));
   1.277 +	//test.Getch();
   1.278 +#endif
   1.279 +	return(EVirtual);
   1.280 +	};
   1.281 +
   1.282 +MConsumer* TVirConsumer::Consumer()
   1.283 +	{
   1.284 +#if defined(__TRACE__)
   1.285 +	test.Printf(_L("TVirConsumer::Consumer\n"));
   1.286 +	//test.Getch();
   1.287 +#endif
   1.288 +	return(this);
   1.289 +	}
   1.290 +
   1.291 +void TVirConsumer::Consume(const TDesC& aStr)
   1.292 +	{
   1.293 +#if defined(__TRACE__)
   1.294 +	test.Printf(_L("TVirConsumer::Consume\n"));
   1.295 +	//test.Getch();
   1.296 +#endif
   1.297 +	test.Printf(_L("Consumed: %S\n"),&aStr);
   1.298 +	}
   1.299 +
   1.300 +TSpecies TVirPipe::Species() const
   1.301 +	{
   1.302 +#if defined(__TRACE__)
   1.303 +	test.Printf(_L("TVirPipe::Species\n"));
   1.304 +	//test.Getch();
   1.305 +#endif
   1.306 +	return(EVirtual);
   1.307 +	};
   1.308 +
   1.309 +MProducer* TVirPipe::Producer()
   1.310 +	{
   1.311 +#if defined(__TRACE__)
   1.312 +	test.Printf(_L("TVirPipe::Producer\n"));
   1.313 +	//test.Getch();
   1.314 +#endif
   1.315 +	return(this);
   1.316 +	}
   1.317 +
   1.318 +MConsumer* TVirPipe::Consumer()
   1.319 +	{
   1.320 +#if defined(__TRACE__)
   1.321 +	test.Printf(_L("TVirPipe::Consumer\n"));
   1.322 +	//test.Getch();
   1.323 +#endif
   1.324 +	return(this);
   1.325 +	}
   1.326 +
   1.327 +TPtrC TVirPipe::Produce()
   1.328 +	{
   1.329 +#if defined(__TRACE__)
   1.330 +	test.Printf(_L("TVirPipe::Produce\n"));
   1.331 +	//test.Getch();
   1.332 +#endif
   1.333 +	return(iBuf);
   1.334 +	}
   1.335 +
   1.336 +void TVirPipe::Consume(const TDesC& aStr)
   1.337 +	{
   1.338 +#if defined(__TRACE__)
   1.339 +	test.Printf(_L("TVirPipe::Consume(s)\n"));
   1.340 +	//test.Getch();
   1.341 +#endif
   1.342 +	iBuf=aStr;
   1.343 +	}
   1.344 +
   1.345 +void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2)
   1.346 +	{
   1.347 +#if defined(__TRACE__)
   1.348 +	test.Printf(_L("TVirPipe::Consume(s,s)\n"));
   1.349 +	//test.Getch();
   1.350 +#endif
   1.351 +	iBuf.Format(_L("%S%S"),&aStr1,&aStr2);
   1.352 +	}
   1.353 +
   1.354 +void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3)
   1.355 +	{
   1.356 +#if defined(__TRACE__)
   1.357 +	test.Printf(_L("TVirPipe::Consume(s,s,s)\n"));
   1.358 +	//test.Getch();
   1.359 +#endif
   1.360 +	iBuf.Format(_L("%S%S%S"),&aStr1,&aStr2,&aStr3);
   1.361 +	}
   1.362 +
   1.363 +void TVirPipe::Consume(const TDesC& aStr1,const TDesC& aStr2,const TDesC& aStr3,const TDesC& aStr4)
   1.364 +	{
   1.365 +#if defined(__TRACE__)
   1.366 +	test.Printf(_L("TVirPipe::Consume(s,s,s,s)\n"));
   1.367 +	//test.Getch();
   1.368 +#endif
   1.369 +	iBuf.Format(_L("%S%S%S%S"),&aStr1,&aStr2,&aStr3,&aStr4);
   1.370 +	}
   1.371 +
   1.372 +LOCAL_C MProducer& Producer(TBase& aBase)
   1.373 +	{
   1.374 +#if defined(__TRACE__)
   1.375 +	test.Printf(_L("Producer(TBase&)\n"));
   1.376 +	//test.Getch();
   1.377 +#endif
   1.378 +	MProducer* prod=aBase.Producer();
   1.379 +	test(prod!=NULL);
   1.380 +	return(*prod);
   1.381 +	}
   1.382 +
   1.383 +LOCAL_C MConsumer& Consumer(TBase& aBase)
   1.384 +	{
   1.385 +#if defined(__TRACE__)
   1.386 +	test.Printf(_L("Consumer(TBase&)\n"));
   1.387 +	//test.Getch();
   1.388 +#endif
   1.389 +	MConsumer* cons=aBase.Consumer();
   1.390 +	test(cons!=NULL);
   1.391 +	return(*cons);
   1.392 +	}
   1.393 +
   1.394 +LOCAL_C void testCopy1(MConsumer& aConsumer,MProducer& aProducer)
   1.395 +//
   1.396 +// Copy a string from the producer to the consumer.
   1.397 +//
   1.398 +	{
   1.399 +
   1.400 +#if defined(__TRACE__)
   1.401 +	test.Printf(_L("testCopy1()\n"));
   1.402 +	//test.Getch();
   1.403 +#endif
   1.404 +	aConsumer.Consume(aProducer.Produce());
   1.405 +	}
   1.406 +
   1.407 +LOCAL_C void testCopy2(MConsumer& aConsumer,MProducer& aProducer)
   1.408 +//
   1.409 +// Copy two strings from the producer to the consumer.
   1.410 +//
   1.411 +	{
   1.412 +
   1.413 +#if defined(__TRACE__)
   1.414 +	test.Printf(_L("testCopy2()\n"));
   1.415 +	//test.Getch();
   1.416 +#endif
   1.417 +	TPtrC s1=aProducer.Produce();
   1.418 +	TPtrC s2=aProducer.Produce();
   1.419 +	aConsumer.Consume(s1,s2);
   1.420 +	}
   1.421 +
   1.422 +LOCAL_C void testCopy3(MConsumer& aConsumer,MProducer& aProducer)
   1.423 +//
   1.424 +// Copy three strings from the producer to the consumer.
   1.425 +//
   1.426 +	{
   1.427 +
   1.428 +#if defined(__TRACE__)
   1.429 +	test.Printf(_L("testCopy3()\n"));
   1.430 +	//test.Getch();
   1.431 +#endif
   1.432 +	TPtrC s1=aProducer.Produce();
   1.433 +	TPtrC s2=aProducer.Produce();
   1.434 +	TPtrC s3=aProducer.Produce();
   1.435 +	aConsumer.Consume(s1,s2,s3);
   1.436 +	}
   1.437 +
   1.438 +LOCAL_C void testCopy4(MConsumer& aConsumer,MProducer& aProducer)
   1.439 +//
   1.440 +// Copy four strings from the producer to the consumer.
   1.441 +//
   1.442 +	{
   1.443 +
   1.444 +#if defined(__TRACE__)
   1.445 +	test.Printf(_L("testCopy4()\n"));
   1.446 +	//test.Getch();
   1.447 +#endif
   1.448 +	TPtrC s1=aProducer.Produce();
   1.449 +	TPtrC s2=aProducer.Produce();
   1.450 +	TPtrC s3=aProducer.Produce();
   1.451 +	TPtrC s4=aProducer.Produce();
   1.452 +	aConsumer.Consume(s1,s2,s3,s4);
   1.453 +	}
   1.454 +
   1.455 +LOCAL_C void testMulti()
   1.456 +//
   1.457 +// Test multiple inheritance without virtual bases.
   1.458 +//
   1.459 +	{
   1.460 +
   1.461 +#if defined(__TRACE__)
   1.462 +	test.Printf(_L("testMulti()\n"));
   1.463 +	//test.Getch();
   1.464 +#endif
   1.465 +	test.Next(_L("without virtual base classes"));
   1.466 +//
   1.467 +	TProducer prod;
   1.468 +	TConsumer cons;
   1.469 +	TPipe pipe;
   1.470 +	testCopy1(Consumer(pipe),Producer(prod));
   1.471 +	testCopy2(Consumer(cons),Producer(pipe));
   1.472 +//
   1.473 +	testCopy3(Consumer(pipe),Producer(prod));
   1.474 +	testCopy4(Consumer(cons),Producer(pipe));
   1.475 +//
   1.476 +	testCopy4(Consumer(pipe),Producer(prod));
   1.477 +	testCopy3(Consumer(cons),Producer(pipe));
   1.478 +//
   1.479 +	testCopy2(Consumer(pipe),Producer(prod));
   1.480 +	testCopy1(Consumer(cons),Producer(pipe));
   1.481 +	}
   1.482 +
   1.483 +LOCAL_C void testVirt()
   1.484 +//
   1.485 +// Test multiple inheritance with virtual bases.
   1.486 +//
   1.487 +	{
   1.488 +
   1.489 +#if defined(__TRACE__)
   1.490 +	test.Printf(_L("testVirt()\n"));
   1.491 +	//test.Getch();
   1.492 +#endif
   1.493 +	test.Next(_L("with virtual base classes"));
   1.494 +//
   1.495 +	TVirProducer prod;
   1.496 +	TVirConsumer cons;
   1.497 +	TVirPipe pipe;
   1.498 +	testCopy1(Consumer(pipe),Producer(prod));
   1.499 +	testCopy2(Consumer(cons),Producer(pipe));
   1.500 +//
   1.501 +	testCopy3(Consumer(pipe),Producer(prod));
   1.502 +	testCopy4(Consumer(cons),Producer(pipe));
   1.503 +//
   1.504 +	testCopy4(Consumer(pipe),Producer(prod));
   1.505 +	testCopy3(Consumer(cons),Producer(pipe));
   1.506 +//
   1.507 +	testCopy2(Consumer(pipe),Producer(prod));
   1.508 +	testCopy1(Consumer(cons),Producer(pipe));
   1.509 +	}
   1.510 +
   1.511 +GLDEF_C TInt E32Main()
   1.512 +//
   1.513 +// Test the multiple inheritance implementation.
   1.514 +//
   1.515 +	{
   1.516 +#if defined(__TRACE__)
   1.517 +	test.Printf(_L("E32Main()\n"));
   1.518 +	//test.Getch();
   1.519 +#endif
   1.520 +	test.Title();
   1.521 +//
   1.522 +	test.Start(_L("Multiple Inheritance"));
   1.523 +	testMulti();
   1.524 +//
   1.525 +	testVirt();
   1.526 +//
   1.527 +	test.End();
   1.528 +	test.Close();
   1.529 +	return(KErrNone);
   1.530 +	}
   1.531 +