textrendering/texthandling/tfields/T_ROMAN.CPP
changeset 53 11e2bb0d14ba
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
46:6124ff6478cc 53:11e2bb0d14ba
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include "../sfields/FLDNUMS.H"
    19 #include "../sfields/FLDNUMS.H"
    20 #include <e32test.h>
    20 #include "T_ROMAN.h"
    21 #include <e32std.h>
    21 
       
    22 #define test(cond)											\
       
    23 	{														\
       
    24 	TBool __bb = (cond);									\
       
    25 	TEST(__bb);												\
       
    26 	if (!__bb)												\
       
    27 		{													\
       
    28 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
       
    29 		User::Leave(1);										\
       
    30 		}													\
       
    31 	}
    22 
    32 
    23 #define UNUSED_VAR(a) a = a
    33 #define UNUSED_VAR(a) a = a
    24 
    34 
    25 const TInt KTestCleanupStack=0x40;
    35 const TInt KTestCleanupStack=0x40;
    26 
    36 
    27 LOCAL_D RTest test(_L("Testing denery to Roman numeral converter"));
       
    28 LOCAL_D CTrapCleanup* TheTrapCleanup;
    37 LOCAL_D CTrapCleanup* TheTrapCleanup;
    29 
    38 
    30 //
    39 //
    31 
    40 
    32 LOCAL_C void GetValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
    41 void CT_ROMAN::GetValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
    33 	{
    42 	{
    34 	TPtr ptr=aBuf->Des();
    43 	TPtr ptr=aBuf->Des();
    35 	TInt size=aNumeral.DeneryToChar(ptr,aDenery);
    44 	TInt size=aNumeral.DeneryToChar(ptr,aDenery);
    36 	if (size>0)
    45 	if (size>0)
    37 		{
    46 		{
    41 			test(size==KErrNone);
    50 			test(size==KErrNone);
    42 		}
    51 		}
    43 	}
    52 	}
    44 
    53 
    45 
    54 
    46 LOCAL_D void DisplayValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
    55 void CT_ROMAN::DisplayValue(HBufC* aBuf,TInt aDenery,TDeneryToCharBase& aNumeral)
    47 	{
    56 	{
    48 	GetValue(aBuf,aDenery,aNumeral);
    57 	GetValue(aBuf,aDenery,aNumeral);
    49 	test.Printf(_L("%D: "),aDenery);
    58 	INFO_PRINTF2(_L("%D: "),aDenery);
    50 		test.Printf(*aBuf);
    59 	INFO_PRINTF1(*aBuf);
    51 		test.Printf(_L("\n"));
    60 	INFO_PRINTF1(_L("\n"));
    52 	}
    61 	}
    53 
    62 
    54 
    63 
    55 LOCAL_C void test1()
    64 void CT_ROMAN::test1()
    56 	{
    65 	{
    57 	test.Start(_L("Testing with buffer of adequate size"));
    66 	INFO_PRINTF1(_L("Testing with buffer of adequate size"));
    58 	test.Next(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_ROMAN-0001 "));
    67 	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-ETEXT-LEGACY-T_ROMAN-0001 "));
    59 	HBufC* hbuf = HBufC::NewL(10); 
    68 	HBufC* hbuf = HBufC::NewL(10); 
    60 	CleanupStack::PushL(hbuf);
    69 	CleanupStack::PushL(hbuf);
    61 	TRomanNumeral roman;
    70 	TRomanNumeral roman;
    62 	GetValue(hbuf,4,roman);
    71 	GetValue(hbuf,4,roman);
    63 	TPtr buf = hbuf->Des();
    72 	TPtr buf = hbuf->Des();
    64 		test(buf==_L("IV"));
    73 		test(buf==_L("IV"));
    65 	CleanupStack::PopAndDestroy();
    74 	CleanupStack::PopAndDestroy();
    66 	//
    75 	//
    67 	test.Next(_L("Testing with inadequate buffer"));
    76 	INFO_PRINTF1(_L("Testing with inadequate buffer"));
    68 	HBufC* minibuf = HBufC::NewL(1); 
    77 	HBufC* minibuf = HBufC::NewL(1); 
    69 	CleanupStack::PushL(minibuf);
    78 	CleanupStack::PushL(minibuf);
    70 	GetValue(minibuf,4,roman);
    79 	GetValue(minibuf,4,roman);
    71 	TPtr buf2 = minibuf->Des();
    80 	TPtr buf2 = minibuf->Des();
    72 		test(buf2==_L("IV"));
    81 		test(buf2==_L("IV"));
    73 	CleanupStack::PopAndDestroy();
    82 	CleanupStack::PopAndDestroy();
    74 	}
    83 	}
    75 
    84 
    76 
    85 
    77 LOCAL_C void test2()
    86 void CT_ROMAN::test2()
    78 	{
    87 	{
    79 	test.Next(_L("Testing Roman numerals for a range of denery values"));
    88 	INFO_PRINTF1(_L("Testing Roman numerals for a range of denery values"));
    80 	HBufC* hbuf = HBufC::NewL(10); 
    89 	HBufC* hbuf = HBufC::NewL(10); 
    81 	CleanupStack::PushL(hbuf);
    90 	CleanupStack::PushL(hbuf);
    82 	TRomanNumeral roman;
    91 	TRomanNumeral roman;
    83 
    92 
    84 	DisplayValue(hbuf,1,roman);
    93 	DisplayValue(hbuf,1,roman);
   100 
   109 
   101 	CleanupStack::PopAndDestroy();
   110 	CleanupStack::PopAndDestroy();
   102 	}
   111 	}
   103 
   112 
   104 
   113 
   105 LOCAL_C void test3()
   114 void CT_ROMAN::test3()
   106 	{
   115 	{
   107 	test.Next(_L("Testing alphabetic numerals for a range of denery values"));
   116 	INFO_PRINTF1(_L("Testing alphabetic numerals for a range of denery values"));
   108 	HBufC* hbuf = HBufC::NewL(10); 
   117 	HBufC* hbuf = HBufC::NewL(10); 
   109 	CleanupStack::PushL(hbuf);
   118 	CleanupStack::PushL(hbuf);
   110 	TAlphabeticNumeral alpha;
   119 	TAlphabeticNumeral alpha;
   111 
   120 
   112 	DisplayValue(hbuf,1,alpha);
   121 	DisplayValue(hbuf,1,alpha);
   128 
   137 
   129 	CleanupStack::PopAndDestroy();
   138 	CleanupStack::PopAndDestroy();
   130 	}
   139 	}
   131 
   140 
   132 
   141 
   133 LOCAL_C void runTests()
   142 void CT_ROMAN::runTests()
   134 // Test the fields dll.
   143 // Test the fields dll.
   135 //
   144 //
   136     {
   145     {
   137 	// test with HBufs both large enough and too small
   146 	// test with HBufs both large enough and too small
   138 	test1();
   147 	test1();
   143 	// Test alphabetics 
   152 	// Test alphabetics 
   144 	test3();
   153 	test3();
   145     }
   154     }
   146 
   155 
   147 
   156 
   148 LOCAL_C void setupCleanup()
   157 void CT_ROMAN::setupCleanup()
   149 //
   158 //
   150 // Initialise the cleanup stack.
   159 // Initialise the cleanup stack.
   151 //
   160 //
   152     {
   161     {
   153 
   162 
   159 		test(r==KErrNone);\
   168 		test(r==KErrNone);\
   160 		CleanupStack::Pop(KTestCleanupStack);\
   169 		CleanupStack::Pop(KTestCleanupStack);\
   161 		});
   170 		});
   162 	}
   171 	}
   163 
   172 
       
   173 CT_ROMAN::CT_ROMAN()
       
   174     {
       
   175     SetTestStepName(KTestStep_T_ROMAN);
       
   176     }
   164 
   177 
   165 GLDEF_C TInt E32Main()
   178 TVerdict CT_ROMAN::doTestStepL()
   166 //
       
   167 // Test the streaming framework.
       
   168 //
       
   169     {
   179     {
       
   180 	INFO_PRINTF1(_L("Testing denery to Roman numeral converter"));
       
   181     SetTestStepResult(EFail);
   170 
   182 
   171 	test.Title();
   183     __UHEAP_MARK;
   172 	
   184 
   173 	__UHEAP_MARK;
       
   174 	setupCleanup();
   185 	setupCleanup();
   175        
   186     
   176 	TRAPD(r,runTests());
   187     TRAPD(error1, runTests());
   177     test(r == KErrNone);
   188 
   178 	
       
   179 	delete TheTrapCleanup;
   189 	delete TheTrapCleanup;
   180 	__UHEAP_MARKEND;
   190 
   181 	test.End();
   191     __UHEAP_MARKEND;
   182 	test.Close();
   192 
   183 	return 0;
   193     if(error1 == KErrNone)
       
   194         {
       
   195         SetTestStepResult(EPass);
       
   196         }
       
   197 
       
   198     return TestStepResult();
   184     }
   199     }