os/kernelhwsrv/halservices/hal/tsrc/savehal.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/halservices/hal/tsrc/savehal.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,82 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// hal\tsrc\savehal.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32test.h>
    1.22 +#include <f32file.h>
    1.23 +#include <hal.h>
    1.24 +
    1.25 +_LIT(KHalDataFileName, "\\system\\data\\HAL.DAT");
    1.26 +
    1.27 +RTest test(_L("SAVEHAL"));
    1.28 +
    1.29 +const TInt KHalProperties=HAL::EEntryDynamic|HAL::EEntryValid;
    1.30 +
    1.31 +TInt E32Main()
    1.32 +	{
    1.33 +	test.Title();
    1.34 +
    1.35 +	test.Start(_L("Get HAL data"));
    1.36 +	HAL::SEntry* pE;
    1.37 +	TInt nEntries;
    1.38 +	TInt r=HAL::GetAll(nEntries, pE);
    1.39 +	test(r==KErrNone);
    1.40 +	test.Printf(_L("%d entries\n"),nEntries);
    1.41 +
    1.42 +	const HAL::SEntry* pS=pE;
    1.43 +	const HAL::SEntry* pEnd=pS+nEntries;
    1.44 +	TInt* pD=(TInt*)pE;
    1.45 +	TInt s=0;
    1.46 +	for (; pS<pEnd; ++pS, ++s)
    1.47 +		{
    1.48 +		if ((pS->iProperties & KHalProperties)==KHalProperties)
    1.49 +			{
    1.50 +			TInt v=pS->iValue;
    1.51 +			*pD++=s;
    1.52 +			*pD++=v;
    1.53 +			}
    1.54 +		}
    1.55 +	TInt nSaved=(pD-(TInt*)pE)>>1;
    1.56 +	test.Printf(_L("%d entries to be saved\n"),nSaved);
    1.57 +
    1.58 +	test.Next(_L("Connect to file server"));
    1.59 +	RFs fs;
    1.60 +	r=fs.Connect();
    1.61 +	test(r==KErrNone);
    1.62 +
    1.63 +	test.Next(_L("Open file"));
    1.64 +	RFile file;
    1.65 +	r=file.Replace(fs,KHalDataFileName,EFileWrite|EFileShareExclusive);
    1.66 +	test(r==KErrNone);
    1.67 +
    1.68 +	test.Next(_L("Save data"));
    1.69 +	TPckgBuf<TInt> muid;
    1.70 +	r=HAL::Get(HAL::EMachineUid, muid());
    1.71 +	test (r==KErrNone);
    1.72 +	r=file.Write(muid);
    1.73 +	test(r==KErrNone);
    1.74 +	TPtrC8 ptr((const TUint8*)pE, nSaved*8);
    1.75 +	r=file.Write(ptr);
    1.76 +	test(r==KErrNone);
    1.77 +
    1.78 +	file.Close();
    1.79 +	fs.Close();
    1.80 +	User::Free(pE);
    1.81 +
    1.82 +	test.End();
    1.83 +
    1.84 +	return 0;
    1.85 +	}