|
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 <featdiscovery.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 /** |
|
80 * Creates the direcory structure required for the backup to take place. |
|
81 * Will leave if an error occurs other then KErrNone or KErrAlreadyExists as this |
|
82 * indicates the directory structure has not been created. |
|
83 */ |
|
84 |
|
85 TInt TestQueryThreadL(void*) |
|
86 { |
|
87 __UHEAP_MARK; |
|
88 |
|
89 CTrapCleanup* tc = CTrapCleanup::New(); |
|
90 // Query a feature. We don't care about its result. |
|
91 // It is fine as long as it returns. |
|
92 CFeatureDiscovery::IsFeatureSupportedL( TUid::Uid(0x00000001) ); |
|
93 featMgrIsResponsive = 1; |
|
94 RDebug::Print(_L("+++:TestQueryThread: Query completed\r\n")); |
|
95 MainThreadCrS.Signal(); |
|
96 delete tc; |
|
97 |
|
98 __UHEAP_MARKEND; |
|
99 |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 /////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
105 /** |
|
106 @SYMTestCaseID PDS-FEATMGR-CT-XXXX |
|
107 @SYMTestCaseDesc Querying a feature during backup operation. Verify that a |
|
108 response is returned from the server during backup. |
|
109 @SYMTestPriority High |
|
110 @SYMTestActions Start simulating backup operation |
|
111 Create a thread that will query a feature |
|
112 Verify that a response is received in not more than 1.5 second. |
|
113 Otherwise the test fail. |
|
114 @SYMTestExpectedResults Test must not fail |
|
115 @SYMREQ |
|
116 */ |
|
117 void TestBackupQueryResponseL() |
|
118 { |
|
119 _LIT(KThreadName, "QryTh"); |
|
120 featMgrIsResponsive = 0; |
|
121 |
|
122 CFeatMgrBURSim* simulate = CFeatMgrBURSim::NewLC(); |
|
123 RThread queryThread; |
|
124 TRequestStatus queryStatus; |
|
125 |
|
126 CleanupClosePushL( queryThread ); |
|
127 |
|
128 // Simulate a backup |
|
129 RDebug::Print(_L("Simulating Backup of BUR\r\n")); |
|
130 simulate->Simulate_StartBackupL(); |
|
131 |
|
132 TEST2( queryThread.Create(KThreadName, &TestQueryThreadL, 0x2000, 0x1000, 0x10000, NULL, EOwnerProcess), KErrNone ); |
|
133 queryThread.Logon(queryStatus); |
|
134 TEST2( queryStatus.Int(), KRequestPending ); |
|
135 queryThread.Resume(); |
|
136 // Wait for 1.5 second for the query thread to finish. |
|
137 RDebug::Print(_L("+++:MainThread: Wait for query completion...\r\n")); |
|
138 MainThreadCrS.Wait(threadTimeout); |
|
139 // If query is responsive within the 1.5 second frame the following check should pass. |
|
140 TEST2 (featMgrIsResponsive, 1); |
|
141 |
|
142 simulate->Simulate_EndBackupL(); |
|
143 |
|
144 CleanupStack::PopAndDestroy(&queryThread); |
|
145 CleanupStack::PopAndDestroy(simulate); |
|
146 } |
|
147 |
|
148 /** |
|
149 @SYMTestCaseID PDS-FEATMGR-CT-XXXX |
|
150 @SYMTestCaseDesc Querying a feature during backup operation. Verify that a |
|
151 response is returned from the server during backup. |
|
152 @SYMTestPriority High |
|
153 @SYMTestActions Start simulating backup operation |
|
154 Create a thread that will query a feature |
|
155 Verify that a response is received in not more than 1.5 second. |
|
156 Otherwise the test fail. |
|
157 @SYMTestExpectedResults Test must not fail |
|
158 @SYMREQ |
|
159 */ |
|
160 |
|
161 /////////////////////////////////////////////////////////////////////////////////////// |
|
162 |
|
163 void DoTestsL() |
|
164 { |
|
165 MainThreadCrS.CreateLocal(0); |
|
166 |
|
167 TheTest.Start(_L(" @SYMTestCaseID:PDS-FEATMGR-CT-XXXX Backup Query Response")); |
|
168 TestBackupQueryResponseL(); |
|
169 |
|
170 MainThreadCrS.Close(); |
|
171 |
|
172 } |
|
173 |
|
174 TInt E32Main() |
|
175 { |
|
176 TheTest.Title(); |
|
177 |
|
178 CTrapCleanup* tc = CTrapCleanup::New(); |
|
179 |
|
180 __UHEAP_MARK; |
|
181 |
|
182 TRAPD(err, DoTestsL()); |
|
183 TEST2(err, KErrNone); |
|
184 |
|
185 __UHEAP_MARKEND; |
|
186 |
|
187 TheTest.End(); |
|
188 TheTest.Close(); |
|
189 |
|
190 delete tc; |
|
191 |
|
192 User::Heap().Check(); |
|
193 return KErrNone; |
|
194 } |