1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/test/rtest/src/t_fmgrnotify.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,293 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <e32test.h>
1.20 +#include <featmgr.h>
1.21 +#include <featureuids.h>
1.22 +#include <featurecontrol.h>
1.23 +#include <featurenotifier.h>
1.24 +
1.25 +using namespace NFeature;
1.26 +
1.27 +const TUid KNewFeatureUid = {0x7888ABCA};
1.28 +const TUid KNewFeatureUid2 = {0x7888ABCB};
1.29 +
1.30 +///////////////////////////////////////////////////////////////////////////////////////
1.31 +
1.32 +static RTest TheTest(_L("t_fmgrnotify"));
1.33 +
1.34 +///////////////////////////////////////////////////////////////////////////////////////
1.35 +
1.36 +//Deletes all created test files.
1.37 +void DestroyTestEnv()
1.38 + {
1.39 + }
1.40 +
1.41 +///////////////////////////////////////////////////////////////////////////////////////
1.42 +///////////////////////////////////////////////////////////////////////////////////////
1.43 +//Test macros and functions
1.44 +void Check1(TInt aValue, TInt aLine)
1.45 + {
1.46 + if(!aValue)
1.47 + {
1.48 + DestroyTestEnv();
1.49 + RDebug::Print(_L("*** Expression evaluated to false. Line %d\r\n"), aLine);
1.50 + TheTest(EFalse, aLine);
1.51 + }
1.52 + }
1.53 +void Check2(TInt aValue, TInt aExpected, TInt aLine)
1.54 + {
1.55 + if(aValue != aExpected)
1.56 + {
1.57 + DestroyTestEnv();
1.58 + RDebug::Print(_L("*** Expected: %d, got: %d. Line %d\r\n"), aExpected, aValue, aLine);
1.59 + TheTest(EFalse, aLine);
1.60 + }
1.61 + }
1.62 +#define TEST(arg) ::Check1((arg), __LINE__)
1.63 +#define TEST2(aValue, aExpected) ::Check2(aValue, aExpected, __LINE__)
1.64 +
1.65 +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1.66 +
1.67 +_LIT(KFeatureNoChange, "FeatureNoChange");
1.68 +_LIT(KFeatureStatusUpdated, "FeatureStatusUpdated");
1.69 +_LIT(KFeatureDataUpdated, "FeatureDataUpdated");
1.70 +_LIT(KFeatureStatusDataUpdated, "FeatureStatusDataUpdated");
1.71 +_LIT(KFeatureRediscover, "FeatureRediscover");
1.72 +_LIT(KFeatureCreated, "FeatureCreated");
1.73 +_LIT(KFeatureDeleted, "FeatureDeleted");
1.74 +
1.75 +const TPtrC KNotificationText[] = {KFeatureNoChange(), KFeatureStatusUpdated(), KFeatureDataUpdated(),
1.76 + KFeatureStatusDataUpdated(), KFeatureRediscover(), KFeatureCreated(),
1.77 + KFeatureDeleted()};
1.78 +
1.79 +class TTestFeatureObserver : public MFeatureObserver
1.80 + {
1.81 +public:
1.82 + TTestFeatureObserver() :
1.83 + iType(static_cast <TFeatureChangeType> (-1)),
1.84 + iFeatureUid(KNullUid)
1.85 + {
1.86 + }
1.87 + void SetExpected(TFeatureChangeType aType, TUid aFeatureUid)
1.88 + {
1.89 + iType = aType;
1.90 + iFeatureUid = aFeatureUid;
1.91 + }
1.92 + void Reset()
1.93 + {
1.94 + iType = static_cast <TFeatureChangeType> (-1);
1.95 + iFeatureUid = KNullUid;
1.96 + }
1.97 + virtual void HandleNotifyChange(TFeatureChangeType aType, TFeatureEntry aFeature)
1.98 + {
1.99 + TheTest.Printf(_L("=== HandleNotifyChange() called with aType=\"%S\" and aFeature.FeatureUid()=0x%X\r\n"), &KNotificationText[aType], aFeature.FeatureUid());
1.100 + CActiveScheduler::Stop();
1.101 + TEST2(aType, iType);
1.102 + TEST(aFeature.FeatureUid() == iFeatureUid);
1.103 + }
1.104 + virtual void HandleNotifyError(TInt aError)
1.105 + {
1.106 + TheTest.Printf(_L("=== HandleNotifyError() called with error=%d\r\n"), aError);
1.107 + CActiveScheduler::Stop();
1.108 + TEST2(aError, KErrNone);
1.109 + }
1.110 +private:
1.111 + TFeatureChangeType iType;
1.112 + TUid iFeatureUid;
1.113 + };
1.114 +
1.115 +///////////////////////////////////////////////////////////////////////////////////////
1.116 +
1.117 +void AddFeature(RFeatureControl& aCtrl, TUid aFeatureUid)
1.118 + {
1.119 + TBitFlags32 flags;
1.120 + flags.ClearAll();
1.121 + flags.Set(EFeatureSupported);
1.122 + flags.Set(EFeatureModifiable);
1.123 + TFeatureEntry fentry(aFeatureUid, flags, 0x0);
1.124 + TInt err = aCtrl.AddFeature(fentry);
1.125 + TEST2(err, KErrNone);
1.126 + }
1.127 +
1.128 +void DeleteFeature(RFeatureControl& aCtrl, TUid aFeatureUid)
1.129 + {
1.130 + TInt err = aCtrl.DeleteFeature(aFeatureUid);
1.131 + TEST2(err, KErrNone);
1.132 + }
1.133 +
1.134 +/**
1.135 +@SYMTestCaseID PDS-FEATMGR-CT-????
1.136 +@SYMTestCaseDesc
1.137 +@SYMTestPriority High
1.138 +@SYMTestActions
1.139 +@SYMTestExpectedResults Test must not fail
1.140 +@SYMDEF DEF144262
1.141 +*/
1.142 +void NotificationsTest1()
1.143 + {
1.144 + TTestFeatureObserver observer;
1.145 + CFeatureNotifier* notifier = NULL;
1.146 + TRAPD(err, notifier = CFeatureNotifier::NewL(observer));
1.147 + TEST2(err, KErrNone);
1.148 + //Request notification for feature with KNewFeatureUid uid.
1.149 + err = notifier->NotifyRequest(KNewFeatureUid);
1.150 + TEST2(err, KErrNone);
1.151 + err = notifier->NotifyRequest(KNewFeatureUid);
1.152 + TEST2(err, KErrAlreadyExists);
1.153 +
1.154 + RFeatureControl ctrl;
1.155 + err = ctrl.Connect();
1.156 + TEST2(err, KErrNone);
1.157 + //Add a feature with KNewFeatureUid uid and check the notification
1.158 + AddFeature(ctrl, KNewFeatureUid);
1.159 + observer.SetExpected(EFeatureFeatureCreated, KNewFeatureUid);
1.160 + CActiveScheduler::Start();
1.161 + //Set the feature status and data and check the notification
1.162 + err = ctrl.SetFeature(KNewFeatureUid, ETrue, 100);
1.163 + TEST2(err, KErrNone);
1.164 + observer.SetExpected(EFeatureStatusDataUpdated, KNewFeatureUid);
1.165 + CActiveScheduler::Start();
1.166 + //Set the feature data and check the notification
1.167 + err = ctrl.SetFeature(KNewFeatureUid, 200);
1.168 + TEST2(err, KErrNone);
1.169 + observer.SetExpected(EFeatureDataUpdated, KNewFeatureUid);
1.170 + CActiveScheduler::Start();
1.171 + //Enable the feature (it is already enabled) and check the notification
1.172 + err = ctrl.EnableFeature(KNewFeatureUid);
1.173 + TEST2(err, KErrNone);
1.174 + observer.SetExpected(EFeatureNoChange, KNewFeatureUid);//the feature is enabled - no status change
1.175 + CActiveScheduler::Start();
1.176 + //Disable the feature and check the notification
1.177 + err = ctrl.DisableFeature(KNewFeatureUid);
1.178 + TEST2(err, KErrNone);
1.179 + observer.SetExpected(EFeatureStatusUpdated, KNewFeatureUid);
1.180 + CActiveScheduler::Start();
1.181 + //Cancel notifications
1.182 + err = notifier->NotifyCancel(KNewFeatureUid);
1.183 + TEST2(err, KErrNone);
1.184 + err = notifier->NotifyCancel(KNewFeatureUid);
1.185 + TEST2(err, KErrNotFound);
1.186 + //Request notifications again
1.187 + err = notifier->NotifyRequest(KNewFeatureUid);
1.188 + TEST2(err, KErrNone);
1.189 + //Delete the feature and check the notification
1.190 + DeleteFeature(ctrl, KNewFeatureUid);
1.191 + observer.SetExpected(EFeatureFeatureDeleted, KNewFeatureUid);
1.192 + CActiveScheduler::Start();
1.193 + //Cleanup
1.194 + ctrl.Close();
1.195 + delete notifier;
1.196 + }
1.197 +
1.198 +/**
1.199 +@SYMTestCaseID PDS-FEATMGR-CT-????
1.200 +@SYMTestCaseDesc
1.201 +@SYMTestPriority High
1.202 +@SYMTestActions
1.203 +@SYMTestExpectedResults Test must not fail
1.204 +@SYMDEF DEF144262
1.205 +*/
1.206 +void NotificationsTest2()
1.207 + {
1.208 + TTestFeatureObserver observer;
1.209 + CFeatureNotifier* notifier = NULL;
1.210 + TRAPD(err, notifier = CFeatureNotifier::NewL(observer));
1.211 + TEST2(err, KErrNone);
1.212 +
1.213 + RFeatureControl ctrl;
1.214 + err = ctrl.Connect();
1.215 + TEST2(err, KErrNone);
1.216 + //Add two features
1.217 + AddFeature(ctrl, KNewFeatureUid);
1.218 + AddFeature(ctrl, KNewFeatureUid2);
1.219 + //Request notifications for the added features. One of them - duplicated in the array.
1.220 + RFeatureUidArray farray;
1.221 + err = farray.Append(KNewFeatureUid);
1.222 + TEST2(err, KErrNone);
1.223 + err = farray.Append(KNewFeatureUid2);
1.224 + TEST2(err, KErrNone);
1.225 + err = farray.Append(KNewFeatureUid);
1.226 + TEST2(err, KErrNone);
1.227 + //
1.228 + err = notifier->NotifyRequest(farray);
1.229 + TEST2(err, KErrNone);
1.230 + //Enable one of the features (already enabled) and check the notification
1.231 + err = ctrl.EnableFeature(KNewFeatureUid);
1.232 + TEST2(err, KErrNone);
1.233 + observer.SetExpected(EFeatureNoChange, KNewFeatureUid);//the feature is enabled - no status change
1.234 + CActiveScheduler::Start();
1.235 + //Disable the second feature and check the notification
1.236 + err = ctrl.DisableFeature(KNewFeatureUid2);
1.237 + TEST2(err, KErrNone);
1.238 + observer.SetExpected(EFeatureStatusUpdated, KNewFeatureUid2);
1.239 + CActiveScheduler::Start();
1.240 + //Cancel notifications for the second feature
1.241 + err = notifier->NotifyCancel(KNewFeatureUid2);
1.242 + TEST2(err, KErrNone);
1.243 + //Disable the first feature and check notification
1.244 + err = ctrl.DisableFeature(KNewFeatureUid);
1.245 + TEST2(err, KErrNone);
1.246 + observer.SetExpected(EFeatureStatusUpdated, KNewFeatureUid);
1.247 + CActiveScheduler::Start();
1.248 + //Cancel all notifications
1.249 + err = notifier->NotifyCancelAll();
1.250 + TEST2(err, KErrNone);
1.251 + err = notifier->NotifyCancelAll();
1.252 + TEST2(err, KErrNone);
1.253 + //Cleanup
1.254 + farray.Close();
1.255 + ctrl.Close();
1.256 + delete notifier;
1.257 + }
1.258 +
1.259 +void DoTestsL()
1.260 + {
1.261 + CActiveScheduler* scheduler = new CActiveScheduler;
1.262 + TEST(scheduler != NULL);
1.263 + CActiveScheduler::Install(scheduler);
1.264 +
1.265 + TheTest.Start(_L("@SYMTestCaseID:PDS-EFM-CT-4066 Notifications test 1"));
1.266 + NotificationsTest1();
1.267 +
1.268 + TheTest.Next(_L("@SYMTestCaseID:PDS-EFM-CT-4067 Notifications test 2"));
1.269 + NotificationsTest2();
1.270 +
1.271 + delete scheduler;
1.272 + }
1.273 +
1.274 +TInt E32Main()
1.275 + {
1.276 + TheTest.Title();
1.277 +
1.278 + CTrapCleanup* tc = CTrapCleanup::New();
1.279 + TheTest(tc != NULL);
1.280 +
1.281 + __UHEAP_MARK;
1.282 +
1.283 + TRAPD(err, DoTestsL());
1.284 + DestroyTestEnv();
1.285 + TEST2(err, KErrNone);
1.286 +
1.287 + __UHEAP_MARKEND;
1.288 +
1.289 + TheTest.End();
1.290 + TheTest.Close();
1.291 +
1.292 + delete tc;
1.293 +
1.294 + User::Heap().Check();
1.295 + return KErrNone;
1.296 + }