| 57 | } |
| 58 | |
| 59 | Error test_export_texture(const String &version) { |
| 60 | String test_dir = get_test_resources_path().path_join(version).path_join("texture"); |
| 61 | Vector<String> files = gdre::get_recursive_dir_list(test_dir, { "*.ctex" }); |
| 62 | String output_dir = get_tmp_path().path_join(version).path_join("texture"); |
| 63 | for (const String &file : files) { |
| 64 | // original file |
| 65 | String original_file = file.rsplit("-", true, 1)[0]; |
| 66 | String output_file = output_dir.path_join(original_file.get_file()); |
| 67 | gdre::ensure_dir(output_file.get_base_dir()); |
| 68 | |
| 69 | Error err = Exporter::export_file(output_file, file); |
| 70 | CHECK(err == OK); |
| 71 | |
| 72 | Ref<Texture2D> original_texture = ResourceCompatLoader::non_global_load(file); |
| 73 | CHECK(original_texture.is_valid()); |
| 74 | |
| 75 | Ref<Image> original_image = original_texture->get_image(); |
| 76 | CHECK(original_image.is_valid()); |
| 77 | |
| 78 | Ref<Image> exported_image; |
| 79 | exported_image.instantiate(); |
| 80 | exported_image->load(output_file); |
| 81 | CHECK(original_image->get_width() == exported_image->get_width()); |
| 82 | CHECK(original_image->get_height() == exported_image->get_height()); |
| 83 | for (int64_t x = 0; x < original_image->get_width(); x++) { |
| 84 | for (int64_t y = 0; y < original_image->get_height(); y++) { |
| 85 | Color c = original_image->get_pixel(x, y); |
| 86 | Color c2 = exported_image->get_pixel(x, y); |
| 87 | if (c != c2) { |
| 88 | CHECK(c.a == 0.0); |
| 89 | CHECK(c.a == c2.a); |
| 90 | } else { |
| 91 | CHECK(c == c2); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | return OK; |
| 97 | } |
| 98 | |
| 99 | } // namespace TestResourceExport |
no test coverage detected