| 1 | module builder |
| 2 | |
| 3 | import os |
| 4 | import v.pref |
| 5 | |
| 6 | fn test_parse_existing_ico_file() { |
| 7 | icon_path := os.join_path(@VEXEROOT, 'cmd', 'tools', 'vdoc', 'theme', 'favicons', 'favicon.ico') |
| 8 | images := parse_ico_file(icon_path)! |
| 9 | assert images.len > 0 |
| 10 | for image in images { |
| 11 | assert image.image_data.len > 0 |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | fn test_png_to_ico_bytes_roundtrip() { |
| 16 | png_path := os.join_path(@VEXEROOT, 'examples', 'assets', 'logo.png') |
| 17 | png_bytes := os.read_bytes(png_path)! |
| 18 | ico_bytes := png_to_ico_bytes(png_bytes)! |
| 19 | images := parse_ico_bytes(ico_bytes)! |
| 20 | assert images.len == 1 |
| 21 | assert images[0].bytes_in_res == png_bytes.len |
| 22 | assert images[0].image_data == png_bytes |
| 23 | } |
| 24 | |
| 25 | fn test_png_dimensions_reads_valid_png() { |
| 26 | png_path := os.join_path(@VEXEROOT, 'examples', 'assets', 'logo.png') |
| 27 | size := png_dimensions(os.read_bytes(png_path)!)! |
| 28 | assert size.width > 0 |
| 29 | assert size.height > 0 |
| 30 | assert size.width <= max_windows_icon_dimension |
| 31 | assert size.height <= max_windows_icon_dimension |
| 32 | } |
| 33 | |
| 34 | fn test_parse_ico_bytes_rejects_invalid_data() { |
| 35 | if _ := parse_ico_bytes([]u8{}) { |
| 36 | assert false |
| 37 | } else { |
| 38 | assert err.msg().contains('invalid icon file') |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | fn test_windows_icon_flag_parsing() { |
| 43 | target := os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 44 | icon := os.join_path(@VEXEROOT, 'cmd', 'tools', 'vdoc', 'theme', 'favicons', 'favicon.ico') |
| 45 | prefs, _ := pref.parse_args_and_show_errors([], ['', '-os', 'windows', '-icon', icon, target], |
| 46 | false) |
| 47 | assert prefs.icon_path == os.real_path(icon) |
| 48 | assert prefs.build_options.contains('-icon "${os.real_path(icon)}"') |
| 49 | } |
| 50 | |
| 51 | fn test_windows_icon_flag_parsing_with_inline_aliases() { |
| 52 | target := os.join_path(@VEXEROOT, 'examples', 'hello_world.v') |
| 53 | icon := os.join_path(@VEXEROOT, 'examples', 'assets', 'logo.png') |
| 54 | for arg in ['-icon=${icon}', '--icon=${icon}', '-seticon=${icon}', '--seticon=${icon}'] { |
| 55 | prefs, _ := pref.parse_args_and_show_errors([], ['', '-os', 'windows', arg, target], false) |
| 56 | assert prefs.icon_path == os.real_path(icon) |
| 57 | assert prefs.build_options.contains('-icon "${os.real_path(icon)}"') |
| 58 | } |
| 59 | } |
| 60 | |