datacommsserver/esockserver/test/TE_Ini/src/TeIniWriteStep.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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 // Example CTestStep derived implementation
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 #include "TeIniWriteStep.h"
       
    22 
       
    23 //EPOC includes
       
    24 #include <test/testexecutelog.h>
       
    25 #include <es_sock.h>
       
    26 #include <es_ini.h>
       
    27 
       
    28 
       
    29 _LIT(KFileName,				"c:\\te_ini.ini");
       
    30 
       
    31 
       
    32 CTestIniWriteStep::CTestIniWriteStep() : iESockIniData(NULL)
       
    33 /**
       
    34  * Constructor
       
    35  */
       
    36 	{
       
    37 	// Call base class method to set up the human readable name for logging
       
    38 	SetTestStepName(KWriteToIniFile);
       
    39 	}
       
    40 
       
    41 CTestIniWriteStep::~CTestIniWriteStep()
       
    42 /**
       
    43  * Destructor
       
    44  */
       
    45 	{
       
    46 	//delete iESockIniData;
       
    47 	//iESockIniData = NULL;
       
    48 	}
       
    49 
       
    50 
       
    51 TVerdict CTestIniWriteStep::doTestStepL()
       
    52 /**
       
    53  * @return - TVerdict code
       
    54  * Override of base class pure virtual
       
    55  * Demonstrates reading configuration parameters fom an ini iESockIniData section
       
    56  */
       
    57 	{
       
    58 
       
    59 	INFO_PRINTF1(_L("In Test Step WriteToIniFile"));
       
    60 
       
    61 	TInt ret;
       
    62 	TInt numVal1;
       
    63 	// Commented out in p4 cl 224639,"CCOVER: REMOVED CODE THAT WOULD PANIC. This test needs to be fixed"
       
    64 	// TInt numVal2;
       
    65 	// TPtrC ptrVal2;
       
    66 	TPtrC ptrVal1;
       
    67 	TBuf<512> tmpBuf;
       
    68 
       
    69 	iESockIniData = CESockIniData::NewL(KFileName);
       
    70 
       
    71 	// Write with DataSource2
       
    72 	INFO_PRINTF1(_L("Write DataSource2 (medium) to WriteData."));
       
    73 	TRAP(ret, iESockIniData->FindVar(_L("DataSource2"), _L("Number"), numVal1));
       
    74 	TRAP(ret, iESockIniData->FindVar(_L("DataSource2"), _L("String"), ptrVal1));
       
    75 	tmpBuf.Copy(ptrVal1);
       
    76 	// Commented out in p4 cl 224639
       
    77 	// test(file->WriteVar(_L("WriteData"), _L("Number"), numVal1)==KErrNone); 
       
    78  	// test(file->WriteVar(_L("WriteData"), _L("String"), tmpBuf)==KErrNone);
       
    79 	TRAP(ret, iESockIniData->CommitL());
       
    80 	if (ret != KErrNone)
       
    81 		{
       
    82 		ERR_PRINTF2(_L("Failed to Commit DataSource2. Error: %d"), ret);
       
    83 		SetTestStepResult(EFail);
       
    84 		return EFail;
       
    85 		}
       
    86 	else
       
    87 		{
       
    88 		INFO_PRINTF1(_L("Succeeded to Commit DataSource2 "));
       
    89 		}
       
    90 	delete iESockIniData;
       
    91 	iESockIniData = NULL;
       
    92 
       
    93 	// Commented out in p4 cl 224639
       
    94 	// Re-open file and confirm write
       
    95 	// test.Printf(_L("Reopen and confirm\r\n"));
       
    96 	// TRAP(ret,file=CESockIniData::NewL(KFilename));
       
    97 	// test(ret==KErrNone);
       
    98 	// test(file->FindVar(_L("WriteData"), _L("Number"), numVal2));
       
    99 	// test(file->FindVar(_L("WriteData"), _L("String"), ptrVal2));
       
   100 	// test(numVal1==numVal2);
       
   101 	// test(tmpBuf.Compare(ptrVal2)==0);
       
   102 	// delete file;
       
   103 
       
   104 
       
   105 	// Write with DataSource1
       
   106 	INFO_PRINTF1(_L("Write DataSource1 (shorter) to WriteData."));
       
   107 	TRAP(ret,iESockIniData = CESockIniData::NewL(KFileName));
       
   108 	// Commented out in p4 cl 224639
       
   109 	// test(file->FindVar(_L("DataSource1"), _L("Number"), numVal1));
       
   110 	// test(file->FindVar(_L("DataSource1"), _L("String"), ptrVal1));
       
   111 	// tmpBuf.Copy(ptrVal1);
       
   112 	// test(file->WriteVar(_L("WriteData"), _L("Number"), numVal1)==KErrNone);
       
   113 	// test(file->WriteVar(_L("WriteData"), _L("String"), tmpBuf)==KErrNone);
       
   114 	TRAP(ret, iESockIniData->CommitL());
       
   115 	if (ret != KErrNone)
       
   116 		{
       
   117 		ERR_PRINTF2(_L("Failed to Commit DataSource1. Error: %d"), ret);
       
   118 		SetTestStepResult(EFail);
       
   119 		return EFail;
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		INFO_PRINTF1(_L("Succeeded to Commit DataSource1. "));
       
   124 		}
       
   125 	delete iESockIniData;
       
   126 	iESockIniData = NULL;
       
   127 
       
   128 	// Commented out in p4 cl 224639
       
   129 /*  Re-open file and confirm write
       
   130 	test.Printf(_L("Reopen and confirm\r\n"));
       
   131 	TRAP(ret,file=CESockIniData::NewL(KFilename));
       
   132 	test(ret==KErrNone);
       
   133 	test(file->FindVar(_L("WriteData"), _L("Number"), numVal2));
       
   134 	test(file->FindVar(_L("WriteData"), _L("String"), ptrVal2));
       
   135 	test(numVal1==numVal2);
       
   136 	test(tmpBuf.Compare(ptrVal2)==0);
       
   137 	delete file;
       
   138 	
       
   139 	// Write with DataSource2
       
   140 	test.Printf(_L("Write DataSource3 (longer) to WriteData\r\n"));
       
   141 	TRAP(ret,file=CESockIniData::NewL(KFilename));
       
   142 	test(ret==KErrNone);
       
   143 	test(file->FindVar(_L("DataSource3"), _L("Number"), numVal1));
       
   144 	test(file->FindVar(_L("DataSource3"), _L("String"), ptrVal1));
       
   145 	tmpBuf.Copy(ptrVal1);
       
   146 //	test(file->WriteVar(_L("WriteData"), _L("Number"), numVal1)==KErrNone);
       
   147 //	test(file->WriteVar(_L("WriteData"), _L("String"), tmpBuf)==KErrNone);
       
   148 	TRAP(ret, file->CommitL());
       
   149 	test(ret==KErrNone);
       
   150 	delete file;
       
   151 
       
   152 	// Re-open file and confirm write
       
   153 	test.Printf(_L("Reopen and confirm\r\n"));
       
   154 	TRAP(ret,file=CESockIniData::NewL(KFilename));
       
   155 	test(ret==KErrNone);
       
   156 	test(file->FindVar(_L("WriteData"), _L("Number"), numVal2));
       
   157 	test(file->FindVar(_L("WriteData"), _L("String"), ptrVal2));
       
   158 	test(numVal1==numVal2);
       
   159 //	test(tmpBuf.Compare(ptrVal2)==0);
       
   160 	delete file;*/
       
   161 	
       
   162 	return TestStepResult();
       
   163 	}
       
   164 
       
   165 
       
   166