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