aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mappletmetadata/ut_mappletmetadata.cpp
blob: ff31e1ffc945fe9cf6fe02f387003229e66ad316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QtTest/QtTest>

#include "ut_mappletmetadata.h"
#include "mappletmetadata.h"

QString gType = "X-MeeGoApplet";
QString gRunner = "";
QString gApplet = "";
QString gName = "";
QString gIcon = "";
QString gExtraIdentifier = "";

// MDesktop entry stubs
QString MDesktopEntry::value(const QString &key) const
{
    if (key == "Desktop Entry/Type") {
        return QString(gType);
    } else if (key == "Desktop Entry/Name") {
        return QString(gName);
    } else if (key == "Desktop Entry/Icon") {
        return QString(gIcon);
    } else if (key == "Desktop Entry/Exec") {
        return QString(gRunner);
    } else if (key == "X-MeeGoApplet/Applet") {
        return QString(gApplet);
    } else if (key == "X-MeeGoApplet/Identifier") {
        return QString(gExtraIdentifier);
    }
    return QString();
}

bool MDesktopEntry::contains(const QString &key) const
{
    if (key == "Desktop Entry/Type") {
        return gType != "";
    } else if (key == "Desktop Entry/Name") {
        return gName != "";
    } else if (key == "Desktop Entry/Icon") {
        return gIcon != "";
    } else if (key == "Desktop Entry/Exec") {
        return gRunner != "";
    } else if (key == "X-MeeGoApplet/Applet") {
        return gApplet != "";
    } else if (key == "X-MeeGoApplet/Identifier") {
        return gExtraIdentifier != "";
    }
    return false;
}

// QFileInfo stubs
bool QFileInfo::exists() const
{
    if (filePath() == QString(APPLET_LIBS) + QDir::separator() + "inexisting")
        return false;
    else
        return (filePath() == QString(APPLET_LIBS) + QDir::separator() + gApplet ||
                filePath() == QString(APPLET_LIBS) + QDir::separator() + gRunner);
}

bool QFileInfo::isFile() const
{
    if (filePath() == QString(APPLET_LIBS) + QDir::separator() + "inexisting")
        return false;
    else
        return (filePath() == QString(APPLET_LIBS) + QDir::separator() + gApplet ||
                filePath() == QString(APPLET_LIBS) + QDir::separator() + gRunner);
}

bool QFileInfo::isExecutable() const
{
    if (filePath() == QString(APPLET_LIBS) + QDir::separator() + "inexisting")
        return false;
    else
        return (filePath() == QString(APPLET_LIBS) + QDir::separator() + gApplet ||
                filePath() == QString(APPLET_LIBS) + QDir::separator() + gRunner);
}

void Ut_MAppletMetaData::init()
{
    m_subject = new MAppletMetaData("");
    gName = "Unit Test";
    gIcon = "Icon-UnitTest";
    gRunner = "mappletrunner";
    gApplet = "test.so";
}

void Ut_MAppletMetaData::cleanup()
{
    delete m_subject;
    m_subject = 0;
}

void Ut_MAppletMetaData::testValidMetaData()
{
    // Runner is defined. This marks out-of-process applet
    QCOMPARE(m_subject->isValid(), true);

    // Runner is not defined. This marks in-process applet
    gRunner = "";
    QCOMPARE(m_subject->isValid(), true);
}

void Ut_MAppletMetaData::testBinaryMissing()
{
    gApplet = "";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testBinaryAndRunnerPaths()
{
    // APPLET_LIBS path should be prepended to binary and runner paths.
    QString absoluteBinaryPath = QFileInfo(QString(APPLET_LIBS) + QDir::separator() + gApplet).absoluteFilePath();
    QString absoluteRunnerPath = QFileInfo(QString(APPLET_LIBS) + QDir::separator() + gRunner).absoluteFilePath();
    QCOMPARE(m_subject->appletBinary(), absoluteBinaryPath);
    QCOMPARE(m_subject->runnerBinary(), absoluteRunnerPath);
}

void Ut_MAppletMetaData::testInvalidRunner()
{
    gRunner = "inexisting";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testInvalidApplet()
{
    gApplet = "inexisting";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testAppletMissing()
{
    gApplet = "";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testNameMissing()
{
    gName   = "";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testIconMissing()
{
    gIcon   = "";
    QCOMPARE(m_subject->isValid(), false);
}

void Ut_MAppletMetaData::testExtraIdentifier()
{
    gExtraIdentifier = "";
    QVERIFY(!m_subject->contains("X-MeeGoApplet/Identifier"));
    gExtraIdentifier = "foo";
    QVERIFY(m_subject->contains("X-MeeGoApplet/Identifier"));
}

void Ut_MAppletMetaData::testResourceIdentifier()
{
    // Valid cases
    gExtraIdentifier = "foo";
    gApplet = "libfoo.so";
    QCOMPARE(m_subject->resourceIdentifier(), QString("foo"));
    gApplet = M_INSTALL_LIBS "/libfoo.so";
    QCOMPARE(m_subject->resourceIdentifier(), QString("foo"));
    gExtraIdentifier = "xyz";
    gApplet = M_INSTALL_LIBS "/libfoo.so";
    QCOMPARE(m_subject->resourceIdentifier(), QString("xyz"));

    // Invalid cases
    gExtraIdentifier = "";
    gApplet = "";
    QCOMPARE(m_subject->resourceIdentifier(), QString(""));
    gApplet = "foo";
    QCOMPARE(m_subject->resourceIdentifier(), QString(""));
    gApplet = "foo.so";
    QCOMPARE(m_subject->resourceIdentifier(), QString(""));
    gApplet = "libfoo";
    QCOMPARE(m_subject->resourceIdentifier(), QString(""));

}

QTEST_APPLESS_MAIN(Ut_MAppletMetaData)