messagingfw/msgtest/testutils/sms/test/src/MsgScriptsTest.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32std.h>
       
    17 #include <e32test.h>
       
    18 #include <msgtestscripts.h>
       
    19 
       
    20 _LIT(KSmsConfigFile, "c:\\test\\sms\\msgscriptstest.config");
       
    21 RTest test(_L("MsgTestScripts"));
       
    22 RFs fs;
       
    23 
       
    24 _LIT(KSmsItemA, "Name");
       
    25 _LIT(KSmsItemB, "Recipients");
       
    26 _LIT(KSmsItemC, "Self");
       
    27 _LIT(KSmsItemD, "Message");
       
    28 _LIT(KSmsItemE, "Encoding");
       
    29 
       
    30 _LIT(KSmsSection1, "Group");
       
    31 _LIT(KSmsValue1A, "Anthony");
       
    32 _LIT(KSmsValue1B, "+447747065431");
       
    33 _LIT(KSmsValue1C, "+447747065499");
       
    34 _LIT(KSmsValue1D, "");
       
    35 const TInt KSmsValue1E = 0;
       
    36 
       
    37 _LIT(KSmsSection2, "NextGroup");
       
    38 _LIT(KSmsValue2A, "Bill");
       
    39 _LIT(KSmsValue2B, "+447747065445");
       
    40 _LIT(KSmsValue2C, "+447747065498");
       
    41 _LIT(KSmsValue2D, "This\nis\na\nmultiline\nmessage");
       
    42 const TInt KSmsValue2E = 7;
       
    43 
       
    44 _LIT(KSmsSection3, "LastGroup");
       
    45 _LIT(KSmsValue3A, "");
       
    46 _LIT(KSmsValue3B, "");
       
    47 _LIT(KSmsValue3C, "");
       
    48 _LIT(KSmsValue3D, "");
       
    49 const TInt KSmsValue3E = 0;
       
    50 
       
    51 void TestScriptFileL()
       
    52 	{
       
    53 	CScriptFile* scriptFile = CScriptFile::NewLC(fs, KSmsConfigFile);
       
    54 
       
    55 	TPtrC itemValue(KNullDesC);
       
    56 	TInt intValue(0);
       
    57 
       
    58 	//Test Section1
       
    59 	scriptFile->ItemValue(KSmsSection1, KSmsItemA, itemValue, KNullDesC);
       
    60 	test(itemValue == KSmsValue1A);
       
    61 
       
    62 	scriptFile->ItemValue(KSmsSection1, KSmsItemB, itemValue, KNullDesC);
       
    63 	test(itemValue == KSmsValue1B);
       
    64 
       
    65 	scriptFile->ItemValue(KSmsSection1, KSmsItemC, itemValue, KNullDesC);
       
    66 	test(itemValue == KSmsValue1C);
       
    67 
       
    68 	scriptFile->ItemValue(KSmsSection1, KSmsItemD, itemValue, KNullDesC);
       
    69 	test(itemValue == KSmsValue1D);
       
    70 
       
    71 	scriptFile->ItemValue(KSmsSection1, KSmsItemE, intValue, 0);
       
    72 	test(intValue == KSmsValue1E);
       
    73 
       
    74 	//Test Section2
       
    75 	scriptFile->ItemValue(KSmsSection2, KSmsItemA, itemValue, KNullDesC);
       
    76 	test(itemValue == KSmsValue2A);
       
    77 
       
    78 	scriptFile->ItemValue(KSmsSection2, KSmsItemB, itemValue, KNullDesC);
       
    79 	test(itemValue == KSmsValue2B);
       
    80 
       
    81 	scriptFile->ItemValue(KSmsSection2, KSmsItemC, itemValue, KNullDesC);
       
    82 	test(itemValue == KSmsValue2C);
       
    83 
       
    84 	scriptFile->ItemValue(KSmsSection2, KSmsItemD, itemValue, KNullDesC);
       
    85 	test(itemValue == KSmsValue2D);
       
    86 
       
    87 	scriptFile->ItemValue(KSmsSection2, KSmsItemE, intValue, 0);
       
    88 	test(intValue == KSmsValue2E);
       
    89 
       
    90 	//Test Section3
       
    91 	scriptFile->ItemValue(KSmsSection3, KSmsItemA, itemValue, KNullDesC);
       
    92 	test(itemValue == KSmsValue3A);
       
    93 
       
    94 	scriptFile->ItemValue(KSmsSection3, KSmsItemB, itemValue, KNullDesC);
       
    95 	test(itemValue == KSmsValue3B);
       
    96 
       
    97 	scriptFile->ItemValue(KSmsSection3, KSmsItemC, itemValue, KNullDesC);
       
    98 	test(itemValue == KSmsValue3C);
       
    99 
       
   100 	scriptFile->ItemValue(KSmsSection3, KSmsItemD, itemValue, KNullDesC);
       
   101 	test(itemValue == KSmsValue3D);
       
   102 
       
   103 	scriptFile->ItemValue(KSmsSection3, KSmsItemE, intValue, 0);
       
   104 	test(intValue == KSmsValue3E);
       
   105 
       
   106 	CleanupStack::PopAndDestroy(scriptFile);
       
   107 	}
       
   108 
       
   109 void TestHeapFailL()
       
   110 	{
       
   111 	TInt error;
       
   112 	TInt failCount = 0;
       
   113 
       
   114 	//Failure Test CSmsSettings::NewL
       
   115 	do
       
   116 		{
       
   117 		__UHEAP_FAILNEXT(failCount++);
       
   118 
       
   119 		TRAP(error, TestScriptFileL());
       
   120 
       
   121 		__UHEAP_RESET;
       
   122 
       
   123 		if (error)
       
   124 			{
       
   125 			test(error == KErrNoMemory);
       
   126 			}
       
   127 
       
   128 		}
       
   129 	while (error);
       
   130 
       
   131 	test.Printf(_L("TestScriptFileL() Fail Count %d\n"), failCount);
       
   132 
       
   133 	failCount = 0;
       
   134 	}
       
   135 
       
   136 void doMainL()
       
   137 	{
       
   138 	TestScriptFileL();
       
   139 	TestHeapFailL();
       
   140 	}
       
   141 
       
   142 GLDEF_C TInt E32Main()
       
   143 	{
       
   144 	__UHEAP_MARK;
       
   145 	test.Start(_L("Setup"));
       
   146 	CTrapCleanup* theCleanup = CTrapCleanup::New();
       
   147 	TInt ret = fs.Connect();
       
   148 	if (!ret)
       
   149 		TRAP(ret,doMainL());		
       
   150 	test(ret==KErrNone);
       
   151 	fs.Close();
       
   152 	delete theCleanup;	
       
   153 	test.Console()->SetPos(0, 13);
       
   154 	test.End();
       
   155 	test.Close();
       
   156 	__UHEAP_MARKEND;
       
   157 	return(KErrNone);
       
   158 	}
       
   159