lowlevellibsandfws/apputils/tsrc/T_CELL.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 // Written by Martin, May 1996
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <e32test.h>
       
    22 #include <s32mem.h>
       
    23 #include <bacell.h>
       
    24 
       
    25 LOCAL_D RTest test(_L("T_CELL"));
       
    26 
       
    27 class Test
       
    28 	{
       
    29 public:
       
    30 	static void Test1();
       
    31 	static void Test2();
       
    32 	static void Test3();
       
    33 	static void Test4L();
       
    34 	};
       
    35 
       
    36 /**
       
    37 @SYMTestCaseID          SYSLIB-BAFL-CT-0400
       
    38 @SYMTestCaseDesc        Tests the functionality of TCellRef::operator ==() and !=()
       
    39 @SYMTestPriority        High
       
    40 @SYMTestActions         Test the equality of two cells defined by TCellRef's constructor
       
    41                         Test the equality after changing the offsets of the cells already created
       
    42 @SYMTestExpectedResults Test must not fail
       
    43 @SYMREQ                 REQ0000
       
    44 */
       
    45 void Test::Test1()
       
    46 	{
       
    47 	__UHEAP_MARK;
       
    48 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0400 Cells "));
       
    49 	TCellRef c1(0,0);
       
    50 	TCellRef c2(0,0);
       
    51 	TCellRef c3(1,1);
       
    52 	TCellRef c4 = c3;
       
    53 	TCellRef c5(100,100);
       
    54 
       
    55 	test(c1==c2);
       
    56 	test(c3==c4);
       
    57 	test(c1!=c3);
       
    58 
       
    59 	c4 = c5;
       
    60 	test(c4==c5);
       
    61 
       
    62 	c2.Offset(1,1);
       
    63 	test(c2==c3);
       
    64 	c2.Offset(99,99);
       
    65 	test(c2==c5);
       
    66 
       
    67 	c2 = c2 - TCellRef(48,40);
       
    68 	test(c2==TCellRef(52,60));
       
    69 	c2 = c2 + TCellRef(100,100);
       
    70 	test(c2==TCellRef(152,160));
       
    71 
       
    72 	test.End();
       
    73 	__UHEAP_MARKEND;
       
    74 	}
       
    75 
       
    76 /**
       
    77 @SYMTestCaseID          SYSLIB-BAFL-CT-0401
       
    78 @SYMTestCaseDesc        Tests the functionality of TRangeRef::NoRows(),NoCols(),NoCells(),Contains() functions
       
    79 @SYMTestPriority        Medium
       
    80 @SYMTestActions         Test the equality of two objects defined by TRangeRef's
       
    81                         Test the no of rows & columns after a range is defined
       
    82 						Test the existence of a cell after a range is defined.
       
    83 @SYMTestExpectedResults Test must not fail
       
    84 @SYMREQ                 REQ0000
       
    85 */
       
    86 void Test::Test2()
       
    87 	{
       
    88 	__UHEAP_MARK;
       
    89 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0401 Ranges "));
       
    90 
       
    91 	TRangeRef r1(TCellRef(2,3),TCellRef(3,5));
       
    92 	TRangeRef r2(2,3,3,5);
       
    93 	TRangeRef r3(2,4,3,6);
       
    94 	TRangeRef r5(1,0,19,20);
       
    95 
       
    96 	test(r1==r2);
       
    97 	test(r2!=r3);
       
    98 	r2 = r3;
       
    99 	test(r2==r3);
       
   100 
       
   101 	r2.SetRange(2,3,3,5);
       
   102 	test(r2==r1);
       
   103 	r2.SetRange(TCellRef(1,0),TCellRef(19,20));
       
   104 	test(r2==r5);
       
   105 
       
   106 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).NoRows()==2);}
       
   107 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).NoCols()==3);}
       
   108 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).NoCells()==6);}
       
   109 
       
   110 	{test(TRangeRef(TCellRef(1,7),TCellRef(10,20)).NoRows()==10);}
       
   111 	{test(TRangeRef(TCellRef(1,7),TCellRef(10,20)).NoCols()==14);}
       
   112 	{test(TRangeRef(TCellRef(1,7),TCellRef(10,20)).NoCells()==140);}
       
   113 
       
   114 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).Contains(TCellRef(3,3)));}
       
   115 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).Contains(TCellRef(2,3)));}
       
   116 	{test(TRangeRef(TCellRef(2,3),TCellRef(3,5)).Contains(TCellRef(3,5)));}
       
   117 	{test(!TRangeRef(TCellRef(2,3),TCellRef(3,5)).Contains(TCellRef(1,3)));}
       
   118 	{test(!TRangeRef(TCellRef(2,3),TCellRef(3,5)).Contains(TCellRef(3,6)));}
       
   119 
       
   120 	test.End();
       
   121 	__UHEAP_MARKEND;
       
   122 	}
       
   123 
       
   124 /**
       
   125 @SYMTestCaseID          SYSLIB-BAFL-CT-0402
       
   126 @SYMTestCaseDesc        TRangeRef class functionality test
       
   127 @SYMTestPriority        Medium
       
   128 @SYMTestActions         Test range of cells defined by TRangeRef by iteration and checking the count
       
   129 @SYMTestExpectedResults Tests must not fail
       
   130 @SYMREQ                 REQ0000
       
   131 */
       
   132 void Test::Test3()
       
   133 	{
       
   134 	__UHEAP_MARK;
       
   135 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0402 Range iterator "));
       
   136 
       
   137 	{TRangeRef range(TCellRef(2,3),TCellRef(10,24));
       
   138 	TRangeRef::TIter iter(range);
       
   139 	test(iter.iCurrent==range.iFrom);
       
   140 	TInt count = 0;
       
   141 	while (iter.InRange())
       
   142 		{
       
   143 		++iter;
       
   144 		++count;
       
   145 		}
       
   146 	test(count==range.NoCells());
       
   147 	test(iter.iCurrent==TCellRef(range.iTo.iRow+1,range.iFrom.iCol));}
       
   148 
       
   149 	{TRangeRef range(TCellRef(2,3),TCellRef(2,3));
       
   150 	TRangeRef::TIter iter(range);
       
   151 	test(iter.iCurrent==range.iFrom);
       
   152 	TInt count = 0;
       
   153 	while (iter.InRange())
       
   154 		{
       
   155 		++iter;
       
   156 		++count;
       
   157 		}
       
   158 	test(count==1);}
       
   159 
       
   160 
       
   161 	{TRangeRef range(TCellRef(2,3),TCellRef(2,-3));
       
   162 	TRangeRef::TIter iter(range);
       
   163 	test(iter.iCurrent==range.iFrom);
       
   164 	TInt count = 0;
       
   165 	while (iter.InRange())
       
   166 		{
       
   167 		++iter;
       
   168 		++count;
       
   169 		}
       
   170 	test(count==0);}
       
   171 
       
   172 	test.End();
       
   173 	__UHEAP_MARKEND;
       
   174 	}
       
   175 
       
   176 /**
       
   177 @SYMTestCaseID          SYSLIB-BAFL-CT-0403
       
   178 @SYMTestCaseDesc        Tests for RDesWriteStream and RDesReadStream classes
       
   179 @SYMTestPriority        Medium
       
   180 @SYMTestActions         Test the cell's info by writing and reading back from stream.
       
   181 @SYMTestExpectedResults Tests must not fail
       
   182 @SYMREQ                 REQ0000
       
   183 */
       
   184 void Test::Test4L()
       
   185 	{
       
   186 	__UHEAP_MARK;
       
   187 	test.Start(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0403 Streaming "));
       
   188 
       
   189 	TBuf8<64> buf;
       
   190 	RDesWriteStream writeStream(buf);
       
   191 	TCellRef cell1(2,5);
       
   192 	TCellRef cell2(6,8);
       
   193 	TRangeRef range1(12,13,2,5);
       
   194 	writeStream << cell1;
       
   195 	writeStream << cell2;
       
   196 	writeStream.WriteInt32L(KMaxTInt32);
       
   197 	writeStream.WriteInt32L(KMinTInt32);
       
   198 	writeStream << range1;
       
   199 	writeStream.Close();
       
   200 
       
   201 	RDesReadStream readStream(buf);
       
   202 	readStream >> range1;
       
   203 	test(range1==TRangeRef(cell1,cell2));
       
   204 	readStream >> range1;
       
   205 	test(range1.iFrom==TCellRef(KMaxTInt32,KMinTInt32));
       
   206 	test(range1.iTo.iRow==12);
       
   207 	test(range1.iTo.iCol==13);
       
   208 	readStream >> cell2;
       
   209 	test(cell1==cell2);
       
   210 	readStream.Close();
       
   211 
       
   212 	test.End();
       
   213 	__UHEAP_MARKEND;
       
   214 	}
       
   215 
       
   216 TInt E32Main()
       
   217 	{
       
   218 	__UHEAP_MARK;
       
   219 	test.Title();
       
   220 
       
   221 	Test::Test1();
       
   222 	Test::Test2();
       
   223 	Test::Test3();
       
   224 	Test::Test4L();
       
   225 
       
   226 	test.End();
       
   227 	test.Close();
       
   228 
       
   229 	__UHEAP_MARKEND;
       
   230 	return 0;
       
   231 	}