diff -r 000000000000 -r dfb7c4ff071f datacommsserver/esockserver/test/protocols/ptestinternalsocket/src/ptestcases.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datacommsserver/esockserver/test/protocols/ptestinternalsocket/src/ptestcases.cpp Thu Dec 17 09:22:25 2009 +0200 @@ -0,0 +1,6527 @@ +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +#include "ptestcases.h" + +#ifdef SYMBIAN_OLD_EXPORT_LOCATION +#include "es_dummy.h" +#else +#include +#endif +#include "es_ptestinternalsocket.h" +#include +#include +#include "agregate.h" +#include "ss_eintsock_msgs.h" +#include + +#ifdef _DEBUG +// Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module +// (if it could happen through user error then you should give it an explicit, documented, category + code) +_LIT(KSpecAssert_ESockTestptstcs, "ESockTestptstcs."); +#endif + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTestBase +//------------------------------------------------------------------------------------------------- + +/** This is a static method that is called to get a given test running + @param aTestName The name of the test to be run + @the name of the provider starting the test + */ + +//static const TInt KWaitInterval = 10000; //Wait 10 milliseconds before doing checks; +//static const TInt KMaxNumWait = 100; // Wait KWaitIntercal 100 times; + +#define BEGIN_TESTLIST + +#define ADD_TEST(name) \ + if (aTestName == _L(#name))\ + {\ + return CEIntSock ## name::NewL(aProvd);\ + } + +#define END_TESTLIST \ + User::Leave(KErrNotSupported);\ + return NULL; + +CEIntSockTestBase* CEIntSockTestBase::CreateTestL(const TDesC& aTestName, CProxyProvd* aProvd) + { + BEGIN_TESTLIST + ADD_TEST(Test1) + ADD_TEST(Test2) + ADD_TEST(Test3) + ADD_TEST(Test4) + ADD_TEST(Test5) + ADD_TEST(Test6) + ADD_TEST(Test7) + ADD_TEST(Test8) + ADD_TEST(Test9) + ADD_TEST(Test10) + ADD_TEST(Test11) + ADD_TEST(Test12) + ADD_TEST(Test13) + ADD_TEST(Test14) + ADD_TEST(Test15) + ADD_TEST(Test16) + ADD_TEST(Test17) + ADD_TEST(Test18) + ADD_TEST(Test19) + ADD_TEST(Test20) + ADD_TEST(Test21) + ADD_TEST(Test22) + ADD_TEST(Test23) + ADD_TEST(Test25A) + ADD_TEST(Test25B) + ADD_TEST(Test25C) + ADD_TEST(Test26) + ADD_TEST(Test27) + ADD_TEST(Test28A) + ADD_TEST(Test28B) + ADD_TEST(Test29) + ADD_TEST(Test30) + ADD_TEST(Test31) + ADD_TEST(Test32) + ADD_TEST(Test33) + ADD_TEST(Test34) + ADD_TEST(Test35) + ADD_TEST(Test36) + ADD_TEST(Test37) + ADD_TEST(Test38) + ADD_TEST(Test39) + ADD_TEST(Test40) + ADD_TEST(Test41) + ADD_TEST(Test42) + ADD_TEST(Test43) + ADD_TEST(Test44) + ADD_TEST(Test45) + ADD_TEST(Test46) + ADD_TEST(Test47) + ADD_TEST(Test48) + ADD_TEST(Test49) + ADD_TEST(Test50) + ADD_TEST(Test51) + ADD_TEST(Test52) + ADD_TEST(Test53) + ADD_TEST(Test54) + ADD_TEST(Test55) + ADD_TEST(Test56) + ADD_TEST(Test57) + ADD_TEST(Test58) + ADD_TEST(Test59) + ADD_TEST(Test60) + ADD_TEST(Test61) + END_TESTLIST + } + + +void CEIntSockTestBase::StartTestL(const TDesC& aTestName, CProxyProvd* aProvd) + { + CEIntSockTestBase* test = CreateTestL(aTestName,aProvd); + CleanupStack::PushL(test); + test->CEIntSockTestBase::ConstructL(); + CActiveScheduler::Add(test); + CleanupStack::Pop(test); + TRequestStatus* stat = &test->iStatus; + test->SetActive(); + User::RequestComplete(stat,KErrNone); + } + +CEIntSockTestBase::CEIntSockTestBase(CProxyProvd* aProvd) : + CActive(EPriorityNormal), + iProvd(aProvd) + { + iProvd->SetTestStepNotify(this); + } + +void CEIntSockTestBase::ConstructL() + { + SetLoggerL(); + } + +CEIntSockTestBase::~CEIntSockTestBase() + { + if(iProvd) + { + iProvd->SetTestStepNotify(NULL); + } + iLogger.Close(); + } + +/** Override this function if you want cleanup to happen before the completion of + the test case. This function is called before the test is completed + */ +void CEIntSockTestBase::Cleanup() + {} + +/** Sets the test case as active again and prevents the object from being destroyed + when the RunL completes. + + Note: The active object is not complete the request again automatically, if this behaviour is + desired the user must call User::RequestComplete + */ +void CEIntSockTestBase::Reschedule() + { + SetActive(); + iReschedule = TRUE; + } + +/** Attaches the iLogger variable to the TestExecute Log Server. This enable this prt to write to + the testexecute logs as if it were running directly from TestExecute + */ +// SetLoggerL() is taken directly from CTestServer::StartLoggerL() in the TEF src TestServerBase.Cpp + + +void CEIntSockTestBase::SetLoggerL() + { + // Create a cinidata object for parsing the testexecute.ini + CTestExecuteIniData* parseTestExecuteIni = NULL; + TBuf resultFilePath; + TBuf xmlFilePath; + TInt logMode; + TInt logLevel; + + TRAPD(err,parseTestExecuteIni = CTestExecuteIniData::NewL()); + if (err == KErrNone) + { + CleanupStack::PushL(parseTestExecuteIni); + parseTestExecuteIni->ExtractValuesFromIni(); + parseTestExecuteIni->GetKeyValueFromIni(KTEFHtmlKey, resultFilePath); + parseTestExecuteIni->GetKeyValueFromIni(KTEFXmlKey, xmlFilePath); + parseTestExecuteIni->GetKeyValueFromIni(KTEFLogMode, logMode); + parseTestExecuteIni->GetKeyValueFromIni(KTEFLogSeverityKey, logLevel); + } + else + { + resultFilePath.Copy(KTestExecuteLogPath); + xmlFilePath.Copy(KTestExecuteLogPath); + logMode = TLoggerOptions(ELogHTMLOnly); + logLevel = RFileFlogger::TLogSeverity(ESevrAll); + } + Logger().SetLoggerOptions(logMode); + + // Initialise a handle to the file logger + User::LeaveIfError(Logger().Connect()); + RFs fS; + User::LeaveIfError(fS.Connect()); + CleanupClosePushL(fS); + RFile file; + TBuf xmlLogFile(xmlFilePath); + TBuf logFile; + TBuf logFileNameFile(resultFilePath); + logFileNameFile.Append(KTestExecuteScheduleTestLogCompatibilityNameFile); + if(file.Open(fS,logFileNameFile,EFileRead | EFileShareAny) != KErrNone) + { + // For the old flogger we have to create an individual file + _LIT(KTxtLog,"TEIntSock.txt"); + logFile.Copy(KTxtLog); + logMode = TLoggerOptions(0); + Logger().SetLoggerOptions(logMode); + } + else + { + CleanupClosePushL(file); + TBuf8 logFile8; + TInt fileSize; + User::LeaveIfError(file.Size(fileSize)); + User::LeaveIfError(file.Read(logFile8,fileSize)); + logFile.Copy(logFile8); + xmlLogFile.Append(logFile); + _LIT(KXmlExtension,".xml"); + xmlLogFile.Append(KXmlExtension); + _LIT(KHtmExtension,".htm"); + logFile.Append(KHtmExtension); + CleanupStack::Pop(&file); + file.Close(); + } + TBuf logFilePath(resultFilePath); + logFilePath.Append(logFile); + CleanupStack::Pop(&fS); + fS.Close(); + + if (logMode == 0 || logMode == 2) + { + User::LeaveIfError(Logger().HtmlLogger().CreateLog(logFilePath, RTestExecuteLogServ::ELogModeAppend)); + } + if (logMode == 1 || logMode == 2) + { + User::LeaveIfError(Logger().XmlLogger().CreateLog(xmlLogFile,RFileFlogger::ELogModeAppend)); + Logger().XmlLogger().SetLogLevel(RFileFlogger::TLogSeverity(logLevel)); + } + if (parseTestExecuteIni != NULL) + { + CleanupStack::PopAndDestroy(parseTestExecuteIni); + } + } + + + +/** Called by the active scheduler in order to run the test + */ +void CEIntSockTestBase::RunL() + { + iReschedule = EFalse; + TVerdict res = RunTestL(); + if (!iReschedule) + { + Cleanup(); + FinishTest(res); + delete this; + return; + } + } + +void CEIntSockTestBase::AboutToShutdown() + { + // Complete the client before the provider is deleted. + FinishTest(EPass); + iProvd = NULL; + } + +void CEIntSockTestBase::FinishTest(TVerdict aResult) + { + if(iProvd) + { + iProvd->TestComplete(aResult); + } + } + +void CEIntSockTestBase::DoCancel() + { + Cleanup(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest1 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest1::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest1(aProvd); + return ret; + } + +CEIntSockTest1::CEIntSockTest1(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest1::RunTestL() + { + + TInt err; + _LIT(KDescSillyProtocol, "trifle"); + iLogger.WriteFormat(_L("Test 1 - Open and close socket to non-existent protocol")); + + iLogger.WriteFormat(_L("Open socket to protocol - name passed as parameter does not exist")); + err = iSocket.Open(KDescSillyProtocol); + if (err != KErrNotFound) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Open socket to protocol - address family does not exist")); + err = iSocket.Open(KDummyAddrFamily, KSockDatagram, 123411); //Some arbitary number + if (err != KErrBadName) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + return EPass; + } + +void CEIntSockTest1::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest2 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest2::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest2(aProvd); + return ret; + } + +CEIntSockTest2::CEIntSockTest2(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest2::RunTestL() + { + TInt err; + iLogger.WriteFormat(_L("Test 2 - Open and close socket")); + iLogger.WriteFormat(_L("Open socket to protocol by name")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iSocket.Close(); + iLogger.WriteFormat(_L("Open socket to protocol supplying address family")); + err = iSocket.Open(KDummyAddrFamily, KSockDatagram, KDummyOne); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iSocket.Close(); + // this is a null socket for use with accept, can't specify protocol as no parameters + iLogger.WriteFormat(_L("Open null socket")); + err = iSocket.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + return EPass; + } + +void CEIntSockTest2::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest3 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest3::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest3(aProvd); + return ret; + } + +CEIntSockTest3::CEIntSockTest3(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest3::RunTestL() + { + TSockAddr localAddr(KProxyAddrFamily); + TInt err; + iLogger.WriteFormat(_L("Test 3 - Binding")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Binding socket to TSockAddr")); + err = iSocket.Bind(localAddr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Checking LocalName() returns the correct address following the bind")); + TSockAddr actualAddr; + iSocket.LocalName(actualAddr); + if (actualAddr != localAddr) + { + iLogger.WriteFormat(_L("Name didn't match the one passed to Bind()")); + return EFail; + } + + iLogger.WriteFormat(_L("Closing the socket")); + iSocket.Close(); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Setting local port of socket")); + TUint localPort = 7; + err = iSocket.SetLocalPort(localPort); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetLocalPort() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Checking LocalPort() returns the correct port number following the bind")); + TUint actualPort; + actualPort = iSocket.LocalPort(); + if (actualPort != localPort) + { + iLogger.WriteFormat(_L("Port didn't match the one passed to SetLocalPort()")); + return EFail; + } + return EPass; + } + +void CEIntSockTest3::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest4 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest4::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest4(aProvd); + return ret; + } + +CEIntSockTest4::CEIntSockTest4(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest4::RunTestL() + { + TInt err; + TProtocolDesc info; + + iLogger.WriteFormat(_L("Test 4 - ProtocolInfo ")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Getting info about the protocol")); + err = iSocket.Info(info); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Info() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the address is of type PDummyAddrFamily")); + if (info.iAddrFamily != KDummyAddrFamily) + { + iLogger.WriteFormat(_L("Address family in return unexpectedly was %X"),info.iAddrFamily); + return EFail; + } + return EPass; + } + +void CEIntSockTest4::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest5 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest5::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest5(aProvd); + return ret; + } + +CEIntSockTest5::CEIntSockTest5(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1), iRecvBufPtr(NULL, 0) + {} + +TVerdict CEIntSockTest5::RunTestL() + { + + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 5 - Send to and receive from a stream protocol (Descriptor API) ")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (stream protocol)")); + + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + iBuf.Copy ( KSendData() ); + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API")); + iSocket.Send(iBuf,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iRecvBufPtr.Set(( TUint8* )iBuf.PtrZ(), KSendData().Length(), KSendData().Length()); + iSocket.Recv(iRecvBufPtr,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() didn't return KErrNotSupported (returned %d)"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 1)); + return EFail; + } + } + +void CEIntSockTest5::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest6 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest6::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest6(aProvd); + return ret; + } + +CEIntSockTest6::CEIntSockTest6(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest6::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 6 - Send to and receive from a datagram protocol (Descriptor API)")); + + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iAddress.SetFamily (KProxyAddrFamily); + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iBuf.Copy ( KSendData() ); + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API")); + iSocket.Send(iBuf,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 2)); + return EFail; + } + } + +void CEIntSockTest6::Cleanup() + { + iSocket.Close(); + } + + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest7 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest7::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest7(aProvd); + return ret; + } + +CEIntSockTest7::CEIntSockTest7(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest7::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 7 - Send to and receive from a stream protocol (RMBufChain API)")); + iLogger.WriteFormat(_L("Opening PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iAddress.SetFamily(KProxyAddrFamily); + iLogger.WriteFormat(_L("Opening an internal socket (stream protocol)")); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the RMBufChain API")); + + iSendChain.CreateL(KSendData()); + iSocket.Send(iSendChain,0,iStatus); + + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + // dummy prt won't take ownership of this chain. we have still this data. but when we + // do a receive we will get the "same" chain back. so we have to remove the chain that we sent. + // Now data is sent. + iSendChain.Remove (); + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the RMBufChain API")); + + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iRecvChain,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed returning %d"),iStatus.Int()); + return EFail; + } + iRecvChain.CopyOut(iBuf); + + iRecvChain.Free(); + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data recieved")); + return EFail; + } + + return EPass; + } + + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 3)); + return EFail; + } + } + +void CEIntSockTest7::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 4)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 5)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest8 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest8::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest8(aProvd); + return ret; + } + +CEIntSockTest8::CEIntSockTest8(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest8::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 8 - Send to and receive from a datagram protocol (RMBufChain API)")); + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iAddress.SetFamily(KProxyAddrFamily); + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the RMBufChain API")); + + iSendChain.CreateL(KSendData()); + iSocket.Send(iSendChain,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + // dummy prt won't take ownership of this chain. we have still this data. but when we + // do a receive we will get the "same" chain back. so we have to remove the chain that we sent. + // Now we sent + iSendChain.Remove (); + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the RMBufChain API")); + iSocket.Recv(iRecvChain,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + iBuf.SetLength(KSendData().Length()); + iRecvChain.CopyOut(iBuf); + iRecvChain.Free(); + if(iBuf.Compare(KSendData()) == 0) + { + iLogger.WriteFormat(_L("Recv() data matched that sent")); + } + else + { + iLogger.WriteFormat(_L("Recv() data != that send (%S recvd vs %S)"), &iBuf, &KSendData()); + return EFail; + } + + return EPass; + } + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 6)); + return EFail; + } + } + +void CEIntSockTest8::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 7)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 8)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest9 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest9::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest9(aProvd); + return ret; + } + +CEIntSockTest9::CEIntSockTest9(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest9::RunTestL() + { + TInt err; + iLogger.WriteFormat(_L("Test 9 - Get and Set Options")); + iLogger.WriteFormat(_L("Opening to PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Setting Blocked connect to TRUE")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,TRUE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + TPckgBuf boolean; + iLogger.WriteFormat(_L("Getting Blocked connect Sock opt")); + err = iSocket.GetOpt(KDummyOptionSetBlockConnect,28, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Checking that Blocked connect Sock opt returns true")); + if (boolean() != TRUE) + { + iLogger.WriteFormat(_L("GetOpt did not return true - looks like the opt was not set")); + return EFail; + } + iLogger.WriteFormat(_L("Setting Blocked connect to FALSE")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,FALSE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Getting Blocked connect Sock opt")); + err = iSocket.GetOpt(KDummyOptionSetBlockConnect,28, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Checking Blocked connect is FALSE")); + if (boolean() != FALSE) + { + iLogger.WriteFormat(_L("GetOpt did not return false - looks like the opt was not set")); + return EFail; + } + return EPass; + } + +void CEIntSockTest9::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest10 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest10::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest10(aProvd); + return ret; + } + +CEIntSockTest10::CEIntSockTest10(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest10::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 10 - Ioctl")); + iLogger.WriteFormat(_L("Opening PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Sending an ioctl that does nothing")); + iSocket.Ioctl(KDummyIocltJustComplete, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Checking that the Ioctl() completes")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 9)); + return EFail; + } + } + +void CEIntSockTest10::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest11 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest11::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest11(aProvd); + return ret; + } + +CEIntSockTest11::CEIntSockTest11(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest11::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 11 - Cancel Ioctls")); + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Sending an ioclt that does not complete")); + iSocket.Ioctl(KDummyIocltNonCompleting, iStatus); + if (iStatus != KRequestPending) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Completing the ioctl with a SocketOpt")); + err = iSocket.SetOpt(KDummyOptionSetIocltComplete,28); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Checking the completion code for the ioclt")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Sending an ioclt that does not complete")); + iSocket.Ioctl(KDummyIocltNonCompleting, iStatus); + iLogger.WriteFormat(_L("Cancelling the Ioclt")); + iSocket.CancelIoctl(); + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Checking the completion code for the ioclt in KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Completing the ioctl with a SocketOpt")); + err = iSocket.SetOpt(KDummyOptionSetIocltComplete,28); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Checking the completion code for the ioclt in KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 10)); + return EFail; + } + } + +void CEIntSockTest11::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest12 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest12::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest12(aProvd); + return ret; + } + +CEIntSockTest12::CEIntSockTest12(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest12::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 12 - Cancel Accept")); + iLogger.WriteFormat(_L("Opening PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + TSockAddr addr; + iLogger.WriteFormat(_L("Performing Bind")); + err =iSocket.Bind(addr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Listen")); + err = iSocket.Listen(5); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Listen() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Opening a NULL socket")); + err = iNewSock.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Accepting a connection")); + iSocket.Accept(iNewSock,iStatus); + + iLogger.WriteFormat(_L("Setting a sockopt to simulate a connect")); + err = iSocket.SetOpt(KDummyOptionSetConnectComplete,27); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iState = EState2; + Reschedule(); + return EPass; + } + + case EState2: + { + iLogger.WriteFormat(_L("Checking that the accept completes")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Accept() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Closing and then reopenning the new socket")); + iNewSock.Close(); + err = iNewSock.Open(); + if(err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Accepting a connection")); + iSocket.Accept(iNewSock,iStatus); + + iLogger.WriteFormat(_L("Cancelling the accept")); + iSocket.CancelAccept(); + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Checking that the accept completes with KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Accept() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Setting a sockopt to simulate a connect")); + err = iSocket.SetOpt(KDummyOptionSetConnectComplete,27); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Checking that the status code is still KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Accept() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 11)); + return EFail; + } + } + +void CEIntSockTest12::Cleanup() + { + iSocket.Close(); + iNewSock.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest13 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest13::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest13(aProvd); + return ret; + } + +CEIntSockTest13::CEIntSockTest13(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest13::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 13 - Cancel Connect")); + iLogger.WriteFormat(_L("Opening PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Setting sockopt not to complete connect")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,TRUE); //Block connect + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing connect")); + iSocket.Connect(iAddress, iStatus); + if (iStatus != KRequestPending) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Setting sockopt to now complete the connect")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,FALSE); //Unblock Connect + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Checking that the connect completes")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Closing and Reopening socket")); + iSocket.Close(); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Setting sockopt not to complete connect")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,TRUE); //Block connect + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing connect")); + iSocket.Connect(iAddress, iStatus); + if (iStatus != KRequestPending) + { + iLogger.WriteFormat(_L("Ioclt() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Cancelling connect")); + iSocket.CancelConnect(); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Checking that connect completes with KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Cancel() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Attepting to simulate the completion of the connection")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,FALSE); //Unblock Connect + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the status remains KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("iStatus is now %d"),iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 12)); + return EFail; + } + } + +void CEIntSockTest13::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest14 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest14::NewL(CProxyProvd* aProvd) + { + CEIntSockTest14* ret = new(ELeave) CEIntSockTest14(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +CEIntSockTest14::CEIntSockTest14(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest14::~CEIntSockTest14() + { + delete iColl; + } + +void CEIntSockTest14::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iSendItem = iColl->GetNewItemL(); + iIoctlItem = iColl->GetNewItemL(); + iConnectItem = iColl->GetNewItemL(); + } + +TVerdict CEIntSockTest14::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 14 - Transfer Socket")); + iLogger.WriteFormat(_L(" Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Sending through a non completing ioctl")); + iIoctlItem->Start(); + iSocket.Ioctl(KDummyIocltNonCompleting, iIoctlItem->iStatus); + iLogger.WriteFormat(_L("Attempting to transfer the socket from one to another")); + err = iNewSock.Transfer(iSocket); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iSocket.CancelIoctl(); + if (iStatus == KErrCancel) + { + iLogger.WriteFormat(_L("Ioclt() from parent socket returned %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Connecting...")); + iConnectItem->Start(); + iNewSock.Connect(iAddress, iConnectItem->iStatus); + iState = EState2; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState2: + { + if (iIoctlItem->ReturnCode() != KRequestPending) //Since the socket was tranferred cancel should do nothing + { + iLogger.WriteFormat(_L("Cancel) from parent socket returned %d"),iIoctlItem->ReturnCode()); + return EFail; + } + if(iConnectItem->iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with error code %d"),iStatus.Int()); + return EFail; + } + iSendItem->Start(); + iNewSock.Send(KSendData(),0,iSendItem->iStatus); + iState = EState3; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState3: + { + if (iSendItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("Send() from new socket returned %d"),iSendItem->iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iNewSock.Recv(iBuf,0,iStatus); + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() from new socket returned %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Checking that the data is recieved correctly")); + if (iBuf != KSendData()) + { + iLogger.WriteFormat(_L("Recv() did not return any data ")); + return EFail; + } + iNewSock.CancelIoctl(); + iState = EState5; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState5: + { + if (iIoctlItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Ioclt() from new socket returned %d"),iIoctlItem->iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 13)); + return EFail; + } + } + +void CEIntSockTest14::Cleanup() + { + iSocket.Close(); + iNewSock.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest15 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest15::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest15(aProvd); + return ret; + } + +CEIntSockTest15::CEIntSockTest15(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest15::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 15 - Connect socket and close before completion")); + iLogger.WriteFormat(_L("Opening socket to PDummy Two (stream protocol)")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Connecting an internal socket (stream protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iLogger.WriteFormat(_L("Closing the socket without waiting for Connect() to complete")); + // actually it probably is complete as it is pretty much synchronous with this protocol + iSocket.Close(); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Checking the status of the Connect()")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Opening socket to PDummy One (datagram protocol)")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Connecting an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iLogger.WriteFormat(_L("Closing the socket without waiting for Connect() to complete")); + // actually it probably is complete as it is pretty much synchronous with this protocol + iSocket.Close(); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Checking the status of the Connect()")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 14)); + return EFail; + } + } + +void CEIntSockTest15::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest16 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest16::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest16(aProvd); + return ret; + } + +CEIntSockTest16::CEIntSockTest16(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest16::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 16 - Send data and close socket without waiting for Send to complete")); + iLogger.WriteFormat(_L("Opening socket to PDummy One (datagram protocol)")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Connecting an internal socket (stream protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Checking the status of the Connect()")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API")); + TBuf8<20> buf = _L8("pancake"); + iSocket.Send(buf,0,iStatus); + + iLogger.WriteFormat(_L("Close socket before Send() completes")); + iSocket.Close(); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Checking the status of the Send()")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 15)); + return EFail; + } + } + +void CEIntSockTest16::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest17 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest17::NewL(CProxyProvd* aProvd) + { + CEIntSockTest17* ret = new(ELeave) CEIntSockTest17(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +void CEIntSockTest17::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iSendItem = iColl->GetNewItemL(); + iRecvItem = iColl->GetNewItemL(); + } + +CEIntSockTest17::CEIntSockTest17(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest17::~CEIntSockTest17() + { + delete iColl; + } + +TVerdict CEIntSockTest17::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 17 - Cancel Recv")); + iLogger.WriteFormat(_L("Attempting to open socket on PDummy1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Attempting to perform a connect on PDummy1")); + iSocket.Connect(iAddress,iStatus); + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Attempting to perform a recv")); + iRecvItem->Start(); + TInt size = iBuf.MaxLength (); + iBuf.Zero (); + iSocket.Recv(iBuf,0,iRecvItem->iStatus); + + iLogger.WriteFormat(_L("Attempting to perform a send")); + iSendItem->Start(); + iSocket.Send(KSendData(),0,iSendItem->iStatus); + iState = EState3; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState3: + { + if (iSendItem->ReturnCode() != KRequestPending && iRecvItem->ReturnCode() != KRequestPending) + { + if(iSendItem->ReturnCode()!= KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iSendItem->ReturnCode()); + return EFail; + } + iLogger.WriteFormat(_L("Checking that the recv returned correctly")); + if(iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Recv did not return expected data")); + return EFail; + } + iLogger.WriteFormat(_L("Attempting to perform a another recv")); + iBuf.Zero(); + iRecvItem->Start(); + iSocket.Recv(iBuf,0,iRecvItem->iStatus); + + iLogger.WriteFormat(_L("Attempting to cancel the recv")); + iSocket.CancelRecv(); + + iState =EState4; + } + //Else reschedule and wait for soemthing to come in + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState4: + { + iLogger.WriteFormat(_L("Checking that the recv is cancelled")); + if(iRecvItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting to perform a send")); + iSendItem->Start(); + iSocket.Send(KSendData,0,iSendItem->iStatus); + + iState = EState5; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState5: + { + if (iSendItem->ReturnCode() == KRequestPending || iRecvItem->ReturnCode() == KRequestPending) + { + //go back to active scheduler and wait for reschedule + iColl->Kick(); + Reschedule(); + return EFail; + } + if(iSendItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iSendItem->ReturnCode()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the recv is still cancelled")); + if(iRecvItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 16)); + return EFail; + } + } + +void CEIntSockTest17::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest18 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest18::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest18(aProvd); + return ret; + } + +CEIntSockTest18::CEIntSockTest18(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest18::RunTestL() + { + TInt err; + iLogger.WriteFormat(_L("Test 18 - Multiple opens and closes to a single protocol")); + + TInt i; + for (i=0; iOpening socket %d to pdummy 2"),i); + err = iSockets[i].Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + } + + for (i=(KTest18NumSockets-1); i>=0; i--) + { + iLogger.WriteFormat(_L("Closing socket %d"),i); + iSockets[i].Close(); + } + + return EPass; + } + +void CEIntSockTest18::Cleanup() + { + for (TInt i=0; iTest 19 - Multiple opens and closes to various protocols")); + + iLogger.WriteFormat(_L("Opening socket 0 (PDummyOne)")); + err = iSockets[0].Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening socket 1 (PDummyTwo)")); + err = iSockets[1].Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening socket 2 (PDummyThree)")); + err = iSockets[2].Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + for (TInt i=(KTest18NumSockets-1); i>=0; i--) + { + iLogger.WriteFormat(_L("Closing socket %d"),i); + iSockets[i].Close(); + } + + return EPass; + } + +void CEIntSockTest19::Cleanup() + { + for (TInt i=0; iTest 20 - Repeated closes")); + + iLogger.WriteFormat(_L("Opening socket by name (PDummyOne)")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + TInt i; + for (i=0; iClosing socket - iteration %d"),i+1); + iSocket.Close(); + } + + iLogger.WriteFormat(_L("Reopening socket - using protocol family etc (PDummyOne)")); + err = iSocket.Open(KDummyAddrFamily, KSockDatagram, KDummyOne); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + for (i=0; iClosing socket - iteration %d"),i+1); + iSocket.Close(); + } + + return EPass; + } + +void CEIntSockTest20::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest21 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest21::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest21(aProvd); + return ret; + } + +CEIntSockTest21::CEIntSockTest21(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest21::RunTestL() + { + TInt err; + iLogger.WriteFormat(_L("Test 21 - Repeated opens")); + + iLogger.WriteFormat(_L("Attempting to open a socket on pdummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting to open a socket on the same protocol - Should Panic")); + err = iSocket.Open(KDummyOneName); + // Everything below here should never be run due to the panic, but has been left for completeness + iLogger.WriteFormat(_L("Open returned %d"),err); + if (err == KErrNone) + { + return EFail; + } + + iSocket.Close(); + return EPass; + } + +void CEIntSockTest21::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest22 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest22::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest22(aProvd); + return ret; + } + +CEIntSockTest22::CEIntSockTest22(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest22::RunTestL() + { + iLogger.WriteFormat(_L("Test 22 - Close without Open")); + + iLogger.WriteFormat(_L("Attempting to close a socket before openning it")); + iSocket.Close(); + return EPass; + } + +void CEIntSockTest22::Cleanup() + { + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest23 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest23::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest23(aProvd); + return ret; + } + +CEIntSockTest23::CEIntSockTest23(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest23::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + iOut = KSendData; + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 23 Connect with connectData")); + + iLogger.WriteFormat(_L("Opening socket to a datagram protocol (PDummyOne)")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Connecting the internal socket (datagram protocol) with the data in/data out overload")); + iAddress.SetFamily(KProxyAddrFamily); + iOut.Copy (KSendData); + iSocket.Connect(iAddress, iOut, iIn, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Connect() completed with %d"),iStatus.Int()); // KErrNone presumably + + if (iIn.Compare(KSendData) == 0) + { + iLogger.WriteFormat(_L("Data received matched data sent - pass!")); + } + else + { + iLogger.WriteFormat(_L("Data received did not match data sent - fail!")); + return EFail; + } + + iSocket.Close(); + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 17)); + return EFail; + } + } + +void CEIntSockTest23::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest25A +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest25A::NewL(CProxyProvd* aProvd) + { + CEIntSockTest25A* ret = new(ELeave) CEIntSockTest25A(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +CEIntSockTest25A::CEIntSockTest25A(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest25A::~CEIntSockTest25A() + { + delete iColl; + } + +void CEIntSockTest25A::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iConnectItem = iColl->GetNewItemL(); + iIoctlItem = iColl->GetNewItemL(); + } + +TVerdict CEIntSockTest25A::RunTestL() + { + TInt err; + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 25 CancelAll (Connect & Ioclt)")); + + iLogger.WriteFormat(_L("Opening socket to a datagram protocol (PDummyOne)")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Setting option to block connect")); + err = iSocket.SetOpt(KDummyOptionSetBlockConnect,28,TRUE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Connecting the internal socket (datagram protocol) with the data in/data out overload")); + iAddress.SetFamily(KProxyAddrFamily); + iConnectItem->Start(); + iSocket.Connect(iAddress, iConnectItem->iStatus); + iLogger.WriteFormat(_L("Sending through a non completing ioclt")); + iIoctlItem->Start(); + iSocket.Ioctl(KDummyIocltNonCompleting, iIoctlItem->iStatus); + iLogger.WriteFormat(_L("Performing CancelAll")); + iSocket.CancelAll(); + iState = EState2; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState2: + { + if(iConnectItem->ReturnCode() == KRequestPending || iIoctlItem->ReturnCode() == KRequestPending) + { + iColl->Kick(); + Reschedule(); + return EFail; + } + if (iConnectItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Connect returned with %d (KErrCancel Expected)"), iConnectItem->ReturnCode()); + return EFail; + } + if (iIoctlItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Ioctl returned with %d (KErrCancel Expected)"), iIoctlItem->ReturnCode()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 18)); + return EFail; + } + } + +void CEIntSockTest25A::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest25B +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest25B::NewL(CProxyProvd* aProvd) + { + CEIntSockTest25B* ret = new(ELeave) CEIntSockTest25B(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +CEIntSockTest25B::CEIntSockTest25B(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest25B::~CEIntSockTest25B() + { + delete iColl; + } + +void CEIntSockTest25B::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iAcceptItem = iColl->GetNewItemL(); + iIoctlItem = iColl->GetNewItemL(); + } + +TVerdict CEIntSockTest25B::RunTestL() + { + TInt err; + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 25 CancelAll (Accept & Ioclt)")); + + iLogger.WriteFormat(_L("Opening socket to a datagram protocol (PDummyThree)")); + + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + TSockAddr addr; + iLogger.WriteFormat(_L("Performing Bind")); + err =iSocket.Bind(addr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Listen")); + err = iSocket.Listen(5); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Listen() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Opening a NULL socket")); + err = iNewSock.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Accepting a connection")); + iAcceptItem->Start(); + iSocket.Accept(iNewSock,iAcceptItem->iStatus); + iLogger.WriteFormat(_L("Sending through a non completing ioclt")); + iIoctlItem->Start(); + iSocket.Ioctl(KDummyIocltNonCompleting, iIoctlItem->iStatus); + iLogger.WriteFormat(_L("Performing CancelAll")); + iSocket.CancelAll(); + + iState = EState2; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState2: + { + if (iAcceptItem->ReturnCode() == KRequestPending || iIoctlItem->ReturnCode() == KRequestPending) + { + Reschedule(); //No change of status b/c we are waiting for a timeout + iColl->Kick(); + return EFail; + } + if (iAcceptItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Accept returned with %d (KErrCancel Expected)"), iAcceptItem->ReturnCode()); + return EFail; + } + if (iIoctlItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Ioctl returned with %d (KErrCancel Expected)"), iIoctlItem->ReturnCode()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 19)); + return EFail; + + } + } + +void CEIntSockTest25B::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest25C +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest25C::NewL(CProxyProvd* aProvd) + { + CEIntSockTest25C* ret = new(ELeave) CEIntSockTest25C(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +CEIntSockTest25C::CEIntSockTest25C(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest25C::~CEIntSockTest25C() + { + delete iColl; + } + +void CEIntSockTest25C::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iRecvItem = iColl->GetNewItemL(); + iIoctlItem = iColl->GetNewItemL(); + } + +TVerdict CEIntSockTest25C::RunTestL() + { + TInt err; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 25 CancelAll (Recv & Ioclt)")); + + iLogger.WriteFormat(_L("Opening socket to a datagram protocol (PDummyOne)")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Peforming Connect")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Performing Recv that will not return")); + iRecvItem->Start(); + iSocket.Recv(iRecvBuf,0,iRecvItem->iStatus); + iLogger.WriteFormat(_L("Sending through a non completing ioclt")); + iIoctlItem->Start(); + iSocket.Ioctl(KDummyIocltNonCompleting, iIoctlItem->iStatus); + iLogger.WriteFormat(_L("Performing CancelAll")); + iSocket.CancelAll(); + iState = EState3; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState3: + { + if (iRecvItem->ReturnCode() == KRequestPending || iIoctlItem->ReturnCode() == KRequestPending) + { + iColl->Kick(); + Reschedule(); //No change of status b/c we are waiting for a timeout + return EFail; + } + + if (iRecvItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Connect returned with %d (KErrCancel Expected)"), iRecvItem->ReturnCode()); + return EFail; + } + if (iIoctlItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Ioctl returned with %d (KErrCancel Expected)"), iIoctlItem->ReturnCode()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 20)); + return EFail; + } + } + +void CEIntSockTest25C::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest26 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest26::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest26(aProvd); + return ret; + } + +CEIntSockTest26::CEIntSockTest26(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest26::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 26 - GetDisconnectData Where there is no disconnect data")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API and requesting amount sent")); + iSocket.Send(KSendData,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending an Ioctl that simulates a remote disconnect")); + iSocket.Ioctl(KDummyIocltRemoteDisconnect,iStatus,NULL); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf,0,iStatus); + + iState = EState5; + Reschedule(); + return EPass; + } + case EState5: + { + iLogger.WriteFormat(_L("Recv() returned with %d"),iStatus.Int()); + if (iStatus == KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Getting Disconnect Data for the socket")); + + TBuf8<40> disconnectData; + err = iSocket.GetDisconnectData(disconnectData); + if (err != KErrNotFound) + { + iLogger.WriteFormat(_L("GetDisconnectData() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 21)); + return EFail; + } + } + +void CEIntSockTest26::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest27 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest27::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest27(aProvd); + return ret; + } + +CEIntSockTest27::CEIntSockTest27(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest27::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + _LIT8(KDisconnectData,"Socket has been disconnected"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 27 - GetDisconnectData Where there is disconnect data")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API and requesting amount sent")); + iSocket.Send(KSendData,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending an Ioctl that simulates a remote disconnect")); + iDisconnectBuf = KDisconnectData; + iSocket.Ioctl(KDummyIocltRemoteDisconnect,iStatus,&iDisconnectBuf); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf,0,iStatus); + + iState = EState5; + Reschedule(); + return EPass; + } + case EState5: + { + iLogger.WriteFormat(_L("Recv() returned with %d"),iStatus.Int()); + if (iStatus == KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Getting Disconnect Data for the socket")); + TBuf8<1> tooShort; + err = iSocket.GetDisconnectData(tooShort); + if (err != KErrOverflow) + { + iLogger.WriteFormat(_L("GetDisconnectData() failed with %d"),iStatus.Int()); + return EFail; + } + TBuf8<40> disconnectData; + err = iSocket.GetDisconnectData(disconnectData); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetDisconnectData() failed with %d"),iStatus.Int()); + return EFail; + } + if (disconnectData != KDisconnectData) + { + iLogger.WriteFormat(_L("GetDisconnectData() returned %S. Should have returned %S"), + &disconnectData,&(KDisconnectData())); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 22)); + return EFail; + } + } + +void CEIntSockTest27::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest28A +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest28A::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest28A(aProvd); + return ret; + } + +CEIntSockTest28A::CEIntSockTest28A(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest28A::RunTestL() + { + TInt err; + _LIT8(KConnectData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 29 - Connect with connect data")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Performing a connect with connect data")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress,KConnectData(),iBuf,iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + if (iBuf != KConnectData) + { + iLogger.WriteFormat(_L("Connect out is not equal to connect in. Connect in =%S"),&iBuf); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 23)); + return EFail; + } + } + +void CEIntSockTest28A::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest28B +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest28B::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest28B(aProvd); + return ret; + } + +CEIntSockTest28B::CEIntSockTest28B(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest28B::RunTestL() + { + TInt err; + _LIT8(KConnectData,"1234567890"); + switch(iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 28B - Listen and Accept with connectdata")); + iLogger.WriteFormat(_L("Opening PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + TSockAddr addr; + iLogger.WriteFormat(_L("Performing Bind")); + err =iSocket.Bind(addr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Listen with connect data")); + err = iSocket.Listen(5,KConnectData); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Listen() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Opening a NULL socket")); + err = iNewSock.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Accepting a connection")); + iSocket.Accept(iNewSock, iBuf, iStatus); + + iLogger.WriteFormat(_L("Setting a sockopt to simulate a connect")); + err = iSocket.SetOpt(KDummyOptionSetConnectComplete,27); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt() failed with %d"),err); + return EFail; + } + iState = EState2; + Reschedule(); + return EPass; + } + + case EState2: + { + iLogger.WriteFormat(_L("Checking that the accept completes")); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Accept() failed with %d"),iStatus.Int()); + return EFail; + } + if (iBuf != KConnectData) + { + iLogger.WriteFormat(_L("Connect out is not equal to connect in. Connect in =%S"), &iBuf); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 24)); + return EFail; + } + } + +void CEIntSockTest28B::Cleanup() + { + iSocket.Close(); + } +// CEIntSockTest29 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest29::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest29(aProvd); + return ret; + } + +CEIntSockTest29::CEIntSockTest29(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest29::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 29 - Send() with volume of data returned to client (datagram protocol, descriptor API)")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Performing a connect")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API and requesting amount sent")); + iSocket.Send(KSendData,0,iStatus,iVolume); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + if (iVolume() != KSendData().Length()) + { + iLogger.WriteFormat(_L("Volume of datagrams sent was actually %d instead of 1"),iVolume()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 25)); + return EFail; + } + } + +void CEIntSockTest29::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest30 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest30::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest30(aProvd); + return ret; + } + +CEIntSockTest30::CEIntSockTest30(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1), iRecvBufPtr(NULL, 0) + { + } + +TVerdict CEIntSockTest30::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 30 - Send() with volume of data returned to client (stream protocol, descriptor API)")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API and requesting amount sent")); + iSocket.Send(KSendData,0,iStatus,iVolume); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() didn't return KErrNone (returned %d)"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iRecvBufPtr.Set( (TUint8*)iBuf.PtrZ(), KSendData().Length(), KSendData().Length() ); + iSocket.Recv(iRecvBufPtr,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() didn't return KErrNone (returned %d)"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 26)); + return EFail; + } + } + +void CEIntSockTest30::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest31 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest31::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest31(aProvd); + return ret; + } + +CEIntSockTest31::CEIntSockTest31(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest31::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 31 - Send() with volume of data returned to client (datagram protocol, RMBufChain API)")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the RMBufChain API and requesting amount sent")); + iSendChain.CreateL(KSendData()); + iSocket.Send(iSendChain,0,iStatus,iVolume); + + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + if (iVolume() != KSendData().Length()) + { + iLogger.WriteFormat(_L("Volume of data sent was actually %d instead of 1"),iVolume()); + return EFail; + } + + iSendChain.Remove (); + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the RMBufChain API")); + iBuf.Zero(); + + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iRecvChain,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iRecvChain.CopyOut(iBuf); + iRecvChain.Free(); + + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 27)); + return EFail; + } + } + +void CEIntSockTest31::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 28)); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 29)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest32 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest32::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest32(aProvd); + return ret; + } + +CEIntSockTest32::CEIntSockTest32(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + { + } + +TVerdict CEIntSockTest32::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 32 - Send() with volume of data returned to client (stream protocol, RMBufChain API)")); + + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API and requesting amount sent")); + iSendChain.CreateL(KSendData()); + iSocket.Send(iSendChain,0,iStatus,iVolume); + + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() didn't return KErrNone (returned %d)"),iStatus.Int()); + return EFail; + } + + iSendChain.Remove (); + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iRecvChain,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + iRecvChain.CopyOut(iBuf); + iRecvChain.Free(); + + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() didn't return KErrNone (returned %d)"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 30)); + return EFail; + } + + } + +void CEIntSockTest32::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 31)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 32)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest33 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest33::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest33(aProvd); + return ret; + } + +CEIntSockTest33::CEIntSockTest33(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1), iReadBufPtr(NULL, 0) + {} + +TVerdict CEIntSockTest33::RunTestL() + + { + TInt err; + _LIT8(KWriteData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 33 - Write to and read from a stream protocol (Descriptor API)")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (stream protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Writing data to an internal socket using the descriptor API")); + iSocket.Write(KWriteData,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Write() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Reading data from an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KWriteData().Length()); + iReadBufPtr.Set( (TUint8*)iBuf.PtrZ(), KWriteData().Length(), KWriteData().Length() ); + iSocket.Read(iReadBufPtr,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Read() didn't return KErrNone (returned %d)"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 33)); + return EFail; + } + } + +void CEIntSockTest33::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest34 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest34::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest34(aProvd); + return ret; + } + +CEIntSockTest34::CEIntSockTest34(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest34::RunTestL() + + { + TInt err; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 34 - Shutdown without disconnect data")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing a Connect")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect failed with"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Performing a Shutdown")); + iSocket.Shutdown(RSocket::ENormal,iStatus); + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Shutdown failed with"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 34)); + return EFail; + } + } + +void CEIntSockTest34::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest35 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest35::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest35(aProvd); + return ret; + } + +CEIntSockTest35::CEIntSockTest35(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest35::RunTestL() + + { + TInt err; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 35 - Error during connect")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 3")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Set connect error code to %d"), KExpectedError); + err=iSocket.SetOpt(KDummyOptionSetErrorNextConnect, 0, KExpectedError); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Connect")); + iSocket.Connect(iAddress,iStatus); + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KExpectedError) + { + iLogger.WriteFormat(_L("Connect failed with %d should have returned %d"),iStatus.Int(), KExpectedError); + return EFail; + } + iLogger.WriteFormat(_L("Set blocked connect")); + err=iSocket.SetOpt(KDummyOptionSetBlockConnect, 0, TRUE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Set connect error code to %d"), KExpectedError); + err=iSocket.SetOpt(KDummyOptionSetErrorNextConnect, 0, KExpectedError); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Connect")); + iSocket.Connect(iAddress,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KExpectedError) + { + iLogger.WriteFormat(_L("Connect failed with %d should have returned %d"),iStatus.Int(), KExpectedError); + return EFail; + } + iLogger.WriteFormat(_L("Set blocked connect")); + err=iSocket.SetOpt(KDummyOptionSetBlockConnect, 0, TRUE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Performing Connect")); + iSocket.Connect(iAddress,iStatus); + + iLogger.WriteFormat(_L("Set connect error code to %d"), KExpectedError); + err=iSocket.SetOpt(KDummyOptionSetErrorNextConnect, 0, KExpectedError); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Unblock connect")); + err=iSocket.SetOpt(KDummyOptionSetBlockConnect, 0, FALSE); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Setopt() failed with %d"),err); + return EFail; + } + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KExpectedError) + { + iLogger.WriteFormat(_L("Connect failed with %d should have returned %d"),iStatus.Int(), KExpectedError); + return EFail; + } + return EPass; + } + default: __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 35)); + return EFail; + } + } + +void CEIntSockTest35::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest36 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest36::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest36(aProvd); + return ret; + } + +CEIntSockTest36::CEIntSockTest36(CProxyProvd* aProvd) + : CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest36::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 36 - Send to and receive from a datagram protocol that temporarily flows control off (Descriptor API)")); + + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API - temporarily flowing control off")); + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, KDummyWriteFlowOffTimeout); + iSocket.Send(KSendData,0,iStatus); + iState = EState3; + Reschedule(); + return EPass; + } + + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, 0); + return EFail; + } + + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, 0); + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + return EPass; + } + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 36)); + return EFail; + } + } + +void CEIntSockTest36::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest37 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest37::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest37(aProvd); + return ret; + } + +CEIntSockTest37::CEIntSockTest37(CProxyProvd* aProvd) + : CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest37::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 37 - Send to and receive from a datagram protocol that temporarily flows control off (RMBufChain API)")); + + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the RMBufChain API - temporarily flowing control off")); + + iSendChain.CreateL(KSendData()); + + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, KDummyWriteFlowOffTimeout); + iSocket.Send(iSendChain,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, 0); + return EFail; + } + iSendChain.Remove(); + + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, 0); + iLogger.WriteFormat(_L("Receiving data over an internal socket using the RMBufChain API")); + + iSocket.Recv(iRecvChain, 0, iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + iBuf.SetLength(KSendData().Length()); + iRecvChain.CopyOut(iBuf); + iRecvChain.Free(); + + if (iBuf.Compare(KSendData()) != 0) + { + iLogger.WriteFormat(_L("Recv() data != that send (%S recvd vs %S)"), &iBuf, &KSendData()); + return EFail; + } + + iLogger.WriteFormat(_L("Recv() data matched that sent")); + return EPass; + } + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 37)); + return EFail; + } + } + +void CEIntSockTest37::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 38)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 39)); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest38 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest38::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest38(aProvd); + return ret; + } + +CEIntSockTest38::CEIntSockTest38(CProxyProvd* aProvd) + : CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest38::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 38 - Send to and receive from a datagram protocol that temporarily flows control off (Descriptor API)")); + + iLogger.WriteFormat(_L("Opening PDummy 1")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (datagram protocol)")); + iAddress.SetFamily(KProxyAddrFamily); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iSocket.SetOpt(KDummyOptionSetFlowOffWrite, 0, ETrue); + + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API - flowing control off")); + + iSocket.Send(KSendData, 0, iStatus); + + iLogger.WriteFormat(_L("Cancelling the Send request")); + iSocket.CancelSend(); + + iState = EState3; + Reschedule(); + return EPass; + } + + case EState3: + { + + iLogger.WriteFormat(_L("Checking that the completion code for Send is KErrCancel")); + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iSocket.SetOpt(KDummyOptionSetFlowOffWrite, 0, EFalse); + + iLogger.WriteFormat(_L("Resending data over an internal socket using the descriptor API - will not flow control off")); + + iSocket.Send(KSendData, 0, iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"), iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iBuf, 0, iStatus); + + iState = EState5; + Reschedule(); + return EPass; + } + + case EState5: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + return EPass; + } + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 40)); + return EFail; + } + } + +void CEIntSockTest38::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest39 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest39::NewL( CProxyProvd* aProvd ) + { + CEIntSockTestBase* ret = new ( ELeave ) CEIntSockTest39( aProvd ); + return ret; + } + +CEIntSockTest39::CEIntSockTest39( CProxyProvd* aProvd ) +: CEIntSockTestBase(aProvd), +iState ( EState1 ) + + { + + } + +TVerdict CEIntSockTest39::RunTestL() + { + iLogger.WriteFormat(_L("Test 39 - Open (asynchronous) and close socket")); + iLogger.WriteFormat(_L("Open socket to protocol by name")); + switch ( iState ) + { + case EState1: + { + iLogger.WriteFormat(_L("Open socket by name")); + + iSocket.Open(KDummyTwoName, iStatus); + iState = EState2; + Reschedule (); + return EPass; + } + case EState2: + { + iLogger.WriteFormat(_L("Open return with status code %d"), iStatus.Int() ); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Close the socket")); + iSocket.Close (); + iLogger.WriteFormat(_L("Open socket to protocol supplying address family")); + iSocket.Open(KDummyAddrFamily, KSockDatagram, KDummyOne, iStatus); + iState = EState3; + Reschedule (); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Open with address family return with status code %d"), iStatus.Int() ); + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + { + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 41)); + return EFail; + } + } + } + +void CEIntSockTest39::Cleanup() + { + iSocket.Close (); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest40 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest40::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest40(aProvd); + return ret; + } + +CEIntSockTest40::CEIntSockTest40(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest40::RunTestL() + { + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 40 - Asyn Open and cancel/close socket")); + iLogger.WriteFormat(_L("Asyn Open socket to protocol by name")); + iSocket.Open(KDummyTwoName, iStatus); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Async Open() failed with %d"),iStatus.Int()); + return EFail; + } + iSocket.Close(); + + iLogger.WriteFormat(_L("Async Open socket to protocol supplying address family")); + iSocket.Open(KDummyAddrFamily, KSockDatagram, KDummyOne, iStatus); + + iLogger.WriteFormat(_L("Cancelling/Closing Async Open() ")); + iSocket.Close(); + + iState = EState3; + Reschedule(); + return EPass; + case EState3: + if(iStatus == KErrNone) + { + iSocket.Close(); + } + else if(iStatus != KErrAbort) + { + iLogger.WriteFormat(_L("Cancelling Async Open failed with %d "), iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Open socket to protocol supplying address family")); + err = iSocket.Open(KDummyAddrFamily, KSockDatagram, KDummyOne); + + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Async Open() failed with %d"),err); + return EFail; + } + iSocket.Close(); + return EPass; + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 42)); + return EFail; + } + } + +void CEIntSockTest40::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest41 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest41::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest41(aProvd); + return ret; + } + +CEIntSockTest41::CEIntSockTest41(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest41::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 41 - SendTo/RecvFrom with descriptior (datagram protocol)")); + iLogger.WriteFormat(_L("Opening a datagram socket.")); + err = iSocket.Open (KDummyOneName); + if ( err != KErrNone ) + { + iLogger.WriteFormat(_L("Opening of datagram socket failed.")); + return EFail; + } + iDestAddr.SetFamily(KProxyAddrFamily); + iBuf.Copy (KSendData()); + iSocket.SendTo(iBuf, iDestAddr, 0, iStatus); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with error code %d."), iStatus.Int() ); + return EFail; + } + iBuf.Zero(); + iSocket.RecvFrom (iBuf, iRemoteAddr, 0, iStatus); + iState = EState3; + Reschedule(); + return EPass; + case EState3: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + + if ( iBuf != KSendData() ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 43)); + return EFail; + } + } + +void CEIntSockTest41::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest42 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest42::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest42(aProvd); + return ret; + } + +CEIntSockTest42::CEIntSockTest42(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest42::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 42 - SendTo/RecvFrom with RMBufChain (datagram protocol)")); + iLogger.WriteFormat(_L("Opening a datagram socket.")); + err = iSocket.Open (KDummyOneName); + if ( err != KErrNone ) + { + iLogger.WriteFormat(_L("Opening of datagram socket failed.")); + return EFail; + } + iDestAddr.SetFamily(KProxyAddrFamily); + iSendChain.CreateL(KSendData()); + + iLogger.WriteFormat(_L("SendTo data over an internal socket using the RMBufChain API")); + + iSocket.SendTo(iSendChain, iDestAddr, 0, iStatus); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with error code %d."), iStatus.Int() ); + return EFail; + } + iSendChain.Remove (); + + + iBuf.SetLength(KSendData().Length()); + iSocket.RecvFrom (iRecvChain, iRemoteAddr, 0, iStatus); + iState = EState3; + Reschedule(); + return EPass; + case EState3: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + iRecvChain.CopyOut(iBuf); + iRecvChain.Free (); + if ( iBuf != KSendData ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 44)); + return EFail; + } + } + +void CEIntSockTest42::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 45)); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 46)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest43 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest43::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest43(aProvd); + return ret; + } + +CEIntSockTest43::CEIntSockTest43(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest43::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 43 - SendTo/RecvFrom with length --- descriptior (datagram protocol)")); + iLogger.WriteFormat(_L("Opening a datagram socket.")); + err = iSocket.Open (KDummyOneName); + if ( err != KErrNone ) + { + iLogger.WriteFormat(_L("Opening of datagram socket failed.")); + return EFail; + } + iDestAddr.SetFamily(KProxyAddrFamily); + iBuf.Copy (KSendData()); + iSocket.SendTo(iBuf, iDestAddr, 0, iStatus, iLength); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with error code %d."), iStatus.Int() ); + return EFail; + } + + if ( iLength() != KSendData().Length() ) + { + iLogger.WriteFormat(_L("SendTo didn't return the expected send length.") ); + return EFail; + } + iLength = 0; + iBuf.Zero(); + iSocket.RecvFrom (iBuf, iRemoteAddr, 0, iStatus, iLength); + iState = EState3; + Reschedule(); + return EPass; + case EState3: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + if ( iLength() != 0 ) + { + iLogger.WriteFormat(_L("RecvFrom didn't return the expected send length.")); + return EFail; + } + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + + if ( iBuf != KSendData() ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 47)); + return EFail; + } + } + +void CEIntSockTest43::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest44 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest44::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest44(aProvd); + return ret; + } + +CEIntSockTest44::CEIntSockTest44(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest44::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 44 - SendTo/RecvFrom with RMBufChain (datagram protocol)")); + iLogger.WriteFormat(_L("Opening a datagram socket.")); + err = iSocket.Open (KDummyOneName); + if ( err != KErrNone ) + { + iLogger.WriteFormat(_L("Opening of datagram socket failed.")); + return EFail; + } + iDestAddr.SetFamily(KProxyAddrFamily); + iSendChain.CreateL(KSendData()); + + iLogger.WriteFormat(_L("SendTo data over an internal socket using the RMBufChain API")); + + iSocket.SendTo(iSendChain, iDestAddr, 0, iStatus, iLength); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with error code %d."), iStatus.Int() ); + return EFail; + } + if ( iLength() != KSendData().Length() ) + { + iLogger.WriteFormat(_L("SendTo didn't return the expected send length.") ); + return EFail; + } + + iSendChain.Remove (); + + iLength = 0; + iBuf.SetLength(KSendData().Length()); + iSocket.RecvFrom (iRecvChain, iRemoteAddr, 0, iStatus, iLength); + iState = EState3; + Reschedule(); + return EPass; + case EState3: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + + if ( iLength() != 0 ) + { + iLogger.WriteFormat(_L("RecvFrom didn't return the expected send length %d."), iLength() ); + return EFail; + } + + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + iRecvChain.CopyOut(iBuf); + iRecvChain.Free (); + + if ( iBuf != KSendData ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 48)); + return EFail; + } + } + +void CEIntSockTest44::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 49)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 50)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest45 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest45::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest45(aProvd); + return ret; + } + +CEIntSockTest45::CEIntSockTest45(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest45::RunTestL() + { + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L(" Test 45 - Send and receive a stream protocol that temporarily flows control off(RMBufChain API)")); + iLogger.WriteFormat(_L("Opening PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iDestAddr.SetFamily(KProxyAddrFamily); + iLogger.WriteFormat(_L("Opening an internal socket (stream protocol)")); + iSocket.Connect(iDestAddr, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending data over an internal socket using the RMBufChain API")); + + iSendChain.CreateL(KSendData()); + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, KDummyWriteFlowOffTimeout); + iSocket.Send(iSendChain,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iSendChain.Remove(); + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the RMBufChain API")); + iSocket.SetOpt(KDummyOptionSetTimedFlowOffWrite, 0, 0); + iBuf.SetLength(KSendData().Length()); + iSocket.Recv(iRecvChain,0,iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() failed returning %d"),iStatus.Int()); + return EFail; + } + iRecvChain.CopyOut(iBuf); + iRecvChain.Free(); + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData()) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + + return EPass; + } + + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 51)); + return EFail; + } + } + +void CEIntSockTest45::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 52)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 53)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest46 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest46::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest46(aProvd); + return ret; + } + +CEIntSockTest46::CEIntSockTest46(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest46::RunTestL() + { + + TInt err; + _LIT8(KSendData,"1234567890"); + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 46 - Send to and receive (with RecvOneOrMore )from a stream protocol (Descriptor API) ")); + iLogger.WriteFormat(_L("Opening a socket to PDummy 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Opening an internal socket (stream protocol)")); + + iDestAddr.SetFamily(KProxyAddrFamily); + iSocket.Connect(iDestAddr, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect() failed with %d"),iStatus.Int()); + return EFail; + } + iBuf.Copy ( KSendData() ); + iLogger.WriteFormat(_L("Sending data over an internal socket using the descriptor API")); + iSocket.Send(iBuf,0,iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Send() failed with %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Receiving data over an internal socket using the descriptor API")); + iBuf.Zero(); + iBuf.SetLength(KSendData().Length()); + iSocket.RecvOneOrMore(iBuf,0,iStatus, iLength); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Recv() didn't return KErrNotSupported (returned %d)"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Checking that the data was read into the buffer")); + if (iBuf != KSendData) + { + iLogger.WriteFormat(_L("Incorrect data to recved")); + return EFail; + } + + if ( iLength() != KSendData().Length() ) + { + iLogger.WriteFormat(_L("RecvOneOrMore didn't return the expected send length.") ); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 54)); + return EFail; + } + } + +void CEIntSockTest46::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest47 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest47::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest47(aProvd); + return ret; + } + +CEIntSockTest47::CEIntSockTest47(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest47::RunTestL() + { + + TInt err; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 47 - Ioctl returns not supported on null socket ")); + iLogger.WriteFormat(_L("Opening a null socket")); + err = iSocket.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Perform Ioctl on the null socket")); + + iSocket.Ioctl(KDummyIoctlCheckStarted, iStatus); + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNotSupported) + { + iLogger.WriteFormat(_L("Ioctl operation on null socket returns %d != KErrNotSupported"),iStatus.Int()); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 55)); + return EFail; + } + } + +void CEIntSockTest47::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest48 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest48::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest48(aProvd); + return ret; + } + +CEIntSockTest48::CEIntSockTest48(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest48::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 48 - Ioctl observes InternalOptionBit ")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 1 socket")); + iSocket.Open(KDummyOneName, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 1 socket returns %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Perform Ioctl with InternalIoctlBit")); + iSocket.Ioctl(KInternalIoctlBit, iStatus); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrAccessDenied) + { + iLogger.WriteFormat(_L("Ioctl option with KInternalIoctlBit failed with error = %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("SetOpt with internal options bit")); + err = iSocket.SetOpt(KSocketInternalOptionBit, KSOLSocket); + if (err != KErrAccessDenied) + { + iLogger.WriteFormat(_L("Setopt with internal options bit returned with error = %d != KErrAccessDenied"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Trying to GetOpt internal options bit")); + TPckgBuf boolean; + err = iSocket.GetOpt(KSocketInternalOptionBit, KSOLSocket, boolean); + if (err != KErrAccessDenied) + { + iLogger.WriteFormat(_L("Getopt with internal options bit returned with error = %d != KErrAccessDenied"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Testing StartL() with Ioctl KDummyIoctlCheckStarted")); + iSocket.Ioctl(KDummyIoctlCheckStarted, iStatus, NULL, KIoctlDummyLevel); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl with KDummIoctlCheckStarted returned with error = %d != KErrNone"),iStatus.Int()); + return EFail; + } + return EPass; + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 56)); + return EFail; + } + } + +void CEIntSockTest48::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest49 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest49::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest49(aProvd); + return ret; + } + +CEIntSockTest49::CEIntSockTest49(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest49::RunTestL() + { + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 49 - Ioctl auto bind and check started ")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 1 socket")); + iSocket.Open(KDummyOneName, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 1 socket returns %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Perform Ioctl with KDummyIoctlCheckStarted")); + iSocket.Ioctl(KDummyIoctlCheckStarted, iStatus, NULL, KIoctlDummyLevel); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Ioctl option with KInternalIoctlBit failed with error = %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Auto bind -- Connect the socket")); + iSocket.Connect(iAddress, iStatus); + + iState = EState4; + Reschedule(); + return EPass; + case EState4: + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect failed with = %d != KErrNone"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Checking bound status with Ioctl")); + iSocket.Ioctl(KDummyIoctlCheckBound, iStatus, NULL, KIoctlDummyLevel); + + iState = EState5; + Reschedule(); + return EPass; + case EState5: + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Checking bound status with Ioctl failed with = %d != KErrNone"),iStatus.Int()); + return EFail; + } + return EPass; + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 57)); + return EFail; + } + } + +void CEIntSockTest49::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest50 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest50::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest50(aProvd); + return ret; + } + +CEIntSockTest50::CEIntSockTest50(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest50::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 50 - Get and Set options ")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 1 socket")); + iSocket.Open(KDummyOneName, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 1 socket returns %d"),iStatus.Int()); + return EFail; + } + + const TInt KPort = 666; + iLogger.WriteFormat(_L("Set local port as %d"), KPort); + err = iSocket.SetLocalPort(KPort); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Set local port as 666 failed with error = %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Get local port that is set. should be %d"), KPort); + TInt port = iSocket.LocalPort(); + if (port != KPort) + { + iLogger.WriteFormat(_L("Get local port failed Got = %d Expected = %d"), port, KPort); + return EFail; + } + + iLogger.WriteFormat(_L("SetOpt with KSONonBlockingIO")); + err = iSocket.SetOpt(KSONonBlockingIO, KSOLSocket); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSONonBlockingIO failed with error = %d"), err); + return EFail; + } + + + iLogger.WriteFormat(_L("GetOpt with KSONonBlockingIO")); + TPckgBuf boolean; + err = iSocket.GetOpt(KSONonBlockingIO, KSOLSocket, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSONonBlockingIO failed with error = %d"), err); + return EFail; + } + + if (boolean() != TRUE) + { + iLogger.WriteFormat(_L("The value returned on GetOpt with KSONonBlockingIO failed")); + return EFail; + } + + iLogger.WriteFormat(_L("GetOpt with KSOBlockingIO")); + err = iSocket.GetOpt(KSOBlockingIO, KSOLSocket, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSOBlockingIO failed with error = %d"), err); + return EFail; + } + + if (boolean() != FALSE) + { + iLogger.WriteFormat(_L("The value returned on GetOpt with KSOBlockingIO failed")); + return EFail; + } + + + iLogger.WriteFormat(_L("SetOpt with KSONonBlockingIO")); + err = iSocket.SetOpt(KSONonBlockingIO, KSOLSocket); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSONonBlockingIO failed with error = %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("GetOpt with KSONonBlockingIO")); + err = iSocket.GetOpt(KSONonBlockingIO, KSOLSocket, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSONonBlockingIO failed with error = %d"), err); + return EFail; + } + + if (boolean() != TRUE) + { + iLogger.WriteFormat(_L("The value returned on GetOpt with KSONonBlockingIO failed")); + return EFail; + } + + iLogger.WriteFormat(_L("GetOpt with KSOBlockingIO")); + err = iSocket.GetOpt(KSONonBlockingIO, KSOLSocket, boolean); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSOBlockingIO failed with error = %d"), err); + return EFail; + } + + if (boolean() != TRUE) + { + iLogger.WriteFormat(_L("The value returned on GetOpt with KSOBlockingIO failed")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 58)); + return EFail; + } + } + +void CEIntSockTest50::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest51 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest51::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest51(aProvd); + return ret; + } + +CEIntSockTest51::CEIntSockTest51(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest51::RunTestL() + { + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 51 - Ioctl non-completion tests")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 1 socket")); + iSocket.Open(KDummyOneName, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 1 socket returns %d"),iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Perform Ioctl with KDummyIoctlIgnore.")); + iSocket.Ioctl(KDummyIoctlIgnore, iStatus); + iSocket.CancelAll(); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrCancel) + { + iLogger.WriteFormat(_L("Cancelling of Ioctl returns with err = %d != KErrCancel"), iStatus.Int()); + return EFail; + } + iLogger.WriteFormat(_L("Query the status of previous of Ioctl call.")); + iSocket.Ioctl(KDummyIoctlCancelled, iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + if (iStatus == KErrNotFound) + { + iLogger.WriteFormat(_L("Ioctl returns with err = %d CancellAll failed to cancel the previous Ioctl"), iStatus.Int()); + return EFail; + } + return EPass; + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 59)); + return EFail; + } + } + +void CEIntSockTest51::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest52 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest52::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest52(aProvd); + return ret; + } + +CEIntSockTest52::CEIntSockTest52(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest52::RunTestL() + { + const TUint KBufferSize = 1024; + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 52 - Retention of socket options from before Accept to after Accept")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 2 socket")); + iAcceptingSocket.Open(KDummyThreeName, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 1 socket returns %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Bind the socket")); + TSockAddr addr; + err = iAcceptingSocket.Bind(addr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind failed with error %d"), err); + return EFail; + } + iLogger.WriteFormat(_L("Start listening on the socket")); + err = iAcceptingSocket.Listen(5); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Listening failed with error %d"), err); + return EFail; + } + iLogger.WriteFormat(_L("Opening a null socket")); + err = iSocket.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Opening a null socket returned with error %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("Setting a whole bunch of KSOLSocket options on the accepting socket")); + err = iAcceptingSocket.SetOpt(KSOSendBuf, KSOLSocket, KBufferSize); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSOSendBuf returned with error %d"), err); + return EFail; + } + err = iAcceptingSocket.SetOpt(KSORecvBuf, KSOLSocket, KBufferSize); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSORecvBuf returned with error %d"), err); + return EFail; + } + err = iAcceptingSocket.SetOpt(KSODebug, KSOLSocket, ETrue); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSODebug returned with error %d"), err); + return EFail; + } + err = iAcceptingSocket.SetOpt(KSONonBlockingIO, KSOLSocket); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KSONonBlockingIO returned with error %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("Now simulating a remote connection to complete the accept")); + err = iAcceptingSocket.SetOpt(KDummyOptionSetConnectComplete, KIoctlDummyLevel); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KDummyOptionSetConnectComplete returned with error %d"), err); + return EFail; + } + + // We set the connect complete option. Pdummy needs to run AO to complete the accept. + // So we cannot do the accept here. we move into the next state and do the accept there + // Here just do a self complete and keep going + iStatus = KRequestPending; + iState = EState3; + Reschedule(); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrNone); + return EPass; + } + case EState3: + { + iLogger.WriteFormat(_L("Perform an accept")); + iAcceptingSocket.Accept(iSocket, iStatus); + + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Accept failed with error %d"), iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Retrieve the whole bunch of KSOLSocket options that is set")); + + TInt retrievedOpt; + err = iSocket.GetOpt(KSOSendBuf, KSOLSocket, retrievedOpt); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSOSendBuf returned with error %d"), err); + return EFail; + } + + if (retrievedOpt != KBufferSize) + { + iLogger.WriteFormat(_L("Opt KSOSendBuf did not return the correct value")); + return EFail; + } + + err = iSocket.GetOpt(KSORecvBuf, KSOLSocket, retrievedOpt); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSORecvBuf returned with error %d"), err); + return EFail; + } + + if (retrievedOpt != KBufferSize) + { + iLogger.WriteFormat(_L("Opt KSORecvBuf did not return the correct value")); + return EFail; + } + + err = iSocket.GetOpt(KSODebug, KSOLSocket, retrievedOpt); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSODebug returned with error %d"), err); + return EFail; + } + if (!retrievedOpt) + { + iLogger.WriteFormat(_L("Opt KSODebug did not return the correct value")); + return EFail; + } + + err = iSocket.GetOpt(KSONonBlockingIO, KSOLSocket, retrievedOpt); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("GetOpt with KSONonBlockingIO returned with error %d"), err); + return EFail; + } + if (!retrievedOpt) + { + iLogger.WriteFormat(_L("Opt KSONonBlockingIO did not return the correct value")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 60)); + return EFail; + } + } + +void CEIntSockTest52::Cleanup() + { + iAcceptingSocket.Close(); + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest53 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest53::NewL(CProxyProvd* aProvd) + { + CEIntSockTest53* ret = new(ELeave) CEIntSockTest53(aProvd); + CleanupStack::PushL(ret); + ret->ConstructL(); + CleanupStack::Pop(ret); + return ret; + } + +CEIntSockTest53::CEIntSockTest53(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +CEIntSockTest53::~CEIntSockTest53() + { + delete iColl; + } + +void CEIntSockTest53::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iRecvItem = iColl->GetNewItemL(); + iSendItem = iColl->GetNewItemL(); + } + +TVerdict CEIntSockTest53::RunTestL() + { + TInt err; + _LIT8(KSendData,"abcdefghij"); + _LIT8(KSendData2,"KLMNOPQRST"); + + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 53 - Partial read with descriptor")); + iLogger.WriteFormat(_L("Opening a socket on Dummy protocol 2")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open on Dummy Protocol 2 failed with error %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting a connection")); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect failed with error %d"), iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Sending 20 octets and reciving 10")); + iSendBuf.Copy(KSendData()); + iSendBuf.Append(KSendData2()); + + iRecvItem->Start(); + iSendItem->Start(); + iSocket.Recv(iRecvBuf, 0, iRecvItem->iStatus); + iSocket.Send(iSendBuf, 0, iSendItem->iStatus); + + iState = EState3; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState3: + { + // Check which operation completed first (no order can be enforced) and check to + // see if it was successful. + if ((iSendItem->ReturnCode() != KErrNone) && (iRecvItem->ReturnCode() != KErrNone)) + { + if(iSendItem->ReturnCode() != KRequestPending) + { + iLogger.WriteFormat(_L("Send failed with error %d"), iSendItem->ReturnCode()); + } + else + { + iLogger.WriteFormat(_L("Recv failed with error %d"), iRecvItem->ReturnCode()); + } + return EFail; + } + + iState = EState4; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState4: + { + // Check which operation completed second (no order can be enforced) and check to + // see if it was successful. + if ((iSendItem->ReturnCode() != KErrNone) && (iRecvItem->ReturnCode() != KErrNone)) + { + if(iSendItem->ReturnCode() != KRequestPending) + { + iLogger.WriteFormat(_L("Send failed with error %d"), iSendItem->ReturnCode()); + } + else + { + iLogger.WriteFormat(_L("Recv failed with error %d"), iRecvItem->ReturnCode()); + } + return EFail; + } + + iLogger.WriteFormat(_L("Check whether the Recv gave the first 10octets")); + if (iRecvBuf != KSendData()) + { + iLogger.WriteFormat(_L("Recv data is not matching the first 10octets that is sent")); + return EFail; + } + + iLogger.WriteFormat(_L("Issue another recv to get the rest 10octets")); + iRecvBuf.SetLength(0); + iRecvItem->Start(); + iSocket.Recv(iRecvBuf, 0, iRecvItem->iStatus); + + iState = EState5; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState5: + { + if (iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("Recv failed with error %d"), iRecvItem->ReturnCode()); + return EFail; + } + iLogger.WriteFormat(_L("Check whether the Recv gave the last 10octets")); + if (iRecvBuf != KSendData2()) + { + iLogger.WriteFormat(_L("Recv data is not matching the last 10octets that is sent")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 61)); + return EFail; + + } + } + +void CEIntSockTest53::Cleanup() + { + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest54 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest54::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest54(aProvd); + return ret; + } + +CEIntSockTest54::CEIntSockTest54(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest54::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 54 - RecvFrom not supported on ConnectionOriented socket")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 2 socket")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting a Connect")); + iSocket.Connect(iAddress, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Connect failed with error %d"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Attempt a RecvFrom")); + iSocket.RecvFrom(iRecvBuf,iAddress,0, iStatus,iLen); + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNotSupported) + { + iLogger.WriteFormat(_L("RecvFrom on a connection oriented failed with error %d"), iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 62)); + return EFail; + } + } + +void CEIntSockTest54::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest55 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest55::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest55(aProvd); + return ret; + } + +CEIntSockTest55::CEIntSockTest55(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest55::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 55 - Fail urgent data on a non supported socket")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 1 socket")); + err = iSocket.Open(KDummyOneName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Send urgent data")); + iSendBuf.SetLength(5); + iSocket.SendTo(iSendBuf, iAddress, KSockWriteUrgent, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNotSupported) + { + iLogger.WriteFormat(_L("Send urgent data oepration failed with error %d Expected: KErrNotSupported"),iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 63)); + return EFail; + } + } + +void CEIntSockTest55::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest56 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest56::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest56(aProvd); + return ret; + } + +CEIntSockTest56::CEIntSockTest56(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest56::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 56 - Send to an unconnected socket")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 3 socket")); + err = iSocket.Open(KDummyThreeName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Send urgent data")); + iSendBuf.SetLength(5); + iSocket.Write(iSendBuf, iStatus); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if (iStatus != KErrNotReady) + { + iLogger.WriteFormat(_L("Write operation failed with error %d Expected: KErrNotReady"),iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 64)); + return EFail; + } + } + +void CEIntSockTest56::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest57 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest57::NewL(CProxyProvd* aProvd) + { + CEIntSockTest57* ret = new(ELeave) CEIntSockTest57(aProvd); + CleanupStack::PushL (ret); + ret->ConstructL(); + CleanupStack::Pop(); + return ret; + } + +CEIntSockTest57::CEIntSockTest57(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +void CEIntSockTest57::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iShutdownItem = iColl->GetNewItemL(); + iRecvItem = iColl->GetNewItemL(); + iSendItem = iColl->GetNewItemL(); + } + +CEIntSockTest57::~CEIntSockTest57() + { + delete iColl; + } + +TVerdict CEIntSockTest57::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 57 - Shoutdown with EStopOutput")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 2 socket")); + err = iSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Attempting a shutdown")); + iShutdownItem->Start(); + iSocket.Shutdown(RSocket::EStopOutput, iShutdownItem->iStatus); + if (iShutdownItem->iStatus != KRequestPending) + { + iLogger.WriteFormat(_L("Shutdown failed with %d Expected: KRequestPending"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting a recv")); + iRecvItem->Start(); + iSocket.Recv(iRecvBuf, 0, iRecvItem->iStatus, iRecvLen); + + iState = EState2; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState2: + { + if (iShutdownItem->ReturnCode() != KRequestPending || iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("Shutdown with EStopInput and Recv operation failed with error Shutdown status:%d Recv status: %d"),iShutdownItem->ReturnCode(), iRecvItem->ReturnCode()); + return EFail; + } + + if (iRecvLen() != 10) + { + iLogger.WriteFormat(_L("Recv length matching failed")); + return EFail; + } + + iLogger.WriteFormat(_L("Attempting a Send")); + iSendBuf.SetLength(1); + iSendItem->Start (); + iSocket.Send(iSendBuf, 0, iSendItem->iStatus); + + iState = EState3; + iColl->Kick(); + Reschedule(); + return EPass; + } + + case EState3: + { + if (iSendItem->ReturnCode() != KErrNotReady) + { + iLogger.WriteFormat(_L("Send on a shutdowned socket failed with error %d Expected: KErrNotReady"), iSendItem->ReturnCode()); + return EFail; + } + iLogger.WriteFormat(_L("Attempting to read more data")); + iRecvItem->Start(); + iSocket.Recv(iRecvBuf, 0, iRecvItem->iStatus, iRecvLen); + + iState = EState4; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState4: + { + if (iRecvItem->ReturnCode() != KErrEof) + { + iLogger.WriteFormat(_L("Recv on a shutdowned socket failed with error %d Expected: KErrEof"), iSendItem->ReturnCode()); + return EFail; + } + if (iRecvLen() != 1) + { + iLogger.WriteFormat(_L("Recv length matching failed")); + return EFail; + } + iRecvLen = 0; + iLogger.WriteFormat(_L("Attempting to read more data")); + iRecvItem->Start(); + iSocket.Recv(iRecvBuf, 0, iRecvItem->iStatus, iRecvLen); + + iState = EState5; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState5: + { + if (iRecvItem->ReturnCode() != KErrEof) + { + iLogger.WriteFormat(_L("Recv on a shutdowned socket failed with error %d Expected: KErrEof"), iRecvItem->ReturnCode()); + return EFail; + } + if (iRecvLen() != 0) + { + iLogger.WriteFormat(_L("Recv length matching failed")); + return EFail; + } + iLogger.WriteFormat(_L("Closing the socket")); + iSocket.Close(); + + iState = EState6; + iColl->Kick(); + Reschedule(); + return EPass; + } + case EState6: + { + if (iShutdownItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("Shutdown status returned %d Expected: KErrCancel"), iShutdownItem->ReturnCode()); + return EFail; + } + return EPass; + } + + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 65)); + return EFail; + } + } + +void CEIntSockTest57::Cleanup() + { + iSocket.Close(); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest52 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest58::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest58(aProvd); + return ret; + } + +CEIntSockTest58::CEIntSockTest58(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest58::RunTestL() + { + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 58 - Close before completion of the accept")); + iLogger.WriteFormat(_L("Opening a Dummy Protocol 2 accepting socket")); + err = iAcceptingSocket.Open(KDummyTwoName); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Open a null socket")); + err = iSocket.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Bind the socket")); + TSockAddr addr; + err = iAcceptingSocket.Bind(addr); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Bind failed with error %d"), err); + return EFail; + } + iLogger.WriteFormat(_L("Start listening on the socket")); + err = iAcceptingSocket.Listen(5); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Listening failed with error %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("Perform an accept")); + iAcceptingSocket.Accept(iSocket, iStatus); + + + iLogger.WriteFormat(_L("Now simulating a remote connection to complete the accept")); + err = iAcceptingSocket.SetOpt(KDummyOptionSetConnectComplete, KIoctlDummyLevel); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KDummyOptionSetConnectComplete returned with error %d"), err); + return EFail; + } + + iLogger.WriteFormat(_L("Close the null socket")); + iSocket.Close(); + + iState = EState2; + Reschedule(); + return EPass; + } + case EState2: + { + if ((iStatus != KErrCancel) && (iStatus != KErrNone)) + { + iLogger.WriteFormat(_L("Accept failed on a closed null socket with error %d: Expected: KErrCancel or KErrNone"),iStatus.Int()); + return EFail; + } + + iLogger.WriteFormat(_L("Open a null socket again")); + err = iSocket.Open(); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Perform an accept")); + iAcceptingSocket.Accept(iSocket, iStatus); + + + iLogger.WriteFormat(_L("Now simulating a remote connection to complete the accept")); + err = iAcceptingSocket.SetOpt(KDummyOptionSetConnectComplete, KIoctlDummyLevel); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("SetOpt with KDummyOptionSetConnectComplete returned with error %d"), err); + return EFail; + } + + + iState = EState3; + Reschedule(); + return EPass; + } + case EState3: + { + if (iStatus != KErrNone) + { + iLogger.WriteFormat(_L("Accept failed with error %d"),iStatus.Int()); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 66)); + return EFail; + } + } + +void CEIntSockTest58::Cleanup() + { + iAcceptingSocket.Close(); + iSocket.Close(); + } + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest59 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest59::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest59(aProvd); + return ret; + } + +CEIntSockTest59::CEIntSockTest59(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1) + {} + +TVerdict CEIntSockTest59::RunTestL() + { + _LIT8(KSendData,"1234567890"); + TInt err; + switch(iState) + { + case EState1: + iLogger.WriteFormat(_L("Test 59 - SendTo/RecvFrom with RMBufChain (datagram protocol) with KSockReadPeek")); + iLogger.WriteFormat(_L("Opening a datagram socket.")); + err = iSocket.Open (KDummyOneName); + if ( err != KErrNone ) + { + iLogger.WriteFormat(_L("Opening of datagram socket failed.")); + return EFail; + } + iDestAddr.SetFamily(KProxyAddrFamily); + iSendChain.CreateL(KSendData()); + + iLogger.WriteFormat(_L("SendTo data over an internal socket using the RMBufChain API")); + + iSocket.SendTo(iSendChain, iDestAddr, 0, iStatus, iLength); + iState = EState2; + Reschedule(); + return EPass; + case EState2: + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with error code %d."), iStatus.Int() ); + return EFail; + } + if ( iLength() != KSendData().Length() ) + { + iLogger.WriteFormat(_L("SendTo didn't return the expected send length.") ); + return EFail; + } + + iSendChain.Remove (); + + iLength = 0; + iBuf.SetLength(KSendData().Length()); + iSocket.RecvFrom (iRecvChain, iRemoteAddr, KSockReadPeek, iStatus, iLength); + iState = EState3; + Reschedule(); + return EPass; + case EState3: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + TInt len = iLength(); + if ( iLength() != 0 ) + { + iLogger.WriteFormat(_L("RecvFrom didn't return the expected send length %d."), iLength() ); + return EFail; + } + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + iRecvChain.CopyOut(iBuf); + + if ( iBuf != KSendData ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + + iLength = 0; + iBuf.SetLength(KSendData().Length()); + iSocket.RecvFrom (iRecvChain, iRemoteAddr, 0, iStatus, iLength); + iState = EState4; + Reschedule(); + return EPass; + } + case EState4: + { + if(iStatus != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with error code %d."), iStatus.Int() ); + return EFail; + } + + if (iLength() != 0) + { + iLogger.WriteFormat(_L("RecvFrom didn't return the expected send length %d."), iLength() ); + return EFail; + } + + if (iDestAddr.Family() != iRemoteAddr.Family()) + { + iLogger.WriteFormat(_L("SendTo address is different from RecvFrom address.")); + return EFail; + } + iRecvChain.CopyOut(iBuf); + iRecvChain.Free (); + + if ( iBuf != KSendData ) + { + iLogger.WriteFormat(_L("SendTo data is different from RecvFrom data.")); + return EFail; + } + + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 67)); + return EFail; + } + } + +void CEIntSockTest59::Cleanup() + { + iSocket.Close(); + __ASSERT_DEBUG(iSendChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 68)); + __ASSERT_DEBUG(iRecvChain.IsEmpty(), User::Panic(KSpecAssert_ESockTestptstcs, 69)); + } + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest60 +//------------------------------------------------------------------------------------------------- +CEIntSockTestBase* CEIntSockTest60::NewL(CProxyProvd* aProvd) + { + CEIntSockTest60* ret = new(ELeave) CEIntSockTest60(aProvd); + CleanupStack::PushL (ret); + ret->ConstructL(); + CleanupStack::Pop(); + return ret; + } + +CEIntSockTest60::CEIntSockTest60(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd), + iState(EState1), + iInetAddrTo(INET_ADDR(127,0,0,1),7) + {} + +void CEIntSockTest60::ConstructL() + { + iColl = CAggregateCollection::NewL(iStatus,CAggregateCollection::EAny); + iRecvItem = iColl->GetNewItemL(); + iSendItem = iColl->GetNewItemL(); + } + +CEIntSockTest60::~CEIntSockTest60() + { + delete iColl; + } + +TVerdict CEIntSockTest60::RunTestL() + { + const TInt KIPHeaderSize = 20; //-- IP header size + const TInt KUdpHeaderSize= 8; //-- UDP header size + + _LIT8(KSendData, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + TInt err = KErrNone; + switch (iState) + { + case EState1: + { + iLogger.WriteFormat(_L("Test 60 - Read from socket with KSockReadPeek flag set in different situations")); + iLogger.WriteFormat(_L("Opening a UDP input socket")); + err = iSocketIn.Open(KAfInet, KSockDatagram, KProtocolInetUdp); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Opening a UDP output socket")); + err = iSocketOut.Open(KAfInet, KSockDatagram, KProtocolInetUdp); + if (err != KErrNone) + { + iLogger.WriteFormat(_L("Open() failed with %d"),err); + return EFail; + } + + iLogger.WriteFormat(_L("Bind the address")); + iSocketIn.Bind (iInetAddrTo); + + iLogger.WriteFormat(_L("Send the data")); + iSendBuf.Copy(KSendData()); + iSendItem->Start(); + iSocketOut.SendTo(iSendBuf, iInetAddrTo, 0, iSendItem->iStatus); + + iState = EState2; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState2: + { + if (iSendItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with %d"),iSendItem->ReturnCode()); + return EFail; + } + iLogger.WriteFormat(_L("Peek data from socket and check the size")); + iRecvItem->Start(); + iSocketIn.RecvFrom(iRecvBuf, iInetAddrFrom, KIpHeaderIncluded|KSockReadPeek, iRecvItem->iStatus); + + iState = EState3; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState3: + { + if (iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + + if (iRecvBuf.Length() != (KIPHeaderSize+KUdpHeaderSize+KSendData().Length())) + { + iLogger.WriteFormat(_L("RecvFrom failed to deliver the expected data %d"),err); + return EFail; + } + iLogger.WriteFormat(_L("Peek data from socket and check the size")); + iRecvItem->Start(); + iSocketIn.RecvFrom(iRecvBuf2, iInetAddrFrom, KIpHeaderIncluded|KSockReadPeek, iRecvItem->iStatus); + + iState = EState4; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState4: + { + if (iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + if (iRecvBuf != iRecvBuf2) + { + iLogger.WriteFormat(_L("Received data is not same")); + return EFail; + } + iLogger.WriteFormat(_L("Recv data from socket and check the size")); + iRecvBuf.SetLength(0); + iRecvItem->Start(); + iSocketIn.RecvFrom(iRecvBuf, iInetAddrFrom, 0, iRecvItem->iStatus); + + iState = EState5; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState5: + { + if (iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + if (iRecvBuf.Length() != KSendData().Length()) + { + iLogger.WriteFormat(_L("Received data is not same")); + return EFail; + } + + iLogger.WriteFormat(_L("Peek data from socket and Cancel the recv")); + iRecvItem->Start(); + iRecvBuf.SetLength(0); + iSocketIn.RecvFrom(iRecvBuf, iInetAddrFrom, KIpHeaderIncluded|KSockReadPeek, iRecvItem->iStatus); + iSocketIn.CancelRecv(); + + iLogger.WriteFormat(_L("Send data to the socket")); + iSendItem->Start(); + iSocketOut.SendTo(iSendBuf, iInetAddrTo, 0, iSendItem->iStatus); + + iState = EState6; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState6: + { + if (iRecvItem->ReturnCode() != KErrCancel) + { + iLogger.WriteFormat(_L("CancelRecv failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + + iState = EState7; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState7: + { + if (iSendItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("SendTo failed with %d"),iSendItem->ReturnCode()); + return EFail; + } + + iLogger.WriteFormat(_L("Peek data from socket")); + iRecvBuf.SetLength(0); + iRecvItem->Start(); + iSocketIn.RecvFrom(iRecvBuf, iInetAddrFrom, KIpHeaderIncluded|KSockReadPeek, iRecvItem->iStatus); + + iState = EState8; + Reschedule(); + iColl->Kick(); + return EPass; + } + case EState8: + { + if (iRecvItem->ReturnCode() != KErrNone) + { + iLogger.WriteFormat(_L("RecvFrom failed with %d"),iRecvItem->ReturnCode()); + return EFail; + } + + if (iRecvBuf.Length() != KIPHeaderSize + KUdpHeaderSize + KSendData().Length()) + { + iLogger.WriteFormat(_L("Received data is not same")); + return EFail; + } + return EPass; + } + default: + __ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockTestptstcs, 70)); + return EFail; + } + } + +void CEIntSockTest60::Cleanup() + { + iSocketIn.Close(); + iSocketOut.Close(); + } + + + +//------------------------------------------------------------------------------------------------- +// CEIntSockTest61 +//------------------------------------------------------------------------------------------------- + +CEIntSockTestBase* CEIntSockTest61::NewL(CProxyProvd* aProvd) + { + CEIntSockTestBase* ret = new(ELeave) CEIntSockTest61(aProvd); + return ret; + } + +CEIntSockTest61::CEIntSockTest61(CProxyProvd* aProvd) : + CEIntSockTestBase(aProvd) + {} + +TVerdict CEIntSockTest61::RunTestL() + { + Messages::TNodeId sourceCookie; + Messages::TRuntimeCtxIdOp sourceCookieOp(sourceCookie); + Messages::TNodeIdOp sourceNodeIdOp(sourceCookie); + + // Arbitrary numbers to test with + const TUint16 KSomeWorkerId = 0xf0f0; + const TUint8 KSomeSalt = 127; + TAny* KSomePtr = (TAny*)0xff0000ff; + sourceCookieOp.Set(KSomeSalt, KSomeWorkerId); + sourceNodeIdOp.SetPtr(KSomePtr); + + TEIntSockOpMsgWrapper opMsgWrapper; + CInternalSocketImpl* dummyImplPtr = NULL; + CommsFW::MCommsTransportSender* dummyTransportSender = NULL; + + TBuf8 msgBuff; + TEIntSockMsgExt* msgPtr = const_cast(reinterpret_cast(msgBuff.Ptr())); + + // Test part 1 + iLogger.WriteFormat(_L("Corrupting TEIntSockMsgExt memory with 0xcc")); + Mem::Fill(msgPtr, sizeof(TEIntSockMsgExt), TChar(0xcc)); + + iLogger.WriteFormat(_L("Constructing TEIntSockMsgExt")); + new (msgPtr)TEIntSockMsgExt(ESoCreate, opMsgWrapper, dummyImplPtr, dummyTransportSender, sourceCookie); + + TInt result = Mem::Compare(reinterpret_cast(&sourceCookie), (TInt)sizeof(Messages::TNodeId), + reinterpret_cast(&msgPtr->ImplCookie()), (TInt)sizeof(Messages::TNodeId)); + if (result == 0) + { + iLogger.WriteFormat(_L("Cookie comparison result = 0 as expected")); + } + else + { + iLogger.WriteFormat(_L("Cookie comparison result = %d"), result); + return EFail; + } + + // Test part 2 + iLogger.WriteFormat(_L("Corrupting TEIntSockMsgExt memory with 0xaa")); + Mem::Fill(msgPtr, sizeof(TEIntSockMsgExt), TChar(0xaa)); + + iLogger.WriteFormat(_L("Constructing TEIntSockMsgExt")); + new (msgPtr)TEIntSockMsgExt(ESoCreate, opMsgWrapper, dummyImplPtr, dummyTransportSender, sourceCookie); + + result = Mem::Compare(reinterpret_cast(&sourceCookie), sizeof(Messages::TNodeId), + reinterpret_cast(&msgPtr->ImplCookie()), sizeof(Messages::TNodeId)); + if (result == 0) + { + iLogger.WriteFormat(_L("Cookie comparison result = 0 as expected")); + } + else + { + iLogger.WriteFormat(_L("Cookie comparison result = %d"), result); + return EFail; + } + + return EPass; + } + +void CEIntSockTest61::Cleanup() + { + }