kerneltest/e32test/buffer/t_bflat.cpp
changeset 9 96e5fb8b040d
child 43 c1f20ce4abcf
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     1 // Copyright (c) 1994-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 the License "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 // e32test\buffer\t_bflat.cpp
       
    15 // Overview:
       
    16 // Test all aspects of the CBufFlat class.
       
    17 // API Information:
       
    18 // CBufFlat.
       
    19 // Details:
       
    20 // - Test all the operations of the class and see if methods are implemented -- 
       
    21 // including NewL, Reset, Size, Set Reserve, InsertL, Delete, Ptr, Read, Write and Compress.
       
    22 // - Test CBufFlat constructor is as expected.
       
    23 // - Insert data into the flat storage dynamic buffer and verify that InsertL method
       
    24 // is as expected.
       
    25 // - Delete all data in buffer using Reset() method  and check size is zero.
       
    26 // - Test Ptr, Free, Size, Backptr and SetReserveL methods work as expected.
       
    27 // - Insert data into the buffer, delete some data from the beginning, middle, end and
       
    28 // check for data is as expected. 
       
    29 // - Verify the data in the buffer before and after Compress and Read methods is as expected.
       
    30 // Platforms/Drives/Compatibility:
       
    31 // All 
       
    32 // Assumptions/Requirement/Pre-requisites:
       
    33 // Failures and causes:
       
    34 // Base Port information:
       
    35 // 
       
    36 //
       
    37 
       
    38 #include <e32test.h>
       
    39 
       
    40 LOCAL_D RTest test(_L("T_BFLAT"));
       
    41 
       
    42 class TestCBufFlat
       
    43 	{
       
    44 public:
       
    45 	void Test1();  // Tests all operations of the class.
       
    46 	void Test2();	// Test public methods of class.
       
    47 	};
       
    48 
       
    49 class TestCBufSeg
       
    50 	{
       
    51 public:
       
    52 	void Test1(); 	// Test all operations of the class.
       
    53 	};
       
    54 
       
    55 GLDEF_C void TestCBufFlat::Test1()
       
    56 //
       
    57 // Tests all operations of the class.
       
    58 //
       
    59 	{
       
    60 	TText* tp;
       
    61 	test.Start(_L("Test all operations of CBufFlat"));
       
    62 	CBufFlat* bf=(CBufFlat*)CBufFlat::NewL(100);
       
    63 	bf->Reset();
       
    64 	bf->Size();
       
    65 	bf->SetReserveL(50); // Panics if 50 < iSize
       
    66 	bf->InsertL(0,TPtrC8((TText8*)"Hello World"));
       
    67 	bf->Delete(0,5);
       
    68 	tp=(TText*)bf->Ptr(3).Ptr();
       
    69 	tp=(TText*)bf->BackPtr(3).Ptr();
       
    70 	bf->Read(2,tp,2);
       
    71 	bf->Write(2,tp,2);
       
    72 	bf->Compress();
       
    73 	test.End();
       
    74 	}
       
    75 
       
    76 GLDEF_C void TestCBufFlat::Test2()
       
    77 //
       
    78 // Test all the methods of the class
       
    79 //
       
    80 	{
       
    81 
       
    82 	test.Start(_L("Test constructor of CBufFlat"));
       
    83 	CBufFlat* bf1=(CBufFlat*)CBufFlat::NewL(20);
       
    84 	test(bf1->Size()==0);
       
    85 	test(bf1->Ptr(0).Length()==0);
       
    86 
       
    87 	test.Next(_L("Insert, Reset, Ptr, Free, Size"));
       
    88 	TBuf8<0x40> tb1=(TText8*)"Hello World";
       
    89 	TBuf8<0x40> tb2=(TText8*)"This string is greater than twenty characters long";
       
    90 	TBuf8<0x40> tb3;
       
    91 	bf1->InsertL(0,tb1); // Insert - no expand
       
    92 	test(bf1->Ptr(0)==tb1);
       
    93 	test(bf1->Size()==tb1.Size());
       
    94 	test(bf1->Ptr(0).Length()==tb1.Size());
       
    95 	bf1->InsertL(bf1->Size(),tb2); // Insert and expand
       
    96 	test(bf1->Size()==(tb1.Size()+tb2.Size()));
       
    97 	test(bf1->Ptr(0).Left(tb1.Length())==tb1);
       
    98 	test(bf1->Ptr(tb1.Length())==tb2);
       
    99 	bf1->InsertL(bf1->Size(),tb3);	// Insert a null string
       
   100 	test(bf1->Size()==(tb1.Size()+tb2.Size()));
       
   101 	test(bf1->Ptr(0).Left(tb1.Length())==tb1);
       
   102 	test(bf1->Ptr(tb1.Length())==tb2);
       
   103 	bf1->Reset(); // Reset
       
   104 	test(bf1->Size()==0);
       
   105 	bf1->InsertL(0,tb1); // Insert into a string
       
   106 	bf1->InsertL(5,tb1);
       
   107 	bf1->Delete(16,bf1->Size()-16);
       
   108 	test(bf1->Ptr(0)==TPtrC8((TText8*)"HelloHello World"));
       
   109 //
       
   110 	test.Next(_L("SetReserve"));
       
   111 	bf1->SetReserveL(50); // SetReserve > 0
       
   112 	test(bf1->Size()==16);
       
   113 	test(bf1->Ptr(0).Length()==16);
       
   114 	bf1->Reset();
       
   115 	bf1->SetReserveL(0); // SetReserve = 0
       
   116 	test(bf1->Size()==0);
       
   117 	test(bf1->Ptr(0).Length()==0);
       
   118 //
       
   119 	test.Next(_L("Delete, BackPtr"));
       
   120 	bf1->InsertL(0,tb1);
       
   121 	bf1->Delete(6,1); // Delete Middle
       
   122 	test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orld"));
       
   123 	test(bf1->Size()==10);
       
   124 	bf1->Delete(9,1); // Delete End
       
   125 	test(bf1->Ptr(bf1->Size()).Length()==0);
       
   126 	bf1->InsertL(bf1->Size(),tb3);
       
   127 	test(bf1->Ptr(0)==TPtrC8((TText8*)"Hello orl"));
       
   128 	bf1->Delete(0,2); // Delete Start / BackPtr
       
   129 	test(bf1->BackPtr(5)==TPtrC8((TText8*)"llo o"));
       
   130 	test(bf1->Size()==7);
       
   131 //
       
   132 	test.Next(_L("Write, Compress"));
       
   133 	bf1->Write(1,tb1,5);
       
   134 	test(bf1->Ptr(0)==TPtrC8((TText8*)"lHellol"));
       
   135 	test(bf1->Size()==7);
       
   136 	bf1->Compress(); // Compress
       
   137 	test(bf1->Size()==7);
       
   138 
       
   139 	test.Next(_L("Read"));
       
   140 	bf1->Read(4,tb1,bf1->Size()-4);
       
   141 	test(tb1.Size()==3);
       
   142 	test(tb1==TPtrC8((TText8*)"lol"));
       
   143 //
       
   144 	test.End();
       
   145 	}
       
   146 
       
   147 LOCAL_C void test_CBufFlat()
       
   148 //
       
   149 // Test the BufFlat class.
       
   150 //
       
   151 	{
       
   152 	TestCBufFlat b;
       
   153 
       
   154 	test.Start(_L("All operations"));
       
   155 	b.Test1();
       
   156 	test.Next(_L("All methods"));
       
   157 	b.Test2();
       
   158 //
       
   159 	test.End();
       
   160 	}
       
   161 
       
   162 GLDEF_C TInt E32Main()
       
   163 //
       
   164 // Test the ADT Varray types.
       
   165 //
       
   166 	{
       
   167 	test.Title();
       
   168 	test.Start(_L("class CBufFlat"));
       
   169 	test_CBufFlat();
       
   170 	test.End();
       
   171 	return(0);
       
   172 	}
       
   173