|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // CLASS UNDER TEST |
|
20 #include "caouserafter.h" |
|
21 #include <aiutility.h> |
|
22 #include "caipspropertyobserver.h" |
|
23 |
|
24 #include "MT_AiPSPropertyObserver.h" |
|
25 #include <digia/eunit/eunitmacros.h> |
|
26 |
|
27 const TInt KRandTestUid( 0x017000F5 ); |
|
28 const TInt KRandTestKey( 0x000000FF ); |
|
29 |
|
30 void ChangeKeyValueL( TInt aValue ) |
|
31 { |
|
32 RProperty::Define( TUid::Uid( KRandTestUid ), |
|
33 KRandTestKey, |
|
34 RProperty::EInt ); |
|
35 |
|
36 User::LeaveIfError( |
|
37 RProperty::Set( TUid::Uid( KRandTestUid ), |
|
38 KRandTestKey, |
|
39 aValue ) ); |
|
40 |
|
41 } |
|
42 |
|
43 |
|
44 // CONSTRUCTION |
|
45 MT_AiPSPropertyObserver* MT_AiPSPropertyObserver::NewL() |
|
46 { |
|
47 MT_AiPSPropertyObserver* self = MT_AiPSPropertyObserver::NewLC(); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 MT_AiPSPropertyObserver* MT_AiPSPropertyObserver::NewLC() |
|
53 { |
|
54 MT_AiPSPropertyObserver* self = new( ELeave ) MT_AiPSPropertyObserver(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // Destructor (virtual by CBase) |
|
61 MT_AiPSPropertyObserver::~MT_AiPSPropertyObserver() |
|
62 { |
|
63 #if _BullseyeCoverage |
|
64 cov_write(); |
|
65 #endif |
|
66 } |
|
67 |
|
68 // Default constructor |
|
69 MT_AiPSPropertyObserver::MT_AiPSPropertyObserver() |
|
70 { |
|
71 } |
|
72 |
|
73 // Second phase construct |
|
74 void MT_AiPSPropertyObserver::ConstructL() |
|
75 { |
|
76 // The ConstructL from the base class CEUnitTestSuiteClass must be called. |
|
77 // It generates the test case table. |
|
78 CEUnitTestSuiteClass::ConstructL(); |
|
79 |
|
80 ChangeKeyValueL( 5 ); |
|
81 CAOUserAfter::AfterLD( 2 * 1000000 ); |
|
82 } |
|
83 |
|
84 // METHODS |
|
85 |
|
86 TInt MT_AiPSPropertyObserver::HandleSystemStateChangedL(TAny* aPtr) |
|
87 { |
|
88 MT_AiPSPropertyObserver* self = |
|
89 static_cast<MT_AiPSPropertyObserver*>( aPtr ); |
|
90 TInt value = 0; |
|
91 |
|
92 self->iPSObserver->Get(value); |
|
93 |
|
94 if ( value == 10 ) |
|
95 { |
|
96 self->iStateOk = ETrue; |
|
97 } |
|
98 |
|
99 return KErrNone; |
|
100 } |
|
101 |
|
102 void MT_AiPSPropertyObserver::SetupL( ) |
|
103 { |
|
104 iPSObserver = AiUtility::CreatePSPropertyObserverL( |
|
105 TCallBack( HandleSystemStateChangedL, this ), |
|
106 TUid::Uid( KRandTestUid ), |
|
107 KRandTestKey ); |
|
108 } |
|
109 |
|
110 void MT_AiPSPropertyObserver::Teardown( ) |
|
111 { |
|
112 Release( iPSObserver ); |
|
113 } |
|
114 |
|
115 void MT_AiPSPropertyObserver::TestBasicFunctionalityL( ) |
|
116 { |
|
117 MAiPSPropertyObserver* obs = NULL; |
|
118 // Test that Release(NULL) does not crash |
|
119 Release(obs); |
|
120 |
|
121 // test |
|
122 ChangeKeyValueL( 10 ); |
|
123 CAOUserAfter::AfterLD( 2 * 1000000 ); |
|
124 if( iStateOk ) |
|
125 { |
|
126 EUNIT_ASSERT( ETrue ); |
|
127 return; |
|
128 } |
|
129 EUNIT_ASSERT( EFalse ); |
|
130 } |
|
131 |
|
132 void MT_AiPSPropertyObserver::TestGettersL( ) |
|
133 { |
|
134 TInt err = KErrNone; |
|
135 TBuf16<100> buf16; |
|
136 TBuf8<100> buf8; |
|
137 TInt value = 0; |
|
138 err = iPSObserver->Get(buf16); |
|
139 |
|
140 EUNIT_ASSERT( err != KErrNone ); |
|
141 |
|
142 err = KErrNone; |
|
143 err = iPSObserver->Get(buf8); |
|
144 |
|
145 EUNIT_ASSERT( err != KErrNone ); |
|
146 |
|
147 err = iPSObserver->Get(value); |
|
148 |
|
149 EUNIT_ASSERT( err == KErrNone ); |
|
150 EUNIT_ASSERT( value == 5 || value == 10 ); |
|
151 } |
|
152 |
|
153 void MT_AiPSPropertyObserver::TestDoCancelL( ) |
|
154 { |
|
155 iStateOk = EFalse; |
|
156 ChangeKeyValueL( 10 ); |
|
157 Release(iPSObserver); |
|
158 iPSObserver = NULL; |
|
159 CAOUserAfter::AfterLD( 2 * 1000000 ); |
|
160 if( !iStateOk ) // make sure that the change was cancelled |
|
161 { |
|
162 EUNIT_ASSERT( ETrue ); |
|
163 return; |
|
164 } |
|
165 EUNIT_ASSERT( EFalse ); |
|
166 } |
|
167 |
|
168 // TEST TABLE |
|
169 |
|
170 EUNIT_BEGIN_TEST_TABLE( |
|
171 MT_AiPSPropertyObserver, |
|
172 "Unit test suite for MAiContentItemIterator implementation returned from AiUtility::CreateContentItemArrayIteratorL", |
|
173 "CAiContentItemArrayIterator" ) |
|
174 |
|
175 EUNIT_TEST( |
|
176 "Test one", |
|
177 "MAiContentItemIterator", |
|
178 "All", |
|
179 "FUNCTIONALITY", |
|
180 SetupL, TestBasicFunctionalityL, Teardown) |
|
181 |
|
182 EUNIT_TEST( |
|
183 "Test one", |
|
184 "MAiContentItemIterator", |
|
185 "All", |
|
186 "FUNCTIONALITY", |
|
187 SetupL, TestGettersL, Teardown) |
|
188 |
|
189 EUNIT_TEST( |
|
190 "Test one", |
|
191 "MAiContentItemIterator", |
|
192 "All", |
|
193 "FUNCTIONALITY", |
|
194 SetupL, TestDoCancelL, Teardown) |
|
195 |
|
196 EUNIT_END_TEST_TABLE |
|
197 |
|
198 // END OF FILE |