testexecfw/tef/logger/test/src/testexecuteloggertest.cpp
author Johnson Ma <johnson.ma@nokia.com>
Thu, 13 May 2010 17:42:48 +0800
changeset 3 a5f55a5789f3
parent 0 3e07fef1e154
permissions -rw-r--r--
Defect Fix: TeamTrack DEF145107
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     1
/*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     8
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    11
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    12
* Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    13
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    14
* Description:  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    15
* Demonstration use of the TestExecute standalone logger client API
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    16
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    17
*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    18
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    19
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    20
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    21
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    22
 @file TestExecuteLoggerTest.cpp
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    23
*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
#include <TestExecuteLog.h>
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
#include <e32Cons.h>
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
#include <wrapperutilsplugin.h>
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
_LIT(KLogFile1,"?:\\TestExecuteLoggerTest.txt");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
_LIT(K16BitText,"This is a short line of 16 Bit Text");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    31
_LIT8(K8BitText,"This is a short line of  8 Bit Text");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
_LIT(K16BitFormatText,"This is a short line of 16 Bit Format Text int = %d string = %S");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
_LIT8(K8BitFormatText,"This is a short line of  8 Bit Format Text int = %d string = %S");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    35
_LIT(K16BitString,"The String16");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    36
_LIT8(K8BitString,"The String8");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    37
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    38
LOCAL_C void MainL()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    39
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    40
	TDriveName defaultSysDrive(KTEFLegacySysDrive);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    41
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    42
	RFs fileServer;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    43
	TVersionName version(fileServer.Version().Name());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    44
	
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    45
	if (fileServer.Version().iMajor >= 2 &&
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    46
		fileServer.Version().iBuild >= 1100)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    47
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    48
		RLibrary pluginLibrary;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    49
		TInt pluginErr = pluginLibrary.Load(KTEFWrapperPluginDll);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    50
		if (pluginErr == KErrNone)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    51
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    52
			TLibraryFunction newl;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    53
			newl = pluginLibrary.Lookup(2);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    54
			CWrapperUtilsPlugin* plugin = (CWrapperUtilsPlugin*)newl();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    55
			TDriveUnit driveUnit(plugin->GetSystemDrive());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    56
			defaultSysDrive.Copy(driveUnit.Name());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    57
			delete plugin;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    58
			pluginLibrary.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    59
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    60
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    61
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    62
	TFileName logFile1(KLogFile1);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    63
	logFile1.Replace(0, 2, defaultSysDrive);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    64
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    65
	_LIT(KTitle,"TestExecute Standalone Logger Test Code");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    66
	CConsoleBase* console = Console::NewL(KTitle,TSize(KConsFullScreen,KConsFullScreen));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    67
	CleanupStack::PushL(console);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    68
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
	_LIT(KMessage1,"Connect() To Logger and Close() immediately\r\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
	console->Printf(KMessage1);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
	RTestExecuteLogServ logger;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
	User::LeaveIfError(logger.Connect());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
	logger.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    75
	_LIT(KMessage2,"Immediate re-Connect() To Logger and Close() immediately\r\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
	console->Printf(KMessage2);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
	User::LeaveIfError(logger.Connect());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    78
	logger.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
	_LIT(KMessage3,"Immediate re-Connect() To Logger CreateLog() and Close() immediately\r\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    81
	console->Printf(KMessage3);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
	User::LeaveIfError(logger.Connect());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
	User::LeaveIfError(logger.CreateLog(logFile1,RTestExecuteLogServ::ELogModeOverWrite));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
	logger.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    85
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    86
	// OS needs time to shutdown the server
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    87
	// No delay means we get server terminated from the OS
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
	User::After(1000000);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    90
	_LIT(KMessage4,"Connect() To Logger CreateLog() %S Call API's\r\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    91
	console->Printf(KMessage4,&logFile1);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    92
	User::LeaveIfError(logger.Connect());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
	User::LeaveIfError(logger.CreateLog(logFile1,RTestExecuteLogServ::ELogModeOverWrite));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    94
	TBuf<20> buf16(K16BitString);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    95
	TBuf8<20> buf8(K8BitString);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    96
	logger.Write(K16BitText);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    97
	logger.Write(K8BitText);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    98
	logger.WriteFormat(K16BitFormatText,16,&buf16);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    99
	logger.WriteFormat(K8BitFormatText,8,&buf8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   100
	logger.LogExtra(((TText8*)__FILE__), __LINE__,ESevrInfo,K16BitFormatText,1,&buf16);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   101
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   102
	_LIT(KMessage5,"ALL API's Called - Call Close(),\r\nHit Any Key\r\n");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   103
	console->Printf(KMessage5);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   104
	console->Getch();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   105
	logger.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   106
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   107
	CleanupStack::PopAndDestroy(console);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   108
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   109
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   110
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   111
// Entry point for all Epoc32 executables
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   112
// See PSP Chapter 2 Getting Started
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   113
GLDEF_C TInt E32Main()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   114
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   115
	// Heap balance checking
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   116
	// See PSP Chapter 6 Error Handling
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   117
	__UHEAP_MARK;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   118
	CTrapCleanup* cleanup = CTrapCleanup::New();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   119
	if(cleanup == NULL)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   120
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   121
		return KErrNoMemory;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   122
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   123
	TRAPD(err,MainL());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   124
	_LIT(KPanic,"LoggerTest");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   125
	__ASSERT_ALWAYS(!err, User::Panic(KPanic,err));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   126
	delete cleanup;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   127
	__UHEAP_MARKEND;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   128
	return KErrNone;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   129
    }