homescreenapp/serviceproviders/hsmenuserviceprovider/tsrc/t_hsmenuserviceprovider/src/t_hsmenuentryremovedhandler.cpp
changeset 90 3ac3aaebaee5
child 97 66b5fe3c07fd
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
       
     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 #include <QtGlobal>
       
    19 #include <QSignalSpy>
       
    20  
       
    21 #include "t_hsmenuserviceprovider.h"
       
    22 #include "hsmenuentryremovedhandler.h"
       
    23 #include "t_hsmenuentryremovedcallback.h"
       
    24 #include <cadefs.h>
       
    25 #include "caservice.h"
       
    26 #include "canotifier.h"
       
    27 #include "canotifierfilter.h"
       
    28 
       
    29 
       
    30      
       
    31 void MenuServiceTest::HsMenuEntryRemovedHandlerTest_data()
       
    32 {
       
    33     // define testing data table
       
    34     QTest::addColumn<int>("subscribedId");
       
    35     QTest::addColumn<int>("notifiedChangeType");
       
    36     QTest::addColumn<int>("notificationsCount");
       
    37     QTest::addColumn<int>("callbacksCount");
       
    38     // prepare concrete rows for testing
       
    39     //                                             id   changeType                  
       
    40     QTest::newRow("non_matching_id") << 0 << static_cast<int>(RemoveChangeType) << 1 << 0;
       
    41     
       
    42     QTest::newRow("non_matching_change_type") << 1 << static_cast<int>(AddChangeType) << 1 << 0;
       
    43                                                  
       
    44     QTest::newRow("many_notifications") << 1 << static_cast<int>(RemoveChangeType) << 3  << 1;
       
    45                                                  
       
    46     QTest::newRow("one_notification") << 1 << static_cast<int>(RemoveChangeType) << 1 << 1;
       
    47                                                  
       
    48     QTest::newRow("no_notification") << 1 << static_cast<int>(RemoveChangeType) << 0 << 0;
       
    49 }
       
    50 
       
    51 void MenuServiceTest::HsMenuEntryRemovedHandlerTest()
       
    52 {
       
    53     QFETCH(int, subscribedId);
       
    54     QFETCH(int, notifiedChangeType);
       
    55     QFETCH(int, notificationsCount);
       
    56     QFETCH(int, callbacksCount);
       
    57     
       
    58     QPointer<CaNotifier> caNotifierMock(new CaNotifier());
       
    59     CaService::instance()->mCreateNotifierResult = caNotifierMock.data();
       
    60     
       
    61     T_HsMenuEntryRemovedCallback callbackObj;
       
    62     HsMenuEntryRemovedHandler handler(subscribedId, &callbackObj, SLOT(callback()));
       
    63     
       
    64     QSignalSpy spy(&handler, SIGNAL(notify()));
       
    65     
       
    66     for (int i = 0 ; i < notificationsCount && !caNotifierMock.isNull(); ++i) {
       
    67         caNotifierMock->issueEntryChanged(subscribedId, 
       
    68             static_cast<ChangeType>(notifiedChangeType));
       
    69         qApp->processEvents();
       
    70     }
       
    71     
       
    72     QCOMPARE(callbackObj.callsCount(), callbacksCount);
       
    73     QCOMPARE(spy.count(), callbackObj.callsCount());
       
    74 }