kerneltest/e32test/system/t_reg.cpp
changeset 0 a41df078684a
child 293 0659d0e1a03c
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-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 the License "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 // e32test\system\t_reg.cpp
       
    15 // Overview:
       
    16 // Test the machine configuration functions
       
    17 // API Information:
       
    18 // User::MachineConfiguration, User::SetMachineConfiguration
       
    19 // Details:
       
    20 // - Save machine configuration to different size descriptors and verify
       
    21 // the results are as expected.
       
    22 // - Set the machine configuration back to previous configurations, verify
       
    23 // the results are as expected.
       
    24 // Platforms/Drives/Compatibility:
       
    25 // All.
       
    26 // Assumptions/Requirement/Pre-requisites:
       
    27 // Failures and causes:
       
    28 // Base Port information:
       
    29 // 
       
    30 //
       
    31 
       
    32 #include <e32test.h>
       
    33 #include <e32hal.h>
       
    34 
       
    35 LOCAL_D RTest test(_L("T_REG"));
       
    36 
       
    37 
       
    38 LOCAL_C void testMachineConfiguration()
       
    39 //
       
    40 // Test the machine configuration functions
       
    41 //
       
    42 	{
       
    43 
       
    44 	test.Start(_L("Create test environment"));
       
    45 //	
       
    46 	test.Next(_L("Save machine configuration to tiny descriptor"));
       
    47 	TInt x=0;
       
    48     TPtr8 mc11((TUint8*)&x,sizeof(x));
       
    49 	test(User::MachineConfiguration(mc11,x)==KErrArgument);
       
    50 	test(x!=0);
       
    51 	test(x<10000);
       
    52 //
       
    53 	test.Next(_L("Save machine configuration to just too small descriptor"));
       
    54 	TUint8* pMC1=(TUint8*)User::Alloc(x);
       
    55 	test(pMC1!=NULL);
       
    56 	TInt y;
       
    57     TPtr8 mc12(pMC1,x-1);
       
    58 	test(User::MachineConfiguration(mc12,y)==KErrArgument);
       
    59 	test(y==x);
       
    60 //
       
    61 	test.Next(_L("Save machine configuration properly"));
       
    62     TPtr8 mc13(pMC1,x);
       
    63 	test(User::MachineConfiguration(mc13,y)==KErrNone);
       
    64 	test(y==x);
       
    65 //
       
    66 	test.Next(_L("Save machine configuration to tiny descriptor"));
       
    67 	TInt z=0;
       
    68     TPtr8 mc21((TUint8*)&z,sizeof(z));
       
    69 	test(User::MachineConfiguration(mc21,z)==KErrArgument);
       
    70 	test(z!=0);
       
    71 	test(z<10000);
       
    72 //
       
    73 	test.Next(_L("Save machine configuration to just too small descriptor"));
       
    74 	TUint8* pMC2=(TUint8*)User::Alloc(z);
       
    75 	test(pMC2!=NULL);
       
    76     TPtr8 mc22(pMC2,z-1);
       
    77 	test(User::MachineConfiguration(mc22,y)==KErrArgument);
       
    78 	test(y==z);
       
    79 //
       
    80 	test.Next(_L("Save machine configuration properly"));
       
    81     TPtr8 mc23(pMC2,z);
       
    82 	test(User::MachineConfiguration(mc23,y)==KErrNone);
       
    83 	test(y==z);
       
    84 //
       
    85 //	__KHEAP_MARK;	// GLD 3/2/97 I don't know why the KHEAP checking is no longer working
       
    86 	test.Next(_L("Restore first configuration"));
       
    87 	test(User::SetMachineConfiguration(TPtrC8(pMC1,x))==KErrNone);
       
    88 //	__KHEAP_CHECK(0);
       
    89 //
       
    90 	test.Next(_L("Restore second configuration"));
       
    91 	test(User::SetMachineConfiguration(TPtrC8(pMC2,z))==KErrNone);
       
    92 //	__KHEAP_MARKEND;
       
    93 //
       
    94 	test.Next(_L("Tidy up"));
       
    95 	delete pMC1;
       
    96 	delete pMC2;
       
    97 	test.End();
       
    98 	}
       
    99 
       
   100 
       
   101 GLDEF_C TInt E32Main()
       
   102 //
       
   103 // Test the registry functions.
       
   104 //
       
   105     {
       
   106 
       
   107 	test.Title();
       
   108 //
       
   109 	test.Start(_L("Test Machine Configuration"));
       
   110 	testMachineConfiguration();
       
   111 //
       
   112 	test.End();
       
   113 	return(KErrNone);
       
   114     }
       
   115