Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / common / MafwStubHelper.h
diff --git a/qmafw-gst-subtitles-renderer/unittests/common/MafwStubHelper.h b/qmafw-gst-subtitles-renderer/unittests/common/MafwStubHelper.h
new file mode 100644 (file)
index 0000000..87a6871
--- /dev/null
@@ -0,0 +1,108 @@
+/* 
+ * 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.
+ *
+ */
+
+#ifndef MAFWSTUBHELPER_H_
+#define MAFWSTUBHELPER_H_
+
+#include <QQueue>
+#include <QList>
+#include <QMultiMap>
+#include <QString>
+#include <QVariant>
+
+/**
+ * This class is meant to help implementing stubs needed in unit testing. 
+ * 
+ * Usage: Create instance of MafwStubHelper and provide your stub access 
+ * to it. Initialize MafwStubHelper with function calls the stub is 
+ * expected to get. Implement your stub to ask for return values from 
+ * MafwStubHelper. At the end of a test case, check if all expected
+ * calls are consumed. 
+ */
+
+
+class MafwStubHelper
+{
+public:
+       MafwStubHelper();
+       ~MafwStubHelper();
+       
+       /**
+        * expect - Adds call to expected calls
+        * 
+        * @param  function  Name of the expected function call, without paranthesis.
+        * @param  params    List of expected parameters given to function call.
+        * @param  returns   List of return values to be given to the stub.
+        */
+       void expect(const QString function, const QList<QVariant> params, const QList<QVariant> returns);
+       
+       /**
+     * expect - Adds call to expected calls
+     * 
+     * @param  function  Name of the expected function call, without paranthesis.
+     * @param  returnVal The return value to be given to the stub.
+     */
+       void expect(const QString& function, QVariant returnVal);
+       
+       /**
+        * getReturn - Consumes call from expected calls
+        * 
+        * @param  function  Name of the function call, without paranthesis.
+        * @param  params    List of parameters given to function call.
+        * @param  returns   Empty list for getting the return values.
+        *                                       List is empty at return if function wasn't the next expected function call.
+        */
+       void getReturn(const QString function, const QList<QVariant> params, QList<QVariant>& returns);
+       
+       /**
+     * getReturn - Consumes call from expected calls
+     * 
+     * @param  function  Name of the function call, without paranthesis.
+     * @return return value is invalid if function wasn't the next expected function call.
+     */
+       QVariant getReturn(const QString& function);
+       
+       /**
+        * allCallsConsumed - Checks if all expected calls are consumed
+        * 
+        * @return true, if all expected calls are consumed
+        *         false otherwise.
+        */
+       bool allCallsConsumed() const;
+
+       /**
+        * clear - Clears all data
+        */
+       void clear();
+
+private:
+        void printExpects() const;
+
+       
+private:
+       
+       struct ExpectedItem
+       {
+               QString expectedName;
+               QList<QVariant> expectedParams;
+               QList<QVariant> returnValues;
+       };
+       
+       QQueue<ExpectedItem*> m_expectedCalls;
+};
+
+#endif /*MAFWSTUBHELPER_H_*/