textrendering/textformatting/test/src/TTmCode.cpp
changeset 0 1fb32624e06b
child 16 748ec5531811
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Test code for CTmCode class
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "TAGMA.H"
       
    21 #include "TMSTD.H"
       
    22 
       
    23 #include <e32test.h>
       
    24 
       
    25 #include <bitdev.h>
       
    26 
       
    27 CTrapCleanup* TrapCleanup;
       
    28 RTest test(_L("TTmCode - Tests CTmCode class"));
       
    29 
       
    30 
       
    31 void RunTestsL()
       
    32 	{
       
    33 	CTmCode* code = new(ELeave) CTmCode;
       
    34 	CleanupStack::PushL(code);
       
    35 
       
    36 	// Testcase 1 - Append a number, then check retrived number is the same as the one we appended
       
    37 	code->CreateBufferL();
       
    38 	TInt num = 42;
       
    39 	code->AppendNumberL(num);
       
    40 	TTmCodeReader reader(*code, 0, 0x7FFFFFFF);
       
    41 	test(reader.ReadNumber() == num);
       
    42 
       
    43 	// Testcase 2 - Append largest positive number occupying 1 byte (where a byte is 7 bits in the case of CTmCode), check correct value read back
       
    44 	TInt size;
       
    45 	TInt sizeDelta;
       
    46 	size = code->Size();
       
    47 	num = 63;
       
    48 	TInt pos = code->AppendNumberL(num);
       
    49 	sizeDelta = code->Size() - size;
       
    50 	test(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
       
    51 
       
    52 	// Testcase 3 - Append smallest positive number occupying 2 bytes, check correct value read back
       
    53 	size = code->Size();
       
    54 	num = 64;
       
    55 	pos = code->AppendNumberL(num);
       
    56 	sizeDelta = code->Size() - size;
       
    57 	test(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
       
    58 
       
    59 	// Testcase 4 - Append largest negative number occupying 1 byte, check correct value read back
       
    60 	size = code->Size();
       
    61 	num = -64;
       
    62 	pos = code->AppendNumberL(num);
       
    63 	sizeDelta = code->Size() - size;
       
    64 	test(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
       
    65 
       
    66 	// Testcase 5 - Append smallest negative number occupying 2 bytes, check correct value read back
       
    67 	size = code->Size();
       
    68 	num = -65;
       
    69 	pos = code->AppendNumberL(num);
       
    70 	sizeDelta = code->Size() - size;
       
    71 	test(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
       
    72 
       
    73 	// Testcase 6 - Append rect, check same rect returned
       
    74 	size = code->Size();
       
    75 	TRect rect(1, 1, 2, 2);
       
    76 	pos = code->AppendRectL(rect);
       
    77 	sizeDelta = code->Size() - size;
       
    78 	test(sizeDelta == 4 && (pos - size) == 4 && reader.ReadRect() == rect);
       
    79 
       
    80 	// Testcase 7 - Replace first 2 bytes with 3 different bytes
       
    81 	CTmCode* code2 = new(ELeave) CTmCode;
       
    82 	CleanupStack::PushL(code2);
       
    83 	code2->CreateBufferL();
       
    84 	code2->AppendNumberL(1);
       
    85 	code2->AppendNumberL(1);
       
    86 	code2->AppendNumberL(2);
       
    87 	code->ChangeL(0, 1, *code2);
       
    88 	reader.SetCodePos(0);
       
    89 	test(reader.ReadNumber() == 1 && reader.ReadNumber() == 1 && reader.ReadNumber() == 2 && reader.ReadNumber() == 63);
       
    90 
       
    91 	// Testcase 8 - Insert 1000 numbers, then read them
       
    92 	size = code->Size();
       
    93 	int ii;
       
    94 	for (ii = 0; ii < 1000; ii++)
       
    95 		code->AppendNumberL(ii);
       
    96 	reader.SetCodePos(size);
       
    97 	for (ii = 0; ii < 1000; ii++)
       
    98 		test(reader.ReadNumber() == ii);
       
    99 
       
   100 	// Testcase 9 - Insert number at position 42 (1st segment), then reader to 42 and read number
       
   101 	code->InsertNumberL(4242, 42);
       
   102 	reader.SetCodePos(42);
       
   103 	test(reader.ReadNumber() == 4242);
       
   104 
       
   105 	// Testcase 10 - Insert number so it spans a segment boundary, check it reads back OK
       
   106 	num = -1234567;
       
   107 	code->InsertNumberL(num, 511);
       
   108 	reader.SetCodePos(511);
       
   109 	test(reader.ReadNumber() == num);
       
   110 
       
   111 	// Testcase 11 - ChangeL using a range that spans a segment boundary
       
   112 	code->InsertByteL(0x11, 515);
       
   113 	code2->Reset();
       
   114 	code2->CreateBufferL();
       
   115 	code2->AppendNumberL(0xabababab);
       
   116 	code->ChangeL(510, 515, *code2);
       
   117 	TTmCodeReader reader2(*code, 0, 0x7FFFFFFF);
       
   118 	reader2.SetCodePos(510);
       
   119 	test(reader2.ReadNumber() == static_cast<TInt32>(0xabababab));
       
   120 	test(reader2.ReadByte() == static_cast<TUint8>(0x11));
       
   121 
       
   122 
       
   123 
       
   124 	CleanupStack::PopAndDestroy(code2);
       
   125 	CleanupStack::PopAndDestroy(code);
       
   126 	}
       
   127 
       
   128 
       
   129 TInt E32Main()
       
   130 	{
       
   131 	TrapCleanup = CTrapCleanup::New();
       
   132 	test.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMCODE-0001 CTmCode tests "));
       
   133 	TRAPD(err, RunTestsL());
       
   134 	test(err == KErrNone);
       
   135 	test.End();
       
   136 	test.Close();
       
   137 	delete TrapCleanup;
       
   138 	return 0;
       
   139 	}