|
1 // Copyright (c) 2007-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 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <e32const.h> // KMaxFilename |
|
23 #include <e32modes.h> // EStartupModeUndefined |
|
24 #include <startupproperties.h> |
|
25 #include "tstartupproperties_stepinternalexternal.h" |
|
26 |
|
27 CStartupPropertiesTestStepInternalExternal::CStartupPropertiesTestStepInternalExternal() |
|
28 { |
|
29 SetTestStepName(KCTestCaseInternalExternal); |
|
30 } |
|
31 /** |
|
32 Old Test CaseID APPFWK-STARTUPPROPERTIES-0002 |
|
33 New Test CaseID DEVSRVS-SHMA-STARTUPPROPERTIES-0001 |
|
34 */ |
|
35 |
|
36 TVerdict CStartupPropertiesTestStepInternalExternal::doTestStepL() |
|
37 { |
|
38 INFO_PRINTF1(_L("APPFWK-STARTUPPROPERTIES-0002")); |
|
39 DoTestWithDataL(); |
|
40 DoTestWithNullPointersL(); |
|
41 DoTestResetL(); |
|
42 return TestStepResult(); |
|
43 } |
|
44 |
|
45 void CStartupPropertiesTestStepInternalExternal::DoTestWithDataL() |
|
46 { |
|
47 INFO_PRINTF1(_L("Test 1A, using valid HBufC:s")); |
|
48 |
|
49 // Create an startupprop instance with non default values |
|
50 CStartupProperties* orig = CStartupProperties::NewLC(); |
|
51 _LIT(KString1, "abc_logfile.txt"); |
|
52 _LIT(KString2, "abc logfile txt"); |
|
53 orig->SetFileParamsL(KString1, KString2); |
|
54 orig->SetStartupType(EStartApp); |
|
55 orig->SetStartMethod(EWaitForStart); |
|
56 const TInt KNumber1 = 999; |
|
57 orig->SetNoOfRetries(KNumber1); |
|
58 orig->SetTimeout(KNumber1); |
|
59 const TInt KNonDefaultRestartMode = EStartupModeUndefined+10; |
|
60 orig->SetRecoveryParams(ERestartOSWithMode, KNonDefaultRestartMode); |
|
61 orig->SetMonitored(ETrue); |
|
62 orig->SetViewless(ETrue); |
|
63 orig->SetStartInBackground(ETrue); |
|
64 |
|
65 //Externalize it |
|
66 CBufFlat* const buf = CBufFlat::NewL(orig->Size()); |
|
67 CleanupStack::PushL(buf); |
|
68 orig->ExternalizeL(*buf); |
|
69 |
|
70 // Create a new startupprop instance |
|
71 CStartupProperties* copy = CStartupProperties::NewLC(); |
|
72 |
|
73 // Make sure orig uses non-default values |
|
74 TEST(orig->FileName() != copy->FileName()); |
|
75 TEST(orig->Args() != copy->Args()); |
|
76 TEST(orig->StartupType() != copy->StartupType()); |
|
77 TEST(orig->StartMethod() != copy->StartMethod()); |
|
78 TEST(orig->NoOfRetries() != copy->NoOfRetries()); |
|
79 TEST(orig->Timeout() != copy->Timeout()); |
|
80 TEST(orig->Monitored() != copy->Monitored()); |
|
81 TEST(orig->ActionOnCommandFailure() != copy->ActionOnCommandFailure()); |
|
82 TEST(orig->RecoveryMethod() != copy->RecoveryMethod()); |
|
83 TEST(orig->RestartMode() != copy->RestartMode()); |
|
84 TEST(orig->Viewless() != copy->Viewless()); |
|
85 TEST(orig->StartInBackground() != copy->StartInBackground()); |
|
86 |
|
87 // Internalize the data |
|
88 TPtr8 bufPtr(buf->Ptr(0)); |
|
89 copy->InternalizeL(bufPtr); |
|
90 |
|
91 //And TEST that all members was read back successfully |
|
92 TEST(orig->Version() == copy->Version()); |
|
93 TEST(orig->FileName() == copy->FileName()); |
|
94 TEST(orig->Args() == copy->Args()); |
|
95 TEST(orig->StartupType() == copy->StartupType()); |
|
96 TEST(orig->StartMethod() == copy->StartMethod()); |
|
97 TEST(orig->NoOfRetries() == copy->NoOfRetries()); |
|
98 TEST(orig->Timeout() == copy->Timeout()); |
|
99 TEST(orig->Monitored() == copy->Monitored()); |
|
100 TEST(orig->ActionOnCommandFailure() == copy->ActionOnCommandFailure()); |
|
101 TEST(orig->RecoveryMethod() == copy->RecoveryMethod()); |
|
102 TEST(orig->RestartMode() == copy->RestartMode()); |
|
103 TEST(orig->Viewless() == copy->Viewless()); |
|
104 TEST(orig->StartInBackground() == copy->StartInBackground()); |
|
105 |
|
106 //Externalize the second instance |
|
107 CBufFlat* const buf2 = CBufFlat::NewL(copy->Size()); |
|
108 CleanupStack::PushL(buf2); |
|
109 copy->ExternalizeL(*buf2); |
|
110 |
|
111 //Assert that the first and second buffer have the same contents |
|
112 TEST(buf->Ptr(0) == buf2->Ptr(0)); |
|
113 |
|
114 CleanupStack::PopAndDestroy(buf2); |
|
115 CleanupStack::PopAndDestroy(copy); |
|
116 CleanupStack::PopAndDestroy(buf); |
|
117 CleanupStack::PopAndDestroy(orig); |
|
118 } |
|
119 |
|
120 /** |
|
121 Protect against NULL-pointer errors in the externalize/internalize methods. |
|
122 */ |
|
123 void CStartupPropertiesTestStepInternalExternal::DoTestWithNullPointersL() |
|
124 { |
|
125 INFO_PRINTF1(_L("Test 1B, using NULL pointers")); |
|
126 |
|
127 // Create an startupprop instance with non NULL iFilename and iArgs |
|
128 CStartupProperties* orig = CStartupProperties::NewLC(); |
|
129 |
|
130 //SetActionOnCommandFailure wasn't covered in any other testcase, so to increase testcoverage test it here |
|
131 orig->SetActionOnCommandFailure(EPanicOnCommandFailure); |
|
132 TEST(orig->ActionOnCommandFailure() == EPanicOnCommandFailure); |
|
133 |
|
134 //Externalize it |
|
135 CBufFlat* const buf = CBufFlat::NewL(orig->Size()); |
|
136 CleanupStack::PushL(buf); |
|
137 orig->ExternalizeL(*buf); // this call could dereference NULL |
|
138 |
|
139 // Create a new startupprop instance |
|
140 CStartupProperties* copy = CStartupProperties::NewLC(); |
|
141 |
|
142 // Internalize the data |
|
143 TPtr8 bufPtr(buf->Ptr(0)); |
|
144 copy->InternalizeL(bufPtr); |
|
145 |
|
146 //And TEST that all members was read back successfully |
|
147 TEST(orig->Version() == copy->Version()); |
|
148 TEST(orig->FileName() == copy->FileName()); |
|
149 TEST(orig->Args() == copy->Args()); |
|
150 TEST(orig->StartupType() == copy->StartupType()); |
|
151 TEST(orig->StartMethod() == copy->StartMethod()); |
|
152 TEST(orig->NoOfRetries() == copy->NoOfRetries()); |
|
153 TEST(orig->Timeout() == copy->Timeout()); |
|
154 TEST(orig->Monitored() == copy->Monitored()); |
|
155 TEST(orig->ActionOnCommandFailure() == copy->ActionOnCommandFailure()); |
|
156 TEST(orig->RecoveryMethod() == copy->RecoveryMethod()); |
|
157 TEST(orig->RestartMode() == copy->RestartMode()); |
|
158 TEST(orig->Viewless() == copy->Viewless()); |
|
159 TEST(orig->StartInBackground() == copy->StartInBackground()); |
|
160 |
|
161 //Externalize the second instance |
|
162 CBufFlat* const buf2 = CBufFlat::NewL(copy->Size()); |
|
163 CleanupStack::PushL(buf2); |
|
164 copy->ExternalizeL(*buf2); |
|
165 |
|
166 //Assert that the first and second buffer have the same contents |
|
167 TEST(buf->Ptr(0) == buf2->Ptr(0)); |
|
168 |
|
169 CleanupStack::PopAndDestroy(buf2); |
|
170 CleanupStack::PopAndDestroy(copy); |
|
171 CleanupStack::PopAndDestroy(buf); |
|
172 CleanupStack::PopAndDestroy(orig); |
|
173 } |
|
174 |
|
175 /** |
|
176 Test the Reset() Method of CStartupProperties |
|
177 */ |
|
178 void CStartupPropertiesTestStepInternalExternal::DoTestResetL() |
|
179 { |
|
180 INFO_PRINTF1(_L("Test 1C, test CStartupProperties::Reset() method")); |
|
181 |
|
182 // Create an startupprop instance with non default values |
|
183 CStartupProperties* orig = CStartupProperties::NewLC(); |
|
184 _LIT(KString1, "abc_logfile.txt"); |
|
185 _LIT(KString2, "abc logfile txt"); |
|
186 orig->SetFileParamsL(KString1, KString2); |
|
187 orig->SetStartupType(EStartApp); |
|
188 orig->SetStartMethod(EWaitForStart); |
|
189 const TInt KNumber1 = 999; |
|
190 orig->SetNoOfRetries(KNumber1); |
|
191 orig->SetTimeout(KNumber1); |
|
192 const TInt KNonDefaultRestartMode = EStartupModeUndefined+10; |
|
193 orig->SetRecoveryParams(ERestartOSWithMode, KNonDefaultRestartMode); |
|
194 orig->SetMonitored(ETrue); |
|
195 orig->SetViewless(ETrue); |
|
196 orig->SetStartInBackground(ETrue); |
|
197 |
|
198 CleanupStack::Pop(orig); |
|
199 // Reset the values of startproperties to the default values. |
|
200 orig->Reset(); |
|
201 CleanupStack::PushL(orig); |
|
202 |
|
203 TEST(orig->Version() == 1); |
|
204 TEST(orig->StartupType() == EStartProcess); |
|
205 TEST(orig->StartMethod() == EFireAndForget); |
|
206 TEST(orig->RecoveryMethod() == EIgnoreOnFailure); |
|
207 TEST(orig->RestartMode() == EStartupModeUndefined); |
|
208 TEST(orig->FileName() == KNullDesC); |
|
209 TEST(orig->Args() == KNullDesC); |
|
210 TEST(orig->Viewless() == EFalse); |
|
211 TEST(orig->StartInBackground() == EFalse); |
|
212 TEST(orig->Timeout() == 0); |
|
213 TEST(orig->NoOfRetries() == 0); |
|
214 TEST(orig->Monitored() == EFalse); |
|
215 |
|
216 CleanupStack::PopAndDestroy(orig); |
|
217 } |
|
218 |