X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=qmafw-gst-subtitles-renderer%2Funittests%2Fcommon%2FMafwStubHelper.cpp;fp=qmafw-gst-subtitles-renderer%2Funittests%2Fcommon%2FMafwStubHelper.cpp;h=9e2d4fa117dff8bf343d0bb0490d27e49d3f818d;hb=226d35244df85a27c332d3a3ded1b25b3c7f4951;hp=0000000000000000000000000000000000000000;hpb=57ba96e291a055f69dbfd4ae9f1ae2390e36986e;p=mafwsubrenderer diff --git a/qmafw-gst-subtitles-renderer/unittests/common/MafwStubHelper.cpp b/qmafw-gst-subtitles-renderer/unittests/common/MafwStubHelper.cpp new file mode 100644 index 0000000..9e2d4fa --- /dev/null +++ b/qmafw-gst-subtitles-renderer/unittests/common/MafwStubHelper.cpp @@ -0,0 +1,140 @@ +/* + * This file is part of QMAFW + * + * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights + * reserved. + * + * Contact: Visa Smolander + * + * This software, including documentation, is protected by copyright controlled + * by Nokia Corporation. All rights are reserved. Copying, including + * reproducing, storing, adapting or translating, any or all of this material + * requires the prior written consent of Nokia Corporation. This material also + * contains confidential information which may not be disclosed to others + * without the prior written consent of Nokia. + * + */ + + +#include +#include + +#include "MafwStubHelper.h" + +MafwStubHelper::MafwStubHelper() +{ + m_expectedCalls = QQueue(); +} + +MafwStubHelper::~MafwStubHelper() +{ + clear(); +} + +void MafwStubHelper::printExpects() const +{ + QStringList expectedNames; + for(int i=0; iexpectedName; + } + qDebug() << "Expected calls enqueued (" << m_expectedCalls.size() << "): \n\t" << expectedNames.join(",\n\t "); +} + +void MafwStubHelper::expect(const QString& function, QVariant returnVal) +{ + QList emptyParams; + QList returnList; + returnList << returnVal; + expect(function, emptyParams, returnList); +} + + +void MafwStubHelper::expect(const QString function, const QList params, + const QList returns) +{ + qDebug() << "MafwStubHelper::expect, function = " << function << " " << returns.at(0); + + ExpectedItem* item = new ExpectedItem; + item->expectedName = function; + item->expectedParams = params; + item->returnValues = returns; + m_expectedCalls.enqueue(item); +} + +QVariant MafwStubHelper::getReturn(const QString& function) +{ + QList emptyParams; + QList returnList; + getReturn(function, emptyParams, returnList); + if (returnList.isEmpty()) + { + return QVariant(); + } + else + { + return returnList.first(); + } +} + +void MafwStubHelper::getReturn(const QString function, const QList params, + QList& returns) +{ + // Check if the call is expected + if ( m_expectedCalls.isEmpty() ) + { + qDebug() << "MafwStubHelper::getReturn, function = " << function <<", no expected calls"; + return; + } + if (!m_expectedCalls.isEmpty() && function.compare(m_expectedCalls.head()->expectedName)) + { + qDebug() << "MafwStubHelper::getReturn: " << function << ", not expected (2)"; + printExpects(); + return; + } + ExpectedItem* item = m_expectedCalls.dequeue(); + + // Check if the parameters match + if (!item->expectedParams.isEmpty()) + { + for (int i = 0; i < item->expectedParams.count() && item->expectedParams.count() == params.count(); ++i) + { + if (item->expectedParams.at(i) != params.at(i)) + { + qDebug() << "MafwStubHelper::getReturn: " << function <<", not expected (2)"; + return; + } + } + } + // Expected parameters list was empty but given was not + else if (!params.isEmpty()) + { + qDebug() << "MafwStubHelper::getReturn: " << function <<", not expected (3)"; + return; + } + else + { + } + + // Everything ok, let's find the return values + returns = item->returnValues; + + qDebug() << "MafwStubHelper::getReturn, function: " << function << ", returns: " << returns; + + delete item; +} + +bool MafwStubHelper::allCallsConsumed() const +{ + return m_expectedCalls.isEmpty(); +} + +void MafwStubHelper::clear() +{ + qDebug() << "MafwStubHelper::clear()"; + + qDeleteAll(m_expectedCalls); + m_expectedCalls.clear(); +} + +// End of file