localisation/apparchitecture/tef/tssaac/tssaac_tapp.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2007-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This is a Startup State Aware (SSA) test application used to
       
    15 // test apparc StartApp and StartDocument functionality.
       
    16 // 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @test
       
    24  @internalComponent  Internal Symbian test code
       
    25 */
       
    26 
       
    27 
       
    28 #include <coeccntx.h>
       
    29 
       
    30 #include <apgtask.h>
       
    31 #include <eikenv.h>
       
    32 #include <eikappui.h>
       
    33 #include <eikapp.h>
       
    34 #include <eikdoc.h>
       
    35 #include <eikmenup.h>
       
    36 
       
    37 #include <eikon.hrh>
       
    38 
       
    39 #include <tssaac_tapp.rsg>
       
    40 
       
    41 #include <eikstart.h>
       
    42 #include <s32file.h>
       
    43 #include "tssaac.h"
       
    44 #include <apacmdln.h>
       
    45 #include "appfwk_test_AppUi.h"
       
    46 #include "tstapp.h"
       
    47 
       
    48 
       
    49 
       
    50 ////////////////////////////////////////////////////////////////////////
       
    51 //
       
    52 // CExampleAppView
       
    53 //
       
    54 ////////////////////////////////////////////////////////////////////////
       
    55 class CExampleAppView : public CCoeControl
       
    56     {
       
    57 public:
       
    58 	static CExampleAppView* NewL(const TRect& aRect);
       
    59 	CExampleAppView();
       
    60 	~CExampleAppView();
       
    61     void ConstructL(const TRect& aRect);
       
    62 private:
       
    63 	void Draw(const TRect& /*aRect*/) const;
       
    64 private:
       
    65 	HBufC*  iExampleText;
       
    66     };
       
    67 
       
    68 CExampleAppView::CExampleAppView()
       
    69 	{
       
    70 	}
       
    71 
       
    72 CExampleAppView* CExampleAppView::NewL(const TRect& aRect)
       
    73 	{
       
    74 	CExampleAppView* self = new(ELeave) CExampleAppView();
       
    75 	CleanupStack::PushL(self);
       
    76 	self->ConstructL(aRect);
       
    77 	CleanupStack::Pop();
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 CExampleAppView::~CExampleAppView()
       
    82 	{
       
    83 	delete iExampleText;
       
    84 	}
       
    85 
       
    86 void CExampleAppView::ConstructL(const TRect& aRect)
       
    87     {
       
    88     _LIT(KExampleText, "This is a Startup State Aware (SSA) test application");
       
    89 	TPtrC ptr(KExampleText);
       
    90 	iExampleText = ptr.AllocL();
       
    91 	CreateWindowL();
       
    92 	SetRect(aRect);
       
    93 	ActivateL();
       
    94 	}
       
    95 
       
    96 void CExampleAppView::Draw(const TRect& /*aRect*/) const
       
    97 	{
       
    98 	CWindowGc& gc = SystemGc();
       
    99 	TRect      drawRect = Rect();
       
   100 	const CFont*     fontUsed;
       
   101 
       
   102 	gc.Clear();
       
   103   	fontUsed = iEikonEnv->TitleFont();
       
   104 	gc.UseFont(fontUsed);
       
   105 	TInt   baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2;
       
   106 	gc.DrawText(*iExampleText,drawRect,baselineOffset,CGraphicsContext::ECenter, 0);
       
   107 	gc.DiscardFont();
       
   108 	}
       
   109 
       
   110 
       
   111 ////////////////////////////////////////////////////////////////////////
       
   112 //
       
   113 // CExampleAppUi
       
   114 //
       
   115 ////////////////////////////////////////////////////////////////////////
       
   116 class CExampleAppUi : public CEikAppUi
       
   117     {
       
   118 public:
       
   119     void ConstructL();
       
   120 	~CExampleAppUi();
       
   121 private:
       
   122 	void HandleCommandL(TInt aCommand);
       
   123 private:
       
   124 	CCoeControl* iAppView;
       
   125 	};
       
   126 
       
   127 
       
   128 void CExampleAppUi::ConstructL()
       
   129     {
       
   130     BaseConstructL();
       
   131 	iAppView = CExampleAppView::NewL(ClientRect());
       
   132 	}
       
   133 
       
   134 CExampleAppUi::~CExampleAppUi()
       
   135 	{
       
   136 	delete iAppView;
       
   137 	}
       
   138 
       
   139 void CExampleAppUi::HandleCommandL(TInt aCommand)
       
   140 	{
       
   141 	switch (aCommand)
       
   142 		{
       
   143 	case EEikCmdExit:
       
   144 		Exit();
       
   145 		break;
       
   146 		}
       
   147 	}
       
   148 
       
   149 
       
   150 
       
   151 ////////////////////////////////////////////////////////////////////////
       
   152 //
       
   153 // CExampleDocument
       
   154 //
       
   155 ////////////////////////////////////////////////////////////////////////
       
   156 class CExampleDocument : public CEikDocument
       
   157 	{
       
   158 public:
       
   159 	static CExampleDocument* NewL(CEikApplication& aApp);
       
   160 	CExampleDocument(CEikApplication& aApp);
       
   161 	void ConstructL();
       
   162 private:
       
   163 	CEikAppUi* CreateAppUiL();
       
   164 	};
       
   165 
       
   166 CExampleDocument::CExampleDocument(CEikApplication& aApp)
       
   167 		: CEikDocument(aApp)
       
   168 	{
       
   169 	}
       
   170 
       
   171 CEikAppUi* CExampleDocument::CreateAppUiL()
       
   172 	{
       
   173     return new(ELeave) CExampleAppUi;
       
   174 	}
       
   175 
       
   176 
       
   177 ////////////////////////////////////////////////////////////////////////
       
   178 //
       
   179 // CSysatartApparc
       
   180 //
       
   181 ////////////////////////////////////////////////////////////////////////
       
   182 
       
   183 class CSysatartApparc : public CEikApplication
       
   184 	{
       
   185 private:
       
   186 	// Inherited from class CApaApplication
       
   187 	CApaDocument* CreateDocumentL();
       
   188 	void WriteResultFileL();
       
   189 	TUid AppDllUid() const;
       
   190 	//Test functions and variables
       
   191 	CApaDocument* CreateDocumentL(CApaProcess* aApaProcess);
       
   192 private:	
       
   193 	TInt iLocalizedCaptionLRes1;
       
   194 	TInt iLocalizedCaptionLRes2;
       
   195 	};
       
   196 
       
   197 const TUid KUidSSAACTestApp = { 0x10207F7A };
       
   198 
       
   199 TUid CSysatartApparc::AppDllUid() const
       
   200 	{
       
   201 	return KUidSSAACTestApp;
       
   202 	}
       
   203 
       
   204 /**
       
   205    @SYMTestCaseID          APPFWK-APPARC-0029
       
   206 
       
   207    @SYMPREQ                PREQ967
       
   208 
       
   209    @SYMREQ                 REQ3889
       
   210 
       
   211    @SYMTestCaseDesc        Test the functionality of EnsureCaptionIsLocalisedL()
       
   212 
       
   213    @SYMTestPriority        High
       
   214 
       
   215    @SYMTestStatus          Implemented
       
   216 
       
   217    @SYMTestActions         Call CEikApplication::CreateDocumentL() with a local resource file argument
       
   218    						   When Application specified exists.
       
   219 
       
   220                            API Calls:\n
       
   221 						   CEikApplication::EnsureCaptionIsLocalisedL(TDesC&)
       
   222 
       
   223    @SYMTestExpectedResults (1) AppCaption() returns "tssaac_tapp"
       
   224    						   (2) AppCaption() returns "NewCaption"
       
   225 
       
   226 */
       
   227 CApaDocument* CSysatartApparc::CreateDocumentL(CApaProcess* aApaProcess)
       
   228 	{
       
   229 	_LIT(KPath, "z:\\resource\\apps\\tssaac_tapp_loc.rsc");
       
   230 	_LIT(KCurrentCaption, "tssaac_tapp");
       
   231 	_LIT(KNewCaption, "NewCaption");
       
   232 
       
   233 	//(1) Fetch the existing name of the exe (tssaac_tapp)
       
   234 	TApaAppCaption caption = AppCaption();
       
   235 
       
   236 	iLocalizedCaptionLRes1 = caption.Compare(KCurrentCaption);
       
   237 	RDebug::Print(_L("Expected existing caption: '%S' Actual caption: '%S'"), &KCurrentCaption, &caption);
       
   238 
       
   239 	//Assign a new name to the exe from the local resource file
       
   240 	CEikApplication::EnsureCaptionIsLocalisedL(KPath);
       
   241 
       
   242 	//(2) Fetch the new name of the exe (NewCaption)
       
   243 	caption = AppCaption();
       
   244 
       
   245 	//Assign the result to the member variable
       
   246 	iLocalizedCaptionLRes2 = caption.Compare(KNewCaption);
       
   247 	RDebug::Print(_L("Expected new caption: '%S' Actual caption: '%S'"), &KNewCaption, &caption);
       
   248 
       
   249 	WriteResultFileL();
       
   250 
       
   251 	// Completes all Rendezvous' with the current process in order to notify sysstart and continue
       
   252 	//	launching the next process in the SSC list (this app is launched with EWaitForStart)
       
   253 	RProcess::Rendezvous(KErrNone);
       
   254 
       
   255 	return CEikApplication::CreateDocumentL(aApaProcess);
       
   256 	}
       
   257 
       
   258 
       
   259 CApaDocument* CSysatartApparc::CreateDocumentL()
       
   260 	{
       
   261 	return new (ELeave) CExampleDocument(*this);
       
   262 	}
       
   263 
       
   264 
       
   265 LOCAL_C CApaApplication* NewApplication()
       
   266 	{
       
   267 	return new CSysatartApparc;
       
   268 	}
       
   269 
       
   270 
       
   271 GLDEF_C TInt E32Main()
       
   272 	{
       
   273 	return EikStart::RunApplication(NewApplication);
       
   274 	}
       
   275 
       
   276 /**
       
   277   Write the results to the result file, to be later extracted by
       
   278   testexecute test case.
       
   279   These contain the results of the test. The order in
       
   280   which these results are written in MUST match the order in which
       
   281   they are read and tested in CSysStartApparcTestStep::GetApparcResultsL()
       
   282   and the expected result tested in CSysStartApparcTestStep::Testxxx must
       
   283   match that in the test specification\n
       
   284 
       
   285   The format is:
       
   286   LocalisedCaptionRes1 result=value1 		Pass = 0 Fail = non-zero
       
   287   LocalisedCaptionRes2 result=value2 		Pass = 0 Fail = non-zero
       
   288 
       
   289   '=' is used as the deliminator.
       
   290 */
       
   291 void CSysatartApparc::WriteResultFileL()
       
   292 	{
       
   293 	RFs	fs;
       
   294  	User::LeaveIfError(fs.Connect());
       
   295  	CleanupClosePushL(fs);
       
   296 
       
   297 	RFileWriteStream writer;
       
   298 	User::LeaveIfError(writer.Replace(fs, KSsaacResultFile, EFileWrite));
       
   299 	CleanupClosePushL(writer);
       
   300 
       
   301 	// write data to file
       
   302 	writer << _L("LocalizedCaptionRes1 count=");
       
   303 	writer.WriteInt16L(iLocalizedCaptionLRes1);
       
   304 	writer << _L("\n");
       
   305 	writer << _L("LocalizedCaptionRes2 count=");
       
   306 	writer.WriteInt16L(iLocalizedCaptionLRes2);
       
   307 	writer << _L("\n");
       
   308 	writer.CommitL();
       
   309 	
       
   310 	CleanupStack::PopAndDestroy(2, &fs);
       
   311 	}