--- /dev/null
+/*
+ * This file is part of QMAFW
+ *
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
+ * reserved.
+ *
+ * Contact: Visa Smolander <visa.smolander@nokia.com>
+ *
+ * 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 <QDebug>
+#include <QStringList>
+
+#include "MafwStubHelper.h"
+
+MafwStubHelper::MafwStubHelper()
+{
+ m_expectedCalls = QQueue<ExpectedItem*>();
+}
+
+MafwStubHelper::~MafwStubHelper()
+{
+ clear();
+}
+
+void MafwStubHelper::printExpects() const
+{
+ QStringList expectedNames;
+ for(int i=0; i<m_expectedCalls.size(); i++ )
+ {
+ expectedNames << m_expectedCalls[i]->expectedName;
+ }
+ qDebug() << "Expected calls enqueued (" << m_expectedCalls.size() << "): \n\t" << expectedNames.join(",\n\t ");
+}
+
+void MafwStubHelper::expect(const QString& function, QVariant returnVal)
+{
+ QList<QVariant> emptyParams;
+ QList<QVariant> returnList;
+ returnList << returnVal;
+ expect(function, emptyParams, returnList);
+}
+
+
+void MafwStubHelper::expect(const QString function, const QList<QVariant> params,
+ const QList<QVariant> 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<QVariant> emptyParams;
+ QList<QVariant> returnList;
+ getReturn(function, emptyParams, returnList);
+ if (returnList.isEmpty())
+ {
+ return QVariant();
+ }
+ else
+ {
+ return returnList.first();
+ }
+}
+
+void MafwStubHelper::getReturn(const QString function, const QList<QVariant> params,
+ QList<QVariant>& 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