Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / unittests / common / MafwStubHelper.h
1 /* 
2  * This file is part of QMAFW 
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
5  * reserved.
6  *
7  * Contact: Visa Smolander <visa.smolander@nokia.com>
8  *
9  * This software, including documentation, is protected by copyright controlled
10  * by Nokia Corporation. All rights are reserved. Copying, including
11  * reproducing, storing, adapting or translating, any or all of this material
12  * requires the prior written consent of Nokia Corporation. This material also
13  * contains confidential information which may not be disclosed to others
14  * without the prior written consent of Nokia.
15  *
16  */
17
18 #ifndef MAFWSTUBHELPER_H_
19 #define MAFWSTUBHELPER_H_
20
21 #include <QQueue>
22 #include <QList>
23 #include <QMultiMap>
24 #include <QString>
25 #include <QVariant>
26
27 /**
28  * This class is meant to help implementing stubs needed in unit testing. 
29  * 
30  * Usage: Create instance of MafwStubHelper and provide your stub access 
31  * to it. Initialize MafwStubHelper with function calls the stub is 
32  * expected to get. Implement your stub to ask for return values from 
33  * MafwStubHelper. At the end of a test case, check if all expected
34  * calls are consumed. 
35  */
36
37
38 class MafwStubHelper
39 {
40 public:
41         MafwStubHelper();
42         ~MafwStubHelper();
43         
44         /**
45          * expect - Adds call to expected calls
46          * 
47          * @param  function  Name of the expected function call, without paranthesis.
48          * @param  params    List of expected parameters given to function call.
49          * @param  returns   List of return values to be given to the stub.
50          */
51         void expect(const QString function, const QList<QVariant> params, const QList<QVariant> returns);
52         
53         /**
54      * expect - Adds call to expected calls
55      * 
56      * @param  function  Name of the expected function call, without paranthesis.
57      * @param  returnVal The return value to be given to the stub.
58      */
59         void expect(const QString& function, QVariant returnVal);
60         
61         /**
62          * getReturn - Consumes call from expected calls
63          * 
64          * @param  function  Name of the function call, without paranthesis.
65          * @param  params    List of parameters given to function call.
66          * @param  returns   Empty list for getting the return values.
67          *                                       List is empty at return if function wasn't the next expected function call.
68          */
69         void getReturn(const QString function, const QList<QVariant> params, QList<QVariant>& returns);
70         
71         /**
72      * getReturn - Consumes call from expected calls
73      * 
74      * @param  function  Name of the function call, without paranthesis.
75      * @return return value is invalid if function wasn't the next expected function call.
76      */
77         QVariant getReturn(const QString& function);
78         
79         /**
80          * allCallsConsumed - Checks if all expected calls are consumed
81          * 
82          * @return true, if all expected calls are consumed
83          *         false otherwise.
84          */
85         bool allCallsConsumed() const;
86
87         /**
88          * clear - Clears all data
89          */
90         void clear();
91
92 private:
93         void printExpects() const;
94
95         
96 private:
97         
98         struct ExpectedItem
99         {
100                 QString expectedName;
101                 QList<QVariant> expectedParams;
102                 QList<QVariant> returnValues;
103         };
104         
105         QQueue<ExpectedItem*> m_expectedCalls;
106 };
107
108 #endif /*MAFWSTUBHELPER_H_*/