textrendering/texthandling/tfields/T_FIELD1.CPP
changeset 51 a7c938434754
parent 0 1fb32624e06b
child 55 336bee5c2d35
equal deleted inserted replaced
44:601ab138ba0b 51:a7c938434754
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-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".
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <e32test.h>
    19 #include "T_FIELD1.h"
    20 #include "TESTFAC.H"
    20 #include "TESTFAC.H"
    21 #include <fldset.h>
    21 #include <fldset.h>
    22 #include <flddef.h>
    22 #include <flddef.h>
    23 
    23 
       
    24 #define test(cond)											\
       
    25 	{														\
       
    26 	TBool __bb = (cond);									\
       
    27 	TEST(__bb);												\
       
    28 	if (!__bb)												\
       
    29 		{													\
       
    30 		ERR_PRINTF1(_L("ERROR: Test Failed"));				\
       
    31 		User::Leave(1);										\
       
    32 		}													\
       
    33 	}
       
    34 
    24 #define UNUSED_VAR(a) a = a
    35 #define UNUSED_VAR(a) a = a
    25 
    36 
    26 const TInt KTestCleanupStack=0x40;
    37 const TInt KTestCleanupStack=0x40;
    27 
    38 
    28 LOCAL_D RTest test(_L("Testing Fields"));
       
    29 LOCAL_D CTrapCleanup* TheTrapCleanup;
    39 LOCAL_D CTrapCleanup* TheTrapCleanup;
    30 LOCAL_D CTextFieldSet* TheFieldSet;
    40 LOCAL_D CTextFieldSet* TheFieldSet;
    31 LOCAL_D TTestFieldFactory* TheFactory;
    41 LOCAL_D TTestFieldFactory* TheFactory;
    32 
    42 
    33 
    43 
    34 LOCAL_C TBool UpdateField(TInt aPos)
    44 TBool CT_FIELD1::UpdateField(TInt aPos)
    35 	{
    45 	{
    36 	// find out which field aPos is in
    46 	// find out which field aPos is in
    37 	TFindFieldInfo info;
    47 	TFindFieldInfo info;
    38 	TBool inField=TheFieldSet->FindFields(info,aPos);
    48 	TBool inField=TheFieldSet->FindFields(info,aPos);
    39 		test(inField);
    49 		test(inField);
    49 	CleanupStack::PopAndDestroy();
    59 	CleanupStack::PopAndDestroy();
    50 	return ret;
    60 	return ret;
    51 	}
    61 	}
    52 
    62 
    53 
    63 
    54 LOCAL_C void test1()
    64 void CT_FIELD1::test1()
    55 // Tests that all CTextFieldSet methods exist as specced
    65 // Tests that all CTextFieldSet methods exist as specced
    56 //
    66 //
    57 	{
    67 	{
    58 	test.Next(_L("- Testing that all CTextFieldSet methods exist"));
    68 	INFO_PRINTF1(_L("- Testing that all CTextFieldSet methods exist"));
    59 	// inform TheFieldSet about an imaginary insertion, then an imaginary deletion
    69 	// inform TheFieldSet about an imaginary insertion, then an imaginary deletion
    60 	TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10
    70 	TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10
    61 	TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5
    71 	TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5
    62 	// insert a field & get its initial value
    72 	// insert a field & get its initial value
    63 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
    73 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
    81 	// reset the field array
    91 	// reset the field array
    82 	TheFieldSet->Reset();
    92 	TheFieldSet->Reset();
    83 	}
    93 	}
    84 
    94 
    85 
    95 
    86 LOCAL_C void test2()
    96 void CT_FIELD1::test2()
    87 // Tests inserting, updating and removing a field
    97 // Tests inserting, updating and removing a field
    88 //
    98 //
    89 	{
    99 	{
    90 	test.Next(_L("- Testing field insertion, update and removal"));
   100 	INFO_PRINTF1(_L("- Testing field insertion, update and removal"));
    91 		test(TheFieldSet->CharCount()==0);
   101 		test(TheFieldSet->CharCount()==0);
    92 		test(TheFieldSet->FieldCount()==0);
   102 		test(TheFieldSet->FieldCount()==0);
    93 	// insert a field
   103 	// insert a field
    94 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
   104 	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
    95 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   105 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDummyFieldUid); // pos=0
   139 	TheFieldSet->Reset();
   149 	TheFieldSet->Reset();
   140 	CleanupStack::PopAndDestroy(); // miniBuf
   150 	CleanupStack::PopAndDestroy(); // miniBuf
   141 	}
   151 	}
   142 
   152 
   143 
   153 
   144 LOCAL_C void test3()
   154 void CT_FIELD1::test3()
   145 // Tests InField() in "all" the oddball situations
   155 // Tests InField() in "all" the oddball situations
   146 //
   156 //
   147 	{
   157 	{
   148 	TFindFieldInfo info;
   158 	TFindFieldInfo info;
   149 	test.Next(_L("- Testing InField() calls"));
   159 	INFO_PRINTF1(_L("- Testing InField() calls"));
   150 		test(TheFieldSet->CharCount()==0);
   160 		test(TheFieldSet->CharCount()==0);
   151 		test(TheFieldSet->FieldCount()==0);
   161 		test(TheFieldSet->FieldCount()==0);
   152 	// Zero length doc
   162 	// Zero length doc
   153 	TBool inField=TheFieldSet->FindFields(info,0);
   163 	TBool inField=TheFieldSet->FindFields(info,0);
   154 		test(!inField);
   164 		test(!inField);
   230 		test(info.iFirstFieldPos==0);
   240 		test(info.iFirstFieldPos==0);
   231 	TheFieldSet->Reset();
   241 	TheFieldSet->Reset();
   232 	}
   242 	}
   233 
   243 
   234 
   244 
   235 LOCAL_C void test4()
   245 void CT_FIELD1::test4()
   236 // Tests Insertion and deletion of text around and into fields
   246 // Tests Insertion and deletion of text around and into fields
   237 //
   247 //
   238 	{
   248 	{
   239 	TFindFieldInfo info;
   249 	TFindFieldInfo info;
   240 	test.Next(_L("- Testing insertion and deletion of text around and into fields"));
   250 	INFO_PRINTF1(_L("- Testing insertion and deletion of text around and into fields"));
   241 		test(TheFieldSet->CharCount()==0);
   251 		test(TheFieldSet->CharCount()==0);
   242 		test(TheFieldSet->FieldCount()==0);
   252 		test(TheFieldSet->FieldCount()==0);
   243 	// Insert some text
   253 	// Insert some text
   244 	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   254 	TheFieldSet->NotifyInsertion(0,4); // pos=0, len=4
   245 		test(TheFieldSet->CharCount()==4);
   255 		test(TheFieldSet->CharCount()==4);
   387 	// Finish up
   397 	// Finish up
   388 	TheFieldSet->Reset();
   398 	TheFieldSet->Reset();
   389 	}
   399 	}
   390 
   400 
   391 
   401 
   392 LOCAL_C void test5()
   402 void CT_FIELD1::test5()
   393 // Tests inserting, updating and removing a CDateTimeField
   403 // Tests inserting, updating and removing a CDateTimeField
   394 //
   404 //
   395 	{
   405 	{
   396 	test.Next(_L("- Testing CDateTimeField"));
   406 	INFO_PRINTF1(_L("- Testing CDateTimeField"));
   397 		test(TheFieldSet->CharCount()==0);
   407 		test(TheFieldSet->CharCount()==0);
   398 		test(TheFieldSet->FieldCount()==0);
   408 		test(TheFieldSet->FieldCount()==0);
   399 	// insert a field with default format
   409 	// insert a field with default format
   400 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   410 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   401 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   411 	TInt ret=TheFieldSet->InsertFieldL(0,field,KDateTimeFieldUid); // pos=0
   411 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   421 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   412 	CleanupStack::Pop();
   422 	CleanupStack::Pop();
   413 	CleanupStack::PushL(miniBuf);
   423 	CleanupStack::PushL(miniBuf);
   414 		test(ret==KErrNone);
   424 		test(ret==KErrNone);
   415 	TPtr buf = miniBuf->Des();
   425 	TPtr buf = miniBuf->Des();
   416 	test.Printf(_L("  The field value is: "));
   426 	INFO_PRINTF1(_L("  The field value is: "));
   417 		test.Printf(buf);
   427 	INFO_PRINTF1(buf);
   418 		test.Printf(_L("\n"));
   428 	INFO_PRINTF1(_L("\n"));
   419 	// reset the field array
   429 	// reset the field array
   420 	TheFieldSet->Reset();
   430 	TheFieldSet->Reset();
   421 	CleanupStack::PopAndDestroy(); // miniBuf
   431 	CleanupStack::PopAndDestroy(); // miniBuf
   422 	}
   432 	}
   423 
   433 
   424 
   434 
   425 LOCAL_C void test6()
   435 void CT_FIELD1::test6()
   426 // Tests CDateTimeFields with non-default formatting
   436 // Tests CDateTimeFields with non-default formatting
   427 //
   437 //
   428 	{
   438 	{
   429 	test.Next(_L("- Testing CDateTimeField with non-default formatting"));
   439 	INFO_PRINTF1(_L("- Testing CDateTimeField with non-default formatting"));
   430 		test(TheFieldSet->CharCount()==0);
   440 		test(TheFieldSet->CharCount()==0);
   431 		test(TheFieldSet->FieldCount()==0);
   441 		test(TheFieldSet->FieldCount()==0);
   432 	// create a field and set format
   442 	// create a field and set format
   433 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   443 	CTextField* field = TheFieldSet->NewFieldL(KDateTimeFieldUid);
   434 	((CDateTimeField*)field)->SetFormat(_L("%-A%*I%:1%T%+A")); //
   444 	((CDateTimeField*)field)->SetFormat(_L("%-A%*I%:1%T%+A")); //
   447 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   457 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   448 	CleanupStack::Pop();
   458 	CleanupStack::Pop();
   449 	CleanupStack::PushL(miniBuf);
   459 	CleanupStack::PushL(miniBuf);
   450 		test(ret==KErrNone);
   460 		test(ret==KErrNone);
   451 	TPtr buf = miniBuf->Des();
   461 	TPtr buf = miniBuf->Des();
   452 	test.Printf(_L("  The field value is: "));
   462 	INFO_PRINTF1(_L("  The field value is: "));
   453 		test.Printf(buf);
   463 	INFO_PRINTF1(buf);
   454 		test.Printf(_L("\n"));
   464 	INFO_PRINTF1(_L("\n"));
   455 	// reset the field array
   465 	// reset the field array
   456 	TheFieldSet->Reset();
   466 	TheFieldSet->Reset();
   457 	CleanupStack::PopAndDestroy(); // miniBuf
   467 	CleanupStack::PopAndDestroy(); // miniBuf
   458 	}
   468 	}
   459 
   469 
   460 
   470 
   461 LOCAL_C void test7()
   471 void CT_FIELD1::test7()
   462 // Tests inserting, updating and removing a CPageNumberField
   472 // Tests inserting, updating and removing a CPageNumberField
   463 //
   473 //
   464 	{
   474 	{
   465 	test.Next(_L("- Testing CPageNumberField"));
   475 	INFO_PRINTF1(_L("- Testing CPageNumberField"));
   466 		test(TheFieldSet->CharCount()==0);
   476 		test(TheFieldSet->CharCount()==0);
   467 		test(TheFieldSet->FieldCount()==0);
   477 		test(TheFieldSet->FieldCount()==0);
   468 	// insert a field with default format
   478 	// insert a field with default format
   469 	CTextField* field = TheFieldSet->NewFieldL(KPageNumberFieldUid);
   479 	CTextField* field = TheFieldSet->NewFieldL(KPageNumberFieldUid);
   470 	TInt ret=TheFieldSet->InsertFieldL(0,field,KPageNumberFieldUid); // pos=0
   480 	TInt ret=TheFieldSet->InsertFieldL(0,field,KPageNumberFieldUid); // pos=0
   480 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   490 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   481 	CleanupStack::Pop();
   491 	CleanupStack::Pop();
   482 	CleanupStack::PushL(miniBuf);
   492 	CleanupStack::PushL(miniBuf);
   483 		test(ret==KErrNone);
   493 		test(ret==KErrNone);
   484 	TPtr buf = miniBuf->Des();
   494 	TPtr buf = miniBuf->Des();
   485 	test.Printf(_L("  The field value is: "));
   495 	INFO_PRINTF1(_L("  The field value is: "));
   486 		test.Printf(buf);
   496 	INFO_PRINTF1(buf);
   487 		test.Printf(_L("\n"));
   497 	INFO_PRINTF1(_L("\n"));
   488 	// reset the field array
   498 	// reset the field array
   489 	TheFieldSet->Reset();
   499 	TheFieldSet->Reset();
   490 	CleanupStack::PopAndDestroy(); // miniBuf
   500 	CleanupStack::PopAndDestroy(); // miniBuf
   491 	}
   501 	}
   492 
   502 
   493 
   503 
   494 LOCAL_C void test8()
   504 void CT_FIELD1::test8()
   495 // Tests inserting, updating and removing a CPageNumberField
   505 // Tests inserting, updating and removing a CPageNumberField
   496 //
   506 //
   497 	{
   507 	{
   498 	test.Next(_L("- Testing CFileNameField"));
   508 	INFO_PRINTF1(_L("- Testing CFileNameField"));
   499 		test(TheFieldSet->CharCount()==0);
   509 		test(TheFieldSet->CharCount()==0);
   500 		test(TheFieldSet->FieldCount()==0);
   510 		test(TheFieldSet->FieldCount()==0);
   501 	// insert a field with default format
   511 	// insert a field with default format
   502 	CTextField* field = TheFieldSet->NewFieldL(KFileNameFieldUid);
   512 	CTextField* field = TheFieldSet->NewFieldL(KFileNameFieldUid);
   503 	TInt ret=TheFieldSet->InsertFieldL(0,field,KFileNameFieldUid); // pos=0
   513 	TInt ret=TheFieldSet->InsertFieldL(0,field,KFileNameFieldUid); // pos=0
   513 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   523 	ret=TheFieldSet->NewFieldValueL(miniBuf,0); // pos=0
   514 	CleanupStack::Pop();
   524 	CleanupStack::Pop();
   515 	CleanupStack::PushL(miniBuf);
   525 	CleanupStack::PushL(miniBuf);
   516 		test(ret==KErrNone);
   526 		test(ret==KErrNone);
   517 	TPtr buf = miniBuf->Des();
   527 	TPtr buf = miniBuf->Des();
   518 	test.Printf(_L("  The field value is: "));
   528 	INFO_PRINTF1(_L("  The field value is: "));
   519 		test.Printf(buf);
   529 	INFO_PRINTF1(buf);
   520 		test.Printf(_L("\n"));
   530 	INFO_PRINTF1(_L("\n"));
   521 	// reset the field array
   531 	// reset the field array
   522 	TheFieldSet->Reset();
   532 	TheFieldSet->Reset();
   523 	CleanupStack::PopAndDestroy(); // miniBuf
   533 	CleanupStack::PopAndDestroy(); // miniBuf
   524 	}
   534 	}
   525 
   535 
   526 
   536 
   527 /*
   537 /*
   528 Added to test the fix to 'EDNHARN-4NVDHC: Text fields are not removed correctly in edwin'. Deletion
   538 Added to test the fix to 'EDNHARN-4NVDHC: Text fields are not removed correctly in edwin'. Deletion
   529 of two fields failed to delete the second one.
   539 of two fields failed to delete the second one.
   530 */
   540 */
   531 static void test_multiple_fields()
   541 void CT_FIELD1::test_multiple_fields()
   532 	{
   542 	{
   533 	test.Next(_L(" - testing multiple fields"));
   543 	INFO_PRINTF1(_L(" - testing multiple fields"));
   534 	test(TheFieldSet->CharCount()==0);
   544 	test(TheFieldSet->CharCount()==0);
   535 	test(TheFieldSet->FieldCount()==0);
   545 	test(TheFieldSet->FieldCount()==0);
   536 
   546 
   537 	/*
   547 	/*
   538 	Insert two dummy fields and some imaginary text. Dummy fields have the value 'XXX'.
   548 	Insert two dummy fields and some imaginary text. Dummy fields have the value 'XXX'.
   562 
   572 
   563 	TheFieldSet->Reset();
   573 	TheFieldSet->Reset();
   564 	}
   574 	}
   565 
   575 
   566 
   576 
   567 LOCAL_C void testFields()
   577 void CT_FIELD1::testFields()
   568 // Test the fields dll.
   578 // Test the fields dll.
   569 //
   579 //
   570     {
   580     {
   571 	test.Start(_L("Testing Fields"));
   581 	INFO_PRINTF1(_L("Testing Fields"));
   572 	
   582 	
   573 	// instantiate the  FieldSet and use the default factory
   583 	// instantiate the  FieldSet and use the default factory
   574 	TheFactory = new(ELeave) TTestFieldFactory();
   584 	TheFactory = new(ELeave) TTestFieldFactory();
   575 	TheFieldSet = CTextFieldSet::NewL();
   585 	TheFieldSet = CTextFieldSet::NewL();
   576 	TheFieldSet->SetFieldFactory(TheFactory);
   586 	TheFieldSet->SetFieldFactory(TheFactory);
   599 	delete TheFactory;
   609 	delete TheFactory;
   600 	//CleanupStack::PopAndDestroy(); 
   610 	//CleanupStack::PopAndDestroy(); 
   601     }
   611     }
   602 
   612 
   603 
   613 
   604 LOCAL_C void setupCleanup()
   614 void CT_FIELD1::setupCleanup()
   605 //
   615 //
   606 // Initialise the cleanup stack.
   616 // Initialise the cleanup stack.
   607 //
   617 //
   608     {
   618     {
   609 
   619 
   615 		test(r==KErrNone);\
   625 		test(r==KErrNone);\
   616 		CleanupStack::Pop(KTestCleanupStack);\
   626 		CleanupStack::Pop(KTestCleanupStack);\
   617 		});
   627 		});
   618 	}
   628 	}
   619 
   629 
   620 
   630 CT_FIELD1::CT_FIELD1()
   621 GLDEF_C TInt E32Main()
       
   622 //
       
   623 // Test the streaming framework.
       
   624 //
       
   625     {
   631     {
   626 
   632     SetTestStepName(KTestStep_T_FIELD1);
   627 	test.Title();
   633     }
   628 	
   634 
   629 	__UHEAP_MARK;
   635 TVerdict CT_FIELD1::doTestStepL()
       
   636     {
       
   637 	INFO_PRINTF1(_L("Testing Fields"));
       
   638     SetTestStepResult(EFail);
       
   639 
       
   640     __UHEAP_MARK;
       
   641 
   630 	setupCleanup();
   642 	setupCleanup();
   631 	TRAPD(r,testFields());
   643     
   632     UNUSED_VAR(r);
   644     TRAPD(error1, testFields());
   633     test(r == KErrNone);
       
   634 
   645 
   635 	delete TheTrapCleanup;
   646 	delete TheTrapCleanup;
   636 	
   647 
   637 	__UHEAP_MARKEND;
   648     __UHEAP_MARKEND;
   638 	test.End();
   649 
   639 	test.Close();
   650     if(error1 == KErrNone)
   640 	return 0;
   651         {
       
   652         SetTestStepResult(EPass);
       
   653         }
       
   654 
       
   655     return TestStepResult();
   641     }
   656     }