textrendering/textformatting/test/src/TInlineText.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) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-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".
    23 #include <frmtview.h>
    23 #include <frmtview.h>
    24 #include <txtlaydc.h>
    24 #include <txtlaydc.h>
    25 #include <fbs.h>
    25 #include <fbs.h>
    26 #include <w32std.h>
    26 #include <w32std.h>
    27 #include <inlinetext.h>
    27 #include <inlinetext.h>
    28 
    28 #include "tinlinetext.h"
    29 namespace LocalToFile
    29 
       
    30 namespace LocalToTInlineText
    30 {
    31 {
    31 
    32 
    32 _LIT(KTInlineText, "TInlineText");
    33 _LIT(KTInlineText, "TInlineText");
    33 const TInt KDisplayWidthWide = 202;
    34 const TInt KDisplayWidthWide = 202;
    34 const TInt KDisplayWidthThin = 102;
    35 const TInt KDisplayWidthThin = 102;
    35 const TInt KDisplayHeight = 100;
    36 const TInt KDisplayHeight = 100;
    36 const TInt KPictureCharacter = 0xFFFC;
    37 const TInt KPictureCharacter = 0xFFFC;
    37 RTest test(KTInlineText);
    38 
       
    39 CTInLineTextStep* TestStep = NULL;
       
    40 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
       
    41 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
       
    42 
    38 
    43 
    39 enum TInlineTextPanic { EAccessOutsideText = 1 };
    44 enum TInlineTextPanic { EAccessOutsideText = 1 };
    40 void Panic(TInlineTextPanic)
    45 void Panic(TInlineTextPanic)
    41     {
    46     {
    42     User::Panic(_L("TInlineText"), EAccessOutsideText);
    47     User::Panic(_L("TInlineText"), EAccessOutsideText);
   149 private:
   154 private:
   150 	const TDesC* iDes;
   155 	const TDesC* iDes;
   151 	CParaFormat* iParagraphFormat;
   156 	CParaFormat* iParagraphFormat;
   152 	};
   157 	};
   153 }
   158 }
   154 using namespace LocalToFile;
   159 using namespace LocalToTInlineText;
   155 
   160 
   156 class CTestTextView	// slightly naughty
   161 class CTestTextView	// slightly naughty
   157 	{
   162 	{
   158 public:
   163 public:
   159 	static void SetContextForFlickerFreeRedraw(CTextView* aView, CBitmapContext* aContext)
   164 	static void SetContextForFlickerFreeRedraw(CTextView* aView, CBitmapContext* aContext)
   167 _LIT(KAddressMarker, "> ");
   172 _LIT(KAddressMarker, "> ");
   168 _LIT(KSpace, " ");
   173 _LIT(KSpace, " ");
   169 _LIT(KLength, ", Length of Data = %d 16-bit words\r\n");
   174 _LIT(KLength, ", Length of Data = %d 16-bit words\r\n");
   170 _LIT(KSpaces, "                                                                      ");
   175 _LIT(KSpaces, "                                                                      ");
   171 _LIT(KPeriod, ".");
   176 _LIT(KPeriod, ".");
   172 _LIT(KSingleString, "%s\r\n");
   177 _LIT(KSingleString, "%S\r\n");
   173 //_LIT(KDoubleString, "%s <%s>\r\n");
   178 //_LIT(KDoubleString, "%s <%s>\r\n");
   174 //_LIT(KLinefeed, "\r\n");
   179 //_LIT(KLinefeed, "\r\n");
   175 
   180 
   176 void PrintTestData (const TDesC& aTitle , const TDesC16& aData)
   181 void PrintTestData (const TDesC& aTitle , const TDesC16& aData)
   177 	{
   182 	{
   186 
   191 
   187 	buffer.Zero();
   192 	buffer.Zero();
   188 	buffer.Append(aTitle);
   193 	buffer.Append(aTitle);
   189 	buffer.Append(KLength);
   194 	buffer.Append(KLength);
   190 
   195 
   191 	test.Printf(buffer, length);
   196 	TBuf<256> buf;
       
   197 	buf.AppendFormat(buffer, length);
       
   198 	TESTPRINT(buf);
   192 
   199 
   193 	for (i = 0 ; i < length ; i += 8)
   200 	for (i = 0 ; i < length ; i += 8)
   194 		{
   201 		{
   195 		buffer.Zero();
   202 		buffer.Zero();
   196 		buffer.AppendNumFixedWidth(i, EHex, 8);
   203 		buffer.AppendNumFixedWidth(i, EHex, 8);
   215 				{
   222 				{
   216 				buffer += KPeriod;
   223 				buffer += KPeriod;
   217 				}
   224 				}
   218 			}
   225 			}
   219 		buffer.ZeroTerminate();
   226 		buffer.ZeroTerminate();
   220 		test.Printf(KSingleString, buffer.Ptr());
   227 		buf.Zero();
       
   228 		buf.AppendFormat(KSingleString,buffer.Ptr());
       
   229 		TESTPRINT(buf);		
   221 		}
   230 		}
   222 
   231 
   223 	}
   232 	}
   224 
   233 
   225 void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize)
   234 void PrintTestData(const TDesC& aTitle, const TText16* aDataBuffer, const TInt aSize)
  1201 	switch (count)
  1210 	switch (count)
  1202 		{
  1211 		{
  1203 	case 5:
  1212 	case 5:
  1204 		line1 = &(aDevice->LineArray().Line(4));
  1213 		line1 = &(aDevice->LineArray().Line(4));
  1205 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][5]);
  1214 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][5]);
  1206 		test(0 != line1);
  1215 		TESTPOINT(0 != line1);
  1207 		test(0 != line2);
  1216 		TESTPOINT(0 != line2);
  1208 		test(line1->iLineData.Compare(line2->iLineData) == 0);
  1217 		TESTPOINT(line1->iLineData.Compare(line2->iLineData) == 0);
  1209 	case 4:
  1218 	case 4:
  1210 		line1 = &(aDevice->LineArray().Line(3));
  1219 		line1 = &(aDevice->LineArray().Line(3));
  1211 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][4]);
  1220 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][4]);
  1212 		test(0 != line1);
  1221 		TESTPOINT(0 != line1);
  1213 		test(0 != line2);
  1222 		TESTPOINT(0 != line2);
  1214 		test(line1->iLineData.Compare(line2->iLineData) == 0);
  1223 		TESTPOINT(line1->iLineData.Compare(line2->iLineData) == 0);
  1215 	case 3:
  1224 	case 3:
  1216 		line1 = &(aDevice->LineArray().Line(2));
  1225 		line1 = &(aDevice->LineArray().Line(2));
  1217 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][3]);
  1226 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][3]);
  1218 		test(0 != line1);
  1227 		TESTPOINT(0 != line1);
  1219 		test(0 != line2);
  1228 		TESTPOINT(0 != line2);
  1220 		test(line1->iLineData.Compare(line2->iLineData) == 0);
  1229 		TESTPOINT(line1->iLineData.Compare(line2->iLineData) == 0);
  1221 	case 2:
  1230 	case 2:
  1222 		line1 = &(aDevice->LineArray().Line(1));
  1231 		line1 = &(aDevice->LineArray().Line(1));
  1223 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][2]);
  1232 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][2]);
  1224 		test(0 != line1);
  1233 		TESTPOINT(0 != line1);
  1225 		test(0 != line2);
  1234 		TESTPOINT(0 != line2);
  1226 		test(line1->iLineData.Compare(line2->iLineData) == 0);
  1235 		TESTPOINT(line1->iLineData.Compare(line2->iLineData) == 0);
  1227 	case 1:
  1236 	case 1:
  1228 		line1 = &(aDevice->LineArray().Line(0));
  1237 		line1 = &(aDevice->LineArray().Line(0));
  1229 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][1]);
  1238 		line2 = aDevice->LineArray().Find(KTestStrings[aIndex][aNumChar][1]);
  1230 		test(0 != line1);
  1239 		TESTPOINT(0 != line1);
  1231 		test(0 != line2);
  1240 		TESTPOINT(0 != line2);
  1232 		// Can't always do a direct comparison of lines because same string
  1241 		// Can't always do a direct comparison of lines because same string
  1233 		// may appear in more than one line, so compare contents
  1242 		// may appear in more than one line, so compare contents
  1234 		test(line1->iLineData.Compare(line2->iLineData) == 0);
  1243 		TESTPOINT(line1->iLineData.Compare(line2->iLineData) == 0);
  1235 		}
  1244 		}
  1236 	aLayout->SetInterfaceProvider(NULL);
  1245 	aLayout->SetInterfaceProvider(NULL);
  1237 	CleanupStack::PopAndDestroy(interfaceProvider);
  1246 	CleanupStack::PopAndDestroy(interfaceProvider);
  1238 	}
  1247 	}
  1239 
  1248 
  1240 void GeneralCombinationTestsTextViewL(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView, TInt aNumChar)
  1249 void GeneralCombinationTestsTextViewL(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView, TInt aNumChar)
  1241 	{
  1250 	{
  1242 	// For all tests carried out from here up to 20 chars will fit on a line
  1251 	// For all tests carried out from here up to 20 chars will fit on a line
  1243 	test.Start(_L("Test L-P"));
  1252 	TESTPRINT(_L("Test L-P"));
  1244 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 0);
  1253 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 0);
  1245 	test.Next(_L("Test X L-P"));
  1254 	TESTPRINT(_L("Test X L-P"));
  1246 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 1);
  1255 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 1);
  1247 	test.Next(_L("Test P-T"));
  1256 	TESTPRINT(_L("Test P-T"));
  1248 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 2);
  1257 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 2);
  1249 	test.Next(_L("Test P-T Y"));
  1258 	TESTPRINT(_L("Test P-T Y"));
  1250 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 3);
  1259 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 3);
  1251 	test.Next(_L("Test L-P-T"));
  1260 	TESTPRINT(_L("Test L-P-T"));
  1252 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 4);
  1261 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 4);
  1253 	test.Next(_L("Test L-C-T"));
  1262 	TESTPRINT(_L("Test L-C-T"));
  1254 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 5);
  1263 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 5);
  1255 	test.Next(_L("Test X L-P-T"));
  1264 	TESTPRINT(_L("Test X L-P-T"));
  1256 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 6);
  1265 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 6);
  1257 	test.Next(_L("Test X L-C-T"));
  1266 	TESTPRINT(_L("Test X L-C-T"));
  1258 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 7);
  1267 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 7);
  1259 	test.Next(_L("Test L-P-T Y"));
  1268 	TESTPRINT(_L("Test L-P-T Y"));
  1260 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 8);
  1269 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 8);
  1261 	test.Next(_L("Test L-C-T Y"));
  1270 	TESTPRINT(_L("Test L-C-T Y"));
  1262 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 9);
  1271 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 9);
  1263 	test.Next(_L("Test X L-P-T Y"));
  1272 	TESTPRINT(_L("Test X L-P-T Y"));
  1264 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 10);
  1273 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 10);
  1265 	test.Next(_L("Test X L-C-T Y"));
  1274 	TESTPRINT(_L("Test X L-C-T Y"));
  1266 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 11);
  1275 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 11);
  1267 	test.End();
       
  1268 	}
  1276 	}
  1269 
  1277 
  1270 void SpecificTestsTextViewL(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView, TInt aNumChar)
  1278 void SpecificTestsTextViewL(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView, TInt aNumChar)
  1271 	{
  1279 	{
  1272 	// For all tests carried out from here up to 10 chars will fit on a line
  1280 	// For all tests carried out from here up to 10 chars will fit on a line
  1273 	test.Start(_L("Test P-T B"));
  1281     TESTPRINT(_L("Test P-T B"));
  1274 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 12);
  1282 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 12);
  1275 	test.Next(_L("Test X P-T one"));
  1283 	TESTPRINT(_L("Test X P-T one"));
  1276 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 13);
  1284 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 13);
  1277 	test.Next(_L("Test X P-T two"));
  1285 	TESTPRINT(_L("Test X P-T two"));
  1278 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 14);
  1286 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 14);
  1279 	test.Next(_L("Test X L-P-T one"));
  1287 	TESTPRINT(_L("Test X L-P-T one"));
  1280 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 15);
  1288 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 15);
  1281 	test.Next(_L("Test X L-P-T two"));
  1289 	TESTPRINT(_L("Test X L-P-T two"));
  1282 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 16);
  1290 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 16);
  1283 	test.Next(_L("Test X L-P-T three"));
  1291 	TESTPRINT(_L("Test X L-P-T three"));
  1284 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 17);
  1292 	DoLineTestL(aText, aLayout, aDevice, aView, aNumChar, 17);
  1285 	test.End();
       
  1286 	}
  1293 	}
  1287 
  1294 
  1288 void DoLineTestForINC141914L(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView)
  1295 void DoLineTestForINC141914L(TDes& aText, CTextLayout* aLayout, CTestGraphicsDevice* aDevice, CTextView* aView)
  1289     {
  1296     {
  1290     /*
  1297     /*
  1443     CleanupStack::PopAndDestroy(layout);
  1450     CleanupStack::PopAndDestroy(layout);
  1444     CleanupStack::PopAndDestroy(scheduler);
  1451     CleanupStack::PopAndDestroy(scheduler);
  1445     __UHEAP_MARKEND;
  1452     __UHEAP_MARKEND;
  1446     }
  1453     }
  1447 
  1454 
  1448 TInt E32Main()
  1455 TVerdict CTInLineTextStep::doTestStepL()
  1449 	{
  1456 	{
       
  1457     SetTestStepResult(EPass);
       
  1458     TestStep = this;
       
  1459     
  1450 	__UHEAP_MARK;
  1460 	__UHEAP_MARK;
  1451 	test.Title();
  1461 	TESTPRINT(KTInlineText);
  1452 	static CTrapCleanup* TrapCleanup = CTrapCleanup::New();
  1462 	TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-INLINETEXT-0001 General combination tests - no inline text "));
  1453 	test.Start(_L(" @SYMTestCaseID:SYSLIB-FORM-LEGACY-INLINETEXT-0001 General combination tests - no inline text "));
       
  1454 	TInt error = RFbsSession::Connect();
  1463 	TInt error = RFbsSession::Connect();
  1455 	if (error == KErrNotFound)
  1464 	if (error == KErrNotFound)
  1456 		{
  1465 		{
  1457 		FbsStartup();
  1466 		FbsStartup();
  1458 		error = RFbsSession::Connect();
  1467 		error = RFbsSession::Connect();
  1459 		}
  1468 		}
  1460 	test(error == KErrNone);
  1469 	TEST(error == KErrNone);
  1461 	TRAP(error, RunGeneralCombinationTestsL(0));
  1470 	TRAP(error, RunGeneralCombinationTestsL(0));
  1462 	test(error == KErrNone);
  1471 	TEST(error == KErrNone);
  1463 	test.Next(_L("General combination tests - single char inline text"));
  1472 	TESTPRINT(_L("General combination tests - single char inline text"));
  1464 	TRAP(error, RunGeneralCombinationTestsL(1));
  1473 	TRAP(error, RunGeneralCombinationTestsL(1));
  1465 	test(error == KErrNone);
  1474 	TEST(error == KErrNone);
  1466 	test.Next(_L("General combination tests - multi char inline text"));
  1475 	TESTPRINT(_L("General combination tests - multi char inline text"));
  1467 	TRAP(error, RunGeneralCombinationTestsL(2));
  1476 	TRAP(error, RunGeneralCombinationTestsL(2));
  1468 	test(error == KErrNone);
  1477 	TEST(error == KErrNone);
  1469 	test.Next(_L("Specific tests - no inline text"));
  1478 	TESTPRINT(_L("Specific tests - no inline text"));
  1470 	TRAP(error, RunSpecificTestsL(0));
  1479 	TRAP(error, RunSpecificTestsL(0));
  1471 	test(error == KErrNone);
  1480 	TEST(error == KErrNone);
  1472 	test.Next(_L("Specific tests - single char inline text"));
  1481 	TESTPRINT(_L("Specific tests - single char inline text"));
  1473 	TRAP(error, RunSpecificTestsL(1));
  1482 	TRAP(error, RunSpecificTestsL(1));
  1474 	test(error == KErrNone);
  1483 	TEST(error == KErrNone);
  1475 	test.Next(_L("Specific tests - multi char inline text"));
  1484 	TESTPRINT(_L("Specific tests - multi char inline text"));
  1476 	TRAP(error, RunSpecificTestsL(2));
  1485 	TRAP(error, RunSpecificTestsL(2));
  1477 	test(error == KErrNone);
  1486 	TEST(error == KErrNone);
  1478 	
  1487 	
  1479     test.Next(_L("Defect tests - for INC141914"));
  1488     TESTPRINT(_L("Defect tests - for INC141914"));
  1480     TRAP(error, RunTestsForINC141914L());
  1489     TRAP(error, RunTestsForINC141914L());
  1481     test(error == KErrNone);
  1490     TEST(error == KErrNone);
  1482     
  1491     
  1483 	RFbsSession::Disconnect();
  1492 	RFbsSession::Disconnect();
  1484 	test.End();
       
  1485 	delete TrapCleanup;
       
  1486 	test.Close();
       
  1487 	__UHEAP_MARKEND;
  1493 	__UHEAP_MARKEND;
  1488 	User::Heap().Check();
  1494 	User::Heap().Check();
  1489 	return error;
  1495 	return TestStepResult();
  1490 	}
  1496 	}