camerauis/cameraxui/cxengine/tsrc/unit/utils/cxetestutils.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     1 /*
       
     2 * Copyright (c) 2009 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 <QSignalSpy>
       
    19 #include <QTest>
       
    20 
       
    21 #include "cxetestutils.h"
       
    22 
       
    23 /*!
       
    24 * Wait for a signal (or multiple instances of the same signal) to be caught
       
    25 * by signal spy. Returns false if signal is not received within the given
       
    26 * timeout.
       
    27 *
       
    28 * @param spy               Signal spy attached to the signal to wait for.
       
    29 * @param ms                Timeout in milliseconds
       
    30 * @param count             How many instances of the signal to wait for
       
    31 *                          (default 1)
       
    32 * @param allowExtraSignals True to ignore any extranous signal. Setting
       
    33 *                          this as false will cause this function to return
       
    34 *                          false the spy receives more signals than received
       
    35 * @return       True if signal(s) were received, false if timed out or
       
    36 *               signal spy was invalid.
       
    37 */
       
    38 bool CxeTestUtils::waitForSignal(
       
    39     QSignalSpy &spy, int ms, int count, bool allowExtraSignals)
       
    40 {
       
    41     int waitingTime = 0;
       
    42 
       
    43     if (spy.isValid()) {
       
    44         while (spy.count() < count && waitingTime < ms) {
       
    45             QTest::qWait(CXE_TEST_POLL_TIME);
       
    46             waitingTime += CXE_TEST_POLL_TIME;
       
    47         }
       
    48         if (spy.count() > count && !allowExtraSignals) {
       
    49             CX_DEBUG(("waitForSignal() - got too many signals for %s, count = %d",
       
    50                       spy.signal().constData(), spy.count()));
       
    51             return false;
       
    52         } else if (spy.count() >= count) {
       
    53             CX_DEBUG(("waitForSignal() - got signal %s successfully, count = %d",
       
    54                       spy.signal().constData(), spy.count()));
       
    55             return true;
       
    56         } else {
       
    57             CX_DEBUG(("waitForSignal() - signal %s timed out, waitingTime = %d",
       
    58                       spy.signal().constData(), waitingTime));
       
    59             return false;
       
    60         }
       
    61     } else {
       
    62         CX_DEBUG(("waitForSignal() - given signalspy is not valid!"));
       
    63         return false;
       
    64     }
       
    65 }