os/kernelhwsrv/halservices/hal/tsrc/savehal.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 1995-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 // hal\tsrc\savehal.cpp
    15 // 
    16 //
    17 
    18 #include <e32test.h>
    19 #include <f32file.h>
    20 #include <hal.h>
    21 
    22 _LIT(KHalDataFileName, "\\system\\data\\HAL.DAT");
    23 
    24 RTest test(_L("SAVEHAL"));
    25 
    26 const TInt KHalProperties=HAL::EEntryDynamic|HAL::EEntryValid;
    27 
    28 TInt E32Main()
    29 	{
    30 	test.Title();
    31 
    32 	test.Start(_L("Get HAL data"));
    33 	HAL::SEntry* pE;
    34 	TInt nEntries;
    35 	TInt r=HAL::GetAll(nEntries, pE);
    36 	test(r==KErrNone);
    37 	test.Printf(_L("%d entries\n"),nEntries);
    38 
    39 	const HAL::SEntry* pS=pE;
    40 	const HAL::SEntry* pEnd=pS+nEntries;
    41 	TInt* pD=(TInt*)pE;
    42 	TInt s=0;
    43 	for (; pS<pEnd; ++pS, ++s)
    44 		{
    45 		if ((pS->iProperties & KHalProperties)==KHalProperties)
    46 			{
    47 			TInt v=pS->iValue;
    48 			*pD++=s;
    49 			*pD++=v;
    50 			}
    51 		}
    52 	TInt nSaved=(pD-(TInt*)pE)>>1;
    53 	test.Printf(_L("%d entries to be saved\n"),nSaved);
    54 
    55 	test.Next(_L("Connect to file server"));
    56 	RFs fs;
    57 	r=fs.Connect();
    58 	test(r==KErrNone);
    59 
    60 	test.Next(_L("Open file"));
    61 	RFile file;
    62 	r=file.Replace(fs,KHalDataFileName,EFileWrite|EFileShareExclusive);
    63 	test(r==KErrNone);
    64 
    65 	test.Next(_L("Save data"));
    66 	TPckgBuf<TInt> muid;
    67 	r=HAL::Get(HAL::EMachineUid, muid());
    68 	test (r==KErrNone);
    69 	r=file.Write(muid);
    70 	test(r==KErrNone);
    71 	TPtrC8 ptr((const TUint8*)pE, nSaved*8);
    72 	r=file.Write(ptr);
    73 	test(r==KErrNone);
    74 
    75 	file.Close();
    76 	fs.Close();
    77 	User::Free(pE);
    78 
    79 	test.End();
    80 
    81 	return 0;
    82 	}