diff -r adb51f74b890 -r 72c709219fcd mediasettings/videosettingsplugin/tsrc/testaccesspointentry/src/testaccesspointentry.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mediasettings/videosettingsplugin/tsrc/testaccesspointentry/src/testaccesspointentry.cpp Fri Oct 15 16:29:10 2010 +0300 @@ -0,0 +1,250 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: TestAccessPointEntry class implementation +* +*/ + +// INCLUDE FILES +#include +#include +#include + + +#include "stub/inc/cpitemdatahelper.h" +#include "stub/inc/cpsettingformentryitemdata.h" +#include "stub/inc/cmapplsettingsui.h" +#include "stub/inc/cmconnectionmethod_shim.h" +#include "stub/inc/cmmanager_shim.h" +#include "stub/inc/videosettingsgroup.h" + +#include "testaccesspointentry.h" +#include "videosettingsgroup.h" +#include "cmmanager_shim.h" +#include "cmconnectionmethod_shim.h" + +// trick to get access to protected/private members. +#define private public +#include "videosettingsaccesspointentry.h" +#undef private + +// --------------------------------------------------------------------------- +// initTestCase +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::initTestCase() +{ + mItemHelper = new CpItemDataHelper; + mGroup = new VideoSettingsGroup(*mItemHelper); +} + +// --------------------------------------------------------------------------- +// cleanupTestCase +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::cleanupTestCase() +{ + delete mGroup; + mGroup = 0; + delete mItemHelper; + mItemHelper = 0; +} + +// --------------------------------------------------------------------------- +// init +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::init() +{ + mTestObject = new VideoSettingsAccessPointEntry(*mItemHelper, QString("test"), mGroup); +} + +// --------------------------------------------------------------------------- +// cleanup +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::cleanup() +{ + delete mTestObject; + mTestObject = 0; +} + +// --------------------------------------------------------------------------- +// testConstructor +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testConstructor() +{ + // verify clicked signal connection. + ConnectionHolder connection = mItemHelper->mConnections[mTestObject]; + QCOMPARE( connection.signal, SIGNAL(clicked()) ); + QVERIFY( connection.receiver == mTestObject ); + QCOMPARE( connection.method, SLOT(openSelectionDialogSlot()) ); + + // verify mApplSettings construction + QVERIFY( mTestObject->mApplSettings ); + QVERIFY( disconnect(mTestObject->mApplSettings, SIGNAL(finished(uint)), mTestObject, SLOT(accessPointDialogFinished(uint))) ); + connect(mTestObject->mApplSettings, SIGNAL(finished(uint)), mTestObject, SLOT(accessPointDialogFinished(uint))); + + // verify mSelection initial values + QVERIFY( mTestObject->mSelection.result == CmApplSettingsUi::SelectionTypeConnectionMethod ); + QVERIFY( mTestObject->mSelection.id == 0 ); + + // verify CmManagerShim construction + QVERIFY( mTestObject->mCmManager ); + + // verify base class 'construction' + QCOMPARE( mTestObject->mText, QString("test") ); + QVERIFY( mTestObject->mDescription.isNull() ); +} + +// --------------------------------------------------------------------------- +// testConstructor +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testDestructor() +{ + CmManagerShim::mDestructorCount = 0; + cleanup(); + QCOMPARE( CmManagerShim::mDestructorCount, 1 ); +} + +// --------------------------------------------------------------------------- +// testSetIapId +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testSetIapId() +{ + // with empty cmArray + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); + + // with non-empty cmArray, but id is not found. + mTestObject->mCmManager->mConnectionMethods[0] = new CmConnectionMethodShim(0, 4, QString("0")); + mTestObject->mCmManager->mConnectionMethods[2] = new CmConnectionMethodShim(2, 6, QString("2")); + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); + + // with non-empty cmArray, and id is found, but CmManagerShim throws at that id. + mTestObject->mCmManager->mConnectionMethods[1] = new CmConnectionMethodShim(1, 5, QString("1")); + CmManagerShim::mConnectionMethodThrowsAtId = 1; + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, hbTrId("txt_videos_dblist_none") ); + + // with non-empty cmArray, and id is found. + CmManagerShim::mConnectionMethodThrowsAtId = -1; + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, QString("1") ); + + // with non-empty cmArray, and id is found, but CmManagerShim throws at id before. + CmManagerShim::mConnectionMethodThrowsAtId = 0; + mTestObject->mDescription = QString(); + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, QString("1") ); + + // with non-empty cmArray, and id is found, but CmManagerShim throws at id after. + CmManagerShim::mConnectionMethodThrowsAtId = 2; + mTestObject->mDescription = QString(); + mTestObject->setIapId(5); + QCOMPARE( mTestObject->mDescription, QString("1") ); +} + +// --------------------------------------------------------------------------- +// testCreateSettingView +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testCreateSettingView() +{ + QVERIFY(mTestObject->callCreateSettingView() == 0 ); +} + +// --------------------------------------------------------------------------- +// testOpenSelectionDialogSlot +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testOpenSelectionDialogSlot() +{ + connect(this, SIGNAL(testSignal()), mTestObject, SLOT(openSelectionDialogSlot())); + QSet filter; + filter.insert(1); + mTestObject->mApplSettings->mListItems = QFlags(); + mTestObject->mApplSettings->mBearerTypeFilter = filter; + mTestObject->mApplSettings->mOpenCallAmount = 0; + + emit testSignal(); + + QVERIFY( mTestObject->mApplSettings->mListItems.testFlag(CmApplSettingsUi::ShowConnectionMethods) ); + QVERIFY( mTestObject->mApplSettings->mListItems.testFlag(CmApplSettingsUi::ShowDestinations) == false); + QCOMPARE( mTestObject->mApplSettings->mBearerTypeFilter.count(), 0); + QVERIFY( mTestObject->mApplSettings->mSelection.result == CmApplSettingsUi::SelectionTypeConnectionMethod ); + QCOMPARE( mTestObject->mApplSettings->mOpenCallAmount, 1 ); +} + +// --------------------------------------------------------------------------- +// testAccessPointDialogFinished +// --------------------------------------------------------------------------- +// +void TestAccessPointEntry::testAccessPointDialogFinished() +{ + // error + mTestObject->mApplSettings->mSelection.id = 5; + mTestObject->mSelection.id = 0; + mTestObject->mDescription = QString(); + mGroup->mApId = 0; + + mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorCancel); + + QCOMPARE( mTestObject->mSelection.id, (uint)0 ); + + // no error + mTestObject->mDescription = QString(); + mTestObject->mCmManager->mConnectionMethods[5] = new CmConnectionMethodShim(5, 4, QString("5")); + + mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); + + QCOMPARE( mTestObject->mSelection.id, mTestObject->mApplSettings->mSelection.id ); + QCOMPARE( mGroup->mApId, (uint)4 ); + QCOMPARE( mTestObject->mDescription, QString("5") ); + + // no error, but CmManagerShim throws at that id. + mTestObject->mSelection.id = 0; + mTestObject->mDescription = QString(); + mGroup->mApId = 0; + CmManagerShim::mConnectionMethodThrowsAtId = 5; + + mTestObject->mApplSettings->emitFinished(CmApplSettingsUi::ApplSettingsErrorNone); + + QCOMPARE( mTestObject->mSelection.id, (uint)0 ); + QCOMPARE( mGroup->mApId, (uint)0 ); + QVERIFY( mTestObject->mDescription.isNull() ); +} + +// --------------------------------------------------------------------------- +// main +// --------------------------------------------------------------------------- +// +int main(int argc, char *argv[]) +{ + HbApplication app(argc, argv); + + TestAccessPointEntry tc; + + char *pass[3]; + pass[0] = argv[0]; + pass[1] = "-o"; + pass[2] = "c:\\data\\TestAccessPointEntry.txt"; + + return QTest::qExec(&tc, 3, pass); +} + +// end of file