Changeset View
Standalone View
tests/core/DownloadManagerTest.cpp
- This file was added.
1 | /* GCompris - DownloadManagerTest.cpp | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright (C) 2018 Alex Kovrigin <a.kovrigin0@gmail.com> | ||||
4 | * GCompris (C) 2018 GCompris Developers <gcompris-devel@kde.org> | ||||
5 | * | ||||
6 | * Authors: | ||||
7 | * Alex Kovrigin <a.kovrigin0@gmail.com> | ||||
8 | * | ||||
9 | * This program is free software; you can redistribute it and/or modify | ||||
jjazeix: it would be better to name it DownloadManagerTest to keep consistency with other tests classes | |||||
10 | * it under the terms of the GNU General Public License as published by | ||||
11 | * the Free Software Foundation; either version 3 of the License, or | ||||
12 | * (at your option) any later version. | ||||
13 | * | ||||
14 | * This program is distributed in the hope that it will be useful, | ||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | * GNU General Public License for more details. | ||||
18 | * | ||||
19 | * You should have received a copy of the GNU General Public License | ||||
20 | * along with this program; if not, see <https://www.gnu.org/licenses/>. | ||||
21 | */ | ||||
22 | | ||||
23 | #include <QObject> | ||||
don't bother testing this function, I've tried to find better but didn't (for example, it would have been nice to have a function accessing the registered objects but I didn't find one) jjazeix: don't bother testing this function, I've tried to find better but didn't (for example, it would… | |||||
24 | #include <QtTest> | ||||
25 | #include <QDebug> | ||||
26 | #include <QString> | ||||
27 | | ||||
28 | #include "src/core/DownloadManager.h" | ||||
29 | #include "src/core/ApplicationInfo.h" | ||||
30 | #include "ApplicationSettingsMock.h" | ||||
31 | /** | ||||
this works because on Linux, we use ogg. But it will fail on macOS (as COMPRESSED_AUDIO will be aac) or Windows (mp3 is used). jjazeix: this works because on Linux, we use ogg. But it will fail on macOS (as COMPRESSED_AUDIO will be… | |||||
32 | * @brief The DownloadManagerTest class Unit tests class for DownloadManager testing | ||||
33 | * @sa DownloadManager | ||||
34 | */ | ||||
35 | class DownloadManagerTest : public QObject | ||||
36 | { | ||||
37 | Q_OBJECT | ||||
38 | public: | ||||
39 | explicit DownloadManagerTest(QObject *parent = nullptr) : QObject(parent) | ||||
40 | { } | ||||
41 | private slots: | ||||
42 | /** | ||||
43 | * @brief initTestCase Case for basic functonality of DownloadManager | ||||
44 | */ | ||||
45 | void initTestCase() | ||||
46 | { | ||||
47 | ApplicationSettingsMock::getInstance()->setIsAutomaticDownloadsEnabled(false); | ||||
48 | subject = DownloadManager::getInstance(); | ||||
49 | } | ||||
yes, according to the code, to return false, it would mean that either a download for the same file already started. jjazeix: yes, according to the code, to return false, it would mean that either a download for the same… | |||||
50 | | ||||
51 | void test_getVoicesResourceForLocale_data() | ||||
52 | { | ||||
53 | QTest::addColumn<QString>("locale"); | ||||
54 | QTest::addColumn<QString>("language"); | ||||
55 | | ||||
The easier way to have it return false, would be to do checkDownloadRestriction return true. jjazeix: The easier way to have it return false, would be to do checkDownloadRestriction return true.
To… | |||||
56 | QTest::newRow("en_US") << "en_US" << "en"; | ||||
57 | QTest::newRow("en_UK") << "en_UK" << "en"; | ||||
58 | QTest::newRow("ru_RU") << "ru_RU" << "ru"; | ||||
59 | QTest::newRow("de_DE") << "de_DE" << "de"; | ||||
60 | QTest::newRow("fr_FR") << "fr_FR" << "fr"; | ||||
61 | } | ||||
62 | void test_getVoicesResourceForLocale() | ||||
63 | { | ||||
64 | QFETCH(QString, locale); | ||||
65 | QFETCH(QString, language); | ||||
66 | | ||||
67 | QCOMPARE( subject->getVoicesResourceForLocale(locale), | ||||
68 | QString("data2/voices-%1/voices-%2.rcc").arg(COMPRESSED_AUDIO, language) ); | ||||
69 | } | ||||
70 | | ||||
71 | void test_haveLocalResource_data() | ||||
72 | { | ||||
73 | QTest::addColumn<QString>("resource"); | ||||
why not using the "money.rcc" registered above? jjazeix: why not using the "money.rcc" registered above?
Or better, register it on this function… | |||||
74 | QTest::addColumn<bool>("expected_success"); | ||||
75 | | ||||
76 | QTest::newRow("invalid.invalid") << "invalid.invalid" << false; | ||||
no need to test this one, it will be too complicated to download voices and register them (and not wanted). jjazeix: no need to test this one, it will be too complicated to download voices and register them (and… | |||||
77 | QTest::newRow("no.no") << "no.no" << false; | ||||
78 | QTest::newRow("money.rcc") << "money.rcc" << true; | ||||
79 | QTest::newRow("penalty.rcc") << "penalty.rcc" << true; | ||||
80 | } | ||||
81 | void test_haveLocalResource() | ||||
82 | { | ||||
83 | QFETCH(QString, resource); | ||||
84 | QFETCH(bool, expected_success); | ||||
85 | | ||||
86 | QVERIFY(expected_success == subject->haveLocalResource(resource)); | ||||
87 | } | ||||
88 | | ||||
89 | void test_downloadResource_data() | ||||
90 | { | ||||
91 | QTest::addColumn<QString>("resource"); | ||||
92 | | ||||
93 | QTest::newRow("invalid.blabla") << "invalid.blabla"; | ||||
94 | QTest::newRow("algorithm.rcc") << "algorithm.rcc"; | ||||
95 | } | ||||
96 | void test_downloadResource() | ||||
97 | { | ||||
98 | QFETCH(QString, resource); | ||||
99 | | ||||
100 | QVERIFY(subject->downloadResource(resource)); | ||||
101 | QVERIFY(!subject->downloadResource(resource)); | ||||
102 | } | ||||
103 | | ||||
104 | void test_updateResource_data() | ||||
105 | { | ||||
106 | QTest::addColumn<QString>("resource"); | ||||
107 | QTest::addColumn<bool>("expected_success"); | ||||
108 | | ||||
109 | QTest::newRow("invalid.haha") << "invalid.haha" << false; | ||||
110 | QTest::newRow("money.rcc") << "money.rcc" << true; | ||||
111 | } | ||||
112 | void test_updateResource() | ||||
113 | { | ||||
114 | QFETCH(QString, resource); | ||||
115 | QFETCH(bool, expected_success); | ||||
116 | | ||||
117 | QVERIFY(expected_success == subject->updateResource(resource)); | ||||
118 | } | ||||
119 | | ||||
120 | void test_downloadIsRunning_data() | ||||
121 | { | ||||
122 | QTest::addColumn<QString>("resource"); | ||||
123 | | ||||
124 | QTest::newRow("colors.rcc") << "colors.rcc"; | ||||
125 | } | ||||
126 | void test_downloadIsRunning() | ||||
127 | { | ||||
128 | QFETCH(QString, resource); | ||||
129 | | ||||
130 | subject->abortDownloads(); | ||||
131 | QVERIFY(!subject->downloadIsRunning()); | ||||
132 | QVERIFY(subject->downloadResource(resource)); | ||||
133 | QVERIFY(subject->downloadIsRunning()); | ||||
134 | subject->abortDownloads(); | ||||
135 | } | ||||
136 | | ||||
137 | void test_registerResource_data() | ||||
138 | { | ||||
139 | QTest::addColumn<QString>("resource"); | ||||
140 | QTest::addColumn<bool>("expected_success"); | ||||
141 | | ||||
142 | QTest::newRow("invalid.rcc") << "invalid.rcc" << false; | ||||
143 | QTest::newRow("money.rcc") << "money.rcc" << true; | ||||
144 | } | ||||
145 | void test_registerResource() | ||||
146 | { | ||||
147 | QFETCH(QString, resource); | ||||
148 | QFETCH(bool, expected_success); | ||||
149 | | ||||
150 | QVERIFY(expected_success == subject->registerResource(resource)); | ||||
151 | } | ||||
152 | | ||||
153 | void test_isDataRegistered_data() | ||||
154 | { | ||||
155 | QTest::addColumn<QString>("resource"); | ||||
156 | QTest::addColumn<QString>("register_mode"); | ||||
157 | | ||||
158 | QTest::newRow("invalid.rcc") << "invalid.rcc" << "invalid"; | ||||
159 | QTest::newRow("money.rcc") << "money.rcc" << "register"; | ||||
160 | QTest::newRow("mosaic.rcc") << "mosaic.rcc" << "no_register"; | ||||
161 | QTest::newRow("money.rcc") << "money.rcc" << "register"; | ||||
162 | } | ||||
163 | void test_isDataRegistered() | ||||
164 | { | ||||
165 | QFETCH(QString, resource); | ||||
166 | QFETCH(QString, register_mode); | ||||
167 | | ||||
168 | if(register_mode == "register") { | ||||
169 | QVERIFY(QResource::registerResource( | ||||
170 | QString("./%1/rcc/%2").arg(GCOMPRIS_DATA_FOLDER, resource), | ||||
171 | QString(":/gcompris/data/%1").arg(resource))); | ||||
172 | | ||||
173 | QVERIFY(subject->isDataRegistered(resource)); | ||||
I've been debugging and trying to solve this issue for some time, but I couldn't find the solution. subject->isDataRegistered(resource) Always returns false. alexkovrigin: I've been debugging and trying to solve this issue for some time, but I couldn't find the… | |||||
This function is a bit tricky and not really easy to test. jjazeix: This function is a bit tricky and not really easy to test.
Basically, when we register an… | |||||
I think, I did it. Don't think it's the nicest solution, but it does its job alexkovrigin: I think, I did it. Don't think it's the nicest solution, but it does its job | |||||
174 | } | ||||
175 | else if(register_mode == "no_register") { | ||||
176 | QVERIFY(!subject->isDataRegistered(resource)); | ||||
177 | } | ||||
178 | else if(register_mode == "invalid") { | ||||
179 | QVERIFY(!subject->registerResource(resource)); | ||||
180 | QVERIFY(!subject->isDataRegistered(resource)); | ||||
181 | } | ||||
182 | else { | ||||
183 | qDebug() << "Incorrect register_mode!"; | ||||
184 | QVERIFY(false); | ||||
185 | } | ||||
186 | } | ||||
187 | private: | ||||
188 | /** | ||||
189 | * @brief subject The DownloadManager object, that is the test subject | ||||
190 | */ | ||||
191 | DownloadManager * subject; | ||||
192 | }; | ||||
typo (Resource) + use const reference for passing arguments that won't be updated to avoid copies. jjazeix: typo (Resource) + use const reference for passing arguments that won't be updated to avoid… | |||||
alexkovrigin: I removed those functions into the caller one. | |||||
193 | | ||||
194 | QTEST_MAIN(DownloadManagerTest); | ||||
195 | #include "DownloadManagerTest.moc" |
it would be better to name it DownloadManagerTest to keep consistency with other tests classes