messagingfw/biomsgfw/BIUTTSRC/t_ipaddr.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 harness 
       
    15 // 
       
    16 //
       
    17 
       
    18 //  Includes...
       
    19 #include <e32test.h>
       
    20 #include <ipaddr.h>
       
    21 
       
    22 //  Global functions..
       
    23 //  functions()
       
    24 GLDEF_C void doMainL();
       
    25 GLDEF_C TInt E32Main();
       
    26 
       
    27 //forward reference
       
    28 
       
    29 //  Resources..
       
    30 GLDEF_C RTest test(_L("BIO Test CIpAddress"));
       
    31 LOCAL_D CTrapCleanup*       myCleanup;
       
    32 
       
    33 //*****************************************************************************
       
    34 //
       
    35 //  Implementation; global stuff
       
    36 //
       
    37 //*****************************************************************************
       
    38 GLDEF_C TInt E32Main()
       
    39     {
       
    40 	__UHEAP_MARK;
       
    41 	myCleanup = CTrapCleanup::New();
       
    42 	TRAPD(err,doMainL());		
       
    43 	test(err==KErrNone);
       
    44 	delete myCleanup;	
       
    45 	test.End();
       
    46 	test.Close();
       
    47 	__UHEAP_MARKEND;
       
    48 	return(KErrNone);
       
    49     }
       
    50 
       
    51 _LIT(KTestInOut1, "123.123.123.123");
       
    52 _LIT(KTestInOut2, "123.5.123.12");
       
    53 _LIT(KTestInOut3, "smtp.dial.pipex.com");
       
    54 _LIT(KTestInOut4, "Kenny is hacking the message server again.com");
       
    55 _LIT(KTestInOut5, "");
       
    56 _LIT(KTestInOut6, " ");
       
    57 _LIT(KTestInOut7, "  ");
       
    58 
       
    59 _LIT(KTestIn1, "005.012.123.32");
       
    60 _LIT(KTestOut1, "5.12.123.32");
       
    61 
       
    62 _LIT(KTestIn2, "5.12.123.032");
       
    63 _LIT(KTestOut2, "5.12.123.32");
       
    64 
       
    65 _LIT(KTestIn3, "005.002.003.002");
       
    66 _LIT(KTestOut3, "5.2.3.2");
       
    67 
       
    68 _LIT(KTestIn4, "  5.2.3.2");
       
    69 _LIT(KTestOut4, "5.2.3.2");
       
    70 
       
    71 void TestL(TInt aCurTest, const TDesC& aIn, const TDesC& aOut);
       
    72 
       
    73 void TestInOutL(TInt aCurTest, const TDesC& aInOut)
       
    74 	{
       
    75 	TestL(aCurTest, aInOut, aInOut);
       
    76 	}
       
    77 
       
    78 void RunTestsL()
       
    79 	{
       
    80 	TInt curTest=0;
       
    81 
       
    82 	TestInOutL(++curTest, KTestInOut1);
       
    83 	TestInOutL(++curTest, KTestInOut2);
       
    84 	TestInOutL(++curTest, KTestInOut3);
       
    85 	TestInOutL(++curTest, KTestInOut4);
       
    86 	TestInOutL(++curTest, KTestInOut5);
       
    87 	TestInOutL(++curTest, KTestInOut6);
       
    88 	TestInOutL(++curTest, KTestInOut7);
       
    89 
       
    90 	TestL(++curTest, KTestIn1, KTestOut1);
       
    91 	TestL(++curTest, KTestIn2, KTestOut2);
       
    92 	TestL(++curTest, KTestIn3, KTestOut3);
       
    93 	TestL(++curTest, KTestIn4, KTestOut4);
       
    94 	}
       
    95 
       
    96 void TestL(TInt aCurTest, const TDesC& aIn, const TDesC& aOut)
       
    97 	{
       
    98 	test.Printf(_L("Test %d\n\tIn=\"%S\"\n"), aCurTest, &aIn);
       
    99 	CIpAddress* ip = CIpAddress::NewLC(aIn);
       
   100 	test.Printf(_L("\tExpOut=\"%S\"\n"), &aOut);
       
   101 	test.Printf(_L("\tActOut=\"%S\"\n"), &ip->Addr());
       
   102 	test(ip->Addr().Compare(aOut)==0);
       
   103 	CleanupStack::PopAndDestroy(ip);
       
   104 	}
       
   105 
       
   106 
       
   107 GLDEF_C void doMainL()
       
   108     {
       
   109     test.Title();
       
   110     test.Start(_L("Test IP Addr"));
       
   111 	RunTestsL();	// Qualified: comment to ignore false leavescan error
       
   112     }