os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/OpenFileByHandle7806.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "TestPlayerUtils.h"
sl@0
    17
#include "OpenFileByHandle7806.h"
sl@0
    18
sl@0
    19
CTestMmfAclntOpenFile7806::CTestMmfAclntOpenFile7806(const TDesC& aTestName, const TDesC& aSectName)
sl@0
    20
	: CTestMmfAclntOpenFile7804(aTestName, aSectName)
sl@0
    21
	{}
sl@0
    22
sl@0
    23
CTestMmfAclntOpenFile7806* CTestMmfAclntOpenFile7806::NewL(const TDesC& aTestName, const TDesC& aSectName)
sl@0
    24
	{
sl@0
    25
	CTestMmfAclntOpenFile7806* self = new (ELeave) CTestMmfAclntOpenFile7806(aTestName, aSectName);
sl@0
    26
	return self;
sl@0
    27
	}
sl@0
    28
sl@0
    29
/**
sl@0
    30
 * Open new file.
sl@0
    31
 */
sl@0
    32
TVerdict CTestMmfAclntOpenFile7806::DoTestL(CMdaAudioPlayerUtility* aPlayer)
sl@0
    33
	{
sl@0
    34
	TVerdict iAllocTestStepResult=EPass;
sl@0
    35
	TInt err = KErrNone;
sl@0
    36
	TBool result = EFalse;
sl@0
    37
	
sl@0
    38
	//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
sl@0
    39
	if( PerformTestL(aPlayer) != EPass )
sl@0
    40
		{
sl@0
    41
		err = iError;
sl@0
    42
		}
sl@0
    43
sl@0
    44
	if (err != KErrNone)
sl@0
    45
		{
sl@0
    46
		INFO_PRINTF2(_L("Test error, returned error code =  %d"), err);
sl@0
    47
		User::Leave(err);
sl@0
    48
		}
sl@0
    49
	else
sl@0
    50
		{
sl@0
    51
		//Check the iAllocTestStepResult
sl@0
    52
		if (iAllocTestStepResult != EPass)
sl@0
    53
			{
sl@0
    54
			result = ETrue;
sl@0
    55
			}
sl@0
    56
		}	
sl@0
    57
	
sl@0
    58
	TInt failCount = 1;
sl@0
    59
	TBool completed = EFalse;
sl@0
    60
	iAllocTestStepResult = EPass; // XXX check?? assume pass
sl@0
    61
	TBool reachedEnd = EFalse; // Note: declare outside loop to help with debugging
sl@0
    62
	for(;;)	
sl@0
    63
		{
sl@0
    64
		__UHEAP_SETFAIL(RHeap::EFailNext, failCount);
sl@0
    65
		__MM_HEAP_MARK;
sl@0
    66
sl@0
    67
		//>>>>>>>>>>>>>>>>>>>>>>>>Test Method Call<<<<<<<<<<<<<<<<<<<<<<<<<<
sl@0
    68
		TVerdict verdict = EFail;
sl@0
    69
		TRAP(err, verdict = PerformTestL(aPlayer));
sl@0
    70
		
sl@0
    71
		if (err == KErrNone && verdict != EPass) 
sl@0
    72
			{
sl@0
    73
			err = iError;
sl@0
    74
			}
sl@0
    75
sl@0
    76
		completed = EFalse;
sl@0
    77
		if (err == KErrNone)
sl@0
    78
			{
sl@0
    79
			TAny *testAlloc = User::Alloc(1); // when this fails, we passed through all allocs within test
sl@0
    80
			if (testAlloc == NULL)
sl@0
    81
				{
sl@0
    82
				reachedEnd = ETrue;
sl@0
    83
				failCount -= 1;
sl@0
    84
				}
sl@0
    85
			else
sl@0
    86
				{
sl@0
    87
				User::Free(testAlloc);	
sl@0
    88
				}			
sl@0
    89
			
sl@0
    90
			//Check the iAllocTestStepResult
sl@0
    91
			if (iAllocTestStepResult != EPass)
sl@0
    92
				{
sl@0
    93
				result = ETrue;
sl@0
    94
				}
sl@0
    95
			
sl@0
    96
			completed = reachedEnd || result;
sl@0
    97
			}
sl@0
    98
		else if (err != KErrNoMemory) // bad error code
sl@0
    99
			{
sl@0
   100
			completed = ETrue;
sl@0
   101
			result = EFail;
sl@0
   102
			}			
sl@0
   103
sl@0
   104
		__MM_HEAP_MARKEND;
sl@0
   105
		__UHEAP_SETFAIL(RHeap::ENone, 0);
sl@0
   106
sl@0
   107
		if (completed)
sl@0
   108
			{
sl@0
   109
			break; // exit loop
sl@0
   110
			}
sl@0
   111
sl@0
   112
		failCount++;
sl@0
   113
		}
sl@0
   114
sl@0
   115
	failCount -= 1; // Failcount of 1 equates to 0 successful allocs, etc
sl@0
   116
sl@0
   117
	if (err != KErrNone || result)
sl@0
   118
		{
sl@0
   119
		TBuf<80> format;
sl@0
   120
		iAllocTestStepResult = EFail;
sl@0
   121
		if (result)
sl@0
   122
			{
sl@0
   123
			format.Format(_L("  Bad result with %d memory allocations tested\n"), failCount);
sl@0
   124
			}
sl@0
   125
		else
sl@0
   126
			{
sl@0
   127
			format.Format(_L("  Error(%d) with %d memory allocations tested\n"), err, failCount);
sl@0
   128
			}
sl@0
   129
		Log(format);
sl@0
   130
		}
sl@0
   131
	else 
sl@0
   132
		{
sl@0
   133
		TBuf<80> format;
sl@0
   134
		format.Format(_L("  Completed OK with %d memory allocations tested\n"), failCount);
sl@0
   135
		Log(format);
sl@0
   136
		}
sl@0
   137
sl@0
   138
	return iAllocTestStepResult;
sl@0
   139
	}
