commsconfig/commsdatabaseshim/TE_commdb/src/Step_045_xx.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     1 //
       
     2 // Copyright (c) 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 "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 // This contains CommDb Unit Test Cases 045.XX
       
    19 
       
    20 // EPOC includes
       
    21 #include <e32base.h>
       
    22 #include <commdb.h>
       
    23 #include <d32comm.h>
       
    24 #include <cdbstore.h>
       
    25 
       
    26 // Test system includes
       
    27 #include "Teststepcommdb.h"
       
    28 #include "Step_045_xx.h"
       
    29 
       
    30 
       
    31 CCommDbTest045_01::CCommDbTest045_01()
       
    32 	{
       
    33 	// store the name of this test case
       
    34 	SetTestStepName(_L("step_045_01"));
       
    35 	}
       
    36 
       
    37 CCommDbTest045_01::~CCommDbTest045_01()
       
    38 	{}
       
    39 
       
    40 TVerdict CCommDbTest045_01::doTestStepL( void )
       
    41 	{
       
    42 	if(executeStepL()!=KErrNone)
       
    43          SetTestStepResult(EFail);        SetTestStepResult(EPass);	return TestStepResult();
       
    44 	}
       
    45 
       
    46 TVerdict CCommDbTest045_01::doTestStepPreambleL()
       
    47 	{
       
    48         SetTestStepResult(EPass);	return TestStepResult();
       
    49 	}
       
    50 
       
    51 TInt CCommDbTest045_01::executeStepL()
       
    52 	{
       
    53 	CStoreableOverrideSettings* overSet=CStoreableOverrideSettings::NewL(CStoreableOverrideSettings::EParamListPartial);
       
    54 	CleanupStack::PushL(overSet);
       
    55 
       
    56 	TUint32 setUint = 5000;
       
    57 	User::LeaveIfError(overSet->SetIntOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_IWF_TO_MS), setUint));
       
    58 
       
    59 	TBool setBool = ETrue;
       
    60 	User::LeaveIfError(overSet->SetBoolOverride(TPtrC(DIAL_OUT_ISP), TPtrC(SERVICE_IF_CALLBACK_ENABLED), setBool));
       
    61 
       
    62 	TBuf8<KCommsDbSvrMaxFieldLength> set8String(_L8("Hi There!!"));
       
    63 	User::LeaveIfError(overSet->SetDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_IF_CALLBACK_INFO), set8String));
       
    64 	
       
    65 	TBuf<KCommsDbSvrMaxFieldLength> set16String(_L("Hi There!!"));
       
    66 	User::LeaveIfError(overSet->SetDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_DEFAULT_TEL_NUM), set16String));
       
    67 
       
    68 	TBuf<KCommsDbSvrMaxFieldLength> setLongString(_L("SEND \"hello\"\nWAIT 20\n{\n\"hello back\"\n"));	//Lots of stuff, nothing important
       
    69 	User::LeaveIfError(overSet->SetLongDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_LOGIN_SCRIPT), setLongString));
       
    70 
       
    71 	HBufC8* storeBuf=HBufC8::NewLC(1024);	//Create a buf on the heap to use as the store
       
    72 	TPtr8 storePtr=storeBuf->Des();
       
    73 
       
    74 	RDesWriteStream writeStream;
       
    75 	writeStream.Open(storePtr);
       
    76 	writeStream.PushL();
       
    77 	
       
    78 	overSet->ExternalizeL(writeStream);
       
    79 	writeStream.Close();
       
    80 	CleanupStack::Pop();	//writeStream
       
    81 
       
    82 	//Settings have been stored to stream (storeBuf),
       
    83 	//now read them into a new settings object and check them
       
    84 
       
    85 	CStoreableOverrideSettings* restoreOverSet=CStoreableOverrideSettings::NewL(CStoreableOverrideSettings::EParamListPartial);
       
    86 	CleanupStack::PushL(restoreOverSet);
       
    87 
       
    88 	RDesReadStream readStream;
       
    89 	readStream.Open(storePtr);
       
    90 	readStream.PushL();
       
    91 
       
    92 	restoreOverSet->InternalizeL(readStream);
       
    93 	readStream.Close();
       
    94 	CleanupStack::Pop();	//readStream
       
    95 
       
    96 	//Check we've got the same stuff in the restored object as in the original
       
    97 	TUint32 restoredUint;
       
    98 	TBool restoredBool;
       
    99 	TBuf8<KCommsDbSvrMaxFieldLength> restored8String;
       
   100 	TBuf<KCommsDbSvrMaxFieldLength> restored16String;
       
   101 	TBuf<KCommsDbSvrMaxFieldLength> restoredLongString;
       
   102 
       
   103 	User::LeaveIfError(restoreOverSet->GetIntOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_IWF_TO_MS), restoredUint));
       
   104 	User::LeaveIfError(restoreOverSet->GetBoolOverride(TPtrC(DIAL_OUT_ISP), TPtrC(SERVICE_IF_CALLBACK_ENABLED), restoredBool));
       
   105 	User::LeaveIfError(restoreOverSet->GetDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_IF_CALLBACK_INFO), restored8String));
       
   106 	User::LeaveIfError(restoreOverSet->GetDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_DEFAULT_TEL_NUM), restored16String));
       
   107 	User::LeaveIfError(restoreOverSet->GetLongDesOverride(TPtrC(DIAL_OUT_ISP), TPtrC(ISP_LOGIN_SCRIPT), restoredLongString));
       
   108 
       
   109 	CleanupStack::PopAndDestroy(restoreOverSet);
       
   110 	CleanupStack::PopAndDestroy(storeBuf);
       
   111 	CleanupStack::PopAndDestroy(overSet);
       
   112 
       
   113 	//Now do a comparison
       
   114 	if(restoredUint!=setUint
       
   115 		||restoredBool!=setBool
       
   116 		||restored8String!=set8String
       
   117 		||restored16String!=set16String
       
   118 		||restoredLongString!=setLongString)
       
   119 		return KErrGeneral;
       
   120 
       
   121 
       
   122 	return KErrNone;
       
   123 	}
       
   124 	
       
   125 TVerdict CCommDbTest045_01::doTestStepPostambleL()
       
   126 	{
       
   127         SetTestStepResult(EPass);	return TestStepResult();
       
   128 	}
       
   129 
       
   130 ////////////////////////////////////////////////////////////////////////////////
       
   131 
       
   132 CCommDbTest045_02::CCommDbTest045_02()
       
   133 	{
       
   134 	// store the name of this test case
       
   135 	SetTestStepName(_L("step_045_02"));
       
   136 	}
       
   137 
       
   138 CCommDbTest045_02::~CCommDbTest045_02()
       
   139 	{}
       
   140 
       
   141 TVerdict CCommDbTest045_02::doTestStepL( void )
       
   142 	{
       
   143 	if(executeStepL()!=KErrEof)
       
   144          SetTestStepResult(EFail);        SetTestStepResult(EPass);	return TestStepResult();
       
   145 	}
       
   146 
       
   147 TVerdict CCommDbTest045_02::doTestStepPreambleL()
       
   148 	{
       
   149         SetTestStepResult(EPass);	return TestStepResult();
       
   150 	}
       
   151 
       
   152 TInt CCommDbTest045_02::executeStepL()
       
   153 	{
       
   154 	HBufC8* storeBuf=HBufC8::NewLC(1024);	//Create a buf on the heap to use as the store
       
   155 	TPtr8 storePtr=storeBuf->Des();
       
   156 
       
   157 	//Try and restore from a blank stream
       
   158 
       
   159 	CStoreableOverrideSettings* restoreOverSet=CStoreableOverrideSettings::NewL(CStoreableOverrideSettings::EParamListPartial);
       
   160 	CleanupStack::PushL(restoreOverSet);
       
   161 
       
   162 	RDesReadStream readStream;
       
   163 	storePtr=storeBuf->Des();
       
   164 	readStream.Open(storePtr);
       
   165 	readStream.PushL();
       
   166 
       
   167 	TRAPD(err, restoreOverSet->InternalizeL(readStream));
       
   168 	readStream.Close();
       
   169 	CleanupStack::Pop();	//readStream
       
   170 
       
   171 
       
   172 	CleanupStack::PopAndDestroy(restoreOverSet);
       
   173 	CleanupStack::PopAndDestroy(storeBuf);
       
   174 
       
   175 	return err;
       
   176 	}
       
   177 	
       
   178 TVerdict CCommDbTest045_02::doTestStepPostambleL()
       
   179 	{
       
   180         SetTestStepResult(EPass);	return TestStepResult();
       
   181 	}
       
   182 
       
   183 //////////////////////////////////////////////////////////////////////////
       
   184 
       
   185 CCommDbTest045_03::CCommDbTest045_03()
       
   186 	{
       
   187 	// store the name of this test case
       
   188 	SetTestStepName(_L("step_045_03"));
       
   189 	}
       
   190 
       
   191 CCommDbTest045_03::~CCommDbTest045_03()
       
   192 	{}
       
   193 
       
   194 TVerdict CCommDbTest045_03::doTestStepL( void )
       
   195 	{
       
   196 	INFO_PRINTF1(_L("Step 045.03 called "));
       
   197 
       
   198 	SetTestStepResult(EPass);
       
   199 	CCommDbTest045_01* step045_01 = new(ELeave) CCommDbTest045_01;
       
   200 	CleanupStack::PushL(step045_01);
       
   201 	doTestStepWithHeapFailureL( *step045_01, KErrNone);
       
   202 	CleanupStack::PopAndDestroy(step045_01);
       
   203 
       
   204 	CCommDbTest045_02* step045_02 = new(ELeave) CCommDbTest045_02;
       
   205 	CleanupStack::PushL(step045_02);
       
   206 	doTestStepWithHeapFailureL( *step045_02, KErrEof);
       
   207 	CleanupStack::PopAndDestroy(step045_02);
       
   208 
       
   209 	return TestStepResult();
       
   210 	}