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