|
1 // Copyright (c) 2010 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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <e32debug.h> |
|
18 #include <bautils.h> |
|
19 #include <featurecontrol.h> |
|
20 #include "t_fmgrbursim.h" |
|
21 |
|
22 /////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
24 RTest TheTest(_L("t_fmgrbur test")); |
|
25 |
|
26 const TUint threadTimeout = 1500000; // thread timeout = 1.5 second |
|
27 |
|
28 static RSemaphore MainThreadCrS; |
|
29 static TInt featMgrIsResponsive = 0; |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////// |
|
32 /////////////////////////////////////////////////////////////////////////////////////// |
|
33 //Test macros and functions |
|
34 void Check1(TInt aValue, TInt aLine, TBool aPrintThreadName = EFalse) |
|
35 { |
|
36 if(!aValue) |
|
37 { |
|
38 //DeleteTestFiles(); |
|
39 if(aPrintThreadName) |
|
40 { |
|
41 RThread th; |
|
42 TName name = th.Name(); |
|
43 RDebug::Print(_L("*** Thread %S, Line %d\r\n"), &name, aLine); |
|
44 } |
|
45 else |
|
46 { |
|
47 RDebug::Print(_L("*** Line %d\r\n"), aLine); |
|
48 } |
|
49 TheTest(EFalse, aLine); |
|
50 } |
|
51 } |
|
52 |
|
53 void Check2(TInt aValue, TInt aExpected, TInt aLine, TBool aPrintThreadName = EFalse) |
|
54 { |
|
55 if(aValue != aExpected) |
|
56 { |
|
57 //DeleteTestFiles(); |
|
58 if(aPrintThreadName) |
|
59 { |
|
60 RThread th; |
|
61 TName name = th.Name(); |
|
62 RDebug::Print(_L("*** Thread %S, Line %d Expected error: %d, got: %d\r\n"), &name, aLine, aExpected, aValue); |
|
63 } |
|
64 else |
|
65 { |
|
66 RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
67 } |
|
68 TheTest(EFalse, aLine); |
|
69 } |
|
70 } |
|
71 #define TEST(arg) ::Check1((arg), __LINE__) |
|
72 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
73 #define TTEST(arg) ::Check1((arg), __LINE__, ETrue) |
|
74 #define TTEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__, ETrue) |
|
75 |
|
76 // ------------------------- ------------------------- |
|
77 // setup and cleanup functions |
|
78 |
|
79 TInt TestModifyThreadL(void*) |
|
80 { |
|
81 __UHEAP_MARK; |
|
82 |
|
83 CTrapCleanup* tc = CTrapCleanup::New(); |
|
84 // Modify a feature. We don't care about its result. |
|
85 // It is fine as long as it returns. |
|
86 RFeatureControl rfc; |
|
87 TEST2( rfc.Connect(), KErrNone ); |
|
88 rfc.EnableFeature( TUid::Uid(0x00000001) ); |
|
89 rfc.Close(); |
|
90 featMgrIsResponsive = 1; |
|
91 RDebug::Print(_L("+++:TestModifyThread: Modification completed\r\n")); |
|
92 MainThreadCrS.Signal(); |
|
93 delete tc; |
|
94 |
|
95 __UHEAP_MARKEND; |
|
96 |
|
97 return KErrNone; |
|
98 } |
|
99 /** |
|
100 @SYMTestCaseID PDS-FEATMGR-CT-XXXX |
|
101 @SYMTestCaseDesc Querying a feature during backup operation. Verify that a |
|
102 response is returned from the server during backup. |
|
103 @SYMTestPriority High |
|
104 @SYMTestActions Start simulating backup operation |
|
105 Create a thread that will query a feature |
|
106 Verify that a response is received in not more than 1.5 second. |
|
107 Otherwise the test fail. |
|
108 @SYMTestExpectedResults Test must not fail |
|
109 @SYMREQ |
|
110 */ |
|
111 void TestBackupModificationResponseL() |
|
112 { |
|
113 _LIT(KThreadName, "MdfTh"); |
|
114 featMgrIsResponsive = 0; |
|
115 |
|
116 CFeatMgrBURSim* simulate = CFeatMgrBURSim::NewLC(); |
|
117 RThread modifyThread; |
|
118 TRequestStatus modifyStatus; |
|
119 |
|
120 CleanupClosePushL( modifyThread ); |
|
121 |
|
122 |
|
123 // Simulate a backup |
|
124 RDebug::Print(_L("Simulating Backup of BUR\r\n")); |
|
125 simulate->Simulate_StartBackupL(); |
|
126 |
|
127 TEST2( modifyThread.Create(KThreadName, &TestModifyThreadL, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone ); |
|
128 modifyThread.Logon(modifyStatus); |
|
129 TEST2( modifyStatus.Int(), KRequestPending ); |
|
130 modifyThread.Resume(); |
|
131 // Wait for 1.5 second for the query thread to finish. |
|
132 RDebug::Print(_L("+++:MainThread: Wait for modification completion...\r\n")); |
|
133 MainThreadCrS.Wait(threadTimeout); |
|
134 // The modification request should NOT be responsive within the 1.5 second frame. |
|
135 // It should only be responsive after back up ended. |
|
136 TEST2 (featMgrIsResponsive, 0); |
|
137 simulate->Simulate_EndBackupL(); |
|
138 |
|
139 MainThreadCrS.Wait(threadTimeout); |
|
140 |
|
141 // The modification request now must be responsive within the 1.5 second frame. |
|
142 TEST2 (featMgrIsResponsive, 1); |
|
143 |
|
144 CleanupStack::PopAndDestroy(&modifyThread); |
|
145 CleanupStack::PopAndDestroy(simulate); |
|
146 } |
|
147 |
|
148 /////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
|
150 void DoTestsL() |
|
151 { |
|
152 MainThreadCrS.CreateLocal(0); |
|
153 |
|
154 TheTest.Start(_L(" @SYMTestCaseID:PDS-FEATMGR-CT-XXXX Backup Modification Response")); |
|
155 TestBackupModificationResponseL(); |
|
156 |
|
157 MainThreadCrS.Close(); |
|
158 |
|
159 } |
|
160 |
|
161 TInt E32Main() |
|
162 { |
|
163 TheTest.Title(); |
|
164 |
|
165 CTrapCleanup* tc = CTrapCleanup::New(); |
|
166 |
|
167 __UHEAP_MARK; |
|
168 |
|
169 TRAPD(err, DoTestsL()); |
|
170 TEST2(err, KErrNone); |
|
171 |
|
172 __UHEAP_MARKEND; |
|
173 |
|
174 TheTest.End(); |
|
175 TheTest.Close(); |
|
176 |
|
177 delete tc; |
|
178 |
|
179 User::Heap().Check(); |
|
180 return KErrNone; |
|
181 } |