1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/testinterfacesettingbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,339 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// @file testinterfacesettingbase.h
1.18 +// @internalComponent
1.19 +//
1.20 +//
1.21 +
1.22 +#include "testinterfacesettingbase.h"
1.23 +#include "testinterfacebase.h"
1.24 +#include "controltransferrequests.h"
1.25 +
1.26 +
1.27 +namespace NUnitTesting_USBDI
1.28 + {
1.29 +
1.30 +CInterfaceSettingBase::CInterfaceSettingBase(const TDesC& aString)
1.31 +: iHashEndpointFunction(EndpointNumberHash),
1.32 + iIdRelEndpoint(EndpointIdentityRelationship),
1.33 + iEndpoints(iHashEndpointFunction,iIdRelEndpoint)
1.34 + {
1.35 + // Set the name of this interface setting
1.36 + iSettingString.Copy(aString);
1.37 + iInterfaceInfo().iString = &iSettingString;
1.38 +
1.39 + // Zero count the number of endpoints used for this setting
1.40 + iInterfaceInfo().iTotalEndpointsUsed = 0;
1.41 + }
1.42 +
1.43 +
1.44 +CInterfaceSettingBase::~CInterfaceSettingBase()
1.45 + {
1.46 + LOG_FUNC
1.47 +
1.48 + iEndpointReaders.ResetAndDestroy();
1.49 + iEndpointWriters.ResetAndDestroy();
1.50 + }
1.51 +
1.52 +
1.53 +const TDesC& CInterfaceSettingBase::Name() const
1.54 + {
1.55 + return iSettingString;
1.56 + }
1.57 +
1.58 +
1.59 +void CInterfaceSettingBase::SetClassCodeL(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol)
1.60 + {
1.61 + // Set class specific information
1.62 + iInterfaceInfo().iClass = TUsbcClassInfo(aClassCode,aSubClassCode,aDeviceProtocol);
1.63 + }
1.64 +
1.65 +
1.66 +TInt CInterfaceSettingBase::AddEndpoint(TEndpoint& aEndpoint)
1.67 + {
1.68 + LOG_FUNC
1.69 +
1.70 + if(aEndpoint.iEndpointNumber == EEndpoint0)
1.71 + {
1.72 + return KErrInUse;
1.73 + }
1.74 +
1.75 + if(iEndpoints.Count() < KMaxEndpointsPerClient)
1.76 + {
1.77 + // Set EEndpoint1, EEndpoint2, EEndpoint3, EEndpoint4 or EEndpoint5
1.78 + iInterfaceInfo().iEndpointData[iEndpoints.Count()] = aEndpoint.iEndpointInfo;
1.79 + iEndpoints.Insert(aEndpoint.iEndpointNumber,aEndpoint);
1.80 +
1.81 + // Update the total endpoints used on this interface
1.82 + iInterfaceInfo().iTotalEndpointsUsed = iEndpoints.Count();
1.83 +
1.84 + return KErrNone;
1.85 + }
1.86 + else
1.87 + {
1.88 + return KErrOverflow;
1.89 + }
1.90 + }
1.91 +
1.92 +
1.93 +void CInterfaceSettingBase::CreateEndpointReaderL(RDevUsbcClient& aClientDriver,TUint aEndpoint)
1.94 + {
1.95 + LOG_FUNC
1.96 + // Create the reader for this endpoint and store in the container
1.97 + CEndpointReader* epReader = new (ELeave) CEndpointReader(aClientDriver,
1.98 + iEndpoints.Find(static_cast<TEndpointNumber>(aEndpoint))->iEndpointNumber);
1.99 + CleanupStack::PushL(epReader);
1.100 + iEndpointReaders.AppendL(epReader);
1.101 + CleanupStack::Pop(epReader);
1.102 + }
1.103 +
1.104 +
1.105 +void CInterfaceSettingBase::CreateEndpointWriterL(RDevUsbcClient& aClientDriver,TUint aEndpoint)
1.106 + {
1.107 + LOG_FUNC
1.108 + // Create the writer for this endpoint and store in the container
1.109 + CEndpointWriter* epWriter = new (ELeave) CEndpointWriter(aClientDriver,
1.110 + iEndpoints.Find(static_cast<TEndpointNumber>(aEndpoint))->iEndpointNumber);
1.111 + CleanupStack::PushL(epWriter);
1.112 + iEndpointWriters.AppendL(epWriter);
1.113 + CleanupStack::Pop(epWriter);
1.114 + }
1.115 +
1.116 +void CInterfaceSettingBase::WriteSpecifiedDataToEndpointL(const TDesC8& aData,TUint16 aEndpointNumber)
1.117 + {
1.118 + LOG_FUNC
1.119 + // Access the correct writer for the given endpoint
1.120 + // and write the data to the host
1.121 + iEndpointWriters[aEndpointNumber-1]->Write(aData, ETrue);
1.122 + }
1.123 +
1.124 +void CInterfaceSettingBase::WriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
1.125 + {
1.126 + LOG_FUNC
1.127 + // Access the correct writer for the given endpoint
1.128 + // and write the data to the host
1.129 + iEndpointWriters[aEndpointNumber-1]->WriteUsingPatternL(aDataPattern,aNumBytes,ETrue);
1.130 + }
1.131 +
1.132 +void CInterfaceSettingBase::RepeatedWriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerWrite, TUint aTotalNumBytes, TUint16 aEndpointNumber)
1.133 + {
1.134 + LOG_FUNC
1.135 + // Access the correct writer for the given endpoint
1.136 + // and write the data to the host
1.137 + iEndpointWriters[aEndpointNumber-1]->WriteInPartsUsingPatternL(aDataPattern,aNumBytesPerWrite,aTotalNumBytes,ETrue);
1.138 + }
1.139 +
1.140 +void CInterfaceSettingBase::WriteCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber)
1.141 + {
1.142 + LOG_FUNC
1.143 +
1.144 + iEndpointWriters[aWriteEndpointNumber-1]->Write(iEndpointReaders[aReadEndpointNumber-1]->Buffer(), ETrue);
1.145 + }
1.146 +
1.147 +void CInterfaceSettingBase::CancelWriteDataToEndpointL(TUint16 aEndpointNumber)
1.148 + {
1.149 + LOG_FUNC
1.150 + // Access the correct writer for the given endpoint
1.151 + // and cancel any outstanding write. This will not of course work for 'synchronous' writes.
1.152 + iEndpointWriters[aEndpointNumber-1]->Cancel();
1.153 + }
1.154 +
1.155 +void CInterfaceSettingBase::WriteSynchronousSpecifiedDataToEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
1.156 + {
1.157 + LOG_FUNC
1.158 + // Access the correct writer for the given endpoint
1.159 + // and write the data to the host
1.160 + iEndpointWriters[aEndpointNumber-1]->WriteSynchronousUsingPatternL(aDataPattern,aNumBytes,ETrue);
1.161 + }
1.162 +
1.163 +void CInterfaceSettingBase::WriteSynchronousSpecifiedDataToAndHaltEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
1.164 + {
1.165 + LOG_FUNC
1.166 + // Access the correct writer for the given endpoint
1.167 + // and write the data to the host
1.168 + iEndpointWriters[aEndpointNumber-1]->WriteSynchronousUsingPatternAndHaltL(aDataPattern,aNumBytes);
1.169 + }
1.170 +
1.171 +void CInterfaceSettingBase::WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber)
1.172 + {
1.173 + LOG_FUNC
1.174 +
1.175 + //Attempt to write the complete cached buffer by starting at zero and choosing the max length posible
1.176 + WriteSynchronousCachedEndpointDataToEndpointL(aReadEndpointNumber, aWriteEndpointNumber, 0, KMaxTInt);
1.177 + }
1.178 +
1.179 +void CInterfaceSettingBase::WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber, TUint aStartPoint, TUint aLength)
1.180 + {
1.181 + LOG_FUNC
1.182 + // Access the correct writer for the given endpoint
1.183 + // Access the 'source' endpoint buffer. This contains data from that endpoint's last read.
1.184 + // Write this data to the host using 'write' endpoint.
1.185 +
1.186 + // Check data
1.187 + TPtr8 dataPtr(iEndpointReaders[aReadEndpointNumber-1]->Buffer());
1.188 + User::LeaveIfError(dataPtr.MaxLength() == 0);
1.189 + if(aStartPoint+aLength>dataPtr.Length())
1.190 + //allow use of excessive length to imply a write of all the rest of the buffer...
1.191 + //..otherwise 'Mid' would panic!
1.192 + {
1.193 + aLength = dataPtr.Length() - aStartPoint;
1.194 + }
1.195 +
1.196 + // Do the 'Write'
1.197 + // Note we need a synchronous 'Write' here
1.198 + iEndpointWriters[aWriteEndpointNumber-1]->WriteSynchronous(iEndpointReaders[aReadEndpointNumber-1]->Buffer().Mid(aStartPoint, aLength), ETrue);
1.199 + }
1.200 +
1.201 +TBool CInterfaceSettingBase::CachedEndpointResultL(const TUint16 aEndpointNumber)
1.202 + {
1.203 + LOG_FUNC
1.204 + // Access endpoint buffer containing data from the endpoint's last read
1.205 + // and validate with the supplied data pattern
1.206 +
1.207 + return iEndpointReaders[aEndpointNumber-1]->IsValid();
1.208 + }
1.209 +
1.210 +TInt CInterfaceSettingBase::NumBytesReadSoFarL(const TUint16 aEndpointNumber)
1.211 + {
1.212 + LOG_FUNC
1.213 + // Access endpoint buffer containing data from the endpoint's last read
1.214 + // and validate with the supplied data pattern
1.215 +
1.216 + return iEndpointReaders[aEndpointNumber-1]->NumBytesReadSoFar();
1.217 + }
1.218 +
1.219 +TInt CInterfaceSettingBase::NumBytesWrittenSoFarL(const TUint16 aEndpointNumber)
1.220 + {
1.221 + LOG_FUNC
1.222 + // Access endpoint buffer containing data from the endpoint's last read
1.223 + // and validate with the supplied data pattern
1.224 +
1.225 + return iEndpointWriters[aEndpointNumber-1]->NumBytesWrittenSoFar();
1.226 + }
1.227 +
1.228 +TBool CInterfaceSettingBase::ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aNumBytes, const TUint16 aEndpointNumber)
1.229 + {
1.230 + LOG_FUNC
1.231 + // Access endpoint buffer containing data from the endpoint's last read
1.232 + // and validate with the supplied data pattern
1.233 +
1.234 + return ValidateCachedEndpointDataL(aDataPattern, 0, aNumBytes, aEndpointNumber);
1.235 + }
1.236 +
1.237 +TBool CInterfaceSettingBase::ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aStartPoint, const TUint aNumBytes, const TUint16 aEndpointNumber)
1.238 + {
1.239 + LOG_FUNC
1.240 + __ASSERT_DEBUG(aDataPattern.Length()!=0, User::Panic(_L("Trying to validate with ZERO LENGTH STRING"), KErrArgument));
1.241 +
1.242 + //Check data in endpoint buffer
1.243 + TPtr8 dataToValidate(iEndpointReaders[aEndpointNumber-1]->Buffer());
1.244 + User::LeaveIfError(dataToValidate.MaxLength() == 0);
1.245 +
1.246 + TUint startPoint = aStartPoint%aDataPattern.Length();
1.247 + TUint numStartBytes = (aDataPattern.Length() - startPoint)%aDataPattern.Length();
1.248 + numStartBytes = aNumBytes<numStartBytes?aNumBytes:numStartBytes; //never test for more than aNumBytes
1.249 + TUint fullRepeats = (aNumBytes-numStartBytes)/aDataPattern.Length();
1.250 + TUint startEndPoint = (fullRepeats*aDataPattern.Length()) + numStartBytes;
1.251 + TUint numEndBytes = aNumBytes - startEndPoint;//fullRepeats*aDataPattern.Length() - numStartBytes;
1.252 + if(numStartBytes)
1.253 + {
1.254 + if(dataToValidate.Left(numStartBytes).Compare(aDataPattern.Mid(startPoint, numStartBytes)) != 0)
1.255 + {
1.256 + RDebug::Printf("ROUND TRIP VALIDATION: Start Bytes Match Failure");
1.257 + RDebug::Printf("ROUND TRIP VALIDATION: numStartBytes = %d", numStartBytes);
1.258 + RDebug::Printf("Start of sent data ...");
1.259 + RDebug::RawPrint(aDataPattern.Mid(startPoint, numStartBytes));
1.260 + RDebug::Printf("\n");
1.261 + RDebug::Printf("ROUND TRIP VALIDATION: Start of returned data ...");
1.262 + RDebug::RawPrint(dataToValidate.Left(numStartBytes));
1.263 + RDebug::Printf("\n");
1.264 + return EFalse;
1.265 + }
1.266 + }
1.267 + if(numEndBytes)
1.268 + {
1.269 + if(dataToValidate.Mid(startEndPoint,numEndBytes).Compare(aDataPattern.Left(numEndBytes)) != 0)
1.270 + {
1.271 + RDebug::Printf("ROUND TRIP VALIDATION: End Bytes Match Failure");
1.272 + RDebug::Printf("ROUND TRIP VALIDATION: startEndPoint = %d, numEndBytes = %d", startEndPoint, numEndBytes);
1.273 + RDebug::Printf("End of sent data ...");
1.274 + RDebug::RawPrint(aDataPattern.Left(numEndBytes));
1.275 + RDebug::Printf("\n");
1.276 + RDebug::Printf("ROUND TRIP VALIDATION: End of returned data ...");
1.277 + RDebug::RawPrint(dataToValidate.Mid(startEndPoint,numEndBytes));
1.278 + RDebug::Printf("\n");
1.279 + return EFalse;
1.280 + }
1.281 + }
1.282 + for(TInt i=0; i<fullRepeats; i++)
1.283 + {
1.284 + if(dataToValidate.Mid(numStartBytes + i*aDataPattern.Length(),aDataPattern.Length()).Compare(aDataPattern) != 0)
1.285 + {
1.286 + RDebug::Printf("ROUND TRIP VALIDATION: Repeated Bytes Match Failure, Repeat %d",i);
1.287 + RDebug::Printf("sent data middle block ...");
1.288 + RDebug::RawPrint(aDataPattern);
1.289 + RDebug::Printf("\n");
1.290 + RDebug::Printf("ROUND TRIP VALIDATION: Middle block of returned data ...");
1.291 + RDebug::RawPrint(dataToValidate.Mid(numStartBytes + i*aDataPattern.Length(),aDataPattern.Length()));
1.292 + RDebug::Printf("\n");
1.293 + return EFalse; //from 'for' loop
1.294 + }
1.295 + }
1.296 + return ETrue;
1.297 + }
1.298 +
1.299 +
1.300 +void CInterfaceSettingBase::ReadDataFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)
1.301 + {
1.302 + LOG_FUNC
1.303 + // Access the correct readerer for the given endpoint
1.304 + // and prepare to read the data to be sent by the host
1.305 + iEndpointReaders[aEndpointNumber-1]->ReadL(aNumBytes);
1.306 + }
1.307 +
1.308 +void CInterfaceSettingBase::CancelAnyReadDataFromEndpointL(TUint16 aEndpointNumber)
1.309 + {
1.310 + LOG_FUNC
1.311 + // Access the correct writer for the given endpoint
1.312 + // and cancel any outstanding write. This will not of course work for 'synchronous' writes.
1.313 + iEndpointReaders[aEndpointNumber-1]->Cancel();
1.314 + }
1.315 +
1.316 +void CInterfaceSettingBase::ReadDataFromAndHaltEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)
1.317 + {
1.318 + LOG_FUNC
1.319 + // Access the correct reader for the given endpoint
1.320 + // and prepare to read the data to be sent by the host
1.321 + iEndpointReaders[aEndpointNumber-1]->ReadAndHaltL(aNumBytes);
1.322 + }
1.323 +
1.324 +void CInterfaceSettingBase::RepeatedReadAndValidateFromEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes, TUint16 aEndpointNumber)
1.325 + {
1.326 + LOG_FUNC
1.327 + // Access the correct reader for the given endpoint
1.328 + // and prepare to read the data to be sent by the host
1.329 + // using multiple 'Reads'
1.330 + iEndpointReaders[aEndpointNumber-1]->RepeatedReadAndValidateL(aDataPattern, aNumBytesPerRead, aTotalNumBytes);
1.331 + }
1.332 +
1.333 +void CInterfaceSettingBase::ReadDataUntilShortFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)
1.334 + {
1.335 + LOG_FUNC
1.336 + // Access the correct reader for the given endpoint
1.337 + // and prepare to read the data to be sent by the host
1.338 + iEndpointReaders[aEndpointNumber-1]->ReadUntilShortL(aNumBytes);
1.339 + }
1.340 + }
1.341 +
1.342 +