summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/test/test-playerbuildinfo.cpp
blob: a250e3797985bdce0263357b220fbd3a088db09d (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 * Copyright (C) 2020 Dominik Riebeling
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include <QtTest>
#include <QObject>
#include "playerbuildinfo.h"
#include "rbsettings.h"

class TestPlayerBuildInfo : public QObject
{
    Q_OBJECT

    private slots:
    void testBuildInfo();
    void testBuildInfo_data();
    void testPlayerInfo();
    void testPlayerInfo_data();
};

const char* testinfo =
    "[release]\n"
    "build_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
    "voice_url=https://buildurl/release/%VERSION%/voice-%TARGET%-%VERSION%.zip\n"
    "manual_url=https://buildurl/release/%VERSION%/manual-%TARGET%-%VERSION%.zip\n"
    "source_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-src-%VERSION%.zip\n"
    "font_url=https://buildurl/release/%VERSION%/fonts-%VERSION%.zip\n"
    "archosfmrecorder=3.11.2\n"
    "iaudiom3=3.11.2,http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip\n"
    "sansae200 = 3.15\n"
    "iriverh100 = 3.11.2, http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip\n"
    "iriverh120 = 3.3\n"
    "iriverh300 = \n"
    "[release-candidate]\n"
    "build_url=https://buildurl/rc/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
    "gigabeatfx=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip\n"
    "archosfmrecorder=f9dce96\n"
    "archosrecorder = f9dce96\n"
    "iaudiox5=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip\n"
    "[development]\n"
    "build_url=https://buildurl/dev/rockbox-%TARGET%.zip\n"
    "iriverh100 = be1be79\n"
    "iaudiox5 = be1be76\n"
    "[dailies]\n"
    "timestamp = 20201113\n"
    "rev = 362f7a3\n"
    "[daily]\n"
    "build_url=https://buildurl/daily/rockbox-%TARGET%-%VERSION%.zip\n"
    "iriverh100 = f9dce00\n"
    "[bleeding]\n"
    "timestamp = 20201114T105723Z\n"
    "rev = be1be79\n"
    "[status]\n"
    "archosfmrecorder=3\n"
    "iriverh100=2\n"
    "iriverh300=1\n"
    "iriverh10=0\n"
    "[voices]\n"
    "3.15=english,francais\n"
    "3.11.2=english\n"
    "daily=deutsch,english,francais\n"
    ;

Q_DECLARE_METATYPE(PlayerBuildInfo::BuildInfo);
Q_DECLARE_METATYPE(PlayerBuildInfo::BuildType);
Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo);

