|
1 // Copyright (c) 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 // |
|
15 |
|
16 #include <e32test.h> |
|
17 #include <f32file.h> |
|
18 #include <sacls.h> |
|
19 #include <e32property.h> |
|
20 #include <featmgr.h> |
|
21 #include <featureuids.h> |
|
22 #include <featurecontrol.h> |
|
23 #include <featdiscovery.h> |
|
24 #include "..\src\inc\featmgrconfiguration.h" |
|
25 |
|
26 /////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 static RTest TheTest(_L("t_fmgrswi")); |
|
29 |
|
30 const TUid KNewFeatureUid = {0x7888ABC2}; |
|
31 |
|
32 /////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
34 //Deletes all created test files. |
|
35 void DestroyTestEnv() |
|
36 { |
|
37 } |
|
38 |
|
39 /////////////////////////////////////////////////////////////////////////////////////// |
|
40 /////////////////////////////////////////////////////////////////////////////////////// |
|
41 //Test macros and functions |
|
42 void Check1(TInt aValue, TInt aLine) |
|
43 { |
|
44 if(!aValue) |
|
45 { |
|
46 DestroyTestEnv(); |
|
47 RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine); |
|
48 TheTest(EFalse, aLine); |
|
49 } |
|
50 } |
|
51 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
52 { |
|
53 if(aValue != aExpected) |
|
54 { |
|
55 DestroyTestEnv(); |
|
56 RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine); |
|
57 TheTest(EFalse, aLine); |
|
58 } |
|
59 } |
|
60 #define TEST(arg) ::Check1((arg), __LINE__) |
|
61 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
62 |
|
63 /////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
65 TInt KillProcess(const TDesC& aProcessName) |
|
66 { |
|
67 TFullName name; |
|
68 //RDebug::Print(_L("Find and kill \"%S\" process.\n"), &aProcessName); |
|
69 TBuf<64> pattern(aProcessName); |
|
70 TInt length = pattern.Length(); |
|
71 pattern += _L("*"); |
|
72 TFindProcess procFinder(pattern); |
|
73 |
|
74 while (procFinder.Next(name) == KErrNone) |
|
75 { |
|
76 if (name.Length() > length) |
|
77 {//If found name is a string containing aProcessName string. |
|
78 TChar c(name[length]); |
|
79 if (c.IsAlphaDigit() || |
|
80 c == TChar('_') || |
|
81 c == TChar('-')) |
|
82 { |
|
83 // If the found name is other valid application name |
|
84 // starting with aProcessName string. |
|
85 //RDebug::Print(_L(":: Process name: \"%S\".\n"), &name); |
|
86 continue; |
|
87 } |
|
88 } |
|
89 RProcess proc; |
|
90 if (proc.Open(name) == KErrNone) |
|
91 { |
|
92 proc.Kill(0); |
|
93 //RDebug::Print(_L("\"%S\" process killed.\n"), &name); |
|
94 } |
|
95 proc.Close(); |
|
96 } |
|
97 return KErrNone; |
|
98 } |
|
99 |
|
100 /** |
|
101 @SYMTestCaseID PDS-EFM-CT-4111 |
|
102 @SYMTestCaseDesc |
|
103 @SYMTestPriority High |
|
104 @SYMTestActions |
|
105 @SYMTestExpectedResults Test must not fail |
|
106 @SYMDEF DEF144262 |
|
107 */ |
|
108 void SWItest() |
|
109 { |
|
110 RFs fs; |
|
111 TInt err = fs.Connect(); |
|
112 TEST2(err, KErrNone); |
|
113 // |
|
114 RFeatureControl ctrl; |
|
115 err = ctrl.Open(); |
|
116 TEST2(err, KErrNone); |
|
117 //Simulate SWI start |
|
118 err = RProperty::Set(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall); |
|
119 TEST2(err, KErrNone); |
|
120 //Notify FeatMgr server that SWI started |
|
121 err = ctrl.SWIStart(); |
|
122 TEST2(err, KErrNone); |
|
123 //Add a new persistent feature (using the same SWI connection) |
|
124 TBitFlags32 flags; |
|
125 flags.ClearAll(); |
|
126 flags.Set(EFeatureSupported); |
|
127 flags.Set(EFeatureModifiable); |
|
128 flags.Set(EFeaturePersisted); |
|
129 TFeatureEntry fentry(KNewFeatureUid, flags, 9876); |
|
130 err = ctrl.AddFeature(fentry); |
|
131 TEST2(err, KErrNone); |
|
132 //Simulate file I/O error |
|
133 (void)fs.SetErrorCondition(KErrGeneral, 4); |
|
134 //Complete the SWI simulation |
|
135 err = RProperty::Set(KUidSystemCategory, KSAUidSoftwareInstallKeyValue, ESASwisInstall | ESASwisStatusSuccess); |
|
136 TEST2(err, KErrNone); |
|
137 //Notify FeatMgr server that SWI completed |
|
138 err = ctrl.SWIEnd(); |
|
139 TEST2(err, KErrNone); |
|
140 //Cleanup |
|
141 ctrl.Close(); |
|
142 (void)fs.SetErrorCondition(KErrNone); |
|
143 fs.Close(); |
|
144 //Kill FeatMgr server |
|
145 err = KillProcess(KServerProcessName); |
|
146 TEST2(err, KErrNone); |
|
147 //Open new connection |
|
148 err = ctrl.Open(); |
|
149 TEST2(err, KErrNone); |
|
150 //The feature should be there |
|
151 TFeatureEntry fentry2(KNewFeatureUid); |
|
152 err = ctrl.FeatureSupported(fentry2); |
|
153 TEST2(err, KFeatureSupported); |
|
154 TEST2(fentry2.FeatureData(), fentry.FeatureData()); |
|
155 //Cleanup |
|
156 err = ctrl.DeleteFeature(KNewFeatureUid); |
|
157 TEST2(err, KErrNone); |
|
158 ctrl.Close(); |
|
159 } |
|
160 |
|
161 void DoTestsL() |
|
162 { |
|
163 CActiveScheduler* scheduler = new CActiveScheduler; |
|
164 TEST(scheduler != NULL); |
|
165 CActiveScheduler::Install(scheduler); |
|
166 |
|
167 TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4111 SWI test")); |
|
168 SWItest(); |
|
169 |
|
170 delete scheduler; |
|
171 } |
|
172 |
|
173 TInt E32Main() |
|
174 { |
|
175 TheTest.Title(); |
|
176 |
|
177 CTrapCleanup* tc = CTrapCleanup::New(); |
|
178 TheTest(tc != NULL); |
|
179 |
|
180 __UHEAP_MARK; |
|
181 |
|
182 TRAPD(err, DoTestsL()); |
|
183 DestroyTestEnv(); |
|
184 TEST2(err, KErrNone); |
|
185 |
|
186 __UHEAP_MARKEND; |
|
187 |
|
188 TheTest.End(); |
|
189 TheTest.Close(); |
|
190 |
|
191 delete tc; |
|
192 |
|
193 User::Heap().Check(); |
|
194 return KErrNone; |
|
195 } |