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