authorisation/userpromptservice/test/tups_backuprestore/step_restore.cpp
changeset 8 35751d3474b7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 the License "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 "tbackuprestorestep.h"
       
    20 #include <test/testexecutelog.h>
       
    21 
       
    22 #include "swi/backuprestore.h"
       
    23 #include "swi/swispubsubdefs.h"
       
    24 
       
    25 CTStepRestore::CTStepRestore()
       
    26 	{
       
    27 	SetTestStepName(KTStepRestore);
       
    28 	}
       
    29 
       
    30 TVerdict CTStepRestore::doTestStepL()
       
    31 	{
       
    32 	if (TestStepResult() != EPass)
       
    33 		{
       
    34 		return TestStepResult();
       
    35 		}
       
    36 	
       
    37 	TInt err = KErrNone;
       
    38 	TRAP(err, RestoreL());
       
    39 	INFO_PRINTF2(_L("RestoreL returned %d"), err);
       
    40 	if (err != KErrNone)
       
    41 		{
       
    42 		// Can't set error to KErrServerBusy, or Testexecute will retry.
       
    43 		SetTestStepResult((err != KErrServerBusy)? static_cast<TVerdict>(err) : EFail);
       
    44 		}
       
    45 
       
    46 	CheckExpectedResultCodesL();
       
    47 	return TestStepResult();
       
    48 	}
       
    49 	
       
    50 void CTStepRestore::RestoreL()
       
    51 	{
       
    52 	RFs fs;
       
    53 	User::LeaveIfError(fs.Connect());
       
    54 	CleanupClosePushL(fs);
       
    55 	fs.ShareProtected();
       
    56 	
       
    57 	Swi::RRestoreSession session;
       
    58 	User::LeaveIfError(session.Connect());
       
    59 	CleanupClosePushL(session);
       
    60 	
       
    61 	while (NextPackage())
       
    62 		{
       
    63 		HBufC8* metadata = ReadMetaDataL(MetaDataCropLength());
       
    64 		CleanupStack::PushL(metadata);
       
    65 		session.StartPackageL(PackageUID(), *metadata);
       
    66 		while (NextFile())
       
    67 			{
       
    68 			RFile sourcefile;
       
    69 			User::LeaveIfError(sourcefile.Open(fs, BackupFileName(), EFileRead));
       
    70 			TPtrC destfilename = InstalledFileName();
       
    71 			session.RestoreFileL(sourcefile, destfilename);
       
    72 			}
       
    73 			
       
    74 		// Create dummy files to simulate restore of data files
       
    75 		while (NextDataFile())
       
    76 			{
       
    77 			TouchL(DataFileName());
       
    78 			}
       
    79 			
       
    80 		session.CommitPackageL();
       
    81 		CleanupStack::PopAndDestroy(metadata);
       
    82 		
       
    83 		TInt property;
       
    84 		User::LeaveIfError(RProperty::Get(KUidSystemCategory, Swi::KUidSoftwareInstallKey, property));
       
    85 			
       
    86 		if (property != Swi::ESwisNone)
       
    87 			{
       
    88 				
       
    89 			// The Pub&Sub property should have been reset to none,
       
    90 			// Regardless of the actual result of the test.
       
    91 			SetTestStepResult(EFail);
       
    92 			User::Leave(KErrGeneral);
       
    93 				
       
    94 			}
       
    95 		
       
    96 		}	
       
    97 	CleanupStack::PopAndDestroy(2, &fs);	// session	
       
    98 	}
       
    99 
       
   100