1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/t_bflat.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,173 @@
1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\buffer\t_bflat.cpp
1.18 +// Overview:
1.19 +// Test all aspects of the CBufFlat class.
1.20 +// API Information:
1.21 +// CBufFlat.
1.22 +// Details:
1.23 +// - Test all the operations of the class and see if methods are implemented --
1.24 +// including NewL, Reset, Size, Set Reserve, InsertL, Delete, Ptr, Read, Write and Compress.
1.25 +// - Test CBufFlat constructor is as expected.
1.26 +// - Insert data into the flat storage dynamic buffer and verify that InsertL method
1.27 +// is as expected.
1.28 +// - Delete all data in buffer using Reset() method and check size is zero.
1.29 +// - Test Ptr, Free, Size, Backptr and SetReserveL methods work as expected.
1.30 +// - Insert data into the buffer, delete some data from the beginning, middle, end and
1.31 +// check for data is as expected.
1.32 +// - Verify the data in the buffer before and after Compress and Read methods is as expected.
1.33 +// Platforms/Drives/Compatibility:
1.34 +// All
1.35 +// Assumptions/Requirement/Pre-requisites:
1.36 +// Failures and causes:
1.37 +// Base Port information:
1.38 +//
1.39 +//
1.40 +
1.41 +#include <e32test.h>
1.42 +
1.43 +LOCAL_D RTest test(_L("T_BFLAT"));
1.44 +
1.45 +class TestCBufFlat
1.46 + {
1.47 +public:
1.48 + void Test1(); // Tests all operations of the class.
1.49 + void Test2(); // Test public methods of class.
1.50 + };
1.51 +
1.52 +class TestCBufSeg
1.53 + {
1.54 +public:
1.55 + void Test1(); // Test all operations of the class.
1.56 + };
1.57 +
1.58 +GLDEF_C void TestCBufFlat::Test1()
1.59 +//
1.60 +// Tests all operations of the class.
1.61 +//
1.62 + {
1.63 + TText* tp;
1.64 + test.Start(_L("Test all operations of CBufFlat"));
1.65 + CBufFlat* bf=(CBufFlat*)CBufFlat::NewL(100);
1.66 + bf->Reset();
1.67 + bf->Size();
1.68 + bf->SetReserveL(50); // Panics if 50 < iSize
1.69 + bf->InsertL(0,TPtrC8((TText8*)"Hello World"));
1.70 + bf->Delete(0,5);
1.71 + tp=(TText*)bf->Ptr(3).Ptr();
1.72 + tp=(TText*)bf->BackPtr(3).Ptr();
1.73 + bf->Read(2,tp,2);
1.74 + bf->Write(2,tp,2);
1.75 + bf->Compress();
1.76 + test.End();
1.77 + }
1.78 +
1.79 +GLDEF_C void TestCBufFlat::Test2()
1.80 +//
1.81 +// Test all the methods of the class
1.82 +//
1.83 + {
1.84 +
1.85 + test.Start(_L("Test constructor of CBufFlat"));
1.86 + CBufFlat* bf1=(CBufFlat*)CBufFlat::NewL(20);
1.87 + test(bf1->Size()==0);
1.88 + test(bf1->Ptr(0).Length()==0);
1.89 +
1.90 + test.Next(_L("Insert, Reset, Ptr, Free, Size"));
1.91 + TBuf8<0x40> tb1=(TText8*)"Hello World";
1.92 + TBuf8<0x40> tb2=(TText8*)"This string is greater than twenty characters long";
1.93 + TBuf8<0x40> tb3;
1.94 + bf1->InsertL(0,tb1); // Insert - no expand
1.95 + test(bf1->Ptr(0)==tb1);
1.96 + test(bf1->Size()==tb1.Size());
1.97 + test(bf1->Ptr(0).Length()==tb1.Size());
1.98 + bf1->InsertL(bf1->Size(),tb2); // Insert and expand
1.99 + test(bf1->Size()==(tb1.Size()+tb2.Size()));
1.100 + test(bf1->Ptr(0).Left(tb1.Length())==tb1);
1.101 + test(bf1->Ptr(tb1.Length())==tb2);
1.102 + bf1->InsertL(bf1->Size(),tb3); // Insert a null string
1.103 + test(bf1->Size()==(tb1.Size()+tb2.Size()));
1.104 + test(bf1->Ptr(0).Left(tb1.Length())==tb1);
1.105 + test(bf1->Ptr(tb1.Length())==tb2);
1.106 + bf1->Reset(); // Reset
1.107 + test(bf1->Size()==0);
1.108 + bf1->InsertL(0,tb1); // Insert into a string
1.109 + bf1->InsertL(5,tb1);
1.110 + bf1->Delete(16,bf1->Size()-16);
1.111 + test(bf1->Ptr(0)==TPtrC8((TText8*)"HelloHello World"));
1.112 +//
1.113 + test.Next(_L("SetReserve"));
1.114 + bf1->SetReserveL(50); // SetReserve > 0
1.115 + test(bf1->Size()==16);
1.116 + test(bf1->Ptr(0).Length()==16);
1.117 + bf1->Reset();
1.118 + bf1->SetReserveL(0); // SetReserve = 0
1.119 + test(bf1->Size()==0);
1.120 + test(bf1->Ptr(0).Length()==0);
1.121 +//
1.122 + test.Next(_L("Delete, BackPtr"));
1.123 + bf1->InsertL(0,tb1);
1.124 + bf1->Delete(6,1); // Delete Middle
1.125 + test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orld"));
1.126 + test(bf1->Size()==10);
1.127 + bf1->Delete(9,1); // Delete End
1.128 + test(bf1->Ptr(bf1->Size()).Length()==0);
1.129 + bf1->InsertL(bf1->Size(),tb3);
1.130 + test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orl"));
1.131 + bf1->Delete(0,2); // Delete Start / BackPtr
1.132 + test(bf1->BackPtr(5)==TPtrC8((TText8*)"llo o"));
1.133 + test(bf1->Size()==7);
1.134 +//
1.135 + test.Next(_L("Write, Compress"));
1.136 + bf1->Write(1,tb1,5);
1.137 + test(bf1->Ptr(0)==TPtrC8((TText8*)"lHellol"));
1.138 + test(bf1->Size()==7);
1.139 + bf1->Compress(); // Compress
1.140 + test(bf1->Size()==7);
1.141 +
1.142 + test.Next(_L("Read"));
1.143 + bf1->Read(4,tb1,bf1->Size()-4);
1.144 + test(tb1.Size()==3);
1.145 + test(tb1==TPtrC8((TText8*)"lol"));
1.146 +//
1.147 + test.End();
1.148 + }
1.149 +
1.150 +LOCAL_C void test_CBufFlat()
1.151 +//
1.152 +// Test the BufFlat class.
1.153 +//
1.154 + {
1.155 + TestCBufFlat b;
1.156 +
1.157 + test.Start(_L("All operations"));
1.158 + b.Test1();
1.159 + test.Next(_L("All methods"));
1.160 + b.Test2();
1.161 +//
1.162 + test.End();
1.163 + }
1.164 +
1.165 +GLDEF_C TInt E32Main()
1.166 +//
1.167 +// Test the ADT Varray types.
1.168 +//
1.169 + {
1.170 + test.Title();
1.171 + test.Start(_L("class CBufFlat"));
1.172 + test_CBufFlat();
1.173 + test.End();
1.174 + return(0);
1.175 + }
1.176 +