| 194 | } |
| 195 | |
| 196 | void test_enable_disable() |
| 197 | { |
| 198 | QString folder_resource = QFINDTESTDATA("testdata/ResourceFolderModel/test_folder"); |
| 199 | QString file_mod = QFINDTESTDATA("testdata/ResourceFolderModel/supercoolmod.jar"); |
| 200 | |
| 201 | QTemporaryDir tmp; |
| 202 | ResourceFolderModel model(tmp.path(), nullptr); |
| 203 | |
| 204 | QCOMPARE(model.size(), 0); |
| 205 | |
| 206 | { |
| 207 | EXEC_UPDATE_TASK(model.installResource(folder_resource), QVERIFY) |
| 208 | } |
| 209 | { |
| 210 | EXEC_UPDATE_TASK(model.installResource(file_mod), QVERIFY) |
| 211 | } |
| 212 | |
| 213 | for (auto res : model.all()) |
| 214 | qDebug() << res->name(); |
| 215 | |
| 216 | QCOMPARE(model.size(), 2); |
| 217 | |
| 218 | auto& res_1 = model.at(0).type() != ResourceType::FOLDER ? model.at(0) : model.at(1); |
| 219 | auto& res_2 = model.at(0).type() == ResourceType::FOLDER ? model.at(0) : model.at(1); |
| 220 | auto id_1 = res_1.internal_id(); |
| 221 | auto id_2 = res_2.internal_id(); |
| 222 | bool initial_enabled_res_2 = res_2.enabled(); |
| 223 | bool initial_enabled_res_1 = res_1.enabled(); |
| 224 | |
| 225 | QVERIFY(res_1.type() != ResourceType::FOLDER && res_1.type() != ResourceType::UNKNOWN); |
| 226 | qDebug() << "res_1 is of the correct type."; |
| 227 | QVERIFY(res_1.enabled()); |
| 228 | qDebug() << "res_1 is initially enabled."; |
| 229 | |
| 230 | QVERIFY(res_1.enable(EnableAction::TOGGLE)); |
| 231 | |
| 232 | QVERIFY(res_1.enabled() == !initial_enabled_res_1); |
| 233 | qDebug() << "res_1 got successfully toggled."; |
| 234 | |
| 235 | QVERIFY(res_1.enable(EnableAction::TOGGLE)); |
| 236 | qDebug() << "res_1 got successfully toggled again."; |
| 237 | |
| 238 | QVERIFY(res_1.enabled() == initial_enabled_res_1); |
| 239 | QVERIFY(res_1.internal_id() == id_1); |
| 240 | qDebug() << "res_1 got back to its initial state."; |
| 241 | |
| 242 | QVERIFY(!res_2.enable(initial_enabled_res_2 ? EnableAction::ENABLE : EnableAction::DISABLE)); |
| 243 | QVERIFY(res_2.enabled() == initial_enabled_res_2); |
| 244 | QVERIFY(res_2.internal_id() == id_2); |
| 245 | } |
| 246 | }; |
| 247 | |
| 248 | QTEST_GUILESS_MAIN(ResourceFolderModelTest) |
nothing calls this directly
no test coverage detected