struct {
    QString target;
    PlayerBuildInfo::BuildInfo item;
    PlayerBuildInfo::BuildType type;
    QString expected;
} testdataBuild[] =
{
    // release builds
    { "iriverh100",       PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeRelease,   "english" },
    { "iriverh300",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "" },
    { "iriverh300",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeRelease,   "" },
    { "iriverh10",        PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "" },
    { "iriverh10",        PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeRelease,   "" },
    { "archosfmrecorder", PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "3.11.2" },
    { "iaudiom3",         PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "3.11.2" },
    { "iaudiom3",         PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeRelease,   "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" },
    { "sansae200",        PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "3.15" },
    { "sansae200",        PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.15/rockbox-sansae200-3.15.zip" },
    { "iriverh100",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeRelease,   "3.11.2" },
    { "iriverh100",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeRelease,   "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" },
    { "iriverh100",       PlayerBuildInfo::BuildVoiceUrl,   PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.11.2/voice-iriverh100-3.11.2.zip" },
    { "iriverh100",       PlayerBuildInfo::BuildManualUrl,  PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.11.2/manual-iriverh100-3.11.2.zip" },
    { "iriverh100",       PlayerBuildInfo::BuildSourceUrl,  PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.11.2/rockbox-iriverh100-src-3.11.2.zip" },
    // h120 uses the same manual as h100.
    { "iriverh120",       PlayerBuildInfo::BuildManualUrl,  PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.3/manual-iriverh100-3.3.zip" },
    { "iriverh100",       PlayerBuildInfo::BuildFontUrl,    PlayerBuildInfo::TypeRelease,   "https://buildurl/release/3.11.2/fonts-3.11.2.zip" },

    // rc builds
    { "gigabeatfx",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeCandidate, "f9dce96" },
    { "gigabeatfx",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" },
    { "archosfmrecorder", PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeCandidate, "f9dce96" },
    { "archosfmrecorder", PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosfmrecorder-f9dce96.zip" },
    { "archosrecorder",   PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeCandidate, "f9dce96" },
    { "archosrecorder",   PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosrecorder-f9dce96.zip" },
    { "iaudiox5",         PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeCandidate, "f9dce96" },
    { "iaudiox5",         PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },
    { "iaudiox5.v",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeCandidate, "f9dce96" },
    { "iaudiox5.v",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },

    // devel builds
    { "iriverh100",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeDevel,     "https://buildurl/dev/rockbox-iriverh100.zip" },
    { "iaudiox5.v",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeDevel,     "be1be76" },
    { "iaudiox5.v",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeDevel,     "https://buildurl/dev/rockbox-iaudiox5.zip" },

    // daily builds
    { "iriverh100",       PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeDaily,     "deutsch,english,francais" },
    { "iriverh100",       PlayerBuildInfo::BuildVersion,    PlayerBuildInfo::TypeDaily,     "f9dce00" },
    { "iriverh100",       PlayerBuildInfo::BuildUrl,        PlayerBuildInfo::TypeDaily,     "https://buildurl/daily/rockbox-iriverh100-f9dce00.zip" },
};

struct {
    QString target;
    PlayerBuildInfo::DeviceInfo item;
    QString expected;
} testdataPlayer[] =
{
    { "archosfmrecorder", PlayerBuildInfo::BuildStatus,      "3"             },
    { "iriverh10",        PlayerBuildInfo::BuildStatus,      "0"             },
    { "iriverh100",       PlayerBuildInfo::BuildStatus,      "2"             },
    { "iriverh300",       PlayerBuildInfo::BuildStatus,      "1"             },
    { "archosfmrecorder", PlayerBuildInfo::BuildStatus,      "3"             },
    { "archosfmrecorder", PlayerBuildInfo::DisplayName,      "Jukebox Recorder FM"},
    { "archosfmrecorder", PlayerBuildInfo::BootloaderMethod, "none"          },
    { "archosfmrecorder", PlayerBuildInfo::BootloaderName,   ""              },
    { "archosfmrecorder", PlayerBuildInfo::BootloaderFile,   ""              },
    { "archosfmrecorder", PlayerBuildInfo::BootloaderFilter, ""              },
    { "archosfmrecorder", PlayerBuildInfo::Encoder,          "lame"          },
    { "archosfmrecorder", PlayerBuildInfo::Brand,            "Archos"        },
    { "archosfmrecorder", PlayerBuildInfo::PlayerPicture,    "archosfmrecorder"},
    { "iriverh100",       PlayerBuildInfo::BuildStatus,      "2"             },
    { "iriverh100",       PlayerBuildInfo::BootloaderMethod, "hex"           },
    { "iriverh100",       PlayerBuildInfo::BootloaderFilter, "*.hex *.zip"   },
    { "ipodmini2g",       PlayerBuildInfo::Encoder,          "rbspeex"       },
    { "078174b1",         PlayerBuildInfo::DisplayName,      "Sansa View"    },
    { "de",               PlayerBuildInfo::LanguageInfo,     "deutsch,Deutsch" },
    { "en_US",            PlayerBuildInfo::LanguageInfo,     "english-us,English (US)" },
};

void TestPlayerBuildInfo::testBuildInfo_data()
{
    QTest::addColumn<QString>("target");
    QTest::addColumn<PlayerBuildInfo::BuildInfo>("item");
    QTest::addColumn<PlayerBuildInfo::BuildType>("type");
    QTest::addColumn<QString>("expected");
    for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++)
        QTest::newRow("") << testdataBuild[i].target << testdataBuild[i].item
                          << testdataBuild[i].type << testdataBuild[i].expected;
}


void TestPlayerBuildInfo::testBuildInfo()
{
    // create a temporary file for test input. Do not use QSettings() to allow
    // creating different format variations.
    QTemporaryFile tf(this);
    tf.open();
    QString filename = tf.fileName();
    tf.write(testinfo);
    tf.close();

    PlayerBuildInfo::instance()->setBuildInfo(filename);

    QFETCH(QString, target);
    QFETCH(PlayerBuildInfo::BuildInfo, item);
    QFETCH(PlayerBuildInfo::BuildType, type);
    QFETCH(QString, expected);

    RbSettings::setValue(RbSettings::CurrentPlatform, target);
    QVariant result = PlayerBuildInfo::instance()->value(item, type);
    if(result.canConvert(QMetaType::QString))
        QCOMPARE(result.toString(), QString(expected));
    else
        QCOMPARE(result.toStringList().join(","), QString(expected));
}


// NOTE: These tests rely on rbutil.ini
void TestPlayerBuildInfo::testPlayerInfo_data()
{
    QTest::addColumn<QString>("target");
    QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item");
    QTest::addColumn<QString>("expected");
    for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++)
        QTest::newRow("") << testdataPlayer[i].target << testdataPlayer[i].item
                          << testdataPlayer[i].expected;
}

void TestPlayerBuildInfo::testPlayerInfo()
{
    // create a temporary file for test input. Do not use QSettings() to allow
    // creating different format variations.
    QTemporaryFile tf(this);
    tf.open();
    QString filename = tf.fileName();
    tf.write(testinfo);
    tf.close();

    PlayerBuildInfo::instance()->setBuildInfo(filename);

    QFETCH(QString, target);
    QFETCH(PlayerBuildInfo::DeviceInfo, item);
    QFETCH(QString, expected);

    QVariant result = PlayerBuildInfo::instance()->value(item, target);
    if(result.canConvert(QMetaType::QString))
        QCOMPARE(result.toString(), QString(expected));
    else
        QCOMPARE(result.toStringList().join(","), QString(expected));
}


QTEST_MAIN(TestPlayerBuildInfo)

// this include is needed because we don't use a separate header file for the
// test class. It also needs to be at the end.
#include "test-playerbuildinfo.moc"