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