symhelp/helpmodel/tsrc/TMODEL.CPP
changeset 0 1f04cf54edd8
equal deleted inserted replaced
-1:000000000000 0:1f04cf54edd8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Test Help Model module
       
    15 // 
       
    16 //
       
    17 
       
    18 // System includes
       
    19 #include <e32test.h>
       
    20 #include <f32file.h>
       
    21 
       
    22 // User includes
       
    23 #include "hlpmodel.h"
       
    24 
       
    25 // Globals
       
    26 static RFs					TheFs;
       
    27 static RTest				TheTest(_L("TMODEL - Test Help Model API"));
       
    28 static CTrapCleanup*		TheTrapCleanup;
       
    29 static CActiveScheduler*	TheScheduler;
       
    30 
       
    31 // Constants
       
    32 const TInt KTestCleanupStack=0x20;
       
    33 
       
    34 
       
    35 /**
       
    36 @SYMTestCaseID PIM-TMODEL-0001 
       
    37 */
       
    38 
       
    39 static void Test1L()
       
    40 	{
       
    41 	__UHEAP_MARK;
       
    42 	TheTest.Next(_L("@SYMTestCaseID PIM-TMODEL-0001 Test 1: Test memory leaks in help model"));
       
    43 	CHlpModel::NewLC(TheFs, NULL);
       
    44 	CleanupStack::PopAndDestroy(); // model
       
    45 	__UHEAP_MARKEND;
       
    46 
       
    47 	__UHEAP_MARK;
       
    48 	CHlpModel* model = CHlpModel::NewLC(TheFs, NULL);
       
    49 	model->OpenL();
       
    50 	CleanupStack::PopAndDestroy(); // model
       
    51 	__UHEAP_MARKEND;
       
    52 	}
       
    53 
       
    54 /**
       
    55 @SYMTestCaseID PIM-TMODEL-0002
       
    56 */
       
    57 	
       
    58 static void Test2L()
       
    59 	{
       
    60 	__UHEAP_MARK;
       
    61 	TheTest.Next(_L("@SYMTestCaseID PIM-TMODEL-0002 Test 2: Test category listing"));
       
    62 	CHlpModel* model = CHlpModel::NewLC(TheFs, NULL);
       
    63 	model->OpenL();
       
    64 
       
    65 	TBuf<KHlpMaxTextColLength> entry;
       
    66 	CDesCArray* catList = new(ELeave) CDesCArrayFlat(2);
       
    67 	CleanupStack::PushL(catList);
       
    68 
       
    69 	model->CategoryListL(catList);
       
    70 	for (TInt i=0; i<catList->Count(); i++)
       
    71 		{
       
    72 		entry.Append(catList->MdcaPoint(i));
       
    73 		TheTest.Printf(_L("\n%S\n"), &entry);
       
    74 		}
       
    75 	//TheTest.Console()->Getch();
       
    76 	model->CloseL();
       
    77 	CleanupStack::PopAndDestroy(2); // catList, model
       
    78 	__UHEAP_MARKEND;
       
    79 	}
       
    80 
       
    81 static void setupFileServerAndSchedulerL()
       
    82 //
       
    83 // Initialise the cleanup stack.
       
    84 //
       
    85 	{
       
    86 	TheTest(TheFs.Connect() == KErrNone);
       
    87 	TheScheduler = new (ELeave) CActiveScheduler;
       
    88 	CActiveScheduler::Install(TheScheduler);
       
    89 	}
       
    90 
       
    91 
       
    92 static void setupCleanup()
       
    93 //
       
    94 // Initialise the cleanup stack.
       
    95 //
       
    96     {
       
    97 	TheTrapCleanup = CTrapCleanup::New();
       
    98 	TheTest(TheTrapCleanup!=NULL);
       
    99 	TRAPD(r,\
       
   100 		{\
       
   101 		for (TInt i=KTestCleanupStack;i>0;i--)\
       
   102 			CleanupStack::PushL((TAny*)0);\
       
   103 		CleanupStack::Pop(KTestCleanupStack);\
       
   104 		});
       
   105 	TheTest(r==KErrNone);
       
   106 	}
       
   107 
       
   108 GLDEF_C TInt E32Main()
       
   109 //
       
   110 // Test Help Model API
       
   111 //
       
   112     {
       
   113 	__UHEAP_MARK;
       
   114 
       
   115 	TheTest.Title();
       
   116 	setupCleanup();
       
   117 	
       
   118 	TRAPD(r,
       
   119 		setupFileServerAndSchedulerL();
       
   120 		Test1L();
       
   121 		Test2L();
       
   122 		)
       
   123 	TheTest(r==KErrNone);
       
   124 
       
   125 	delete TheScheduler;
       
   126 	delete TheTrapCleanup;
       
   127 	TheFs.Close();
       
   128 	TheTest.Close();
       
   129 
       
   130 	__UHEAP_MARKEND;
       
   131 	return KErrNone;
       
   132     }