|
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 <wapmessage.h> |
|
25 #include <wapmsgerr.h> |
|
26 #include "CLWatcher.h" |
|
27 #include "testlog.h" // CWapPushLog class |
|
28 |
|
29 #include <ecom/ecom.h> |
|
30 |
|
31 LOCAL_D RTest test(_L("Final Close Test")); |
|
32 CWapPushLog* gPushLog; |
|
33 |
|
34 class CTestLog : public MWapPushLog |
|
35 { |
|
36 // from MWapPushLog |
|
37 virtual void WPLPrintf(const TDesC& /*aDescription*/) {} |
|
38 virtual void WPLPrintfL(CPushMessage& /*aMessage*/) {} |
|
39 virtual void WPLLogBinaryAsHex(const TDesC& /*aDescription*/) {} |
|
40 virtual void WPLLogError(const TDesC& /*aDescription*/,TInt /*aError*/) {} |
|
41 }; |
|
42 |
|
43 class CTestObserver : public MConnManObserver |
|
44 { |
|
45 // from MConnManObserver |
|
46 void CMOpenConnectionL(TPushConnPoint& /*aConnPoint*/) {} |
|
47 void CMWatcherComplete(CCOWatcherBase& /*aCOWatcher*/, TInt /*aError*/) {} |
|
48 }; |
|
49 |
|
50 class RFinalCloseTest |
|
51 { |
|
52 public: |
|
53 //Test case 1 |
|
54 static TInt Create_Destroy_FinalCloseL(TAny*); |
|
55 static TInt Create_Destroy_TestL(); |
|
56 |
|
57 static void ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction); |
|
58 }; |
|
59 |
|
60 TInt RFinalCloseTest::Create_Destroy_FinalCloseL(TAny*) |
|
61 { |
|
62 __UHEAP_MARK; |
|
63 CTrapCleanup* threadcleanup = CTrapCleanup::New(); |
|
64 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
65 CActiveScheduler::Install(scheduler); |
|
66 |
|
67 TRAPD(err,Create_Destroy_TestL()); |
|
68 |
|
69 test(err==KErrNone); |
|
70 |
|
71 delete scheduler; |
|
72 delete threadcleanup; |
|
73 __UHEAP_MARKEND; |
|
74 return KErrNone; |
|
75 } |
|
76 |
|
77 //The test code for creating and destroying an implementation |
|
78 //To be used in the two test cases above |
|
79 TInt RFinalCloseTest::Create_Destroy_TestL() |
|
80 { |
|
81 CTestLog* log = new(ELeave) CTestLog; |
|
82 CTestObserver* observer = new(ELeave) CTestObserver; |
|
83 |
|
84 CCLUnsecureWatcher* watcher = CCLUnsecureWatcher::NewL(*log, *observer); |
|
85 |
|
86 delete watcher; |
|
87 watcher = NULL; |
|
88 delete observer; |
|
89 observer = NULL; |
|
90 delete log; |
|
91 log = NULL; |
|
92 return KErrNone; |
|
93 } |
|
94 |
|
95 //The test code is used for capturing the PANIC that occurs as a result of not |
|
96 //calling REComSession::FinalClose() when using ECOM plugins. |
|
97 void RFinalCloseTest::ThreadPanicTest(const TDesC& aName,TThreadFunction aFunction) |
|
98 { |
|
99 test.Next(aName); |
|
100 TRequestStatus threadStatus; |
|
101 RThread thread; |
|
102 TBool jit; |
|
103 jit=User::JustInTime(); |
|
104 User::SetJustInTime(EFalse); |
|
105 |
|
106 TInt err=thread.Create(aName,aFunction,KDefaultStackSize*8,KMinHeapSize,0x100000,0); |
|
107 test(err==KErrNone); |
|
108 gPushLog->WPLPrintf(_L("Starting thread to create and destroy CLWatcherBase...")); |
|
109 thread.Logon(threadStatus); |
|
110 thread.Resume(); |
|
111 |
|
112 User::WaitForRequest(threadStatus); |
|
113 gPushLog->WPLPrintf(_L("Checking thread completed correctly...")); |
|
114 |
|
115 if ((thread.ExitType() != EExitKill) || (thread.ExitReason() != 0)) |
|
116 gPushLog->WPLPrintf(_L("Failed!")); |
|
117 //Now check why the thread Exit |
|
118 test(thread.ExitType() == EExitKill); |
|
119 test(thread.ExitReason() == 0); |
|
120 |
|
121 gPushLog->WPLPrintf(_L("Successful.")); |
|
122 |
|
123 thread.Close(); |
|
124 User::SetJustInTime(jit); |
|
125 } |
|
126 |
|
127 LOCAL_C void RunTestL() |
|
128 { |
|
129 __UHEAP_MARK; |
|
130 gPushLog = CWapPushLog::NewL(*test.Console()); |
|
131 CleanupStack::PushL(gPushLog); |
|
132 |
|
133 gPushLog->WPLPrintf(_L("Starting Create Destroy Final Close Panic Test...")); |
|
134 |
|
135 RFinalCloseTest::ThreadPanicTest(_L("Create Destroy Panic Testing"),RFinalCloseTest::Create_Destroy_FinalCloseL); |
|
136 |
|
137 CleanupStack::PopAndDestroy(gPushLog); |
|
138 __UHEAP_MARKEND; |
|
139 } |
|
140 |
|
141 GLDEF_C TInt E32Main() |
|
142 { |
|
143 __UHEAP_MARK; |
|
144 |
|
145 test.Title(); |
|
146 test.Start(_L("@SYMTestCaseID IWS-WAPBROWSER-WAPPUSH-PUSHWATCHER-T_PUSHWATCHERFINALCLOSE-0001 Final Close tests.")); |
|
147 |
|
148 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
149 CActiveScheduler* scheduler = new(ELeave)CActiveScheduler; |
|
150 CActiveScheduler::Install(scheduler); |
|
151 |
|
152 TRAPD(err,RunTestL()); |
|
153 test(err==KErrNone); |
|
154 |
|
155 delete scheduler; |
|
156 delete cleanup; |
|
157 |
|
158 test.End(); |
|
159 test.Close(); |
|
160 |
|
161 __UHEAP_MARKEND; |
|
162 return(0); |
|
163 } |