hswidgetmodel/tsrc/t_hswidgetmodelexe/src/testwidget.cpp
author Jaakko Haukipuro (Nokia-MS/Oulu) <Jaakko.Haukipuro@nokia.com>
Thu, 16 Sep 2010 12:11:40 +0100
changeset 117 c63ee96dbe5f
permissions -rw-r--r--
Missing activityfw and taskswitcher components - fix for Bug 3670

/*
* Copyright (c) 2008 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:  Tests for WidgetBase class.
*
*/


#include "testwidgetmodel.h"
#include "hswidget.h"
#include "hswidget_p.h"
#include "ihswidgetpreferenceservice.h"






void TestWidgetModel::testWidgetInterface()
{
    QGraphicsWidget parent;

    TestWidget3 *w = new TestWidget3(&parent);
    w->mStartResult = HsWidget::StartResultRunning;
    w->mStopResult = HsWidget::StopResultFinished;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    w->start();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->suspend();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->resume();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->stop();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 1);
    QCOMPARE(faultedSpy.count(), 0);
    stoppedSpy.clear();

    w->start();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->setFinishedState();

    QCOMPARE(succeededSpy.count(), 1);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);
    succeededSpy.clear();

    w->start();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->setFaultingState();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 0);

    w->setFaultedState();

    QCOMPARE(succeededSpy.count(), 0);
    QCOMPARE(stoppedSpy.count(), 0);
    QCOMPARE(faultedSpy.count(), 1);

    faultedSpy.clear();
}


void TestWidgetModel::testWidgetConstructor()
{
    {
        TestWidget w(0);
        QVERIFY(!w.widgetPreferenceService());
    }

    {
        HsWidget *parent = new TestWidget(0);
        QVERIFY(parent);
        HsWidget *child = new TestWidget(parent);
        QVERIFY(child);
        QVERIFY(child->parentItem() == parent);
        delete parent;
    }
}


void TestWidgetModel::testWidgetPreferenceService()
{
    QGraphicsWidget parent;

    HsWidget *w = new TestWidget(&parent);
    QObject invalid;
    w->setProperty("http://homescreen.nokia.com/runtimeservices/widgetpreferenceservice", qVariantFromValue(&invalid));
    QVERIFY(!w->widgetPreferenceService());

}


