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