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