sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\system\t_env.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_ENV_CHILD")); sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Environment")); sl@0: sl@0: //parameter slot 1 contains a message queue of TInts which contain control messages sl@0: //parameter slot 2 contains a message queue of TInts sl@0: //parameter slot 3 is a mutex sl@0: //parameter slot 4 is a semaphore sl@0: //parameter slot 5 is a chunk sl@0: sl@0: RMsgQueue controlQueue; sl@0: TInt err = controlQueue.Open(1, EOwnerProcess); sl@0: test(err==KErrNone); sl@0: sl@0: TInt t = 0; sl@0: controlQueue.ReceiveBlocking(t); sl@0: switch (t) sl@0: { sl@0: case 0: sl@0: { sl@0: // out of range test sl@0: User::SetJustInTime(EFalse); sl@0: RMsgQueue intQueue; sl@0: intQueue.Open(-1); //should panic sl@0: break; sl@0: } sl@0: sl@0: case 1: sl@0: { sl@0: // out of range test sl@0: User::SetJustInTime(EFalse); sl@0: RMsgQueue intQueue; sl@0: intQueue.Open(4545); //should panic sl@0: break; sl@0: } sl@0: sl@0: case 2: sl@0: { sl@0: //attempt to read slot which is empty sl@0: RMsgQueue intQueue; sl@0: TInt ret = intQueue.Open(15); //15 is empty sl@0: test(ret == KErrNotFound); sl@0: break; sl@0: } sl@0: sl@0: case 3: sl@0: //attempt to open incorrect handle type sl@0: { sl@0: RMutex mutex; sl@0: TInt ret = mutex.Open(2); //2 is a TInt queue sl@0: test(ret == KErrArgument); sl@0: break; sl@0: } sl@0: case 4: sl@0: sl@0: { sl@0: //test passing a mutex (slot 3) sl@0: RMutex mutex; sl@0: mutex.Open(3, EOwnerThread); sl@0: TFullName name = mutex.FullName(); sl@0: TInt ret = name.CompareF(_L("testmutex")); sl@0: test (ret == KErrNone); sl@0: mutex.Close(); sl@0: break; sl@0: } sl@0: sl@0: case 5: sl@0: { sl@0: //test passing a semaphore (slot 4) sl@0: RSemaphore sem; sl@0: sem.Open(4, EOwnerThread); sl@0: TFullName name = sem.FullName(); sl@0: TInt ret = name.CompareF(_L("testsemaphore")); sl@0: test (ret == KErrNone); sl@0: sem.Close(); sl@0: break; sl@0: } sl@0: sl@0: case 6: sl@0: { sl@0: //test file handle (slots 7=session 8=file) sl@0: _LIT8(KTestData,"test data"); sl@0: RFs session; sl@0: session.Open(7); sl@0: RFile file; sl@0: TInt handle; sl@0: TInt len = User::ParameterLength(8); sl@0: test (len == 4); sl@0: TInt ret = User::GetTIntParameter(8, handle); sl@0: test(ret == KErrNone); sl@0: file.Adopt(session, handle); sl@0: TBuf8<100> rbuf; sl@0: ret = file.Read(0, rbuf); sl@0: test(ret == KErrNone); sl@0: file.Close(); sl@0: ret = rbuf.CompareF(KTestData); sl@0: test(ret == KErrNone); sl@0: sl@0: session.Close(); sl@0: break; sl@0: } sl@0: sl@0: case 7: sl@0: { sl@0: //test a chunk in slot 5 sl@0: RChunk chunk; sl@0: TInt ret = chunk.Open(5, EOwnerThread); sl@0: test (ret == KErrNone); sl@0: TFullName name = chunk.FullName(); sl@0: ret = name.CompareF(_L("testchunk")); sl@0: test (ret == KErrNone); sl@0: chunk.Close(); sl@0: sl@0: break; sl@0: } sl@0: case 8: sl@0: { sl@0: //test passing a 16 bit descriptor // slot 15 sl@0: //_L("16 bit text" sl@0: TBuf16<40> buf; sl@0: TInt len = User::ParameterLength(15); sl@0: TInt ret = User::GetDesParameter(15, buf); sl@0: test (ret == KErrNone); sl@0: test(buf.Length() == len/2); sl@0: ret = buf.CompareF(_L("16 bit text")); sl@0: test (ret == KErrNone); sl@0: sl@0: break; sl@0: } sl@0: case 9: sl@0: { sl@0: //test passing a 8 bit descriptor // slot 15 sl@0: TBuf8<40> buf; sl@0: TInt len = User::ParameterLength(15); sl@0: TInt ret = User::GetDesParameter(15, buf); sl@0: test (ret == KErrNone); sl@0: test (len == buf.Length()); sl@0: ret = buf.CompareF(_L8("8 bit text")); sl@0: test (ret == KErrNone); sl@0: break; sl@0: } sl@0: sl@0: case 10: sl@0: { sl@0: User::SetJustInTime(EFalse); sl@0: TPtr8 bad((TUint8*)0xfeed, 20); sl@0: User::GetDesParameter(15, bad); sl@0: break; sl@0: } sl@0: sl@0: case 11: sl@0: { sl@0: //test passing zero length data sl@0: TBuf8<40> buf; sl@0: TInt len = User::ParameterLength(15); sl@0: TInt ret = User::GetDesParameter(15, buf); sl@0: test (ret == KErrNone); sl@0: test (len == buf.Length()); sl@0: test (len == 0); sl@0: break; sl@0: } sl@0: sl@0: case 12: sl@0: { sl@0: //test getting command line, will be zero at the moment as just a reserved slot sl@0: TBuf8<40> buf; sl@0: TInt len = User::ParameterLength(0); sl@0: TInt ret = User::GetDesParameter(0, buf); sl@0: test (ret == KErrNone); sl@0: test (len == buf.Length()); sl@0: test (len == 0); sl@0: break; sl@0: } sl@0: sl@0: default: sl@0: test(0); sl@0: break; sl@0: } sl@0: sl@0: controlQueue.Close(); sl@0: test.End(); sl@0: return 0; sl@0: }