os/textandloc/textrendering/textformatting/test/src/TTmCode.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2002-2010 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 #include <bitdev.h>
    25 #include "ttmcode.h"
    26 
    27 TVerdict CTTmCodeStep::doTestStepL()
    28 	{
    29     SetTestStepResult(EPass);
    30     INFO_PRINTF1(_L("TTmCode - Tests CTmCode class"));
    31     INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-TTMCODE-0001 CTmCode tests "));
    32 	CTmCode* code = new(ELeave) CTmCode;
    33 	CleanupStack::PushL(code);
    34 
    35 	// Testcase 1 - Append a number, then check retrived number is the same as the one we appended
    36 	code->CreateBufferL();
    37 	TInt num = 42;
    38 	code->AppendNumberL(num);
    39 	TTmCodeReader reader(*code, 0, 0x7FFFFFFF);
    40 	TEST(reader.ReadNumber() == num);
    41 
    42 	// 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
    43 	TInt size;
    44 	TInt sizeDelta;
    45 	size = code->Size();
    46 	num = 63;
    47 	TInt pos = code->AppendNumberL(num);
    48 	sizeDelta = code->Size() - size;
    49 	TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
    50 
    51 	// Testcase 3 - Append smallest positive number occupying 2 bytes, check correct value read back
    52 	size = code->Size();
    53 	num = 64;
    54 	pos = code->AppendNumberL(num);
    55 	sizeDelta = code->Size() - size;
    56 	TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
    57 
    58 	// Testcase 4 - Append largest negative number occupying 1 byte, check correct value read back
    59 	size = code->Size();
    60 	num = -64;
    61 	pos = code->AppendNumberL(num);
    62 	sizeDelta = code->Size() - size;
    63 	TEST(sizeDelta == 1 && (pos - size) == 1 && reader.ReadNumber() == num);
    64 
    65 	// Testcase 5 - Append smallest negative number occupying 2 bytes, check correct value read back
    66 	size = code->Size();
    67 	num = -65;
    68 	pos = code->AppendNumberL(num);
    69 	sizeDelta = code->Size() - size;
    70 	TEST(sizeDelta == 2 && (pos - size) == 2 && reader.ReadNumber() == num);
    71 
    72 	// Testcase 6 - Append rect, check same rect returned
    73 	size = code->Size();
    74 	TRect rect(1, 1, 2, 2);
    75 	pos = code->AppendRectL(rect);
    76 	sizeDelta = code->Size() - size;
    77 	TEST(sizeDelta == 4 && (pos - size) == 4 && reader.ReadRect() == rect);
    78 
    79 	// Testcase 7 - Replace first 2 bytes with 3 different bytes
    80 	CTmCode* code2 = new(ELeave) CTmCode;
    81 	CleanupStack::PushL(code2);
    82 	code2->CreateBufferL();
    83 	code2->AppendNumberL(1);
    84 	code2->AppendNumberL(1);
    85 	code2->AppendNumberL(2);
    86 	code->ChangeL(0, 1, *code2);
    87 	reader.SetCodePos(0);
    88 	TEST(reader.ReadNumber() == 1 && reader.ReadNumber() == 1 && reader.ReadNumber() == 2 && reader.ReadNumber() == 63);
    89 
    90 	// Testcase 8 - Insert 1000 numbers, then read them
    91 	size = code->Size();
    92 	int ii;
    93 	for (ii = 0; ii < 1000; ii++)
    94 		code->AppendNumberL(ii);
    95 	reader.SetCodePos(size);
    96 	for (ii = 0; ii < 1000; ii++)
    97 	    TEST(reader.ReadNumber() == ii);
    98 
    99 	// Testcase 9 - Insert number at position 42 (1st segment), then reader to 42 and read number
   100 	code->InsertNumberL(4242, 42);
   101 	reader.SetCodePos(42);
   102 	TEST(reader.ReadNumber() == 4242);
   103 
   104 	// Testcase 10 - Insert number so it spans a segment boundary, check it reads back OK
   105 	num = -1234567;
   106 	code->InsertNumberL(num, 511);
   107 	reader.SetCodePos(511);
   108 	TEST(reader.ReadNumber() == num);
   109 
   110 	// Testcase 11 - ChangeL using a range that spans a segment boundary
   111 	code->InsertByteL(0x11, 515);
   112 	code2->Reset();
   113 	code2->CreateBufferL();
   114 	code2->AppendNumberL(0xabababab);
   115 	code->ChangeL(510, 515, *code2);
   116 	TTmCodeReader reader2(*code, 0, 0x7FFFFFFF);
   117 	reader2.SetCodePos(510);
   118 	TEST(reader2.ReadNumber() == static_cast<TInt32>(0xabababab));
   119 	TEST(reader2.ReadByte() == static_cast<TUint8>(0x11));
   120 
   121 	CleanupStack::PopAndDestroy(code2);
   122 	CleanupStack::PopAndDestroy(code);
   123 	
   124 	return TestStepResult();
   125 	}
   126