testexecmgmt/ucc/Source/Uccs.v2/Core/CRetrieveCommandFromFile.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 * Switches
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 /***********************************************************************************
       
    22  *
       
    23  * System Includes
       
    24  *
       
    25  **********************************************************************************/
       
    26 #include <stdio.h>
       
    27 #include <assert.h>
       
    28 
       
    29 /***********************************************************************************
       
    30  *
       
    31  * Local Includes
       
    32  *
       
    33  **********************************************************************************/
       
    34 #include "CRetrieveCommandFromFile.h"
       
    35 #include "UCCS_ErrorCodes.h"
       
    36 
       
    37 
       
    38 /***********************************************************************************
       
    39  *
       
    40  * Definitions
       
    41  *
       
    42  **********************************************************************************/
       
    43 #define MAXFILENAME 256
       
    44 
       
    45 
       
    46 /***********************************************************************************
       
    47  *
       
    48  * Construction
       
    49  *
       
    50  **********************************************************************************/
       
    51 CRetrieveCommandFromFile::CRetrieveCommandFromFile()
       
    52 {
       
    53 	iFile = NULL;
       
    54 }
       
    55 
       
    56 CRetrieveCommandFromFile::~CRetrieveCommandFromFile()
       
    57 {
       
    58 
       
    59 #ifdef TESTCASE109
       
    60 	char tempname[10];
       
    61 	sprintf(tempname, "testing");
       
    62 	iFile = new FILE;
       
    63 	iFile->_ptr = tempname;
       
    64 #endif
       
    65 
       
    66 	if( iFile != NULL ) {
       
    67 		fclose( iFile );
       
    68 		iFile = NULL;
       
    69 	}
       
    70 }
       
    71 
       
    72 
       
    73 /***********************************************************************************
       
    74  *
       
    75  * StartUseCase
       
    76  *
       
    77  **********************************************************************************/
       
    78 int CRetrieveCommandFromFile::StartUseCase( int aUsecaseID )
       
    79 {
       
    80 	char fname[MAXFILENAME];
       
    81 
       
    82 	// make sure there isn't a file already open -- this is a defect -- the batchengine
       
    83 	// should catch errors before they get to here
       
    84 	assert( iFile == NULL );
       
    85 
       
    86 	// try and open the file
       
    87 	sprintf( fname, "script.%04d.ucd", aUsecaseID );
       
    88 	iFile = fopen( fname, "r" );
       
    89 	if( iFile == NULL ) {
       
    90 		return UCCS_CANTOPENSCRIPTFILE;
       
    91 	}
       
    92 	iUsecaseID = aUsecaseID;
       
    93 	return UCCS_OK;
       
    94 }
       
    95 
       
    96 
       
    97 /***********************************************************************************
       
    98  *
       
    99  * EndUseCase
       
   100  *
       
   101  **********************************************************************************/
       
   102 int CRetrieveCommandFromFile::EndUseCase()
       
   103 {
       
   104 	fclose(iFile);
       
   105 	iFile = NULL;
       
   106 	return UCCS_OK;
       
   107 }
       
   108 
       
   109 
       
   110 /***********************************************************************************
       
   111  *
       
   112  * GetNextCommand
       
   113  *	
       
   114  **********************************************************************************/
       
   115 int CRetrieveCommandFromFile::GetNextCommand( char *aBuffer, int aLength )
       
   116 {
       
   117 	char *c;
       
   118 	c = fgets( aBuffer, aLength, iFile );
       
   119 	if( c == NULL ) {
       
   120 		return UCCS_NOMORECOMMANDS;
       
   121 	}
       
   122 	return UCCS_OK;
       
   123 }
       
   124 
       
   125