commsfwutils/commsbufs/TE_mbufmgr/src/test21commsbufs.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     1 // Copyright (c) 2002-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 MBufMgr Test Step 21 for commsbufs method
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // Test system includes
       
    22 //#include "networking/log.h"
       
    23 //#include "networking/teststep.h"
       
    24 
       
    25 //#ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    26 //#include "networking/log.h"
       
    27 //#include "networking/teststep.h"
       
    28 //#else
       
    29 //#include <networking/log.h>
       
    30 //#include <networking/teststep.h>
       
    31 //#endif
       
    32 
       
    33 #include "TestStepCTMbufmgr.h"
       
    34 
       
    35 #include "Test21commsbufs.h"
       
    36 #include <comms-infras/commsbufpond.h>
       
    37 // constructor
       
    38 CTest21CommsBufs::CTest21CommsBufs()
       
    39 	{
       
    40 	SetTestStepName( _L("MBufMgrTest21") );	// Store the name of this test case
       
    41 	}
       
    42 
       
    43 // destructor
       
    44 CTest21CommsBufs::~CTest21CommsBufs()
       
    45 	{
       
    46 	}
       
    47 
       
    48 //
       
    49 enum TVerdict CTest21CommsBufs::doTestStepL(void)
       
    50 	{
       
    51 	SetTestStepResult(EFail);
       
    52 			
       
    53 	//-------------- substep 1 --------------------
       
    54 	INFO_PRINTF1(_L("  01 Creating CMBufManager and installing active scheduler:"));
       
    55     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    56 	CActiveScheduler::Install(iActSch);
       
    57 	CreateInstanceMBufMgrL(KMBufDefaultHeapSize);
       
    58 	CleanupClosePushL(iBufPond);
       
    59 	TCommsBufAllocator allocator = iBufPond.Allocator();
       
    60     INFO_PRINTF1(_L("  01 Allocate a RCommsBuf of size 128"));	
       
    61 	RCommsBuf* buf = RCommsBuf::Alloc(128, allocator);
       
    62     INFO_PRINTF1(_L("  01 Check the initial offset and length should be 0 & 128"));
       
    63 	// Check the initial offset and length. MUST be 0 & 128 as we 
       
    64 	// allocated a buffer of size 128
       
    65 	if(buf->Offset() != 0 || buf->Length() != buf->RawSize())
       
    66 	    {
       
    67 	    INFO_PRINTF1(_L("  Error: The offset and length checking failed"));
       
    68 	    return EFail;
       
    69 	    }
       
    70 	
       
    71 	INFO_PRINTF1(_L("  02 Write abcdef"));
       
    72 	_LIT8(KWriteData, "abcdef");
       
    73 	buf->Write(KWriteData, 20); // Write abcdef at offset 20
       
    74 	// Check the offset should be 20
       
    75 	// Check the length should 6 ie; abcdef
       
    76 	INFO_PRINTF1(_L("  02 Check the write offset and length should be 20 & 6"));	
       
    77     if(buf->Offset() != 20 || buf->Length() != KWriteData().Length())
       
    78         {
       
    79         INFO_PRINTF1(_L("  Error 02: The offset and length checking failed"));
       
    80 		return TestStepResult();
       
    81         }
       
    82 	
       
    83     TBuf8<10> buffer;
       
    84     INFO_PRINTF1(_L("  02 Read the buffer at offset 0"));
       
    85     buf->Read(buffer);
       
    86     INFO_PRINTF1(_L("  02 check the content of the read buffer"));
       
    87     if(buffer.Compare(KWriteData()) != 0)
       
    88         {
       
    89         INFO_PRINTF1(_L("  Error 02 The read buffer content is not same as the write buffer"));
       
    90         return TestStepResult();
       
    91         }
       
    92 
       
    93     INFO_PRINTF1(_L("  02 Read the buffer at offset 3"));
       
    94     buf->Read(buffer, 3);
       
    95     INFO_PRINTF1(_L("  02 check the content of the read buffer"));
       
    96     TPtrC8 ptr2 = KWriteData().Right(3); // Should be def
       
    97     if(buffer.Compare(ptr2) != 0)
       
    98         {
       
    99         INFO_PRINTF1(_L("  Error 02 The read buffer content is not same as the write buffer"));
       
   100         return TestStepResult();       
       
   101         }
       
   102 
       
   103     INFO_PRINTF1(_L("  03 Allocate a RCommsBuf of size 128"));   
       
   104     RCommsBuf* buf2 = RCommsBuf::Alloc(128, allocator);
       
   105     INFO_PRINTF1(_L("  03 Write abcdef"));
       
   106     buf2->Write(KWriteData, 10); // Write abcdef at offset 20
       
   107     // Append ghijklm
       
   108     INFO_PRINTF1(_L("  03 Append ghijklm"));
       
   109     _LIT8(KAppendData, "ghijklm");
       
   110     buf2->Append(KAppendData);
       
   111     
       
   112     // Compare the data
       
   113     INFO_PRINTF1(_L("  03 Compare the contained data"));
       
   114     _LIT8(KCompareData, "abcdefghijklm");
       
   115     TBuf8<30> buffer2;
       
   116     buf2->Read(buffer2);
       
   117     if(buffer2.Compare(KCompareData()) != 0)
       
   118         {
       
   119         INFO_PRINTF1(_L("  Error 03 The read buffer content is not same as the write buffer"));
       
   120         return TestStepResult();       
       
   121         }
       
   122     
       
   123     // Prepend 123
       
   124     _LIT8(KPrependData, "12345");
       
   125     INFO_PRINTF1(_L("  03 Prepend 12345"));
       
   126     buf2->Prepend(KPrependData);
       
   127     // Now offset would have been 5
       
   128     if(buf2->Offset() != 5)
       
   129         {
       
   130         INFO_PRINTF1(_L("  Error 03 after prepend the offset is not correct"));
       
   131         return TestStepResult(); 
       
   132         }
       
   133     
       
   134     // Read the whole data
       
   135     buf2->Read(buffer2);
       
   136     
       
   137     _LIT8(KCompareData2, "12345abcdefghijklm");
       
   138     if(buffer2.Compare(KCompareData2()) != 0)
       
   139         {
       
   140         INFO_PRINTF1(_L("  Error 03 After prepend the read buffer is not correct."));
       
   141         return EFail;        
       
   142         }
       
   143      
       
   144     for(TInt i = 0; i < buffer2.Length(); ++i)
       
   145          {
       
   146          if(buffer2[i] != (*buf2)[i])
       
   147              {
       
   148              INFO_PRINTF1(_L("  Error 03 Comparison of individual characters failed."));
       
   149              return TestStepResult();
       
   150              }
       
   151          }
       
   152 
       
   153     buf->Free();
       
   154 	buf2->Free();
       
   155 	CleanupStack::PopAndDestroy(); // pond
       
   156 	CActiveScheduler::Install(NULL);
       
   157 	CleanupStack::PopAndDestroy(iActSch);
       
   158 	
       
   159 	SetTestStepResult(EPass);
       
   160 	return TestStepResult();
       
   161 	}