sl@0
   140
sl@0
   141
CTestMmfAclntRepeatPlayAlloc::CTestMmfAclntRepeatPlayAlloc(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName)
sl@0
   142
	: CTestMmfAclntOpenFile7806(aTestName, aSectName), iSectName(aSectName),iKeyName(aKeyName)
sl@0
   143
	{}
sl@0
   144
sl@0
   145
CTestMmfAclntRepeatPlayAlloc* CTestMmfAclntRepeatPlayAlloc::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName)
sl@0
   146
	{
sl@0
   147
	CTestMmfAclntRepeatPlayAlloc* self = new (ELeave) CTestMmfAclntRepeatPlayAlloc(aTestName, aSectName, aKeyName);
sl@0
   148
	return self;
sl@0
   149
	}
sl@0
   150
sl@0
   151
TVerdict CTestMmfAclntRepeatPlayAlloc::PerformTestL(CMdaAudioPlayerUtility* aPlayer)
sl@0
   152
	{
sl@0
   153
	INFO_PRINTF1( _L("TestPlayerUtils : OpenFileL(RFile&)/Play"));
sl@0
   154
	TInt repeatCount;
sl@0
   155
	TVerdict ret = EFail;
sl@0
   156
	iError = KErrNone;
sl@0
   157
sl@0
   158
	RFs fs;
sl@0
   159
sl@0
   160
	User::LeaveIfError(fs.Connect());
sl@0
   161
	CleanupClosePushL(fs);
sl@0
   162
	User::LeaveIfError(fs.ShareProtected());
sl@0
   163
sl@0
   164
	TBuf<KSizeBuf>	filename;
sl@0
   165
	TPtrC			filename1; 
sl@0
   166
	RFile			file;
sl@0
   167
sl@0
   168
	if(!GetStringFromConfig(iSectName, iKeyName, filename1))
sl@0
   169
		{
sl@0
   170
		return EInconclusive;
sl@0
   171
		}
sl@0
   172
sl@0
   173
	GetDriveName(filename);
sl@0
   174
	filename.Append(filename1);
sl@0
   175
sl@0
   176
	User::LeaveIfError( file.Open( fs, filename, EFileRead ) );
sl@0
   177
	CleanupClosePushL(file);
sl@0
   178
	if(!GetIntFromConfig(_L("SectionRepeatCount"), _L("numOfRepeat"), repeatCount))
sl@0
   179
		{
sl@0
   180
		return EInconclusive;
sl@0
   181
		}
sl@0
   182
	aPlayer->SetRepeats(repeatCount, TTimeIntervalMicroSeconds(2));
sl@0
   183
	aPlayer->OpenFileL(file);
sl@0
   184
	CActiveScheduler::Start();
sl@0
   185
	
sl@0
   186
	if (iError == KErrNone)
sl@0
   187
		{
sl@0
   188
		aPlayer->Play();
sl@0
   189
		CActiveScheduler::Start();
sl@0
   190
		}
sl@0
   191
sl@0
   192
	if (iError == KErrNone)
sl@0
   193
		{
sl@0
   194
		ret = EPass;
sl@0
   195
		}
sl@0
   196
	
sl@0
   197
	aPlayer->Close();	
sl@0
   198
	CleanupStack::PopAndDestroy(2, &fs);
sl@0
   199
sl@0
   200
	return ret;
sl@0
   201
	}