cbsref/telephonyrefplugins/atltsy/integrationtest/src/testltsyphbkread.cpp
changeset 44 8b72faa1200f
equal deleted inserted replaced
39:2473f5e227f9 44:8b72faa1200f
       
     1 // Copyright (c) 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 // 
       
    15 // 
       
    16 
       
    17 //system include 
       
    18 #include <mpbutil.h> 
       
    19 //user include
       
    20 #include "testltsyphbkread.h"
       
    21 //const defination
       
    22 _LIT(KExpectedText, "TelNo 010");
       
    23 _LIT(KExpectedNumber,"+123456010");
       
    24 const TUint KExpectedIndex = 10;
       
    25 
       
    26 CTestLtsyPhbkRead::CTestLtsyPhbkRead(CTestLtsyModel& aTestModel)
       
    27 	: CTestLtsyPhoneStoreBase(aTestModel)
       
    28 	{
       
    29 
       
    30 	}
       
    31 
       
    32 CTestLtsyPhbkRead::~CTestLtsyPhbkRead()
       
    33 	{
       
    34 	}
       
    35 
       
    36 CTestLtsyPhbkRead* CTestLtsyPhbkRead::NewLC(CTestLtsyModel& aTestModel)
       
    37 	{
       
    38 	CTestLtsyPhbkRead* self = new (ELeave)CTestLtsyPhbkRead(aTestModel);
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CTestLtsyPhbkRead* CTestLtsyPhbkRead::NewL(CTestLtsyModel& aTestModel)
       
    45 	{
       
    46 	CTestLtsyPhbkRead* self=CTestLtsyPhbkRead::NewLC(aTestModel);
       
    47 	CleanupStack::Pop(self);
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 void CTestLtsyPhbkRead::ConstructL()
       
    52 	{
       
    53 
       
    54 	}
       
    55 
       
    56 TVerdict CTestLtsyPhbkRead::doTestStepPreambleL()
       
    57 	{
       
    58 	INFO_PRINTF1(_L("CTestLtsyPhbkRead::doTestStepPreambleL called"));
       
    59 	SetTestStepResult(EPass);
       
    60 	return TestStepResult();
       
    61 	}
       
    62 
       
    63 TVerdict CTestLtsyPhbkRead::doTestStepL()
       
    64 	{
       
    65 	INFO_PRINTF1(_L("CTestLtsyPhbkRead::doTestStepL called"));
       
    66 	TInt index = 10;
       
    67 	TRAPD(err,ReadEntryL(index));
       
    68 	if(err != KErrNone)
       
    69 		{
       
    70 		INFO_PRINTF2(_L("The error was returned %d!! when read phonebook"),err);
       
    71 	    SetTestStepResult(EFail);
       
    72 		}
       
    73 	return TestStepResult();
       
    74 	}
       
    75 
       
    76 TVerdict CTestLtsyPhbkRead::doTestStepPostambleL()
       
    77 	{
       
    78 	INFO_PRINTF1(_L("CTestLtsyPhbkRead::doTestStepPostambleL called"));
       
    79 	return TestStepResult();
       
    80 	}
       
    81 
       
    82 void CTestLtsyPhbkRead::ReadEntryL(TInt aIndex)
       
    83 	{
       
    84 	TRequestStatus status;
       
    85 	TBuf8<800> outputPbData;
       
    86 	TUint16 index(0);
       
    87 	TUint8 tonNpi;
       
    88 	TPtrC16 number(NULL,0);
       
    89 	TPtrC16 text(NULL,0);
       
    90 	TUint8 tagValue(0);
       
    91 	CPhoneBookBuffer::TPhBkTagType dataType;
       
    92 	
       
    93 	CPhoneBookBuffer* pbBuffer=new(ELeave) CPhoneBookBuffer(); // used to read phonebook data
       
    94 	CleanupStack::PushL(pbBuffer);
       
    95 	PhoneBookStore().Read(status,aIndex,1,outputPbData);
       
    96 	User::WaitForRequest(status);
       
    97 	TInt r=status.Int();
       
    98 	INFO_PRINTF2(_L("Write() request status = %d"),r);
       
    99 	// Set pbBuffer to point to received phonebook data
       
   100 	pbBuffer->Set(&outputPbData); 
       
   101 	// Start reading received phonebook data
       
   102 	pbBuffer->StartRead();       
       
   103 	while (pbBuffer->GetTagAndType(tagValue,dataType)==KErrNone)
       
   104 		{
       
   105 		switch (tagValue)
       
   106 			{
       
   107 		case RMobilePhoneBookStore::ETagPBAdnIndex:
       
   108 			pbBuffer->GetValue(index);			
       
   109 			break;
       
   110 		case RMobilePhoneBookStore::ETagPBTonNpi:
       
   111 			pbBuffer->GetValue(tonNpi);			
       
   112 			break;
       
   113 		case RMobilePhoneBookStore::ETagPBText:
       
   114 			pbBuffer->GetValue(text);			
       
   115 			break;
       
   116 		case RMobilePhoneBookStore::ETagPBNumber:
       
   117 			pbBuffer->GetValue(number);			
       
   118 			break;
       
   119 		default:
       
   120 			// An unsupported field type - just skip this value
       
   121 			pbBuffer->SkipValue(dataType);
       
   122 			break;
       
   123 			}
       
   124 		}
       
   125 	if((index != KExpectedIndex)||(text.MatchF(KExpectedText)==KErrNotFound)||
       
   126 			                      (number.MatchF(KExpectedNumber)==KErrNotFound))
       
   127 		{
       
   128 		SetTestStepResult(EFail);
       
   129 		}
       
   130 	CleanupStack::PopAndDestroy();             
       
   131 	}
       
   132 
       
   133 // end of file