/**
 * Verify screen blank override behavior.
 */
void PowerManagementTest::testScreenBlank4()
{
    // Unblank to make sure we notice going into blank
    UNBLANK_SCREEN;
    QTest::qWait(1000);

    AccelerometerSensorChannelInterface* accOne = AccelerometerSensorChannelInterface::interface("accelerometersensor");
    QVERIFY2(accOne != NULL && accOne->isValid(), accOne ? accOne->errorString().toLatin1() : "Null pointer");

    connect(accOne, SIGNAL(dataAvailable(const XYZ&)), &helper, SLOT(dataAvailable(const XYZ&)));

    accOne->setStandbyOverride(true);
    accOne->start();

    QTest::qWait(1000);
    QVERIFY2(helper.m_valueCount > 0, "No samples received.");

    // Blank screen
    BLANK_SCREEN;
    QTest::qWait(1000);
    helper.reset(); // Clear the buffer
    QTest::qWait(1000);

    // Verify that values have not come through
    QVERIFY2(helper.m_valueCount >  0, "Adaptor apparently went to standby against rules");

    // Unblank
    UNBLANK_SCREEN;
    QTest::qWait(1000);

    // Reset - in testing the old value might stay in the fakepipe.
    helper.reset();

    // Verity that values comes through again
    QTest::qWait(1000);
    QVERIFY2(helper.m_valueCount > 0, "Not getting values after resume.");

    accOne->stop();

    delete accOne;
}
/**
 * Verify standby override for screen blank and unblank.
 */
void StandbyOverrideTest::testStandbyOverride()
{

    UNBLANK_SCREEN;

    AccelerometerSensorChannelInterface* accOne = AccelerometerSensorChannelInterface::interface("accelerometersensor");
    QVERIFY2(accOne != NULL && accOne->isValid(), accOne ? accOne->errorString().toLatin1() : "Null pointer");

    AccelerometerSensorChannelInterface* accTwo = AccelerometerSensorChannelInterface::interface("accelerometersensor");
    QVERIFY2(accTwo != NULL && accTwo->isValid(), accTwo ? accTwo->errorString().toLatin1() : "Null pointer");

    connect(accOne, SIGNAL(dataAvailable(const XYZ&)), &helper1, SLOT(dataAvailable(const XYZ&)));
    connect(accTwo, SIGNAL(dataAvailable(const XYZ&)), &helper2, SLOT(dataAvailable(const XYZ&)));

    accOne->start();
    accTwo->start();

    QTest::qWait(500);

    // Test standby override true when screen unblank
    accOne->setStandbyOverride(true);
    accTwo->setStandbyOverride(false);
    QTest::qWait(500);
    helper1.reset();  // Clear the buffer
    helper2.reset();
    QTest::qWait(1500);

    QVERIFY2(helper1.m_valueCount > 0, "No samples received.");
    QVERIFY2(helper2.m_valueCount > 0, "No samples received.");

    accOne->setStandbyOverride(false);
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(1500);
    QVERIFY2(helper1.m_valueCount > 0, "No samples received.");
    QVERIFY2(helper2.m_valueCount > 0, "No samples received.");

    // Test standby override when screen blank
    BLANK_SCREEN;
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(1500);

    QVERIFY2(helper1.m_valueCount == 0, "Samples leaking through.");
    QVERIFY2(helper2.m_valueCount == 0, "Samples leaking through.");

    accOne->setStandbyOverride(true);
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(1500);

    QVERIFY2(helper1.m_valueCount > 0, "No samples received.");
    QVERIFY2(helper2.m_valueCount > 0, "No samples received.");

    accOne->setStandbyOverride(false);
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(500);
    QVERIFY2(helper1.m_valueCount == 0, "Samples leaking through.");
    QVERIFY2(helper2.m_valueCount == 0, "Samples leaking through.");

    accOne->setStandbyOverride(true);
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(1500);
    QVERIFY2(helper1.m_valueCount > 0, "No samples received.");
    QVERIFY2(helper2.m_valueCount > 0, "No samples received.");

    accOne->stop();
    QTest::qWait(500);
    helper1.reset();
    helper2.reset();
    QTest::qWait(1500);
    QVERIFY2(helper1.m_valueCount == 0, "Samples leaking through.");
    QVERIFY2(helper2.m_valueCount == 0, "Samples leaking through.");

    accTwo->stop();

    delete accOne;
    delete accTwo;
}