| 35 | } |
| 36 | |
| 37 | Error test_export_project(const String &version, const String &sub_project, const String &original_parent_dir, const String &exported_parent_dir) { |
| 38 | String exported_pck_path = exported_parent_dir.path_join(version).path_join(sub_project); |
| 39 | |
| 40 | String subdir = version.path_join(sub_project.get_base_dir()); |
| 41 | String original_project_zip = original_parent_dir.path_join(subdir).path_join(sub_project.get_file().get_basename() + ".zip"); |
| 42 | // where we will extract the original project |
| 43 | String original_extract_dir = get_tmp_path().path_join("original").path_join(subdir); |
| 44 | // where we will output the exported project during recovery |
| 45 | String exported_recovery_dir = get_tmp_path().path_join("exported").path_join(subdir); |
| 46 | |
| 47 | gdre::rimraf(original_extract_dir); |
| 48 | Error err = gdre::unzip_file_to_dir(original_project_zip, original_extract_dir); |
| 49 | CHECK_EQ(err, OK); |
| 50 | |
| 51 | gdre::rimraf(exported_recovery_dir); |
| 52 | // load the project |
| 53 | err = GDRESettings::get_singleton()->load_project({ exported_pck_path }, false); |
| 54 | CHECK_EQ(err, OK); |
| 55 | // check that we detected the correct engine version |
| 56 | auto ourVersion = GodotVer::parse(version); |
| 57 | REQUIRE(ourVersion.is_valid()); |
| 58 | CHECK(ourVersion->is_valid_semver()); |
| 59 | auto loadedVersion = GodotVer::parse(GDRESettings::get_singleton()->get_version_string()); |
| 60 | REQUIRE(loadedVersion.is_valid()); |
| 61 | CHECK(loadedVersion->is_valid_semver()); |
| 62 | // Godot 3.1 and below did not write the correct patch version to the PCK |
| 63 | if (ourVersion->get_prerelease().is_empty() && ((ourVersion->get_major() == 3 && ourVersion->get_minor() <= 1) || ourVersion->get_major() < 3)) { |
| 64 | CHECK_EQ(ourVersion->get_major(), loadedVersion->get_major()); |
| 65 | CHECK_EQ(ourVersion->get_minor(), loadedVersion->get_minor()); |
| 66 | } else { |
| 67 | CHECK_EQ(*ourVersion.ptr(), loadedVersion); |
| 68 | } |
| 69 | |
| 70 | PckDumper dumper; |
| 71 | err = dumper.check_md5_all_files(); |
| 72 | CHECK_EQ(err, OK); |
| 73 | err = dumper.pck_dump_to_dir(exported_recovery_dir, {}); |
| 74 | CHECK_EQ(err, OK); |
| 75 | ImportExporter import_exporter; |
| 76 | err = import_exporter.export_imports(exported_recovery_dir, {}); |
| 77 | CHECK_EQ(err, OK); |
| 78 | auto import_report = import_exporter.get_report(); |
| 79 | REQUIRE(import_report.is_valid()); |
| 80 | Dictionary json_report = import_report->to_json(); |
| 81 | { |
| 82 | Ref<ImportExporterReport> import_exporter_report2 = ImportExporterReport::from_json(json_report); |
| 83 | CHECK(import_report->is_equal_to(import_exporter_report2)); |
| 84 | } |
| 85 | #ifdef DEBUG_ENABLED |
| 86 | { |
| 87 | String json_report_path = exported_recovery_dir.path_join("json_report.json"); |
| 88 | auto fa = FileAccess::open(json_report_path, FileAccess::WRITE); |
| 89 | REQUIRE(fa.is_valid()); |
| 90 | fa->store_string(JSON::stringify(json_report, "\t", false, true)); |
| 91 | fa->flush(); |
| 92 | } |
| 93 | #endif |
| 94 | CHECK_EQ(import_report->get_failed().size(), 0); |
no test coverage detected