servicediscoveryandcontrol/pnp/test/upnp/unittests/upnpdescriptiontest/src/testupnpdescriptionservicestep.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-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 "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 // Contains implementation of testupnpdescriptionservicestep class
       
    15 // @internalAll
       
    16 // 
       
    17 //
       
    18 
       
    19 // System Include
       
    20 // for StartC32()
       
    21 #include <c32comm.h>
       
    22 #include <e32base.h>
       
    23 
       
    24 // User Include
       
    25 #include "testupnpdescriptionservicestep.h"
       
    26 // library include
       
    27 #include <cupnpdescriptionparser.h>
       
    28 #include <cupnpdescriptioncomposer.h>
       
    29 #include "cpnpdeviceparam.h"
       
    30 #include <cstringpoolmanager.h>
       
    31 #include <testvendordeviceschema.h>
       
    32 #include <testvendorserviceschema.h>
       
    33 
       
    34 _LIT(KDirName, "c:\\upnp\\description\\xml\\");
       
    35 
       
    36 /**
       
    37 Constructor: Sets the test step name.
       
    38 @internalTechnology
       
    39 @test
       
    40 */
       
    41 CTestXmlServiceTestStep::CTestXmlServiceTestStep()
       
    42 	{
       
    43 
       
    44 	SetTestStepName(KTestXmlServiceStep);
       
    45 	}
       
    46 
       
    47 
       
    48 /**
       
    49 Destructor: Closes the iFileServ.
       
    50 @internalTechnology
       
    51 @test
       
    52 */
       
    53 CTestXmlServiceTestStep::~CTestXmlServiceTestStep()
       
    54 	{
       
    55 	}
       
    56 
       
    57 
       
    58 /**
       
    59 Base class virtual doTestStepPreambleL():
       
    60 Create and install the active scheduler and connect to iFileServ (RFs).
       
    61 @internalTechnology
       
    62 @test
       
    63 @param		None
       
    64 @return		EPass or EFail.
       
    65 */
       
    66 TVerdict CTestXmlServiceTestStep::doTestStepPreambleL()
       
    67 	{
       
    68     return TestStepResult();
       
    69 	}	// doTestPreambleL
       
    70 
       
    71 
       
    72 /**
       
    73 Base class pure virtual doTestStepL():
       
    74 Tests the ebo support in http.
       
    75 @internalTechnology
       
    76 @test
       
    77 @param		None
       
    78 @return		EPass or EFail indicating the result of the test step.
       
    79 */
       
    80 TVerdict CTestXmlServiceTestStep::doTestStepL()
       
    81 	{
       
    82 	TPtrC	aInputPath;
       
    83 	TPtrC	aOutputPath;
       
    84 	TBool	aIsService;
       
    85 	TBool	aIsPositive;
       
    86     TInt	err=KErrNone;
       
    87     RFs		fs;
       
    88     RFile	handle;
       
    89     _LIT(KVendorDevice,"Xml_61");
       
    90     _LIT(KVendorService,"Xml_62");
       
    91     User::LeaveIfError(fs.Connect());
       
    92     CleanupClosePushL(fs);
       
    93 
       
    94     // create the output folder
       
    95     
       
    96     err = fs.MkDirAll(KDirName);
       
    97     if ((err != KErrNone) && (err!=KErrAlreadyExists))
       
    98     	{
       
    99     		User::LeaveIfError(err);
       
   100     	}
       
   101 
       
   102 	if(
       
   103 	!GetStringFromConfig(ConfigSection(),KIniInputPath,aInputPath)||
       
   104 	!GetStringFromConfig(ConfigSection(),KIniOutputPath,aOutputPath)||
       
   105 	!GetBoolFromConfig(ConfigSection(),KIniIsTestCasePositive,aIsPositive)||
       
   106 	!GetBoolFromConfig(ConfigSection(),KIniIsInputFileService,aIsService))
       
   107 		{
       
   108 		ERR_PRINTF5(_L("Problem in reading values from ini.			\
       
   109 				\nExpected fields are: \n%S\n \n%S\n \n%S\n \n%S\n" 
       
   110 			  ),&KIniInputPath,&KIniOutputPath,&KIniIsTestCasePositive,&KIniIsInputFileService);
       
   111 		SetTestStepResult(EFail);
       
   112 		return TestStepResult();
       
   113 		}
       
   114 
       
   115 	//-----------------------
       
   116 	RFile 			handle1;
       
   117 	
       
   118 	TRAP(err,handle1.Open(fs, aInputPath, EFileShareReadersOnly));
       
   119 	// For Hardware system path is c:, so descriptionPath value present in '.ini' is referring 'c:'
       
   120 	if ( err == KErrPathNotFound )
       
   121 		{				
       
   122 		RBuf fileName;
       
   123 		TDriveName aSystemDrive;
       
   124 		TDriveUnit driveunit(RFs::GetSystemDrive());
       
   125 		aSystemDrive.Zero();
       
   126 		aSystemDrive=driveunit.Name();				
       
   127 		fileName.CreateL ( aInputPath.Length () );
       
   128 		fileName.Zero();
       
   129 		fileName.Append(aSystemDrive);
       
   130 		fileName.Append ( aInputPath.Mid ( aSystemDrive.Length () ) );		
       
   131 		
       
   132 		err = handle1.Open(fs, fileName, EFileShareReadersOnly);
       
   133 		}
       
   134 	if (err != KErrNone)
       
   135 	    {
       
   136 	    User::LeaveIfError(err);
       
   137 	    }
       
   138 	CleanupClosePushL(handle1);
       
   139 	TInt aFileSize = 0;
       
   140 	handle1.Size(aFileSize);
       
   141 	
       
   142 	HBufC8 * Buf1 = HBufC8::NewL(aFileSize);
       
   143 	TPtr8 Pointer = Buf1->Des();
       
   144 	
       
   145 	TInt err1 = handle1.Read(Pointer,aFileSize);
       
   146 	
       
   147 	CleanupStack::PopAndDestroy(&handle1);
       
   148 
       
   149 	//-----------------------
       
   150 
       
   151     err = handle.Open(fs,aOutputPath,EFileWrite);
       
   152     if (err == KErrNotFound)
       
   153         {
       
   154         err=handle.Create(fs,aOutputPath,EFileWrite);
       
   155         if(err != KErrNone )
       
   156         	SetTestStepResult(EFail);
       
   157         }
       
   158     CleanupClosePushL(handle);
       
   159 
       
   160     RBuf8 aComposedXml;
       
   161     CleanupClosePushL(aComposedXml);
       
   162     CStringPoolManager* poolManager = CStringPoolManager::NewL();
       
   163     CleanupStack::PushL( poolManager );
       
   164     if ( ConfigSection() == KVendorDevice )
       
   165     	poolManager->SetStringTableL( UPNPVENDORDEVICETAGS::Table);
       
   166     else if ( ConfigSection() == KVendorService )
       
   167     	poolManager->SetStringTableL( UPNPVENDORSERVICETAGS::Table);
       
   168     if(aIsService)
       
   169     	{
       
   170         CUPnPServiceDescription *aServDescObj = NULL;
       
   171                	
       
   172         CUPnPDescriptionParser* app = CUPnPDescriptionParser::NewL( poolManager->StringPool() ,CUPnPDescriptionParser::EService);
       
   173 	    CleanupStack::PushL(app);
       
   174 	    CUPnPDescriptionComposer *comp  = CUPnPDescriptionComposer::NewL( poolManager->StringPool());
       
   175 	    CleanupStack::PushL(comp);
       
   176 
       
   177 	    TRAPD(error1,aServDescObj = static_cast<CUPnPServiceDescription*> (app->ParseDescriptionBufL(Pointer)));
       
   178 	    if(error1!=KErrNone)
       
   179 	    	{
       
   180 	    	SetTestStepResult(EFail);
       
   181 	    	SetTestStepError(error1);
       
   182 	    	}
       
   183 	    else
       
   184 	    	{
       
   185 	    	//TRAPD(error2,comp->ComposeServiceXmlL(app->GetServiceDescObj(),aComposedXml));
       
   186 	    	TRAPD(error2,comp->ComposeDescriptionXmlL(aServDescObj,CUPnPDescriptionComposer::EService , aComposedXml));
       
   187 		    if(error2!=KErrNone)
       
   188 		    	{
       
   189 		    	SetTestStepResult(EFail);
       
   190 		    	SetTestStepError(error2);
       
   191 		    	}
       
   192 		    else
       
   193 		    	{
       
   194 		    	SetTestStepResult(EPass);
       
   195 		    	}
       
   196 	    	}
       
   197 	    delete aServDescObj;
       
   198 
       
   199 	    CleanupStack::PopAndDestroy(comp);
       
   200 	    CleanupStack::PopAndDestroy(app);
       
   201     	}
       
   202     else
       
   203     	{
       
   204     	CUPnPDeviceDescription *aDeviceDescObj = NULL;
       
   205     	CUPnPDescriptionParser* app = CUPnPDescriptionParser::NewL(poolManager->StringPool(), CUPnPDescriptionParser::EDevice);
       
   206         CleanupStack::PushL(app);
       
   207         CUPnPDescriptionComposer *comp  = CUPnPDescriptionComposer::NewL( poolManager->StringPool() );
       
   208         CleanupStack::PushL(comp);
       
   209             
       
   210         TRAPD(error1,aDeviceDescObj = static_cast<CUPnPDeviceDescription*> (app->ParseDescriptionBufL(Pointer)));
       
   211         if(error1!=KErrNone)
       
   212         	{
       
   213 	    	SetTestStepResult(EFail);
       
   214 	    	SetTestStepError(error1);        	
       
   215 	    	}
       
   216         else
       
   217         	{
       
   218         	//TRAPD(error2,comp->ComposeDeviceXmlL(app->GetDeviceDescObj(),aComposedXml));
       
   219         	TRAPD(error2,comp->ComposeDescriptionXmlL(aDeviceDescObj, CUPnPDescriptionComposer::EDevice,aComposedXml));
       
   220     	    if(error2!=KErrNone)
       
   221     	    	{
       
   222     	    	SetTestStepResult(EFail);
       
   223     	    	SetTestStepError(error2);
       
   224     	    	}
       
   225     	    else
       
   226     	    	{
       
   227     	    	SetTestStepResult(EPass);
       
   228     	    	}
       
   229     	    	
       
   230         	}
       
   231         delete aDeviceDescObj;
       
   232 
       
   233         CleanupStack::PopAndDestroy(comp);
       
   234         CleanupStack::PopAndDestroy(app);
       
   235     	}
       
   236 
       
   237     
       
   238     delete Buf1;
       
   239     handle.Write(aComposedXml);
       
   240     handle.Close();
       
   241     CleanupStack::PopAndDestroy(poolManager);
       
   242     CleanupStack::PopAndDestroy();
       
   243     CleanupStack::PopAndDestroy(&handle);
       
   244     CleanupStack::PopAndDestroy(&fs);
       
   245 
       
   246 	
       
   247 	return TestStepResult();
       
   248 
       
   249 	}	// doTestStepL
       
   250