os/ossrv/lowlevellibsandfws/pluginfw/Framework/SimpleTests/t_ecomentry.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
// All rights reserved.
sl@0
     4
// This component and the accompanying materials are made available
sl@0
     5
// under the terms of "Eclipse Public License v1.0"
sl@0
     6
// which accompanies this distribution, and is available
sl@0
     7
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
//
sl@0
     9
// Initial Contributors:
sl@0
    10
// Nokia Corporation - initial contribution.
sl@0
    11
//
sl@0
    12
// Contributors:
sl@0
    13
//
sl@0
    14
// Description:
sl@0
    15
//
sl@0
    16
sl@0
    17
#include <e32test.h>
sl@0
    18
#include <f32file.h>
sl@0
    19
#include <s32file.h>
sl@0
    20
#include <bautils.h>
sl@0
    21
sl@0
    22
#include "EComEntry.h"
sl@0
    23
sl@0
    24
sl@0
    25
RTest TheTest(_L("t_ecomentry.exe"));
sl@0
    26
_LIT(KTestFile,"Z:\\Test\\");
sl@0
    27
_LIT(KFile,"Z:\\Test\\Data\\EComTest.aif");
sl@0
    28
_LIT(KTestFileChange,"C:\\EComEntryChangedFile");
sl@0
    29
sl@0
    30
// functions for checking results
sl@0
    31
static void Check(TInt aValue, TInt aLine)
sl@0
    32
	{
sl@0
    33
	if(!aValue)
sl@0
    34
		{
sl@0
    35
        TheTest(EFalse, aLine);
sl@0
    36
		}
sl@0
    37
	}
sl@0
    38
sl@0
    39
static  void Check(TInt aValue, TInt aExpected, TInt aLine)
sl@0
    40
	{
sl@0
    41
	if(aValue != aExpected)
sl@0
    42
		{
sl@0
    43
        RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
sl@0
    44
		TheTest(EFalse, aLine);
sl@0
    45
		}
sl@0
    46
	}
sl@0
    47
sl@0
    48
sl@0
    49
#define TEST(arg) ::Check((arg), __LINE__)
sl@0
    50
#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
sl@0
    51
sl@0
    52
class CEComEntryTest // codescanner::missingcclass
sl@0
    53
	{
sl@0
    54
public:
sl@0
    55
	static void TestEComEntryL();
sl@0
    56
	static void TestEComEntryOOML();
sl@0
    57
	};
sl@0
    58
sl@0
    59
void CEComEntryTest::TestEComEntryL()
sl@0
    60
sl@0
    61
	{
sl@0
    62
	TheTest.Next(_L("Create EComEntry Object....."));
sl@0
    63
	__UHEAP_MARK;
sl@0
    64
sl@0
    65
sl@0
    66
	TInt err=KErrNone;
sl@0
    67
	RFs fs;
sl@0
    68
	err = fs.Connect();
sl@0
    69
	CleanupClosePushL(fs);
sl@0
    70
sl@0
    71
	TEST(err==KErrNone);
sl@0
    72
	TEntry info,infoSecond;
sl@0
    73
	TTime time;
sl@0
    74
	time.UniversalTime();
sl@0
    75
sl@0
    76
	//get entry details for test file
sl@0
    77
	err=fs.Entry(KFile,info);
sl@0
    78
	TEST(err==KErrNone);
sl@0
    79
sl@0
    80
	//get entry details for existing file
sl@0
    81
	err=fs.Entry(KTestFile,infoSecond);
sl@0
    82
	TEST2(err,KErrNone);
sl@0
    83
	fs.Close();
sl@0
    84
	CleanupStack::Pop(&fs);
sl@0
    85
sl@0
    86
	//create ecomentry object
sl@0
    87
sl@0
    88
	CEComEntry* entry= CEComEntry::NewL(info.iName,info.iType[1],info.iType[2]);
sl@0
    89
	CleanupStack::PushL(entry);
sl@0
    90
sl@0
    91
	// not pushed onto cleanup stack as SetNameL will take ownership
sl@0
    92
	HBufC* buf= HBufC::NewL(25);
sl@0
    93
	*buf=KTestFileChange;
sl@0
    94
sl@0
    95
	delete entry->iName;
sl@0
    96
	entry->iName=buf;
sl@0
    97
	entry->SetModified(time);
sl@0
    98
sl@0
    99
	TEST(entry->GetName()==buf->Des());
sl@0
   100
	TEST(entry->GetModified()==time);
sl@0
   101
sl@0
   102
	CleanupStack::PopAndDestroy(entry);
sl@0
   103
	__UHEAP_MARKEND;
sl@0
   104
	}
sl@0
   105
sl@0
   106
sl@0
   107
// out of memory test
sl@0
   108
void CEComEntryTest::TestEComEntryOOML()
sl@0
   109
	{
sl@0
   110
	TheTest.Next(_L("EComEntry Out of Memory Test....."));
sl@0
   111
	TInt processHandlesS = 0;
sl@0
   112
	TInt threadHandlesS = 0;
sl@0
   113
	TInt processHandlesE = 0;
sl@0
   114
	TInt threadHandlesE = 0;
sl@0
   115
	RThread().HandleCount(processHandlesS, threadHandlesS);
sl@0
   116
	for(TInt count=1;;++count)
sl@0
   117
		{
sl@0
   118
		// Setting Heap failure for OOM test
sl@0
   119
		__UHEAP_SETFAIL(RHeap::EDeterministic, count);
sl@0
   120
		__UHEAP_MARK;
sl@0
   121
sl@0
   122
		TRAPD(err,TestEComEntryL());
sl@0
   123
		if(err == KErrNoMemory)
sl@0
   124
			{
sl@0
   125
			__UHEAP_MARKEND;
sl@0
   126
			}
sl@0
   127
		else if(err == KErrNone)
sl@0
   128
			{
sl@0
   129
			__UHEAP_MARKEND;
sl@0
   130
			RDebug::Print(_L("The test succeeded at heap failure rate=%d.\n"), count);
sl@0
   131
			break;
sl@0
   132
			}
sl@0
   133
		else
sl@0
   134
			{
sl@0
   135
			__UHEAP_MARKEND;
sl@0
   136
			TEST2(err, KErrNone);
sl@0
   137
			}
sl@0
   138
		__UHEAP_RESET;
sl@0
   139
		}
sl@0
   140
	__UHEAP_RESET;
sl@0
   141
	RThread().HandleCount(processHandlesE, threadHandlesE);
sl@0
   142
	TEST(processHandlesS == processHandlesE);
sl@0
   143
	TEST(threadHandlesS == threadHandlesE);
sl@0
   144
sl@0
   145
	}
sl@0
   146
sl@0
   147
sl@0
   148
GLDEF_C TInt E32Main()
sl@0
   149
	{
sl@0
   150
	__UHEAP_MARK;
sl@0
   151
	TheTest.Title();
sl@0
   152
	TheTest.Start(_L(" @SYMTestCaseID:SYSLIB-ECOM-LEGACY-ECOMENTRY-0001 Starting tests... "));
sl@0
   153
sl@0
   154
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   155
sl@0
   156
	TRAPD(err2, CEComEntryTest::TestEComEntryOOML());
sl@0
   157
	TheTest(err2==KErrNone);
sl@0
   158
sl@0
   159
	delete cleanup;
sl@0
   160
sl@0
   161
sl@0
   162
	TheTest.End();
sl@0
   163
	TheTest.Close();
sl@0
   164
	__UHEAP_MARKEND;
sl@0
   165
	return(0);
sl@0
   166
	}