summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/test/test-playerbuildinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/test/test-playerbuildinfo.cpp')
-rw-r--r--utils/rbutilqt/test/test-playerbuildinfo.cpp240
1 files changed, 240 insertions, 0 deletions
diff --git a/utils/rbutilqt/test/test-playerbuildinfo.cpp b/utils/rbutilqt/test/test-playerbuildinfo.cpp
new file mode 100644
index 0000000000..a250e37979
--- /dev/null
+++ b/utils/rbutilqt/test/test-playerbuildinfo.cpp
@@ -0,0 +1,240 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2020 Dominik Riebeling
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <QtTest>
22#include <QObject>
23#include "playerbuildinfo.h"
24#include "rbsettings.h"
25
26class TestPlayerBuildInfo : public QObject
27{
28 Q_OBJECT
29
30 private slots:
31 void testBuildInfo();
32 void testBuildInfo_data();
33 void testPlayerInfo();
34 void testPlayerInfo_data();
35};
36
37const char* testinfo =
38 "[release]\n"
39 "build_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
40 "voice_url=https://buildurl/release/%VERSION%/voice-%TARGET%-%VERSION%.zip\n"
41 "manual_url=https://buildurl/release/%VERSION%/manual-%TARGET%-%VERSION%.zip\n"
42 "source_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-src-%VERSION%.zip\n"
43 "font_url=https://buildurl/release/%VERSION%/fonts-%VERSION%.zip\n"
44 "archosfmrecorder=3.11.2\n"
45 "iaudiom3=3.11.2,http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip\n"
46 "sansae200 = 3.15\n"
47 "iriverh100 = 3.11.2, http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip\n"
48 "iriverh120 = 3.3\n"
49 "iriverh300 = \n"
50 "[release-candidate]\n"
51 "build_url=https://buildurl/rc/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
52 "gigabeatfx=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip\n"
53 "archosfmrecorder=f9dce96\n"
54 "archosrecorder = f9dce96\n"
55 "iaudiox5=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip\n"
56 "[development]\n"
57 "build_url=https://buildurl/dev/rockbox-%TARGET%.zip\n"
58 "iriverh100 = be1be79\n"
59 "iaudiox5 = be1be76\n"
60 "[dailies]\n"
61 "timestamp = 20201113\n"
62 "rev = 362f7a3\n"
63 "[daily]\n"
64 "build_url=https://buildurl/daily/rockbox-%TARGET%-%VERSION%.zip\n"
65 "iriverh100 = f9dce00\n"
66 "[bleeding]\n"
67 "timestamp = 20201114T105723Z\n"
68 "rev = be1be79\n"
69 "[status]\n"
70 "archosfmrecorder=3\n"
71 "iriverh100=2\n"
72 "iriverh300=1\n"
73 "iriverh10=0\n"
74 "[voices]\n"
75 "3.15=english,francais\n"
76 "3.11.2=english\n"
77 "daily=deutsch,english,francais\n"
78 ;
79
80Q_DECLARE_METATYPE(PlayerBuildInfo::BuildInfo);
81Q_DECLARE_METATYPE(PlayerBuildInfo::BuildType);
82Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo);
83
84struct {
85 QString target;
86 PlayerBuildInfo::BuildInfo item;
87 PlayerBuildInfo::BuildType type;
88 QString expected;
89} testdataBuild[] =
90{
91 // release builds
92 { "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeRelease, "english" },
93 { "iriverh300", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" },
94 { "iriverh300", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" },
95 { "iriverh10", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" },
96 { "iriverh10", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" },
97 { "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
98 { "iaudiom3", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
99 { "iaudiom3", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" },
100 { "sansae200", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.15" },
101 { "sansae200", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.15/rockbox-sansae200-3.15.zip" },
102 { "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
103 { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" },
104 { "iriverh100", PlayerBuildInfo::BuildVoiceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/voice-iriverh100-3.11.2.zip" },
105 { "iriverh100", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/manual-iriverh100-3.11.2.zip" },
106 { "iriverh100", PlayerBuildInfo::BuildSourceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/rockbox-iriverh100-src-3.11.2.zip" },
107 // h120 uses the same manual as h100.
108 { "iriverh120", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.3/manual-iriverh100-3.3.zip" },
109 { "iriverh100", PlayerBuildInfo::BuildFontUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/fonts-3.11.2.zip" },
110
111 // rc builds
112 { "gigabeatfx", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
113 { "gigabeatfx", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" },
114 { "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
115 { "archosfmrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosfmrecorder-f9dce96.zip" },
116 { "archosrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
117 { "archosrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosrecorder-f9dce96.zip" },
118 { "iaudiox5", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
119 { "iaudiox5", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },
120 { "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
121 { "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },
122
123 // devel builds
124 { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iriverh100.zip" },
125 { "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDevel, "be1be76" },
126 { "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iaudiox5.zip" },
127
128 // daily builds
129 { "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeDaily, "deutsch,english,francais" },
130 { "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDaily, "f9dce00" },
131 { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDaily, "https://buildurl/daily/rockbox-iriverh100-f9dce00.zip" },
132};
133
134struct {
135 QString target;
136 PlayerBuildInfo::DeviceInfo item;
137 QString expected;
138} testdataPlayer[] =
139{
140 { "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" },
141 { "iriverh10", PlayerBuildInfo::BuildStatus, "0" },
142 { "iriverh100", PlayerBuildInfo::BuildStatus, "2" },
143 { "iriverh300", PlayerBuildInfo::BuildStatus, "1" },
144 { "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" },
145 { "archosfmrecorder", PlayerBuildInfo::DisplayName, "Jukebox Recorder FM"},
146 { "archosfmrecorder", PlayerBuildInfo::BootloaderMethod, "none" },
147 { "archosfmrecorder", PlayerBuildInfo::BootloaderName, "" },
148 { "archosfmrecorder", PlayerBuildInfo::BootloaderFile, "" },
149 { "archosfmrecorder", PlayerBuildInfo::BootloaderFilter, "" },
150 { "archosfmrecorder", PlayerBuildInfo::Encoder, "lame" },
151 { "archosfmrecorder", PlayerBuildInfo::Brand, "Archos" },
152 { "archosfmrecorder", PlayerBuildInfo::PlayerPicture, "archosfmrecorder"},
153 { "iriverh100", PlayerBuildInfo::BuildStatus, "2" },
154 { "iriverh100", PlayerBuildInfo::BootloaderMethod, "hex" },
155 { "iriverh100", PlayerBuildInfo::BootloaderFilter, "*.hex *.zip" },
156 { "ipodmini2g", PlayerBuildInfo::Encoder, "rbspeex" },
157 { "078174b1", PlayerBuildInfo::DisplayName, "Sansa View" },
158 { "de", PlayerBuildInfo::LanguageInfo, "deutsch,Deutsch" },
159 { "en_US", PlayerBuildInfo::LanguageInfo, "english-us,English (US)" },
160};
161
162void TestPlayerBuildInfo::testBuildInfo_data()
163{
164 QTest::addColumn<QString>("target");
165 QTest::addColumn<PlayerBuildInfo::BuildInfo>("item");
166 QTest::addColumn<PlayerBuildInfo::BuildType>("type");
167 QTest::addColumn<QString>("expected");
168 for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++)
169 QTest::newRow("") << testdataBuild[i].target << testdataBuild[i].item
170 << testdataBuild[i].type << testdataBuild[i].expected;
171}
172
173
174void TestPlayerBuildInfo::testBuildInfo()
175{
176 // create a temporary file for test input. Do not use QSettings() to allow
177 // creating different format variations.
178 QTemporaryFile tf(this);
179 tf.open();
180 QString filename = tf.fileName();
181 tf.write(testinfo);
182 tf.close();
183
184 PlayerBuildInfo::instance()->setBuildInfo(filename);
185
186 QFETCH(QString, target);
187 QFETCH(PlayerBuildInfo::BuildInfo, item);
188 QFETCH(PlayerBuildInfo::BuildType, type);
189 QFETCH(QString, expected);
190
191 RbSettings::setValue(RbSettings::CurrentPlatform, target);
192 QVariant result = PlayerBuildInfo::instance()->value(item, type);
193 if(result.canConvert(QMetaType::QString))
194 QCOMPARE(result.toString(), QString(expected));
195 else
196 QCOMPARE(result.toStringList().join(","), QString(expected));
197}
198
199
200// NOTE: These tests rely on rbutil.ini
201void TestPlayerBuildInfo::testPlayerInfo_data()
202{
203 QTest::addColumn<QString>("target");
204 QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item");
205 QTest::addColumn<QString>("expected");
206 for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++)
207 QTest::newRow("") << testdataPlayer[i].target << testdataPlayer[i].item
208 << testdataPlayer[i].expected;
209}
210
211void TestPlayerBuildInfo::testPlayerInfo()
212{
213 // create a temporary file for test input. Do not use QSettings() to allow
214 // creating different format variations.
215 QTemporaryFile tf(this);
216 tf.open();
217 QString filename = tf.fileName();
218 tf.write(testinfo);
219 tf.close();
220
221 PlayerBuildInfo::instance()->setBuildInfo(filename);
222
223 QFETCH(QString, target);
224 QFETCH(PlayerBuildInfo::DeviceInfo, item);
225 QFETCH(QString, expected);
226
227 QVariant result = PlayerBuildInfo::instance()->value(item, target);
228 if(result.canConvert(QMetaType::QString))
229 QCOMPARE(result.toString(), QString(expected));
230 else
231 QCOMPARE(result.toStringList().join(","), QString(expected));
232}
233
234
235QTEST_MAIN(TestPlayerBuildInfo)
236
237// this include is needed because we don't use a separate header file for the
238// test class. It also needs to be at the end.
239#include "test-playerbuildinfo.moc"
240