|
1 // Copyright (c) 2005-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 // This test aims to test embedding feature of the application. The dll |
|
15 // launches tpackage application, all messages go via client-server |
|
16 // architecture. Server leaves on the Testpackage step side and is started |
|
17 // in the doTestStepL() function, client places on the tpackage application |
|
18 // side. Server's thread creates and run active scheduler in order to maintain |
|
19 // the active objects.\n |
|
20 // It is relevant that logger uses the same thread in which it was created, |
|
21 // therefore when server receives EMessageServSetFromString message from the |
|
22 // client it activates active object (CMessageActive) in order to output |
|
23 // log buffer into the file in the same thread as lives logger. |
|
24 // The CMessageActive class is activated by calling function |
|
25 // CMessageActive::RequestForTheMessageOutput(TInt aCode), |
|
26 // iStatus sets to aCode value.\n |
|
27 // When client completes its work, it sends message EMessageServStop and |
|
28 // server stops active sheduler so server's thread might be closed.\n |
|
29 // |
|
30 // |
|
31 |
|
32 /** |
|
33 @file |
|
34 @internalComponent - Internal Symbian test code |
|
35 */ |
|
36 |
|
37 |
|
38 |
|
39 #include <coecntrl.h> |
|
40 #include <coeccntx.h> |
|
41 #include <eikdoc.h> |
|
42 #include <apgcli.h> |
|
43 #include <apacmdln.h> |
|
44 #include <ecom/ecom.h> |
|
45 |
|
46 #include "TpackageStarter.h" |
|
47 #include "messageservserver.h" |
|
48 #include "messageservclient.h" |
|
49 |
|
50 #define FORCE_AUTO |
|
51 |
|
52 CTestPackageStep::CTestPackageStep() |
|
53 /** |
|
54 Constructor |
|
55 */ |
|
56 { |
|
57 SetTestStepName(KTestPackageStep); |
|
58 } |
|
59 |
|
60 CTestPackageStep::~CTestPackageStep() |
|
61 /** |
|
62 Destructor |
|
63 */ |
|
64 { |
|
65 } |
|
66 |
|
67 /** |
|
68 @SYMTestCaseID UIF-TPACKAGESTARTER-doTestStepL |
|
69 |
|
70 @SYMPREQ |
|
71 |
|
72 @SYMTestCaseDesc This test aims to test embedding feature of the application. |
|
73 |
|
74 @SYMTestPriority High |
|
75 |
|
76 @SYMTestStatus Implemented |
|
77 |
|
78 @SYMTestActions The dll creates a thread and starts a Message server. Once the |
|
79 message server is up and ready it launches the test client application, |
|
80 tpackage. The server installs and starts an active scheduler to service |
|
81 request messages received from the client and to log the information gathered |
|
82 from the request messages.When the server receives EMessageServSetFromString |
|
83 message from the client, it activates CMessageActive active object in order |
|
84 to output the log buffer. When client completes its work, it sends message |
|
85 EMessageServStop and server stops active sheduler so that server's thread |
|
86 might be closed. |
|
87 |
|
88 @SYMTestExpectedResults All messages send by the client should be processed by |
|
89 the server and outputted in the log file. |
|
90 |
|
91 */ |
|
92 TVerdict CTestPackageStep::doTestStepL() // main function called by E32 |
|
93 { |
|
94 __UHEAP_MARK; |
|
95 SetTestStepID(_L("UIF-TPACKAGESTARTER-doTestStepL")); |
|
96 CActiveScheduler* theSheduler = new CActiveScheduler; |
|
97 CActiveScheduler::Install(theSheduler); |
|
98 |
|
99 iMessage = CMessageActive::NewL(); |
|
100 iMessage->iStep = this; |
|
101 |
|
102 _LIT(KPackageAppFileName,"z:\\sys\\bin\\tpackage.exe"); |
|
103 |
|
104 CApaCommandLine* cmdLine=CApaCommandLine::NewLC(); |
|
105 cmdLine->SetCommandL(EApaCommandViewActivate); |
|
106 cmdLine->SetExecutableNameL(KPackageAppFileName); |
|
107 |
|
108 StartThread(); |
|
109 |
|
110 RApaLsSession ls; |
|
111 User::LeaveIfError(ls.Connect()); |
|
112 CleanupClosePushL(ls); |
|
113 TInt err = ls.StartApp(*cmdLine); |
|
114 if (err != KErrNone) |
|
115 { |
|
116 TEST(EFalse); |
|
117 INFO_PRINTF1(_L("Failed to start application")); |
|
118 // If there is a problem starting the app we have to stop the |
|
119 // message server |
|
120 RMessageServ serv; |
|
121 TInt theRes = serv.Connect(); |
|
122 if(theRes == KErrNone) |
|
123 { |
|
124 serv.Stop(); |
|
125 serv.Close(); |
|
126 // Now make sure we wait until the server has stopped |
|
127 // Not sure this is necessary but safer |
|
128 FOREVER |
|
129 { |
|
130 TFindServer findCountServer(KMessageServerName); |
|
131 TFullName name; |
|
132 if (findCountServer.Next(name)!=KErrNone) |
|
133 { |
|
134 break; |
|
135 } |
|
136 } |
|
137 } |
|
138 } |
|
139 CleanupStack::PopAndDestroy(&ls); |
|
140 |
|
141 CleanupStack::PopAndDestroy(cmdLine); |
|
142 |
|
143 CActiveScheduler::Start(); |
|
144 |
|
145 |
|
146 delete theSheduler; |
|
147 delete iMessage; |
|
148 iMessage = NULL; |
|
149 REComSession::FinalClose(); |
|
150 RecordTestResultL(); |
|
151 CloseTMSGraphicsStep(); |
|
152 __UHEAP_MARKEND; |
|
153 |
|
154 return TestStepResult(); |
|
155 } |
|
156 |
|
157 |
|
158 /** |
|
159 Auxiliary function for TestCaseID TPACKAGESTARTER-doTestStepL |
|
160 |
|
161 This method creates the server thread by invoking RThread::Create() and calls |
|
162 CMessageServServer::ThreadFunction() to start the Message Server. |
|
163 |
|
164 */ |
|
165 TInt CTestPackageStep::StartThread() |
|
166 { |
|
167 TInt res=KErrNone; |
|
168 // create server - if one of this name does not already exist |
|
169 TFindServer findCountServer(KMessageServerName); |
|
170 TFullName name; |
|
171 if (findCountServer.Next(name)!=KErrNone) // we don't exist already |
|
172 { |
|
173 RThread thread; |
|
174 semaphore.CreateLocal(0); // create a semaphore so we know when thread finished |
|
175 res=thread.Create(KMessageServerName, // create new server thread |
|
176 CMessageServServer::ThreadFunction, // thread's main function |
|
177 KDefaultStackSize, |
|
178 KDefaultHeapSize, |
|
179 KDefaultHeapSize, |
|
180 this // passed as TAny* argument to thread function |
|
181 ); |
|
182 |
|
183 if (res==KErrNone) // thread created ok - now start it going |
|
184 { |
|
185 thread.SetPriority(EPriorityNormal); |
|
186 thread.Resume(); // start it going |
|
187 semaphore.Wait(); // wait until it's initialized |
|
188 thread.Close(); // we're no longer interested in the other thread |
|
189 } |
|
190 else // thread not created ok |
|
191 { |
|
192 thread.Close(); // therefore we've no further interest in it |
|
193 } |
|
194 |
|
195 semaphore.Close(); |
|
196 } |
|
197 |
|
198 return res; |
|
199 } |
|
200 |