| 1 | // vtest build: !docker-ubuntu-musl // needs GL/gl.h |
| 2 | module gg |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | const background_path = os.join_path(@VEXEROOT, 'examples/flappylearning/assets/img/background.png') |
| 7 | |
| 8 | fn test_load_image_loads_supported_file_contents() { |
| 9 | img := load_image(background_path)! |
| 10 | assert img.width > 0 |
| 11 | assert img.height > 0 |
| 12 | assert img.nr_channels == 4 |
| 13 | assert img.path == background_path |
| 14 | } |
| 15 | |
| 16 | fn test_load_image_returns_error_for_unsupported_file_contents() { |
| 17 | file := os.join_path(os.vtmp_dir(), 'gg_unsupported_image_${os.getpid()}.jpg') |
| 18 | os.write_file(file, 'not an image') or { panic(err) } |
| 19 | defer { |
| 20 | os.rm(file) or {} |
| 21 | } |
| 22 | load_image(file) or { |
| 23 | assert err.msg().contains('stbi_image failed to load') |
| 24 | return |
| 25 | } |
| 26 | assert false |
| 27 | } |
| 28 | |