~mterry/qtmir/warn-on-xapp

« back to all changes in this revision

Viewing changes to tests/modules/common/mock_desktop_file_reader.h

  • Committer: Gerry Boland
  • Date: 2014-07-01 13:38:06 UTC
  • mto: This revision was merged to the branch mainline in revision 158.
  • Revision ID: gerry.boland@canonical.com-20140701133806-lwfnplkijthydzj4
Update QML plugin: rename to Unity.Application, merge latest unity-mir changes, add tests (not passing yet) and use category logging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License version 3, as published by
 
6
 * the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
#ifndef MOCK_DESKTOP_FILE_READER_H
 
19
#define MOCK_DESKTOP_FILE_READER_H
 
20
 
 
21
#include <Unity/Application/desktopfilereader.h>
 
22
 
 
23
#include <gmock/gmock.h>
 
24
 
 
25
namespace testing
 
26
{
 
27
struct MockDesktopFileReader : public qtmir::DesktopFileReader
 
28
{
 
29
    MockDesktopFileReader(const QString &appId, const QFileInfo& fileInfo)
 
30
        : DesktopFileReader(appId, fileInfo)
 
31
    {
 
32
        using namespace ::testing;
 
33
 
 
34
        ON_CALL(*this, file()).WillByDefault(Invoke(this, &MockDesktopFileReader::doFile));
 
35
        ON_CALL(*this, appId()).WillByDefault(Invoke(this, &MockDesktopFileReader::doAppId));
 
36
        ON_CALL(*this, name()).WillByDefault(Invoke(this, &MockDesktopFileReader::doName));
 
37
        ON_CALL(*this, comment()).WillByDefault(Invoke(this, &MockDesktopFileReader::doComment));
 
38
        ON_CALL(*this, icon()).WillByDefault(Invoke(this, &MockDesktopFileReader::doIcon));
 
39
        ON_CALL(*this, exec()).WillByDefault(Invoke(this, &MockDesktopFileReader::doExec));
 
40
        ON_CALL(*this, path()).WillByDefault(Invoke(this, &MockDesktopFileReader::doPath));
 
41
        ON_CALL(*this, stageHint()).WillByDefault(Invoke(this, &MockDesktopFileReader::doStageHint));
 
42
        ON_CALL(*this, loaded()).WillByDefault(Invoke(this, &MockDesktopFileReader::doLoaded));
 
43
    }
 
44
 
 
45
    MOCK_CONST_METHOD0(file, QString());
 
46
    MOCK_CONST_METHOD0(appId, QString ());
 
47
    MOCK_CONST_METHOD0(name, QString());
 
48
    MOCK_CONST_METHOD0(comment, QString());
 
49
    MOCK_CONST_METHOD0(icon, QString());
 
50
    MOCK_CONST_METHOD0(exec, QString());
 
51
    MOCK_CONST_METHOD0(path, QString());
 
52
    MOCK_CONST_METHOD0(stageHint, QString());
 
53
    MOCK_CONST_METHOD0(loaded, bool());
 
54
 
 
55
    QString doFile() const
 
56
    {
 
57
        return DesktopFileReader::file();
 
58
    }
 
59
 
 
60
    QString doAppId() const
 
61
    {
 
62
        return DesktopFileReader::appId();
 
63
    }
 
64
 
 
65
    QString doName() const
 
66
    {
 
67
        return DesktopFileReader::name();
 
68
    }
 
69
 
 
70
    QString doComment() const
 
71
    {
 
72
        return DesktopFileReader::comment();
 
73
    }
 
74
 
 
75
    QString doIcon() const
 
76
    {
 
77
        return DesktopFileReader::icon();
 
78
    }
 
79
 
 
80
    QString doExec() const
 
81
    {
 
82
        return DesktopFileReader::exec();
 
83
    }
 
84
 
 
85
    QString doPath() const
 
86
    {
 
87
        return DesktopFileReader::path();
 
88
    }
 
89
 
 
90
    QString doStageHint() const
 
91
    {
 
92
        return DesktopFileReader::stageHint();
 
93
    }
 
94
 
 
95
    bool doLoaded() const
 
96
    {
 
97
        return DesktopFileReader::loaded();
 
98
    }
 
99
};
 
100
 
 
101
struct MockDesktopFileReaderFactory : public qtmir::DesktopFileReader::Factory
 
102
{
 
103
    MockDesktopFileReaderFactory()
 
104
    {
 
105
        using namespace ::testing;
 
106
        ON_CALL(*this, createInstance(_, _))
 
107
                .WillByDefault(
 
108
                    Invoke(
 
109
                        this,
 
110
                        &MockDesktopFileReaderFactory::doCreateInstance));
 
111
    }
 
112
 
 
113
    virtual qtmir::DesktopFileReader* doCreateInstance(const QString &appId, const QFileInfo &fi)
 
114
    {
 
115
        using namespace ::testing;
 
116
        auto instance = new NiceMock<MockDesktopFileReader>(appId, fi);
 
117
        ON_CALL(*instance, loaded()).WillByDefault(Return(true));
 
118
 
 
119
        return instance;
 
120
    }
 
121
 
 
122
    MOCK_METHOD2(createInstance, qtmir::DesktopFileReader*(const QString &appId, const QFileInfo &fi));
 
123
};
 
124
}
 
125
 
 
126
#endif // MOCK_DESKTOP_FILE_READER_H