|
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 <featmgr/featurecontrol.h> |
|
20 #include <featmgr/featmgr.h> |
|
21 #include <featdiscovery.h> |
|
22 #include "featmgrtlsdata.h" |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
26 RTest TheTest(_L("t_fmgrunitrefcount test")); |
|
27 |
|
28 const TUid KDummyFeatUid = {0x12345678}; |
|
29 |
|
30 /////////////////////////////////////////////////////////////////////////////////////// |
|
31 //Test macros and functions |
|
32 void Check1(TInt aValue, TInt aLine) |
|
33 { |
|
34 if(!aValue) |
|
35 { |
|
36 //DeleteTestFiles(); |
|
37 RDebug::Print(_L("*** Line %d\r\n"), aLine); |
|
38 TheTest(EFalse, aLine); |
|
39 } |
|
40 } |
|
41 |
|
42 void Check2(TInt aValue, TInt aExpected, TInt aLine) |
|
43 { |
|
44 if(aValue != aExpected) |
|
45 { |
|
46 RDebug::Print(_L("*** Line %d, Expected error: %d, got: %d\r\n"), aLine, aExpected, aValue); |
|
47 TheTest(EFalse, aLine); |
|
48 } |
|
49 } |
|
50 #define TEST(arg) ::Check1((arg), __LINE__) |
|
51 #define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__) |
|
52 |
|
53 /** |
|
54 @SYMTestCaseID PDS-EFM-UT-4112 |
|
55 @SYMTestCaseDesc Unit test for client reference counting. |
|
56 @SYMTestPriority High |
|
57 @SYMTestActions Initialise FeatureManager and check the client reference count |
|
58 Connect using RFeatureControl and check the client reference count |
|
59 Uninitialise FeatureManager and check the client reference count |
|
60 Close RFeatureControl and check the client reference count |
|
61 @SYMTestExpectedResults Test must not fail |
|
62 @SYMDEF DEF144262 |
|
63 */ |
|
64 void TestRefCountFeatureManagerL() |
|
65 { |
|
66 RFeatureControl featCtrl; |
|
67 |
|
68 CleanupClosePushL(featCtrl); |
|
69 FeatureManager::InitializeLibL(); |
|
70 TEST2 (GetClientCount(), 1); // Client count should be 1 at this point |
|
71 |
|
72 featCtrl.Connect(); |
|
73 TEST2 (GetClientCount(), 2); // Client count should be 2 at this point |
|
74 |
|
75 // Both should return same result |
|
76 TEST2 (FeatureManager::FeatureSupported(KDummyFeatUid.iUid), featCtrl.FeatureSupported(KDummyFeatUid)==KFeatureSupported); |
|
77 |
|
78 FeatureManager::UnInitializeLib(); |
|
79 TEST2 (GetClientCount(), 1); // Client count should be 1 at this point |
|
80 |
|
81 CleanupStack::PopAndDestroy(&featCtrl); |
|
82 TEST2 (GetClientCount(), 0); // Client count should be 0 at this point |
|
83 } |
|
84 |
|
85 /** |
|
86 @SYMTestCaseID PDS-EFM-UT-4113 |
|
87 @SYMTestCaseDesc Unit test for client reference counting. |
|
88 @SYMTestPriority High |
|
89 @SYMTestActions Create CFeatureDiscovery object and check the client reference count |
|
90 Connect using RFeatureControl and check the client reference count |
|
91 Delete the CFeatureDiscovery object and check the client reference count |
|
92 Close RFeatureControl and check the client reference count |
|
93 @SYMTestExpectedResults Test must not fail |
|
94 @SYMDEF DEF144262 |
|
95 */ |
|
96 void TestRefCountCFeatureDiscoveryL() |
|
97 { |
|
98 RFeatureControl featCtrl; |
|
99 CleanupClosePushL(featCtrl); |
|
100 CFeatureDiscovery* featDisc = CFeatureDiscovery::NewLC(); |
|
101 TEST2 (GetClientCount(), 1); // Client count should be 1 at this point |
|
102 featCtrl.Connect(); |
|
103 TEST2 (GetClientCount(), 2); // Client count should be 2 at this point |
|
104 |
|
105 // Both should return same result |
|
106 TEST2 (featDisc->IsSupported(KDummyFeatUid), featCtrl.FeatureSupported(KDummyFeatUid)==KFeatureSupported); |
|
107 |
|
108 CleanupStack::PopAndDestroy(featDisc); |
|
109 TEST2 (GetClientCount(), 1); // Client count should be 1 at this point |
|
110 |
|
111 CleanupStack::PopAndDestroy(&featCtrl); |
|
112 TEST2 (GetClientCount(), 0); // Client count should be 0 at this point |
|
113 } |
|
114 |
|
115 /////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
117 void DoTestsL() |
|
118 { |
|
119 TheTest.Start(_L(" @SYMTestCaseID:PDS-EFM-UT-4112 Client Reference Count using FeatureManager")); |
|
120 TestRefCountFeatureManagerL(); |
|
121 TheTest.Next(_L(" @SYMTestCaseID:PDS-EFM-UT-4113 Client Reference Count using CFeatureDiscovery")); |
|
122 TestRefCountCFeatureDiscoveryL(); |
|
123 |
|
124 } |
|
125 |
|
126 TInt E32Main() |
|
127 { |
|
128 TheTest.Title(); |
|
129 |
|
130 CTrapCleanup* tc = CTrapCleanup::New(); |
|
131 |
|
132 __UHEAP_MARK; |
|
133 |
|
134 TRAPD(err, DoTestsL()); |
|
135 TEST2(err, KErrNone); |
|
136 |
|
137 __UHEAP_MARKEND; |
|
138 |
|
139 TheTest.End(); |
|
140 TheTest.Close(); |
|
141 |
|
142 delete tc; |
|
143 |
|
144 User::Heap().Check(); |
|
145 return KErrNone; |
|
146 } |