imservices/ossprotocoladaptation/tsrc/ossadapmt/src/ossadapmt.cpp
changeset 46 860cd8a5168c
parent 35 085f765766a0
equal deleted inserted replaced
35:085f765766a0 46:860cd8a5168c
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  ossadapmt.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <StifTestInterface.h>
       
    22 #include "ossadapmt.h"
       
    23 #include <flogger.h>
       
    24 #include <SettingServerClient.h>
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 //extern  ?external_data;
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 //extern ?external_function( ?arg_type,?arg_type );
       
    31 
       
    32 // CONSTANTS
       
    33 //const ?type ?constant_var = ?constant;
       
    34 
       
    35 // MACROS
       
    36 //#define ?macro ?macro_def
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 //const ?type ?constant_var = ?constant;
       
    40 //#define ?macro_name ?macro_def
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 //enum ?declaration
       
    44 //typedef ?declaration
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 //?type ?function_name( ?arg_type, ?arg_type );
       
    48 
       
    49 // FORWARD DECLARATIONS
       
    50 //class ?FORWARD_CLASSNAME;
       
    51 
       
    52 // ============================= LOCAL FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // ?function_name ?description.
       
    56 // ?description
       
    57 // Returns: ?value_1: ?description
       
    58 //          ?value_n: ?description_line1
       
    59 //                    ?description_line2
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 /*
       
    63 ?type ?function_name(
       
    64     ?arg_type arg,  // ?description
       
    65     ?arg_type arg)  // ?description
       
    66     {
       
    67 
       
    68     ?code  // ?comment
       
    69 
       
    70     // ?comment
       
    71     ?code
       
    72     }
       
    73 */
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ===============================
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // Cossadapmt::Cossadapmt
       
    79 // C++ default constructor can NOT contain any code, that
       
    80 // might leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 Cossadapmt::Cossadapmt (
       
    84     CTestModuleIf& aTestModuleIf ) :
       
    85 		CScriptBase ( aTestModuleIf )
       
    86 	{
       
    87 	}
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Cossadapmt::ConstructL
       
    91 // Symbian 2nd phase constructor can leave.
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void Cossadapmt::ConstructL()
       
    95 	{
       
    96 	//Read logger settings to check whether test case name is to be
       
    97 	//appended to log file name.
       
    98 	RSettingServer settingServer;
       
    99 	TInt ret = settingServer.Connect();
       
   100 
       
   101 	if ( ret != KErrNone )
       
   102 		{
       
   103 		User::Leave ( ret );
       
   104 		}
       
   105 
       
   106 	// Struct to StifLogger settigs.
       
   107 	TLoggerSettings loggerSettings;
       
   108 
       
   109 	// Parse StifLogger defaults from STIF initialization file.
       
   110 	ret = settingServer.GetLoggerSettings ( loggerSettings );
       
   111 
       
   112 	if ( ret != KErrNone )
       
   113 		{
       
   114 		User::Leave ( ret );
       
   115 		}
       
   116 
       
   117 	// Close Setting server session
       
   118 	settingServer.Close();
       
   119 
       
   120 	TFileName logFileName;
       
   121 
       
   122 	if ( loggerSettings.iAddTestCaseTitle )
       
   123 		{
       
   124 		TName title;
       
   125 		TestModuleIf().GetTestCaseTitleL ( title );
       
   126 		logFileName.Format ( KossadapmtLogFileWithTitle, &title );
       
   127 		}
       
   128 	else
       
   129 		{
       
   130 		logFileName.Copy ( KossadapmtLogFile );
       
   131 		}
       
   132 
       
   133 	iLog = CStifLogger::NewL ( KossadapmtLogPath,
       
   134 
       
   135 	                           logFileName,
       
   136 	                           CStifLogger::ETxt,
       
   137 	                           CStifLogger::EFile,
       
   138 	                           EFalse );
       
   139 	TestModuleIf().SetBehavior ( CTestModuleIf::ETestLeaksHandles );
       
   140 
       
   141 	}
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // Cossadapmt::NewL
       
   145 // Two-phased constructor.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 Cossadapmt* Cossadapmt::NewL (
       
   149     CTestModuleIf& aTestModuleIf )
       
   150 	{
       
   151 	Cossadapmt* self = new ( ELeave ) Cossadapmt ( aTestModuleIf );
       
   152 
       
   153 	CleanupStack::PushL ( self );
       
   154 	self->ConstructL();
       
   155 	CleanupStack::Pop();
       
   156 
       
   157 	return self;
       
   158 
       
   159 	}
       
   160 
       
   161 // Destructor
       
   162 Cossadapmt::~Cossadapmt()
       
   163 	{
       
   164 
       
   165 	// Delete resources allocated from test methods
       
   166 	Delete();
       
   167 
       
   168 	// Delete logger
       
   169 	delete iLog;
       
   170 
       
   171 	}
       
   172 
       
   173 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // LibEntryL is a polymorphic Dll entry point.
       
   177 // Returns: CScriptBase: New CScriptBase derived object
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C CScriptBase* LibEntryL (
       
   181     CTestModuleIf& aTestModuleIf ) // Backpointer to STIF Test Framework
       
   182 	{
       
   183 
       
   184 	return ( CScriptBase* ) Cossadapmt::NewL ( aTestModuleIf );
       
   185 
       
   186 	}
       
   187 
       
   188 // CONSTANTS
       
   189 const TInt KTLogBufferLength = 256;
       
   190 
       
   191 _LIT ( KTLogDir,  "osmt" );
       
   192 _LIT ( KTLogFile, "ossadapmt.txt" );
       
   193 
       
   194 void TOssAdapMtLogger::Log ( TRefByValue<const TDesC> aFmt, ... )
       
   195 	{
       
   196 	VA_LIST list;
       
   197 	VA_START ( list, aFmt );
       
   198 
       
   199 	// Print to log file
       
   200 	TBuf<KTLogBufferLength> buf;
       
   201 	buf.FormatList ( aFmt, list );
       
   202 
       
   203 	// Write to log file
       
   204 	RFileLogger::Write ( KTLogDir, KTLogFile, EFileLoggingModeAppend, buf );
       
   205 
       
   206 	}
       
   207 
       
   208 //  End of File