installationservices/swi/test/tsishelper/tsishelperstep.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-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 /**
       
    20  @file tsishelperstep.cpp
       
    21 */
       
    22 #include "tsishelperstep.h"
       
    23 #include <test/testexecutelog.h>
       
    24 #include "sishelperclient.h"
       
    25 #include "swi/launcher.h"
       
    26 
       
    27 namespace Swi
       
    28 {
       
    29 class RUiHandler;
       
    30 }
       
    31 
       
    32 CTSISHelperStepController::CTSISHelperStepController()
       
    33 	{
       
    34 	SetTestStepName(KTSISHelperStepController);
       
    35 	}
       
    36 
       
    37 TVerdict CTSISHelperStepController::doTestStepL()
       
    38 	{
       
    39 	SetTestStepResult(EFail);
       
    40 	TPtrC sisFileName;
       
    41 	GetStringFromConfig(ConfigSection(),_L("SIS"), sisFileName);
       
    42 	Swi::TSisHelperStartParams params(sisFileName);
       
    43 	User::LeaveIfError(startSisHelper(params));
       
    44 	Swi::RSisHelper server;
       
    45 	User::LeaveIfError(server.Connect());
       
    46 	server.OpenDrmContentL(ContentAccess::EExecute);
       
    47 	HBufC8* controller = server.SisControllerLC();
       
    48 	TPtrC expectedController;
       
    49 	GetStringFromConfig(ConfigSection(),_L("ExpectedController"), expectedController);
       
    50 
       
    51 	RFile file;
       
    52 	User::LeaveIfError(file.Open(iFs, expectedController, EFileRead));
       
    53 	TInt pos=0;
       
    54 	User::LeaveIfError(file.Seek(ESeekEnd,pos));
       
    55 	TInt expectedLength = pos;
       
    56 	pos = 0;
       
    57 
       
    58 	User::LeaveIfError(file.Seek(ESeekStart, pos));
       
    59 
       
    60 	if (expectedLength == controller->Des().Length())
       
    61 		{
       
    62 		HBufC8* expectedBuffer = HBufC8::NewLC(expectedLength);
       
    63 		TPtr8 expected(expectedBuffer->Des());
       
    64 		file.Read(expected);
       
    65 		if (expected.Compare(controller->Des()) == 0)
       
    66 			{
       
    67 			SetTestStepResult(EPass);
       
    68 			}
       
    69 		CleanupStack::PopAndDestroy(expectedBuffer);	
       
    70 		}
       
    71 	
       
    72 	CleanupStack::PopAndDestroy(controller);
       
    73 	file.Close();
       
    74 	server.Close();
       
    75 	return TestStepResult();
       
    76 	}
       
    77 
       
    78 
       
    79 CTSISHelperStepData::CTSISHelperStepData()
       
    80 	{
       
    81 	SetTestStepName(KTSISHelperStepData);
       
    82 	}
       
    83 
       
    84 TVerdict CTSISHelperStepData::doTestStepL()
       
    85 	{
       
    86 	SetTestStepResult(EFail);
       
    87 		
       
    88 	// Start the SISHelper
       
    89 	TPtrC sisFileName;
       
    90 	GetStringFromConfig(ConfigSection(),_L("SIS"), sisFileName);
       
    91 	Swi::TSisHelperStartParams params(sisFileName);
       
    92 	User::LeaveIfError(startSisHelper(params));
       
    93 	Swi::RSisHelper server;
       
    94 	User::LeaveIfError(server.Connect());
       
    95 	server.OpenDrmContentL(ContentAccess::EExecute);
       
    96 
       
    97 	TInt dataUnit = 0;
       
    98 	GetIntFromConfig(ConfigSection(),_L("DataUnit"), dataUnit);
       
    99 	TInt fileNumber = 0;
       
   100 	GetIntFromConfig(ConfigSection(),_L("FileNumber"), fileNumber);
       
   101 	
       
   102 	// Create a file handle to pass
       
   103 	RFs sharedFs;
       
   104 	RFile sharedFile;
       
   105 	User::LeaveIfError(sharedFs.Connect());
       
   106 	User::LeaveIfError(sharedFs.ShareProtected());
       
   107 	_LIT(KTempFileName,"\\tsishelper.temp");
       
   108 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   109 	TBuf<64> tempFileName (sysDrive.Name());
       
   110 	tempFileName.Append(KTempFileName);
       
   111 	
       
   112 	User::LeaveIfError(sharedFile.Replace (sharedFs, tempFileName, EFileWrite));
       
   113 
       
   114 	TInt fakeUiHandler=0;
       
   115 	Swi::RUiHandler& uiHandler=reinterpret_cast<Swi::RUiHandler&>(fakeUiHandler);
       
   116 	User::LeaveIfError(server.ExtractFileL(sharedFs, sharedFile, fileNumber, dataUnit, uiHandler));
       
   117 	sharedFile.Close();
       
   118 	sharedFs.Close();
       
   119 	
       
   120 	TPtrC expectedData;
       
   121 	GetStringFromConfig(ConfigSection(),_L("ExpectedData"), expectedData);
       
   122 	RFile oldFile;
       
   123 	User::LeaveIfError(oldFile.Open(iFs, expectedData, EFileRead));
       
   124 	RFile newFile;
       
   125 	User::LeaveIfError(newFile.Open(iFs, tempFileName, EFileRead));  // KErrBusy means SISHelper didn't close!
       
   126 	
       
   127 	TInt expectedLength(0);
       
   128 	oldFile.Seek(ESeekEnd,expectedLength);
       
   129 	TInt actualLength(0);
       
   130 	newFile.Seek(ESeekEnd,actualLength);
       
   131 	
       
   132 	if (expectedLength == actualLength)
       
   133 		{
       
   134 		TInt pos = 0;
       
   135 		oldFile.Seek(ESeekStart, pos);
       
   136 		newFile.Seek(ESeekStart, pos);
       
   137 		SetTestStepResult(EPass);
       
   138 		for (TInt i=0; i<expectedLength; i++)
       
   139 			{
       
   140 			TInt8 oldChar;
       
   141 			TInt8 newChar;
       
   142 			TPckg<TInt8> oldPkg(oldChar);
       
   143 			TPckg<TInt8> newPkg(newChar);
       
   144 			oldFile.Read(oldPkg);
       
   145 			newFile.Read(newPkg);
       
   146 			if (oldChar != newChar)
       
   147 				{
       
   148 				SetTestStepResult(EFail);
       
   149 				break;
       
   150 				}
       
   151 			}
       
   152 		}	
       
   153 	oldFile.Close();
       
   154 	newFile.Close();
       
   155 	
       
   156 	RFs fs;
       
   157 	User::LeaveIfError(fs.Connect());
       
   158 	// Delete the temp file	
       
   159 	TInt error = fs.Delete(tempFileName);
       
   160 	if (error != KErrNone && error != KErrNotFound)
       
   161 		{
       
   162 		User::Leave(error);
       
   163 		} 
       
   164 	fs.Close(); 
       
   165 	server.Close();
       
   166 	return TestStepResult();
       
   167 	}