v2 / vlib / gg / image_private_test.v
27 lines · 23 sloc · 722 bytes · 77e978cae58fd2c701bd0cd73168dc28baa2a21f
Raw
1// vtest build: !docker-ubuntu-musl // needs GL/gl.h
2module gg
3
4import os
5
6const background_path = os.join_path(@VEXEROOT, 'examples/flappylearning/assets/img/background.png')
7
8fn 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
16fn 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