void TestWidgetModel::testWidgetStart_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("startResult");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Constructed -> Running")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidget::StartResultRunning
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Running")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidget::StartResultRunning
        << 0
        << 0
        << 0;

    // ---

    QTest::newRow("Constructed -> Finished")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StartResultFinished
        << 1
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StartResultFinished
        << 1
        << 0
        << 0;

    // ---

    QTest::newRow("Constructed -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 1;

    QTest::newRow("Finished -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 1;

    // ---

    QTest::newRow("Running -> Running")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Faulting -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finishing -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Suspended -> Suspended")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidget::StartResultFaulted
        << 0
        << 0
        << 0;
}


void TestWidgetModel::testWidgetStart()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
    QFETCH(int, startResult);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;
    w->mStartResult = (HsWidget::StartResult)startResult;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->start();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetSuspend_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("suspendResult");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Running -> Suspended")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidget::SuspendResultSuspended
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 1;

    QTest::newRow("Running -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::SuspendResultFaulting
        << 0
        << 0
        << 0;

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Faulting -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finishing -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Suspended -> Suspended")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidget::SuspendResultFaulted
        << 0
        << 0
        << 0;
}


void TestWidgetModel::testWidgetSuspend()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
    QFETCH(int, suspendResult);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;
    w->mSuspendResult = (HsWidget::SuspendResult)suspendResult;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->suspend();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetResume_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("resumeResult");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Suspended -> Running")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidget::ResumeResultRunning
        << 0
        << 0
        << 0;

    QTest::newRow("Suspended -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 1;

    QTest::newRow("Suspended -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::ResumeResultFaulting
        << 0
        << 0
        << 0;

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Running")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Faulting -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finishing -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::ResumeResultFaulted
        << 0
        << 0
        << 0;
}


void TestWidgetModel::testWidgetResume()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
    QFETCH(int, resumeResult);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;
    w->mResumeResult = (HsWidget::ResumeResult)resumeResult;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->resume();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetStop_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("stopResult");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Running -> Finished")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StopResultFinished
        << 0
        << 1
        << 0;

    QTest::newRow("Running -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::StopResultFinishing
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 1;

    QTest::newRow("Running -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::StopResultFaulting
        << 0
        << 0
        << 0;

    // ---

    QTest::newRow("Suspended -> Finished")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StopResultFinished
        << 0
        << 1
        << 0;

    QTest::newRow("Suspended -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::StopResultFinishing
        << 0
        << 0
        << 0;

    QTest::newRow("Suspended -> Faulted")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 1;

    QTest::newRow("Suspended -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::StopResultFaulting
        << 0
        << 0
        << 0;

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Faulting -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 0;

    QTest::newRow("Finishing -> Finishing")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidget::StopResultFaulted
        << 0
        << 0
        << 0;
}


void TestWidgetModel::testWidgetStop()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
    QFETCH(int, stopResult);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;
    w->mStopResult = (HsWidget::StopResult)stopResult;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->stop();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetSetFinished_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Finished")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 1
        << 0
        << 0;

    QTest::newRow("Suspended -> Finished")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 1
        << 0
        << 0;

    QTest::newRow("Finishing -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 1
        << 0;

    QTest::newRow("Faulting -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 1;
}


void TestWidgetModel::testWidgetSetFinished()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->setFinished();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetSetFaulted_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Finished")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 1;

    QTest::newRow("Suspended -> Finished")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 1;

    QTest::newRow("Finishing -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 1;

    QTest::newRow("Faulting -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 1;
}


void TestWidgetModel::testWidgetSetFaulted()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->setFaulted();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}


void TestWidgetModel::testWidgetSetFaulting_data()
{
    QTest::addColumn<int>("fromState");
    QTest::addColumn<int>("toState");
    QTest::addColumn<int>("succeededEmitCount");
    QTest::addColumn<int>("stoppedEmitCount");
    QTest::addColumn<int>("faultedEmitCount");

    // ---

    QTest::newRow("Constructed -> Constructed")
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << (int)HsWidgetPrivate::WidgetStateConstructed
        << 0
        << 0
        << 0;

    QTest::newRow("Finished -> Finished")
        << (int)HsWidgetPrivate::WidgetStateFinished
        << (int)HsWidgetPrivate::WidgetStateFinished
        << 0
        << 0
        << 0;

    QTest::newRow("Faulting -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << 0
        << 0
        << 0;

    QTest::newRow("Running -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateRunning
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << 0
        << 0
        << 0;

    QTest::newRow("Suspended -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateSuspended
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << 0
        << 0
        << 0;

    QTest::newRow("Finishing -> Faulting")
        << (int)HsWidgetPrivate::WidgetStateFinishing
        << (int)HsWidgetPrivate::WidgetStateFaulting
        << 0
        << 0
        << 0;
}


void TestWidgetModel::testWidgetSetFaulting()
{
    QFETCH(int, fromState);
    QFETCH(int, toState);
	QFETCH(int, succeededEmitCount);
    QFETCH(int, stoppedEmitCount);
	QFETCH(int, faultedEmitCount);

    TestWidget* w = new TestWidget();
    HsWidgetPrivate *wp = new HsWidgetPrivate(w);

    wp->mState = (HsWidgetPrivate::WidgetState)fromState;

    QSignalSpy succeededSpy(w, SIGNAL(succeeded()));
    QSignalSpy stoppedSpy(w, SIGNAL(stopped()));
    QSignalSpy faultedSpy(w, SIGNAL(faulted()));

    wp->setFaulting();

    QVERIFY(wp->mState == toState);
    QCOMPARE(succeededSpy.count(), succeededEmitCount);
    QCOMPARE(stoppedSpy.count(), stoppedEmitCount);
    QCOMPARE(faultedSpy.count(), faultedEmitCount);

    delete w;
}