|
1 // Copyright (c) 2004-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 // t_finalclose.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32std.h> |
|
19 #include <e32test.h> |
|
20 #include <e32panic.h> |
|
21 #include <e32uid.h> |
|
22 #include <f32file.h> |
|
23 #include <bautils.h> |
|
24 #include <biouids.h> |
|
25 #include <msvreg.h> |
|
26 #include <msvids.h> |
|
27 #include "MSVSERV.H" |
|
28 #include <msventry.h> |
|
29 #include "msvutils.h" |
|
30 #include <regpsdll.h> |
|
31 #include <biodb.h> |
|
32 |
|
33 #include <wapp.h> |
|
34 #include "biotestutils.h" |
|
35 #include <ecom/ecom.h> |
|
36 |
|
37 LOCAL_D RTest test(_L("Final Close Test")); |
|
38 CBioTestUtils* theUtils; |
|
39 |
|
40 #define CBASESCRIPTPARSER CBaseScriptParser2 |
|
41 |
|
42 class CParseTestActive : public CTestActive |
|
43 { |
|
44 public: |
|
45 IMPORT_C CParseTestActive(CBASESCRIPTPARSER& aParser, const TDesC& aSms) : |
|
46 iParser(aParser), iMessage(aSms) {} |
|
47 IMPORT_C void StartL() |
|
48 { |
|
49 iParser.ParseL(iStatus, iMessage); |
|
50 CTestActive::StartL(); |
|
51 } |
|
52 private: |
|
53 CBASESCRIPTPARSER& iParser; |
|
54 const TDesC& iMessage; |
|
55 }; |
|
56 |
|
57 class CProcessTestActive : public CTestActive |
|
58 { |
|
59 public: |
|
60 IMPORT_C CProcessTestActive(CBASESCRIPTPARSER& aParser) : |
|
61 iParser(aParser){} |
|
62 |
|
63 IMPORT_C void StartL() |
|
64 { |
|
65 iParser.ProcessL(iStatus); |
|
66 CTestActive::StartL(); |
|
67 } |
|
68 private: |
|
69 CBASESCRIPTPARSER& iParser; |
|
70 }; |
|
71 |
|
72 class RFinalCloseTest |
|
73 { |
|
74 public: |
|
75 //Test case 1 |
|
76 static TInt Create_Destroy_FinalCloseL(TAny*); |
|
77 static TInt Create_Destroy_TestL(RTest& aTest); |
|
78 |
|
79 static void ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction); |
|
80 }; |
|
81 |
|
82 //The test code for creating and destroying an implementation |
|
83 //To be used in the two test cases above |
|
84 TInt RFinalCloseTest::Create_Destroy_TestL(RTest& aTest) |
|
85 { |
|
86 const TPtrC KWappTestTxtFileDir = _L("c:\\test\\bio\\wappfinalclose\\"); |
|
87 CBioTestUtils* tempUtils = CBioTestUtils::NewL(aTest); |
|
88 |
|
89 tempUtils->GoServerSideL(); |
|
90 |
|
91 CMsvEntrySelection* msvSelection = tempUtils->GenerateMessagesL(KWappTestTxtFileDir, EFalse); |
|
92 CleanupStack::PushL(msvSelection); |
|
93 TMsvId msgId = (*msvSelection)[0]; |
|
94 |
|
95 tempUtils->GoClientSideL(); |
|
96 |
|
97 CBASESCRIPTPARSER* parser = tempUtils->CreateParserL(msgId); |
|
98 test(parser != NULL); |
|
99 |
|
100 HBufC* message = HBufC::NewL(2048); |
|
101 CleanupStack::PushL(message); |
|
102 message->Des().Copy(tempUtils->MessageBodyL((*msvSelection)[0])); |
|
103 |
|
104 CParseTestActive* parseTest = new(ELeave) CParseTestActive(*parser, message->Des()); |
|
105 CleanupStack::PushL(parseTest); |
|
106 |
|
107 parseTest->StartL(); |
|
108 CActiveScheduler::Start(); |
|
109 CleanupStack::PopAndDestroy(parseTest); |
|
110 |
|
111 CProcessTestActive* processTest = new(ELeave) CProcessTestActive(*parser); |
|
112 CleanupStack::PushL(processTest); |
|
113 |
|
114 processTest->StartL(); |
|
115 CActiveScheduler::Start(); |
|
116 |
|
117 CleanupStack::PopAndDestroy(3, msvSelection); |
|
118 |
|
119 delete parser; |
|
120 parser = NULL; |
|
121 |
|
122 delete tempUtils; |
|
123 tempUtils = NULL; |
|
124 |
|
125 return KErrNone; |
|
126 } |
|
127 |
|
128 TInt RFinalCloseTest::Create_Destroy_FinalCloseL(TAny* /*aArg*/) |
|
129 { |
|
130 __UHEAP_MARK; |
|
131 |
|
132 CTrapCleanup* threadcleanup = CTrapCleanup::New(); |
|
133 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
134 CActiveScheduler::Install(scheduler); |
|
135 |
|
136 RTest tempTest(_L("Final Close Test")); |
|
137 |
|
138 TRAPD(err,Create_Destroy_TestL(tempTest)); |
|
139 |
|
140 test(err==KErrNone); |
|
141 |
|
142 delete scheduler; |
|
143 delete threadcleanup; |
|
144 |
|
145 tempTest.Close(); |
|
146 |
|
147 __UHEAP_MARKEND; |
|
148 |
|
149 return KErrNone; |
|
150 } |
|
151 |
|
152 //The test code is used for capturing the PANIC that occurs as a result of not |
|
153 //calling REComSession::FinalClose() when using ECOM plugins. |
|
154 void RFinalCloseTest::ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction) |
|
155 { |
|
156 test.Next(aName); |
|
157 TRequestStatus threadStatus; |
|
158 RThread thread; |
|
159 TBool jit; |
|
160 jit=User::JustInTime(); |
|
161 User::SetJustInTime(EFalse); |
|
162 |
|
163 TInt err=thread.Create(aName,aFunction,KDefaultStackSize*8,KMinHeapSize,0x100000,NULL); |
|
164 test(err==KErrNone); |
|
165 thread.Logon(threadStatus); |
|
166 theUtils->WriteComment(_L("Starting thread to create and destroy CMsvBIOWapAccessParser...")); |
|
167 thread.Resume(); |
|
168 |
|
169 User::WaitForRequest(threadStatus); |
|
170 //Now check why the thread Exit |
|
171 theUtils->WriteComment(_L("Checking thread completed correctly...")); |
|
172 |
|
173 |
|
174 if ((thread.ExitType() != EExitKill) || (thread.ExitReason() != 0)) |
|
175 theUtils->TestHarnessFailed(KErrAbort); |
|
176 |
|
177 test((thread.ExitType()== EExitKill) && (thread.ExitReason() == 0)); |
|
178 theUtils->WriteComment(_L("Successful.")); |
|
179 |
|
180 thread.Close(); |
|
181 User::SetJustInTime(jit); |
|
182 } |
|
183 |
|
184 |
|
185 LOCAL_C void RunTestL() |
|
186 { |
|
187 __UHEAP_MARK; |
|
188 |
|
189 theUtils = CBioTestUtils::NewL(test); |
|
190 CleanupStack::PushL(theUtils); |
|
191 |
|
192 theUtils->TestStart(1); |
|
193 |
|
194 RFinalCloseTest::ThreadPanicTest(_L("Create Destroy Panic Testing"),RFinalCloseTest::Create_Destroy_FinalCloseL); |
|
195 |
|
196 theUtils->TestHarnessCompleted(); |
|
197 CleanupStack::PopAndDestroy(theUtils); |
|
198 |
|
199 __UHEAP_MARKEND; |
|
200 } |
|
201 |
|
202 GLDEF_C TInt E32Main() |
|
203 { |
|
204 __UHEAP_MARK; |
|
205 |
|
206 test.Title(); |
|
207 test.Start(_L("Final Close tests.")); |
|
208 |
|
209 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
210 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
211 CActiveScheduler::Install(scheduler); |
|
212 |
|
213 TRAPD(err,RunTestL()); |
|
214 test(err==KErrNone); |
|
215 |
|
216 delete scheduler; |
|
217 delete cleanup; |
|
218 |
|
219 test.End(); |
|
220 test.Close(); |
|
221 |
|
222 __UHEAP_MARKEND; |
|
223 return(0); |
|
224 } |