textandlocutils/jplangutil/test/tsrc/tjplangutil.cpp
changeset 40 91ef7621b7fc
equal deleted inserted replaced
21:f2f7b3284356 40:91ef7621b7fc
       
     1 /*
       
     2 * Copyright (c) 2010 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 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <e32test.h>
       
    22 #include <jplangutil.h>
       
    23 
       
    24 ///////////////////////////////////////////////////////////////////////////////////////
       
    25 RTest TheTest(_L("TestJPLangUtil"));
       
    26 	
       
    27 ///////////////////////////////////////////////////////////////////////////////////////
       
    28 ///////////////////////////////////////////////////////////////////////////////////////
       
    29 //Tests macroses and functions.
       
    30 //If (!aValue) then the test will be panicked, the test data files will be deleted.
       
    31 static void Check(TInt aValue, TInt aLine)
       
    32 	{
       
    33 	if(!aValue)
       
    34 		{
       
    35 		TheTest(EFalse, aLine);
       
    36 		}
       
    37 	}
       
    38 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
       
    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 //Use these to test conditions.
       
    49 #define TEST(arg) ::Check((arg), __LINE__)
       
    50 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
       
    51 
       
    52 const TInt KDesLength = 24;
       
    53 _LIT( KText, "Text" );
       
    54 
       
    55 LOCAL_C void TestJLUConvertHalfToFullWidth()
       
    56     {
       
    57     TBuf<KDesLength> unisrc( KText );
       
    58     TBuf<KDesLength> unides; 
       
    59     TInt status = JPLangUtil::ConvertHalfToFullWidth( unisrc, unides );
       
    60     TEST(status == 4);
       
    61     }
       
    62 
       
    63 LOCAL_C void TestJLUConvertFullToHalfWidth()
       
    64     {
       
    65     TBuf<KDesLength> unisrc( KText );
       
    66     TBuf<KDesLength> unides; 
       
    67     TInt status = JPLangUtil::ConvertFullToHalfWidth( unisrc, unides );
       
    68     TEST(status == 0);
       
    69     }
       
    70 
       
    71 LOCAL_C void DoE32MainL()
       
    72 	{
       
    73 	TheTest.Start(_L("TestJPLangUtil:\n"));
       
    74 
       
    75 	TestJLUConvertHalfToFullWidth();
       
    76 	TestJLUConvertFullToHalfWidth();
       
    77     }
       
    78 
       
    79 //  Global Functions
       
    80 
       
    81 GLDEF_C TInt E32Main()
       
    82 	{
       
    83 	__UHEAP_MARK;
       
    84 
       
    85 	TheTest.Title();
       
    86 
       
    87 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
       
    88 	TEST(trapCleanup != NULL);
       
    89 
       
    90 	TRAPD(error, DoE32MainL());
       
    91 	TEST2(error, KErrNone);
       
    92 
       
    93 	delete trapCleanup;
       
    94 
       
    95 	TheTest.End();
       
    96 	TheTest.Close();
       
    97 
       
    98 	__UHEAP_MARKEND;
       
    99 	return KErrNone;
       
   100 	}