]> luflow.net public git repositories - flow-texpack.git/blob - tests/cli.rs
Initial commit.
[flow-texpack.git] / tests / cli.rs
1 // flow-texpack: A program that will allow you to generate texture atlas.
2 // public domain License
3
4 use assert_cmd::cargo::*;
5 use std::path::PathBuf;
6
7 use flow_texpack::{Texture, exists_file, remove_dir_all, remove_file};
8
9 fn verify_texture_size(image_path: &PathBuf, width: u32, height: u32) {
10 let mut t1 = Texture::new();
11 t1.load(image_path, false, false, false, 0, 1024);
12 assert_eq!(t1.width, width);
13 assert_eq!(t1.height, height);
14 }
15
16 fn validate_descriptor_json(json_path: &PathBuf) {
17 let contents = std::fs::read_to_string(json_path).unwrap();
18 let mut lines = contents.lines();
19
20 assert_eq!(Some("{"), lines.next());
21 assert_eq!(Some("\t\"ImageAtlas\":"), lines.next());
22 assert_eq!(Some("\t{"), lines.next());
23 assert_eq!(Some("\t\t\"info\":"), lines.next());
24 assert_eq!(Some("\t\t{"), lines.next());
25 assert_eq!(Some("\t\t\t\"numberOfAtlasImages\": 1,"), lines.next());
26 assert_eq!(
27 Some("\t\t\t\"generatedWith\": \"https://luflow.net/git-repos/flow-texpack.git\""),
28 lines.next()
29 );
30 assert_eq!(Some("\t\t},"), lines.next());
31 assert_eq!(Some("\t\t\"AtlasImage\":"), lines.next());
32 assert_eq!(Some("\t\t["), lines.next());
33
34 // files part:
35 assert_eq!(Some("\t\t\t{"), lines.next());
36 assert_eq!(Some("\t\t\t\t\"n\": \"atlas0.png\","), lines.next());
37 assert_eq!(Some("\t\t\t\t\"numImages\": 2,"), lines.next());
38 assert_eq!(Some("\t\t\t\t\"width\": 64,"), lines.next());
39 assert_eq!(Some("\t\t\t\t\"height\": 64,"), lines.next());
40 assert_eq!(Some("\t\t\t\t\"generateMipMaps\": 1,"), lines.next());
41 assert_eq!(Some("\t\t\t\t\"img\":"), lines.next());
42 assert_eq!(Some("\t\t\t\t["), lines.next());
43 assert_eq!(Some("\t\t\t\t\t{"), lines.next());
44 assert_eq!(
45 Some(
46 "\t\t\t\t\t\t\"n\": \"white_32x32.png\", \"x\": 0, \"y\": 0, \"w\": 32, \"h\": 32, \"trimmed\": 0, \"rotated\": 0, \"fx\": 0, \"fy\": 0, \"fw\": 32, \"fh\": 32"
47 ),
48 lines.next()
49 );
50 assert_eq!(Some("\t\t\t\t\t},"), lines.next());
51 assert_eq!(Some("\t\t\t\t\t{"), lines.next());
52 assert_eq!(
53 Some(
54 "\t\t\t\t\t\t\"n\": \"white_32x16.png\", \"x\": 0, \"y\": 36, \"w\": 32, \"h\": 16, \"trimmed\": 0, \"rotated\": 0, \"fx\": 0, \"fy\": 0, \"fw\": 32, \"fh\": 16"
55 ),
56 lines.next()
57 );
58 assert_eq!(Some("\t\t\t\t\t}"), lines.next());
59 assert_eq!(Some("\t\t\t\t]"), lines.next());
60 assert_eq!(Some("\t\t\t}"), lines.next());
61
62 assert_eq!(Some("\t\t]"), lines.next());
63 assert_eq!(Some("\t}"), lines.next());
64 assert_eq!(Some("}"), lines.next());
65 }
66
67 fn validate_descriptor_txt(txt_path: &PathBuf, with_header: bool) {
68 let contents = std::fs::read_to_string(txt_path).unwrap();
69 let mut lines = contents.lines();
70
71 if with_header {
72 assert_eq!(Some("/*"), lines.next());
73 assert_eq!(
74 Some("\t ************************************************"),
75 lines.next()
76 );
77 assert_eq!(
78 Some("\t * Generated with: https://luflow.net/git-repos/flow-texpack.git"),
79 lines.next()
80 );
81 assert_eq!(
82 Some("\t ************************************************"),
83 lines.next()
84 );
85 assert_eq!(Some(""), lines.next());
86 assert_eq!(
87 Some("\t ************************************************"),
88 lines.next()
89 );
90 assert_eq!(Some("\t * Format description:"), lines.next());
91 assert_eq!(
92 Some("\t ************************************************"),
93 lines.next()
94 );
95 assert_eq!(Some("\t [info]"), lines.next());
96 assert_eq!(Some("\t numberOfAtlasImages,generatedWith"), lines.next());
97 assert_eq!(Some(""), lines.next());
98 assert_eq!(
99 Some("\t [AtlasImage (repeated numberOfAtlasImages)]"),
100 lines.next()
101 );
102 assert_eq!(
103 Some(
104 "\t atlasImageName,numberOfImages,atlasImageWidth,atlasImageHeight,generateMipMaps"
105 ),
106 lines.next()
107 );
108 assert_eq!(Some(""), lines.next());
109 assert_eq!(Some("\t [Image (repeated numberOfImages)]"), lines.next());
110 assert_eq!(
111 Some(
112 "\t name,x,y,w,h,trimmed,rotated,fx,fy,fw,fh (NOTE: fx,fy,fw,fh valid if trimmed==1)"
113 ),
114 lines.next()
115 );
116 assert_eq!(Some(""), lines.next());
117 assert_eq!(Some("\t Text format example:"), lines.next());
118 assert_eq!(Some("\t [info]"), lines.next());
119 assert_eq!(Some("\t [AtlasImage]"), lines.next());
120 assert_eq!(Some("\t [Image]"), lines.next());
121 assert_eq!(Some("\t [Image]"), lines.next());
122 assert_eq!(Some("\t ..."), lines.next());
123 assert_eq!(Some("\t [AtlasImage]"), lines.next());
124 assert_eq!(Some("\t [Image]"), lines.next());
125 assert_eq!(Some("\t [Image]"), lines.next());
126 assert_eq!(Some("\t ..."), lines.next());
127 assert_eq!(Some("*/@"), lines.next());
128 }
129
130 assert_eq!(
131 Some("1,https://luflow.net/git-repos/flow-texpack.git"),
132 lines.next()
133 );
134 assert_eq!(Some("atlas0.png,2,64,64,1"), lines.next());
135 assert_eq!(
136 Some("white_32x32.png,0,0,32,32,0,0,0,0,32,32"),
137 lines.next()
138 );
139 assert_eq!(
140 Some("white_32x16.png,0,36,32,16,0,0,0,0,32,16"),
141 lines.next()
142 );
143 }
144
145 fn get_hash_value(hash_path: &PathBuf) -> u64 {
146 let result = std::fs::read_to_string(hash_path);
147
148 let old_hash_value = match result {
149 Ok(old_hash_value) => old_hash_value.parse().unwrap(),
150 Err(_) => 0,
151 };
152
153 return old_hash_value;
154 }
155
156 // *************************************************
157 // Integration tests that should fail:
158 // *************************************************
159 #[test]
160 fn cli_error_no_arguments() -> Result<(), Box<dyn std::error::Error>> {
161 let mut cmd = cargo_bin_cmd!("flow-texpack");
162
163 cmd.assert().failure();
164
165 Ok(())
166 }
167
168 #[test]
169 fn cli_error_no_input() -> Result<(), Box<dyn std::error::Error>> {
170 let mut cmd = cargo_bin_cmd!("flow-texpack");
171
172 cmd.arg("-i");
173 cmd.assert().failure();
174
175 Ok(())
176 }
177
178 #[test]
179 fn cli_error_no_input_v2() -> Result<(), Box<dyn std::error::Error>> {
180 let mut cmd = cargo_bin_cmd!("flow-texpack");
181
182 cmd.arg("--input");
183 cmd.assert().failure();
184
185 Ok(())
186 }
187
188 #[test]
189 fn cli_error_no_input_v3() -> Result<(), Box<dyn std::error::Error>> {
190 let mut cmd = cargo_bin_cmd!("flow-texpack");
191
192 cmd.arg("-i").arg("test_data2");
193 cmd.assert().failure();
194
195 Ok(())
196 }
197
198 #[test]
199 fn cli_error_no_input_file() -> Result<(), Box<dyn std::error::Error>> {
200 let mut cmd = cargo_bin_cmd!("flow-texpack");
201
202 cmd.arg("--input-file");
203 cmd.assert().failure();
204
205 Ok(())
206 }
207
208 #[test]
209 fn cli_error_no_input_file_v2() -> Result<(), Box<dyn std::error::Error>> {
210 let mut cmd = cargo_bin_cmd!("flow-texpack");
211
212 cmd.arg("--input-file").arg("test_data/input_not_found.txt");
213 cmd.assert().failure();
214
215 Ok(())
216 }
217
218 #[test]
219 fn cli_error_no_exclude_file() -> Result<(), Box<dyn std::error::Error>> {
220 let mut cmd = cargo_bin_cmd!("flow-texpack");
221
222 cmd.arg("-i").arg("test_data").arg("--exclude-file");
223 cmd.assert().failure();
224
225 Ok(())
226 }
227
228 #[test]
229 fn cli_error_no_exclude_file_v2() -> Result<(), Box<dyn std::error::Error>> {
230 let mut cmd = cargo_bin_cmd!("flow-texpack");
231
232 cmd.arg("-i")
233 .arg("test_data")
234 .arg("--exclude-file")
235 .arg("test_data/exclude_not_found.txt");
236 cmd.assert().failure();
237
238 Ok(())
239 }
240
241 #[test]
242 fn cli_error_no_output() -> Result<(), Box<dyn std::error::Error>> {
243 let mut cmd = cargo_bin_cmd!("flow-texpack");
244
245 cmd.arg("-i").arg("test_data").arg("-o");
246 cmd.assert().failure();
247
248 Ok(())
249 }
250
251 #[test]
252 fn cli_error_no_output_v2() -> Result<(), Box<dyn std::error::Error>> {
253 let mut cmd = cargo_bin_cmd!("flow-texpack");
254
255 cmd.arg("-i").arg("test_data").arg("--output");
256 cmd.assert().failure();
257
258 Ok(())
259 }
260
261 #[test]
262 fn cli_error_invalid_atlas_descriptor() -> Result<(), Box<dyn std::error::Error>> {
263 let mut cmd = cargo_bin_cmd!("flow-texpack");
264
265 cmd.arg("-i")
266 .arg("test_data")
267 .arg("-o")
268 .arg("test_data/out/atlas")
269 .arg("--atlas-descriptor")
270 .arg("invalid");
271 cmd.assert().failure();
272
273 Ok(())
274 }
275
276 #[test]
277 fn cli_error_invalid_atlas_image() -> Result<(), Box<dyn std::error::Error>> {
278 let mut cmd = cargo_bin_cmd!("flow-texpack");
279
280 cmd.arg("-i")
281 .arg("test_data")
282 .arg("-o")
283 .arg("test_data/out/atlas")
284 .arg("--atlas-image")
285 .arg("invalid");
286 cmd.assert().failure();
287
288 Ok(())
289 }
290
291 #[test]
292 fn cli_error_invalid_atlas_size() -> Result<(), Box<dyn std::error::Error>> {
293 let mut cmd = cargo_bin_cmd!("flow-texpack");
294
295 cmd.arg("-i")
296 .arg("test_data")
297 .arg("-o")
298 .arg("test_data/out/atlas")
299 .arg("--atlas-size")
300 .arg("invalid");
301 cmd.assert().failure();
302
303 Ok(())
304 }
305
306 #[test]
307 fn cli_error_invalid_load_filter() -> Result<(), Box<dyn std::error::Error>> {
308 let mut cmd = cargo_bin_cmd!("flow-texpack");
309
310 cmd.arg("-i")
311 .arg("test_data")
312 .arg("-o")
313 .arg("test_data/out/atlas")
314 .arg("--load-filter")
315 .arg("invalid");
316 cmd.assert().failure();
317
318 Ok(())
319 }
320
321 #[test]
322 fn cli_error_invalid_max_atlases() -> Result<(), Box<dyn std::error::Error>> {
323 let mut cmd = cargo_bin_cmd!("flow-texpack");
324
325 cmd.arg("-i")
326 .arg("test_data")
327 .arg("-o")
328 .arg("test_data/out/atlas")
329 .arg("--max-atlases")
330 .arg("4097");
331 cmd.assert().failure();
332
333 Ok(())
334 }
335
336 #[test]
337 fn cli_error_invalid_padding() -> Result<(), Box<dyn std::error::Error>> {
338 let mut cmd = cargo_bin_cmd!("flow-texpack");
339
340 cmd.arg("-i")
341 .arg("test_data")
342 .arg("-o")
343 .arg("test_data/out/atlas")
344 .arg("-p")
345 .arg("17");
346 cmd.assert().failure();
347
348 Ok(())
349 }
350
351 #[test]
352 fn cli_error_invalid_padding_v2() -> Result<(), Box<dyn std::error::Error>> {
353 let mut cmd = cargo_bin_cmd!("flow-texpack");
354
355 cmd.arg("-i")
356 .arg("test_data")
357 .arg("-o")
358 .arg("test_data/out/atlas")
359 .arg("--pad")
360 .arg("17");
361 cmd.assert().failure();
362
363 Ok(())
364 }
365
366 #[test]
367 fn cli_error_invalid_rect_heuristic() -> Result<(), Box<dyn std::error::Error>> {
368 let mut cmd = cargo_bin_cmd!("flow-texpack");
369
370 cmd.arg("-i")
371 .arg("test_data")
372 .arg("-o")
373 .arg("test_data/out/atlas")
374 .arg("--rect-heuristic")
375 .arg("invalid");
376 cmd.assert().failure();
377
378 Ok(())
379 }
380
381 // *************************************************
382 // Integration tests that should succeed:
383 // *************************************************
384 #[test]
385 fn cli_success_input_defaults() -> Result<(), Box<dyn std::error::Error>> {
386 let mut cmd = cargo_bin_cmd!("flow-texpack");
387 let out_file_path = "test_data/cli_success_input_defaults/atlas";
388 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
389
390 cmd.arg("-i")
391 .arg("test_data/white_32x32.png")
392 .arg("-o")
393 .arg(out_file_path);
394 cmd.assert().success();
395
396 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
397 let json_path = PathBuf::from(format!("{}.json", out_file_path));
398 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
399
400 assert_eq!(exists_file(&hash_path), true);
401 assert_eq!(exists_file(&json_path), true);
402 assert_eq!(exists_file(&image_path), true);
403 assert_eq!(get_hash_value(&hash_path) > 0, true);
404
405 verify_texture_size(&image_path, 64, 64);
406
407 remove_dir_all(&parent_path);
408
409 assert_eq!(exists_file(&hash_path), false);
410 assert_eq!(exists_file(&json_path), false);
411 assert_eq!(exists_file(&image_path), false);
412
413 Ok(())
414 }
415
416 #[test]
417 fn cli_success_input_defaults_v2() -> Result<(), Box<dyn std::error::Error>> {
418 let mut cmd = cargo_bin_cmd!("flow-texpack");
419 let out_file_path = "test_data/cli_success_input_defaults_v2/atlas";
420 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
421
422 cmd.arg("--input")
423 .arg("test_data/white_32x32.png")
424 .arg("-o")
425 .arg(out_file_path);
426 cmd.assert().success();
427
428 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
429 let json_path = PathBuf::from(format!("{}.json", out_file_path));
430 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
431
432 assert_eq!(exists_file(&hash_path), true);
433 assert_eq!(exists_file(&json_path), true);
434 assert_eq!(exists_file(&image_path), true);
435 assert_eq!(get_hash_value(&hash_path) > 0, true);
436
437 verify_texture_size(&image_path, 64, 64);
438
439 remove_dir_all(&parent_path);
440
441 assert_eq!(exists_file(&hash_path), false);
442 assert_eq!(exists_file(&json_path), false);
443 assert_eq!(exists_file(&image_path), false);
444
445 Ok(())
446 }
447
448 #[test]
449 fn cli_success_input_with_exclude_defaults() -> Result<(), Box<dyn std::error::Error>> {
450 let mut cmd = cargo_bin_cmd!("flow-texpack");
451 let out_file_path = "test_data/cli_success_input_with_exclude_defaults/atlas";
452 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
453
454 cmd.arg("-i")
455 .arg("test_data/white_32x32.png")
456 .arg("test_data/blue_32x32.png")
457 .arg("-e")
458 .arg("test_data/white_32x32.png")
459 .arg("-o")
460 .arg(out_file_path);
461 cmd.assert().success();
462
463 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
464 let json_path = PathBuf::from(format!("{}.json", out_file_path));
465 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
466
467 assert_eq!(exists_file(&hash_path), true);
468 assert_eq!(exists_file(&json_path), true);
469 assert_eq!(exists_file(&image_path), true);
470 assert_eq!(get_hash_value(&hash_path) > 0, true);
471
472 verify_texture_size(&image_path, 64, 64);
473
474 remove_dir_all(&parent_path);
475
476 assert_eq!(exists_file(&hash_path), false);
477 assert_eq!(exists_file(&json_path), false);
478 assert_eq!(exists_file(&image_path), false);
479
480 Ok(())
481 }
482
483 #[test]
484 fn cli_success_input_with_exclude_defaults_v2() -> Result<(), Box<dyn std::error::Error>> {
485 let mut cmd = cargo_bin_cmd!("flow-texpack");
486 let out_file_path = "test_data/cli_success_input_with_exclude_defaults_v2/atlas";
487 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
488
489 cmd.arg("-i")
490 .arg("test_data/white_32x32.png")
491 .arg("test_data/blue_32x32.png")
492 .arg("--exclude")
493 .arg("test_data/white_32x32.png")
494 .arg("-o")
495 .arg(out_file_path);
496 cmd.assert().success();
497
498 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
499 let json_path = PathBuf::from(format!("{}.json", out_file_path));
500 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
501
502 assert_eq!(exists_file(&hash_path), true);
503 assert_eq!(exists_file(&json_path), true);
504 assert_eq!(exists_file(&image_path), true);
505 assert_eq!(get_hash_value(&hash_path) > 0, true);
506
507 verify_texture_size(&image_path, 64, 64);
508
509 remove_dir_all(&parent_path);
510
511 assert_eq!(exists_file(&hash_path), false);
512 assert_eq!(exists_file(&json_path), false);
513 assert_eq!(exists_file(&image_path), false);
514
515 Ok(())
516 }
517
518 #[test]
519 fn cli_success_input_defaults_verbose() -> Result<(), Box<dyn std::error::Error>> {
520 let mut cmd = cargo_bin_cmd!("flow-texpack");
521 let out_file_path = "test_data/cli_success_input_defaults_verbose/atlas";
522 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
523
524 cmd.arg("-i")
525 .arg("test_data/white_32x32.png")
526 .arg("-o")
527 .arg(out_file_path)
528 .arg("-v");
529 cmd.assert().success();
530
531 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
532 let json_path = PathBuf::from(format!("{}.json", out_file_path));
533 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
534
535 assert_eq!(exists_file(&hash_path), true);
536 assert_eq!(exists_file(&json_path), true);
537 assert_eq!(exists_file(&image_path), true);
538 assert_eq!(get_hash_value(&hash_path) > 0, true);
539
540 verify_texture_size(&image_path, 64, 64);
541
542 remove_dir_all(&parent_path);
543
544 assert_eq!(exists_file(&hash_path), false);
545 assert_eq!(exists_file(&json_path), false);
546 assert_eq!(exists_file(&image_path), false);
547
548 Ok(())
549 }
550
551 #[test]
552 fn cli_success_input_defaults_verbose_v2() -> Result<(), Box<dyn std::error::Error>> {
553 let mut cmd = cargo_bin_cmd!("flow-texpack");
554 let out_file_path = "test_data/cli_success_input_defaults_verbose_v2/atlas";
555 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
556
557 cmd.arg("-i")
558 .arg("test_data/white_32x32.png")
559 .arg("-o")
560 .arg(out_file_path)
561 .arg("--verbose");
562 cmd.assert().success();
563
564 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
565 let json_path = PathBuf::from(format!("{}.json", out_file_path));
566 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
567
568 assert_eq!(exists_file(&hash_path), true);
569 assert_eq!(exists_file(&json_path), true);
570 assert_eq!(exists_file(&image_path), true);
571 assert_eq!(get_hash_value(&hash_path) > 0, true);
572
573 verify_texture_size(&image_path, 64, 64);
574
575 remove_dir_all(&parent_path);
576
577 assert_eq!(exists_file(&hash_path), false);
578 assert_eq!(exists_file(&json_path), false);
579 assert_eq!(exists_file(&image_path), false);
580
581 Ok(())
582 }
583
584 #[test]
585 fn cli_success_input_defaults_log() -> Result<(), Box<dyn std::error::Error>> {
586 let mut cmd = cargo_bin_cmd!("flow-texpack");
587 let out_file_path = "test_data/cli_success_input_defaults_log/atlas";
588 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
589
590 cmd.arg("-i")
591 .arg("test_data/white_32x32.png")
592 .arg("-o")
593 .arg(out_file_path)
594 .arg("-l");
595 cmd.assert().success();
596
597 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
598 let json_path = PathBuf::from(format!("{}.json", out_file_path));
599 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
600 let log_path = PathBuf::from("flow-texpack.log");
601
602 assert_eq!(exists_file(&hash_path), true);
603 assert_eq!(exists_file(&json_path), true);
604 assert_eq!(exists_file(&image_path), true);
605 assert_eq!(get_hash_value(&hash_path) > 0, true);
606 assert_eq!(exists_file(&log_path), true);
607
608 verify_texture_size(&image_path, 64, 64);
609
610 remove_dir_all(&parent_path);
611 remove_file(&log_path);
612
613 assert_eq!(exists_file(&hash_path), false);
614 assert_eq!(exists_file(&json_path), false);
615 assert_eq!(exists_file(&image_path), false);
616 assert_eq!(exists_file(&log_path), false);
617
618 Ok(())
619 }
620
621 #[test]
622 fn cli_success_input_defaults_version() -> Result<(), Box<dyn std::error::Error>> {
623 let mut cmd = cargo_bin_cmd!("flow-texpack");
624
625 cmd.arg("-V");
626 cmd.assert().success();
627
628 Ok(())
629 }
630
631 #[test]
632 fn cli_success_input_defaults_version_v2() -> Result<(), Box<dyn std::error::Error>> {
633 let mut cmd = cargo_bin_cmd!("flow-texpack");
634
635 cmd.arg("--version");
636 cmd.assert().success();
637
638 Ok(())
639 }
640
641 #[test]
642 fn cli_success_input_defaults_help() -> Result<(), Box<dyn std::error::Error>> {
643 let mut cmd = cargo_bin_cmd!("flow-texpack");
644
645 cmd.arg("-h");
646 cmd.assert().success();
647
648 Ok(())
649 }
650
651 #[test]
652 fn cli_success_input_defaults_help_v2() -> Result<(), Box<dyn std::error::Error>> {
653 let mut cmd = cargo_bin_cmd!("flow-texpack");
654
655 cmd.arg("--help");
656 cmd.assert().success();
657
658 Ok(())
659 }
660
661 #[test]
662 fn cli_success_input_defaults_force() -> Result<(), Box<dyn std::error::Error>> {
663 let mut cmd = cargo_bin_cmd!("flow-texpack");
664 let out_file_path = "test_data/cli_success_input_defaults_force/atlas";
665 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
666
667 cmd.arg("-i")
668 .arg("test_data/white_32x32.png")
669 .arg("-o")
670 .arg(out_file_path)
671 .arg("-f");
672 cmd.assert().success();
673
674 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
675 let json_path = PathBuf::from(format!("{}.json", out_file_path));
676 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
677
678 assert_eq!(exists_file(&hash_path), true);
679 assert_eq!(exists_file(&json_path), true);
680 assert_eq!(exists_file(&image_path), true);
681 assert_eq!(get_hash_value(&hash_path) == 0, true);
682
683 verify_texture_size(&image_path, 64, 64);
684
685 remove_dir_all(&parent_path);
686
687 assert_eq!(exists_file(&hash_path), false);
688 assert_eq!(exists_file(&json_path), false);
689 assert_eq!(exists_file(&image_path), false);
690
691 Ok(())
692 }
693
694 #[test]
695 fn cli_success_input_defaults_force_v2() -> Result<(), Box<dyn std::error::Error>> {
696 let mut cmd = cargo_bin_cmd!("flow-texpack");
697 let out_file_path = "test_data/cli_success_input_defaults_force_v2/atlas";
698 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
699
700 cmd.arg("-i")
701 .arg("test_data/white_32x32.png")
702 .arg("-o")
703 .arg(out_file_path)
704 .arg("--force");
705 cmd.assert().success();
706
707 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
708 let json_path = PathBuf::from(format!("{}.json", out_file_path));
709 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
710
711 assert_eq!(exists_file(&hash_path), true);
712 assert_eq!(exists_file(&json_path), true);
713 assert_eq!(exists_file(&image_path), true);
714 assert_eq!(get_hash_value(&hash_path) == 0, true);
715
716 verify_texture_size(&image_path, 64, 64);
717
718 remove_dir_all(&parent_path);
719
720 assert_eq!(exists_file(&hash_path), false);
721 assert_eq!(exists_file(&json_path), false);
722 assert_eq!(exists_file(&image_path), false);
723
724 Ok(())
725 }
726
727 #[test]
728 fn cli_success_input_defaults_force_square() -> Result<(), Box<dyn std::error::Error>> {
729 let mut cmd = cargo_bin_cmd!("flow-texpack");
730 let out_file_path = "test_data/cli_success_input_defaults_force_square/atlas";
731 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
732
733 cmd.arg("-i")
734 .arg("test_data/white_32x16.png")
735 .arg("-o")
736 .arg(out_file_path)
737 .arg("--force-square");
738 cmd.assert().success();
739
740 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
741 let json_path = PathBuf::from(format!("{}.json", out_file_path));
742 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
743
744 assert_eq!(exists_file(&hash_path), true);
745 assert_eq!(exists_file(&json_path), true);
746 assert_eq!(exists_file(&image_path), true);
747 assert_eq!(get_hash_value(&hash_path) > 0, true);
748
749 verify_texture_size(&image_path, 1024, 1024);
750
751 remove_dir_all(&parent_path);
752
753 assert_eq!(exists_file(&hash_path), false);
754 assert_eq!(exists_file(&json_path), false);
755 assert_eq!(exists_file(&image_path), false);
756
757 Ok(())
758 }
759
760 #[test]
761 fn cli_success_input_defaults_atlas_image_png() -> Result<(), Box<dyn std::error::Error>> {
762 let mut cmd = cargo_bin_cmd!("flow-texpack");
763 let out_file_path = "test_data/cli_success_input_defaults_atlas_image_png/atlas";
764 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
765
766 cmd.arg("-i")
767 .arg("test_data/green_32x32.png")
768 .arg("-o")
769 .arg(out_file_path)
770 .arg("--atlas-image")
771 .arg("png");
772 cmd.assert().success();
773
774 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
775 let json_path = PathBuf::from(format!("{}.json", out_file_path));
776 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
777
778 assert_eq!(exists_file(&hash_path), true);
779 assert_eq!(exists_file(&json_path), true);
780 assert_eq!(exists_file(&image_path), true);
781 assert_eq!(get_hash_value(&hash_path) > 0, true);
782
783 verify_texture_size(&image_path, 64, 64);
784
785 remove_dir_all(&parent_path);
786
787 assert_eq!(exists_file(&hash_path), false);
788 assert_eq!(exists_file(&json_path), false);
789 assert_eq!(exists_file(&image_path), false);
790
791 Ok(())
792 }
793
794 #[test]
795 fn cli_success_input_defaults_atlas_image_tga() -> Result<(), Box<dyn std::error::Error>> {
796 let mut cmd = cargo_bin_cmd!("flow-texpack");
797 let out_file_path = "test_data/cli_success_input_defaults_atlas_image_tga/atlas";
798 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
799
800 cmd.arg("-i")
801 .arg("test_data/green_32x32.png")
802 .arg("-o")
803 .arg(out_file_path)
804 .arg("--atlas-image")
805 .arg("tga");
806 cmd.assert().success();
807
808 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
809 let json_path = PathBuf::from(format!("{}.json", out_file_path));
810 let image_path = PathBuf::from(format!("{}0.tga", out_file_path));
811
812 assert_eq!(exists_file(&hash_path), true);
813 assert_eq!(exists_file(&json_path), true);
814 assert_eq!(exists_file(&image_path), true);
815 assert_eq!(get_hash_value(&hash_path) > 0, true);
816
817 verify_texture_size(&image_path, 64, 64);
818
819 remove_dir_all(&parent_path);
820
821 assert_eq!(exists_file(&hash_path), false);
822 assert_eq!(exists_file(&json_path), false);
823 assert_eq!(exists_file(&image_path), false);
824
825 Ok(())
826 }
827
828 #[test]
829 fn cli_success_input_defaults_atlas_image_tiff() -> Result<(), Box<dyn std::error::Error>> {
830 let mut cmd = cargo_bin_cmd!("flow-texpack");
831 let out_file_path = "test_data/cli_success_input_defaults_atlas_image_tiff/atlas";
832 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
833
834 cmd.arg("-i")
835 .arg("test_data/green_32x32.png")
836 .arg("-o")
837 .arg(out_file_path)
838 .arg("--atlas-image")
839 .arg("tiff");
840 cmd.assert().success();
841
842 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
843 let json_path = PathBuf::from(format!("{}.json", out_file_path));
844 let image_path = PathBuf::from(format!("{}0.tiff", out_file_path));
845
846 assert_eq!(exists_file(&hash_path), true);
847 assert_eq!(exists_file(&json_path), true);
848 assert_eq!(exists_file(&image_path), true);
849 assert_eq!(get_hash_value(&hash_path) > 0, true);
850
851 verify_texture_size(&image_path, 64, 64);
852
853 remove_dir_all(&parent_path);
854
855 assert_eq!(exists_file(&hash_path), false);
856 assert_eq!(exists_file(&json_path), false);
857 assert_eq!(exists_file(&image_path), false);
858
859 Ok(())
860 }
861
862 #[test]
863 fn cli_success_input_defaults_atlas_image_webp() -> Result<(), Box<dyn std::error::Error>> {
864 let mut cmd = cargo_bin_cmd!("flow-texpack");
865 let out_file_path = "test_data/cli_success_input_defaults_atlas_image_webp/atlas";
866 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
867
868 cmd.arg("-i")
869 .arg("test_data/green_32x32.png")
870 .arg("-o")
871 .arg(out_file_path)
872 .arg("--atlas-image")
873 .arg("webp");
874 cmd.assert().success();
875
876 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
877 let json_path = PathBuf::from(format!("{}.json", out_file_path));
878 let image_path = PathBuf::from(format!("{}0.webp", out_file_path));
879
880 assert_eq!(exists_file(&hash_path), true);
881 assert_eq!(exists_file(&json_path), true);
882 assert_eq!(exists_file(&image_path), true);
883 assert_eq!(get_hash_value(&hash_path) > 0, true);
884
885 verify_texture_size(&image_path, 64, 64);
886
887 remove_dir_all(&parent_path);
888
889 assert_eq!(exists_file(&hash_path), false);
890 assert_eq!(exists_file(&json_path), false);
891 assert_eq!(exists_file(&image_path), false);
892
893 Ok(())
894 }
895
896 #[test]
897 fn cli_success_input_defaults_atlas_descriptor_json() -> Result<(), Box<dyn std::error::Error>> {
898 let mut cmd = cargo_bin_cmd!("flow-texpack");
899 let out_file_path = "test_data/cli_success_input_defaults_atlas_descriptor_json/atlas";
900 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
901
902 cmd.arg("-i")
903 .arg("test_data/green_32x32.png")
904 .arg("-o")
905 .arg(out_file_path)
906 .arg("--atlas-descriptor")
907 .arg("json");
908 cmd.assert().success();
909
910 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
911 let json_path = PathBuf::from(format!("{}.json", out_file_path));
912 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
913
914 assert_eq!(exists_file(&hash_path), true);
915 assert_eq!(exists_file(&json_path), true);
916 assert_eq!(exists_file(&image_path), true);
917 assert_eq!(get_hash_value(&hash_path) > 0, true);
918
919 verify_texture_size(&image_path, 64, 64);
920
921 remove_dir_all(&parent_path);
922
923 assert_eq!(exists_file(&hash_path), false);
924 assert_eq!(exists_file(&json_path), false);
925 assert_eq!(exists_file(&image_path), false);
926
927 Ok(())
928 }
929
930 #[test]
931 fn cli_success_input_defaults_atlas_descriptor_txt() -> Result<(), Box<dyn std::error::Error>> {
932 let mut cmd = cargo_bin_cmd!("flow-texpack");
933 let out_file_path = "test_data/cli_success_input_defaults_atlas_descriptor_txt/atlas";
934 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
935
936 cmd.arg("-i")
937 .arg("test_data/green_32x32.png")
938 .arg("-o")
939 .arg(out_file_path)
940 .arg("--atlas-descriptor")
941 .arg("txt");
942 cmd.assert().success();
943
944 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
945 let json_path = PathBuf::from(format!("{}.txt", out_file_path));
946 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
947
948 assert_eq!(exists_file(&hash_path), true);
949 assert_eq!(exists_file(&json_path), true);
950 assert_eq!(exists_file(&image_path), true);
951 assert_eq!(get_hash_value(&hash_path) > 0, true);
952
953 verify_texture_size(&image_path, 64, 64);
954
955 remove_dir_all(&parent_path);
956
957 assert_eq!(exists_file(&hash_path), false);
958 assert_eq!(exists_file(&json_path), false);
959 assert_eq!(exists_file(&image_path), false);
960
961 Ok(())
962 }
963
964 #[test]
965 fn cli_success_input_defaults_atlas_descriptor_txt_desc() -> Result<(), Box<dyn std::error::Error>>
966 {
967 let mut cmd = cargo_bin_cmd!("flow-texpack");
968 let out_file_path = "test_data/cli_success_input_defaults_atlas_descriptor_txt_desc/atlas";
969 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
970
971 cmd.arg("-i")
972 .arg("test_data/green_32x32.png")
973 .arg("-o")
974 .arg(out_file_path)
975 .arg("--atlas-descriptor")
976 .arg("txt");
977 cmd.assert().success();
978
979 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
980 let json_path = PathBuf::from(format!("{}.txt", out_file_path));
981 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
982
983 assert_eq!(exists_file(&hash_path), true);
984 assert_eq!(exists_file(&json_path), true);
985 assert_eq!(exists_file(&image_path), true);
986 assert_eq!(get_hash_value(&hash_path) > 0, true);
987
988 verify_texture_size(&image_path, 64, 64);
989
990 remove_dir_all(&parent_path);
991
992 assert_eq!(exists_file(&hash_path), false);
993 assert_eq!(exists_file(&json_path), false);
994 assert_eq!(exists_file(&image_path), false);
995
996 Ok(())
997 }
998
999 #[test]
1000 fn cli_success_input_defaults_atlas_size_64() -> Result<(), Box<dyn std::error::Error>> {
1001 let mut cmd = cargo_bin_cmd!("flow-texpack");
1002 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_64/atlas";
1003 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1004
1005 cmd.arg("-i")
1006 .arg("test_data/white_32x32.png")
1007 .arg("-o")
1008 .arg(out_file_path)
1009 .arg("--atlas-size")
1010 .arg("pot64")
1011 .arg("--force-square");
1012 cmd.assert().success();
1013
1014 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1015 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1016 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1017
1018 assert_eq!(exists_file(&hash_path), true);
1019 assert_eq!(exists_file(&json_path), true);
1020 assert_eq!(exists_file(&image_path), true);
1021 assert_eq!(get_hash_value(&hash_path) > 0, true);
1022
1023 verify_texture_size(&image_path, 64, 64);
1024
1025 remove_dir_all(&parent_path);
1026
1027 assert_eq!(exists_file(&hash_path), false);
1028 assert_eq!(exists_file(&json_path), false);
1029 assert_eq!(exists_file(&image_path), false);
1030
1031 Ok(())
1032 }
1033
1034 #[test]
1035 fn cli_success_input_defaults_atlas_size_128() -> Result<(), Box<dyn std::error::Error>> {
1036 let mut cmd = cargo_bin_cmd!("flow-texpack");
1037 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_128/atlas";
1038 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1039
1040 cmd.arg("-i")
1041 .arg("test_data/white_32x32.png")
1042 .arg("-o")
1043 .arg(out_file_path)
1044 .arg("--atlas-size")
1045 .arg("pot128")
1046 .arg("--force-square");
1047 cmd.assert().success();
1048
1049 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1050 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1051 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1052
1053 assert_eq!(exists_file(&hash_path), true);
1054 assert_eq!(exists_file(&json_path), true);
1055 assert_eq!(exists_file(&image_path), true);
1056 assert_eq!(get_hash_value(&hash_path) > 0, true);
1057
1058 verify_texture_size(&image_path, 128, 128);
1059
1060 remove_dir_all(&parent_path);
1061
1062 assert_eq!(exists_file(&hash_path), false);
1063 assert_eq!(exists_file(&json_path), false);
1064 assert_eq!(exists_file(&image_path), false);
1065
1066 Ok(())
1067 }
1068
1069 #[test]
1070 fn cli_success_input_defaults_atlas_size_256() -> Result<(), Box<dyn std::error::Error>> {
1071 let mut cmd = cargo_bin_cmd!("flow-texpack");
1072 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_256/atlas";
1073 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1074
1075 cmd.arg("-i")
1076 .arg("test_data/white_32x32.png")
1077 .arg("-o")
1078 .arg(out_file_path)
1079 .arg("--atlas-size")
1080 .arg("pot256")
1081 .arg("--force-square");
1082 cmd.assert().success();
1083
1084 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1085 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1086 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1087
1088 assert_eq!(exists_file(&hash_path), true);
1089 assert_eq!(exists_file(&json_path), true);
1090 assert_eq!(exists_file(&image_path), true);
1091 assert_eq!(get_hash_value(&hash_path) > 0, true);
1092
1093 verify_texture_size(&image_path, 256, 256);
1094
1095 remove_dir_all(&parent_path);
1096
1097 assert_eq!(exists_file(&hash_path), false);
1098 assert_eq!(exists_file(&json_path), false);
1099 assert_eq!(exists_file(&image_path), false);
1100
1101 Ok(())
1102 }
1103
1104 #[test]
1105 fn cli_success_input_defaults_atlas_size_512() -> Result<(), Box<dyn std::error::Error>> {
1106 let mut cmd = cargo_bin_cmd!("flow-texpack");
1107 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_512/atlas";
1108 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1109
1110 cmd.arg("-i")
1111 .arg("test_data/white_32x32.png")
1112 .arg("-o")
1113 .arg(out_file_path)
1114 .arg("--atlas-size")
1115 .arg("pot512")
1116 .arg("--force-square");
1117 cmd.assert().success();
1118
1119 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1120 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1121 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1122
1123 assert_eq!(exists_file(&hash_path), true);
1124 assert_eq!(exists_file(&json_path), true);
1125 assert_eq!(exists_file(&image_path), true);
1126 assert_eq!(get_hash_value(&hash_path) > 0, true);
1127
1128 verify_texture_size(&image_path, 512, 512);
1129
1130 remove_dir_all(&parent_path);
1131
1132 assert_eq!(exists_file(&hash_path), false);
1133 assert_eq!(exists_file(&json_path), false);
1134 assert_eq!(exists_file(&image_path), false);
1135
1136 Ok(())
1137 }
1138
1139 #[test]
1140 fn cli_success_input_defaults_atlas_size_1024() -> Result<(), Box<dyn std::error::Error>> {
1141 let mut cmd = cargo_bin_cmd!("flow-texpack");
1142 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_1024/atlas";
1143 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1144
1145 cmd.arg("-i")
1146 .arg("test_data/white_32x32.png")
1147 .arg("-o")
1148 .arg(out_file_path)
1149 .arg("--atlas-size")
1150 .arg("pot1024")
1151 .arg("--force-square");
1152 cmd.assert().success();
1153
1154 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1155 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1156 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1157
1158 assert_eq!(exists_file(&hash_path), true);
1159 assert_eq!(exists_file(&json_path), true);
1160 assert_eq!(exists_file(&image_path), true);
1161 assert_eq!(get_hash_value(&hash_path) > 0, true);
1162
1163 verify_texture_size(&image_path, 1024, 1024);
1164
1165 remove_dir_all(&parent_path);
1166
1167 assert_eq!(exists_file(&hash_path), false);
1168 assert_eq!(exists_file(&json_path), false);
1169 assert_eq!(exists_file(&image_path), false);
1170
1171 Ok(())
1172 }
1173
1174 #[test]
1175 fn cli_success_input_defaults_atlas_size_2048() -> Result<(), Box<dyn std::error::Error>> {
1176 let mut cmd = cargo_bin_cmd!("flow-texpack");
1177 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_2048/atlas";
1178 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1179
1180 cmd.arg("-i")
1181 .arg("test_data/white_32x32.png")
1182 .arg("-o")
1183 .arg(out_file_path)
1184 .arg("--atlas-size")
1185 .arg("pot2048")
1186 .arg("--force-square");
1187 cmd.assert().success();
1188
1189 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1190 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1191 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1192
1193 assert_eq!(exists_file(&hash_path), true);
1194 assert_eq!(exists_file(&json_path), true);
1195 assert_eq!(exists_file(&image_path), true);
1196 assert_eq!(get_hash_value(&hash_path) > 0, true);
1197
1198 verify_texture_size(&image_path, 2048, 2048);
1199
1200 remove_dir_all(&parent_path);
1201
1202 assert_eq!(exists_file(&hash_path), false);
1203 assert_eq!(exists_file(&json_path), false);
1204 assert_eq!(exists_file(&image_path), false);
1205
1206 Ok(())
1207 }
1208
1209 #[test]
1210 fn cli_success_input_defaults_atlas_size_4096() -> Result<(), Box<dyn std::error::Error>> {
1211 let mut cmd = cargo_bin_cmd!("flow-texpack");
1212 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_4096/atlas";
1213 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1214
1215 cmd.arg("-i")
1216 .arg("test_data/white_32x32.png")
1217 .arg("-o")
1218 .arg(out_file_path)
1219 .arg("--atlas-size")
1220 .arg("pot4096")
1221 .arg("--force-square");
1222 cmd.assert().success();
1223
1224 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1225 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1226 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1227
1228 assert_eq!(exists_file(&hash_path), true);
1229 assert_eq!(exists_file(&json_path), true);
1230 assert_eq!(exists_file(&image_path), true);
1231 assert_eq!(get_hash_value(&hash_path) > 0, true);
1232
1233 verify_texture_size(&image_path, 4096, 4096);
1234
1235 remove_dir_all(&parent_path);
1236
1237 assert_eq!(exists_file(&hash_path), false);
1238 assert_eq!(exists_file(&json_path), false);
1239 assert_eq!(exists_file(&image_path), false);
1240
1241 Ok(())
1242 }
1243
1244 #[test]
1245 fn cli_success_input_defaults_atlas_size_8192() -> Result<(), Box<dyn std::error::Error>> {
1246 let mut cmd = cargo_bin_cmd!("flow-texpack");
1247 let out_file_path = "test_data/cli_success_input_defaults_atlas_size_8192/atlas";
1248 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1249
1250 cmd.arg("-i")
1251 .arg("test_data/white_32x32.png")
1252 .arg("-o")
1253 .arg(out_file_path)
1254 .arg("--atlas-size")
1255 .arg("pot8192")
1256 .arg("--force-square");
1257 cmd.assert().success();
1258
1259 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1260 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1261 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1262
1263 assert_eq!(exists_file(&hash_path), true);
1264 assert_eq!(exists_file(&json_path), true);
1265 assert_eq!(exists_file(&image_path), true);
1266 assert_eq!(get_hash_value(&hash_path) > 0, true);
1267
1268 verify_texture_size(&image_path, 8192, 8192);
1269
1270 remove_dir_all(&parent_path);
1271
1272 assert_eq!(exists_file(&hash_path), false);
1273 assert_eq!(exists_file(&json_path), false);
1274 assert_eq!(exists_file(&image_path), false);
1275
1276 Ok(())
1277 }
1278
1279 #[test]
1280 fn cli_success_input_defaults_rect_heuristic_short_side_fit()
1281 -> Result<(), Box<dyn std::error::Error>> {
1282 let mut cmd = cargo_bin_cmd!("flow-texpack");
1283 let out_file_path = "test_data/cli_success_input_defaults_rect_heuristic_short_side_fit/atlas";
1284 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1285
1286 cmd.arg("-i")
1287 .arg("test_data/white_32x32.png")
1288 .arg("test_data/red_32x32.png")
1289 .arg("test_data/green_32x32.png")
1290 .arg("test_data/blue_32x32.png")
1291 .arg("-o")
1292 .arg(out_file_path)
1293 .arg("-p")
1294 .arg("0")
1295 .arg("--atlas-size")
1296 .arg("pot64")
1297 .arg("--rect-heuristic")
1298 .arg("short-side-fit");
1299 cmd.assert().success();
1300
1301 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1302 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1303 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1304
1305 assert_eq!(exists_file(&hash_path), true);
1306 assert_eq!(exists_file(&json_path), true);
1307 assert_eq!(exists_file(&image_path), true);
1308 assert_eq!(get_hash_value(&hash_path) > 0, true);
1309
1310 verify_texture_size(&image_path, 64, 64);
1311
1312 remove_dir_all(&parent_path);
1313
1314 assert_eq!(exists_file(&hash_path), false);
1315 assert_eq!(exists_file(&json_path), false);
1316 assert_eq!(exists_file(&image_path), false);
1317
1318 Ok(())
1319 }
1320
1321 #[test]
1322 fn cli_success_input_defaults_rect_heuristic_long_side_fit()
1323 -> Result<(), Box<dyn std::error::Error>> {
1324 let mut cmd = cargo_bin_cmd!("flow-texpack");
1325 let out_file_path = "test_data/cli_success_input_defaults_rect_heuristic_long_side_fit/atlas";
1326 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1327
1328 cmd.arg("-i")
1329 .arg("test_data/white_32x32.png")
1330 .arg("test_data/red_32x32.png")
1331 .arg("test_data/green_32x32.png")
1332 .arg("test_data/blue_32x32.png")
1333 .arg("-o")
1334 .arg(out_file_path)
1335 .arg("-p")
1336 .arg("0")
1337 .arg("--atlas-size")
1338 .arg("pot64")
1339 .arg("--rect-heuristic")
1340 .arg("long-side-fit");
1341 cmd.assert().success();
1342
1343 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1344 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1345 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1346
1347 assert_eq!(exists_file(&hash_path), true);
1348 assert_eq!(exists_file(&json_path), true);
1349 assert_eq!(exists_file(&image_path), true);
1350 assert_eq!(get_hash_value(&hash_path) > 0, true);
1351
1352 verify_texture_size(&image_path, 64, 64);
1353
1354 remove_dir_all(&parent_path);
1355
1356 assert_eq!(exists_file(&hash_path), false);
1357 assert_eq!(exists_file(&json_path), false);
1358 assert_eq!(exists_file(&image_path), false);
1359
1360 Ok(())
1361 }
1362
1363 #[test]
1364 fn cli_success_input_defaults_rect_heuristic_area_fit() -> Result<(), Box<dyn std::error::Error>> {
1365 let mut cmd = cargo_bin_cmd!("flow-texpack");
1366 let out_file_path = "test_data/cli_success_input_defaults_rect_heuristic_area_fit/atlas";
1367 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1368
1369 cmd.arg("-i")
1370 .arg("test_data/white_32x32.png")
1371 .arg("test_data/red_32x32.png")
1372 .arg("test_data/green_32x32.png")
1373 .arg("test_data/blue_32x32.png")
1374 .arg("-o")
1375 .arg(out_file_path)
1376 .arg("-p")
1377 .arg("0")
1378 .arg("--atlas-size")
1379 .arg("pot64")
1380 .arg("--rect-heuristic")
1381 .arg("area-fit");
1382 cmd.assert().success();
1383
1384 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1385 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1386 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1387
1388 assert_eq!(exists_file(&hash_path), true);
1389 assert_eq!(exists_file(&json_path), true);
1390 assert_eq!(exists_file(&image_path), true);
1391 assert_eq!(get_hash_value(&hash_path) > 0, true);
1392
1393 verify_texture_size(&image_path, 64, 64);
1394
1395 remove_dir_all(&parent_path);
1396
1397 assert_eq!(exists_file(&hash_path), false);
1398 assert_eq!(exists_file(&json_path), false);
1399 assert_eq!(exists_file(&image_path), false);
1400
1401 Ok(())
1402 }
1403
1404 #[test]
1405 fn cli_success_input_defaults_rect_heuristic_bottom_left() -> Result<(), Box<dyn std::error::Error>>
1406 {
1407 let mut cmd = cargo_bin_cmd!("flow-texpack");
1408 let out_file_path = "test_data/cli_success_input_defaults_rect_heuristic_bottom_left/atlas";
1409 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1410
1411 cmd.arg("-i")
1412 .arg("test_data/white_32x32.png")
1413 .arg("test_data/red_32x32.png")
1414 .arg("test_data/green_32x32.png")
1415 .arg("test_data/blue_32x32.png")
1416 .arg("-o")
1417 .arg(out_file_path)
1418 .arg("-p")
1419 .arg("0")
1420 .arg("--atlas-size")
1421 .arg("pot64")
1422 .arg("--rect-heuristic")
1423 .arg("bottom-left");
1424 cmd.assert().success();
1425
1426 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1427 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1428 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1429
1430 assert_eq!(exists_file(&hash_path), true);
1431 assert_eq!(exists_file(&json_path), true);
1432 assert_eq!(exists_file(&image_path), true);
1433 assert_eq!(get_hash_value(&hash_path) > 0, true);
1434
1435 verify_texture_size(&image_path, 64, 64);
1436
1437 remove_dir_all(&parent_path);
1438
1439 assert_eq!(exists_file(&hash_path), false);
1440 assert_eq!(exists_file(&json_path), false);
1441 assert_eq!(exists_file(&image_path), false);
1442
1443 Ok(())
1444 }
1445
1446 #[test]
1447 fn cli_success_input_defaults_rect_heuristic_contact_point()
1448 -> Result<(), Box<dyn std::error::Error>> {
1449 let mut cmd = cargo_bin_cmd!("flow-texpack");
1450 let out_file_path = "test_data/cli_success_input_defaults_rect_heuristic_contact_point/atlas";
1451 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1452
1453 cmd.arg("-i")
1454 .arg("test_data/white_32x32.png")
1455 .arg("test_data/red_32x32.png")
1456 .arg("test_data/green_32x32.png")
1457 .arg("test_data/blue_32x32.png")
1458 .arg("-o")
1459 .arg(out_file_path)
1460 .arg("-p")
1461 .arg("0")
1462 .arg("--atlas-size")
1463 .arg("pot64")
1464 .arg("--rect-heuristic")
1465 .arg("contact-point");
1466 cmd.assert().success();
1467
1468 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1469 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1470 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1471
1472 assert_eq!(exists_file(&hash_path), true);
1473 assert_eq!(exists_file(&json_path), true);
1474 assert_eq!(exists_file(&image_path), true);
1475 assert_eq!(get_hash_value(&hash_path) > 0, true);
1476
1477 verify_texture_size(&image_path, 64, 64);
1478
1479 remove_dir_all(&parent_path);
1480
1481 assert_eq!(exists_file(&hash_path), false);
1482 assert_eq!(exists_file(&json_path), false);
1483 assert_eq!(exists_file(&image_path), false);
1484
1485 Ok(())
1486 }
1487
1488 #[test]
1489 fn cli_success_input_defaults_premultiply() -> Result<(), Box<dyn std::error::Error>> {
1490 let mut cmd = cargo_bin_cmd!("flow-texpack");
1491 let out_file_path = "test_data/cli_success_input_defaults_premultiply/atlas";
1492 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1493
1494 cmd.arg("-i")
1495 .arg("test_data/white_32x32.png")
1496 .arg("-o")
1497 .arg(out_file_path)
1498 .arg("-p")
1499 .arg("0");
1500 cmd.assert().success();
1501
1502 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1503 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1504 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1505
1506 assert_eq!(exists_file(&hash_path), true);
1507 assert_eq!(exists_file(&json_path), true);
1508 assert_eq!(exists_file(&image_path), true);
1509 assert_eq!(get_hash_value(&hash_path) > 0, true);
1510
1511 verify_texture_size(&image_path, 32, 32);
1512
1513 remove_dir_all(&parent_path);
1514
1515 assert_eq!(exists_file(&hash_path), false);
1516 assert_eq!(exists_file(&json_path), false);
1517 assert_eq!(exists_file(&image_path), false);
1518
1519 Ok(())
1520 }
1521
1522 #[test]
1523 fn cli_success_input_defaults_trim() -> Result<(), Box<dyn std::error::Error>> {
1524 let mut cmd = cargo_bin_cmd!("flow-texpack");
1525 let out_file_path = "test_data/cli_success_input_defaults_trim/atlas";
1526 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1527
1528 cmd.arg("-i")
1529 .arg("test_data/blue_trimmable_128x128.png")
1530 .arg("-o")
1531 .arg(out_file_path)
1532 .arg("-p")
1533 .arg("0")
1534 .arg("-t");
1535 cmd.assert().success();
1536
1537 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1538 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1539 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1540
1541 assert_eq!(exists_file(&hash_path), true);
1542 assert_eq!(exists_file(&json_path), true);
1543 assert_eq!(exists_file(&image_path), true);
1544 assert_eq!(get_hash_value(&hash_path) > 0, true);
1545
1546 verify_texture_size(&image_path, 32, 32);
1547
1548 remove_dir_all(&parent_path);
1549
1550 assert_eq!(exists_file(&hash_path), false);
1551 assert_eq!(exists_file(&json_path), false);
1552 assert_eq!(exists_file(&image_path), false);
1553
1554 Ok(())
1555 }
1556
1557 #[test]
1558 fn cli_success_input_defaults_unique() -> Result<(), Box<dyn std::error::Error>> {
1559 let mut cmd = cargo_bin_cmd!("flow-texpack");
1560 let out_file_path = "test_data/cli_success_input_defaults_unique/atlas";
1561 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1562
1563 cmd.arg("-i")
1564 .arg("test_data/white_128x128.png")
1565 .arg("test_data/white_128x128_v2.png")
1566 .arg("-o")
1567 .arg(out_file_path)
1568 .arg("-p")
1569 .arg("0")
1570 .arg("-u");
1571 cmd.assert().success();
1572
1573 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1574 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1575 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1576
1577 assert_eq!(exists_file(&hash_path), true);
1578 assert_eq!(exists_file(&json_path), true);
1579 assert_eq!(exists_file(&image_path), true);
1580 assert_eq!(get_hash_value(&hash_path) > 0, true);
1581
1582 verify_texture_size(&image_path, 128, 128);
1583
1584 remove_dir_all(&parent_path);
1585
1586 assert_eq!(exists_file(&hash_path), false);
1587 assert_eq!(exists_file(&json_path), false);
1588 assert_eq!(exists_file(&image_path), false);
1589
1590 Ok(())
1591 }
1592
1593 #[test]
1594 fn cli_success_input_defaults_rotate() -> Result<(), Box<dyn std::error::Error>> {
1595 let mut cmd = cargo_bin_cmd!("flow-texpack");
1596 let out_file_path = "test_data/cli_success_input_defaults_rotate/atlas";
1597 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1598
1599 cmd.arg("-i")
1600 .arg("test_data/white_128x64.png")
1601 .arg("test_data/white_32x16.png")
1602 .arg("-o")
1603 .arg(out_file_path)
1604 .arg("--rect-heuristic")
1605 .arg("long-side-fit")
1606 .arg("-r");
1607 cmd.assert().success();
1608
1609 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1610 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1611 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1612
1613 assert_eq!(exists_file(&hash_path), true);
1614 assert_eq!(exists_file(&json_path), true);
1615 assert_eq!(exists_file(&image_path), true);
1616 assert_eq!(get_hash_value(&hash_path) > 0, true);
1617
1618 verify_texture_size(&image_path, 256, 128);
1619
1620 remove_dir_all(&parent_path);
1621
1622 assert_eq!(exists_file(&hash_path), false);
1623 assert_eq!(exists_file(&json_path), false);
1624 assert_eq!(exists_file(&image_path), false);
1625
1626 Ok(())
1627 }
1628
1629 #[test]
1630 fn cli_success_input_defaults_adjust_size() -> Result<(), Box<dyn std::error::Error>> {
1631 let mut cmd = cargo_bin_cmd!("flow-texpack");
1632 let out_file_path = "test_data/cli_success_input_defaults_adjust_size/atlas";
1633 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1634
1635 cmd.arg("-i")
1636 .arg("test_data/white_128x128.png")
1637 .arg("-o")
1638 .arg(out_file_path)
1639 .arg("--atlas-size")
1640 .arg("pot64")
1641 .arg("-p")
1642 .arg("0")
1643 .arg("--adjust-size");
1644 cmd.assert().success();
1645
1646 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1647 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1648 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1649
1650 assert_eq!(exists_file(&hash_path), true);
1651 assert_eq!(exists_file(&json_path), true);
1652 assert_eq!(exists_file(&image_path), true);
1653 assert_eq!(get_hash_value(&hash_path) > 0, true);
1654
1655 verify_texture_size(&image_path, 128, 128);
1656
1657 remove_dir_all(&parent_path);
1658
1659 assert_eq!(exists_file(&hash_path), false);
1660 assert_eq!(exists_file(&json_path), false);
1661 assert_eq!(exists_file(&image_path), false);
1662
1663 Ok(())
1664 }
1665
1666 #[test]
1667 fn cli_success_input_defaults_adjust_fit() -> Result<(), Box<dyn std::error::Error>> {
1668 let mut cmd = cargo_bin_cmd!("flow-texpack");
1669 let out_file_path = "test_data/cli_success_input_defaults_adjust_fit/atlas";
1670 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1671
1672 cmd.arg("-i")
1673 .arg("test_data/white_128x128.png")
1674 .arg("-o")
1675 .arg(out_file_path)
1676 .arg("--atlas-size")
1677 .arg("pot64")
1678 .arg("-p")
1679 .arg("0")
1680 .arg("--adjust-fit");
1681 cmd.assert().success();
1682
1683 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1684 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1685 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1686
1687 assert_eq!(exists_file(&hash_path), true);
1688 assert_eq!(exists_file(&json_path), true);
1689 assert_eq!(exists_file(&image_path), true);
1690 assert_eq!(get_hash_value(&hash_path) > 0, true);
1691
1692 verify_texture_size(&image_path, 64, 64);
1693
1694 remove_dir_all(&parent_path);
1695
1696 assert_eq!(exists_file(&hash_path), false);
1697 assert_eq!(exists_file(&json_path), false);
1698 assert_eq!(exists_file(&image_path), false);
1699
1700 Ok(())
1701 }
1702
1703 #[test]
1704 fn cli_success_input_defaults_validate_descriptor_json() -> Result<(), Box<dyn std::error::Error>> {
1705 let mut cmd = cargo_bin_cmd!("flow-texpack");
1706 let out_file_path = "test_data/cli_success_input_defaults_validate_descriptor_json/atlas";
1707 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1708
1709 cmd.arg("-i")
1710 .arg("test_data/white_32x32.png")
1711 .arg("test_data/white_32x16.png")
1712 .arg("-o")
1713 .arg(out_file_path)
1714 .arg("--atlas-size")
1715 .arg("pot64")
1716 .arg("--generate-mipmaps")
1717 .arg("-p")
1718 .arg("4");
1719 cmd.assert().success();
1720
1721 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1722 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1723 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1724
1725 assert_eq!(exists_file(&hash_path), true);
1726 assert_eq!(exists_file(&json_path), true);
1727 assert_eq!(exists_file(&image_path), true);
1728 assert_eq!(get_hash_value(&hash_path) > 0, true);
1729
1730 verify_texture_size(&image_path, 64, 64);
1731 validate_descriptor_json(&json_path);
1732
1733 remove_dir_all(&parent_path);
1734
1735 assert_eq!(exists_file(&hash_path), false);
1736 assert_eq!(exists_file(&json_path), false);
1737 assert_eq!(exists_file(&image_path), false);
1738
1739 Ok(())
1740 }
1741
1742 #[test]
1743 fn cli_success_input_defaults_validate_descriptor_txt() -> Result<(), Box<dyn std::error::Error>> {
1744 let mut cmd = cargo_bin_cmd!("flow-texpack");
1745 let out_file_path = "test_data/cli_success_input_defaults_validate_descriptor_txt/atlas";
1746 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1747
1748 cmd.arg("-i")
1749 .arg("test_data/white_32x32.png")
1750 .arg("test_data/white_32x16.png")
1751 .arg("-o")
1752 .arg(out_file_path)
1753 .arg("--atlas-size")
1754 .arg("pot64")
1755 .arg("--atlas-descriptor")
1756 .arg("txt")
1757 .arg("--generate-mipmaps")
1758 .arg("-p")
1759 .arg("4");
1760 cmd.assert().success();
1761
1762 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1763 let txt_path = PathBuf::from(format!("{}.txt", out_file_path));
1764 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1765
1766 assert_eq!(exists_file(&hash_path), true);
1767 assert_eq!(exists_file(&txt_path), true);
1768 assert_eq!(exists_file(&image_path), true);
1769 assert_eq!(get_hash_value(&hash_path) > 0, true);
1770
1771 verify_texture_size(&image_path, 64, 64);
1772 validate_descriptor_txt(&txt_path, false);
1773
1774 remove_dir_all(&parent_path);
1775
1776 assert_eq!(exists_file(&hash_path), false);
1777 assert_eq!(exists_file(&txt_path), false);
1778 assert_eq!(exists_file(&image_path), false);
1779
1780 Ok(())
1781 }
1782
1783 #[test]
1784 fn cli_success_input_defaults_validate_descriptor_txt_header()
1785 -> Result<(), Box<dyn std::error::Error>> {
1786 let mut cmd = cargo_bin_cmd!("flow-texpack");
1787 let out_file_path = "test_data/cli_success_input_defaults_validate_descriptor_txt_header/atlas";
1788 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1789
1790 cmd.arg("-i")
1791 .arg("test_data/white_32x32.png")
1792 .arg("test_data/white_32x16.png")
1793 .arg("-o")
1794 .arg(out_file_path)
1795 .arg("--atlas-size")
1796 .arg("pot64")
1797 .arg("--atlas-descriptor")
1798 .arg("txt-desc")
1799 .arg("--generate-mipmaps")
1800 .arg("--pad")
1801 .arg("4");
1802 cmd.assert().success();
1803
1804 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1805 let txt_path = PathBuf::from(format!("{}.txt", out_file_path));
1806 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1807
1808 assert_eq!(exists_file(&hash_path), true);
1809 assert_eq!(exists_file(&txt_path), true);
1810 assert_eq!(exists_file(&image_path), true);
1811 assert_eq!(get_hash_value(&hash_path) > 0, true);
1812
1813 verify_texture_size(&image_path, 64, 64);
1814 validate_descriptor_txt(&txt_path, true);
1815
1816 remove_dir_all(&parent_path);
1817
1818 assert_eq!(exists_file(&hash_path), false);
1819 assert_eq!(exists_file(&txt_path), false);
1820 assert_eq!(exists_file(&image_path), false);
1821
1822 Ok(())
1823 }
1824
1825 #[test]
1826 fn cli_success_input_defaults_load_filter_bmp() -> Result<(), Box<dyn std::error::Error>> {
1827 let mut cmd = cargo_bin_cmd!("flow-texpack");
1828 let out_file_path = "test_data/cli_success_input_defaults_load_filter_bmp/atlas";
1829 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1830
1831 cmd.arg("-i")
1832 .arg("test_data/white_32x32.bmp")
1833 .arg("test_data/white_128x128.png")
1834 .arg("-o")
1835 .arg(out_file_path)
1836 .arg("--load-filter")
1837 .arg("bmp");
1838 cmd.assert().success();
1839
1840 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1841 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1842 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1843
1844 assert_eq!(exists_file(&hash_path), true);
1845 assert_eq!(exists_file(&json_path), true);
1846 assert_eq!(exists_file(&image_path), true);
1847 assert_eq!(get_hash_value(&hash_path) > 0, true);
1848
1849 verify_texture_size(&image_path, 64, 64);
1850
1851 remove_dir_all(&parent_path);
1852
1853 assert_eq!(exists_file(&hash_path), false);
1854 assert_eq!(exists_file(&json_path), false);
1855 assert_eq!(exists_file(&image_path), false);
1856
1857 Ok(())
1858 }
1859
1860 #[test]
1861 fn cli_success_input_defaults_load_filter_hdr() -> Result<(), Box<dyn std::error::Error>> {
1862 let mut cmd = cargo_bin_cmd!("flow-texpack");
1863 let out_file_path = "test_data/cli_success_input_defaults_load_filter_hdr/atlas";
1864 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1865
1866 cmd.arg("-i")
1867 .arg("test_data/white_32x32.hdr")
1868 .arg("test_data/white_128x128.png")
1869 .arg("-o")
1870 .arg(out_file_path)
1871 .arg("--load-filter")
1872 .arg("hdr");
1873 cmd.assert().success();
1874
1875 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1876 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1877 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1878
1879 assert_eq!(exists_file(&hash_path), true);
1880 assert_eq!(exists_file(&json_path), true);
1881 assert_eq!(exists_file(&image_path), true);
1882 assert_eq!(get_hash_value(&hash_path) > 0, true);
1883
1884 verify_texture_size(&image_path, 64, 64);
1885
1886 remove_dir_all(&parent_path);
1887
1888 assert_eq!(exists_file(&hash_path), false);
1889 assert_eq!(exists_file(&json_path), false);
1890 assert_eq!(exists_file(&image_path), false);
1891
1892 Ok(())
1893 }
1894
1895 #[test]
1896 fn cli_success_input_defaults_load_filter_jpg() -> Result<(), Box<dyn std::error::Error>> {
1897 let mut cmd = cargo_bin_cmd!("flow-texpack");
1898 let out_file_path = "test_data/cli_success_input_defaults_load_filter_jpg/atlas";
1899 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1900
1901 cmd.arg("-i")
1902 .arg("test_data/white_32x32.jpg")
1903 .arg("test_data/white_128x128.png")
1904 .arg("-o")
1905 .arg(out_file_path)
1906 .arg("--load-filter")
1907 .arg("jpg");
1908 cmd.assert().success();
1909
1910 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1911 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1912 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1913
1914 assert_eq!(exists_file(&hash_path), true);
1915 assert_eq!(exists_file(&json_path), true);
1916 assert_eq!(exists_file(&image_path), true);
1917 assert_eq!(get_hash_value(&hash_path) > 0, true);
1918
1919 verify_texture_size(&image_path, 64, 64);
1920
1921 remove_dir_all(&parent_path);
1922
1923 assert_eq!(exists_file(&hash_path), false);
1924 assert_eq!(exists_file(&json_path), false);
1925 assert_eq!(exists_file(&image_path), false);
1926
1927 Ok(())
1928 }
1929
1930 #[test]
1931 fn cli_success_input_defaults_load_filter_png() -> Result<(), Box<dyn std::error::Error>> {
1932 let mut cmd = cargo_bin_cmd!("flow-texpack");
1933 let out_file_path = "test_data/cli_success_input_defaults_load_filter_png/atlas";
1934 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1935
1936 cmd.arg("-i")
1937 .arg("test_data/white_32x32.png")
1938 .arg("test_data/white_128x128.png")
1939 .arg("-o")
1940 .arg(out_file_path)
1941 .arg("--load-filter")
1942 .arg("png");
1943 cmd.assert().success();
1944
1945 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1946 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1947 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1948
1949 assert_eq!(exists_file(&hash_path), true);
1950 assert_eq!(exists_file(&json_path), true);
1951 assert_eq!(exists_file(&image_path), true);
1952 assert_eq!(get_hash_value(&hash_path) > 0, true);
1953
1954 verify_texture_size(&image_path, 256, 256);
1955
1956 remove_dir_all(&parent_path);
1957
1958 assert_eq!(exists_file(&hash_path), false);
1959 assert_eq!(exists_file(&json_path), false);
1960 assert_eq!(exists_file(&image_path), false);
1961
1962 Ok(())
1963 }
1964
1965 #[test]
1966 fn cli_success_input_defaults_load_filter_tga() -> Result<(), Box<dyn std::error::Error>> {
1967 let mut cmd = cargo_bin_cmd!("flow-texpack");
1968 let out_file_path = "test_data/cli_success_input_defaults_load_filter_tga/atlas";
1969 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
1970
1971 cmd.arg("-i")
1972 .arg("test_data/white_32x32.tga")
1973 .arg("test_data/white_128x128.png")
1974 .arg("-o")
1975 .arg(out_file_path)
1976 .arg("--load-filter")
1977 .arg("tga");
1978 cmd.assert().success();
1979
1980 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
1981 let json_path = PathBuf::from(format!("{}.json", out_file_path));
1982 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
1983
1984 assert_eq!(exists_file(&hash_path), true);
1985 assert_eq!(exists_file(&json_path), true);
1986 assert_eq!(exists_file(&image_path), true);
1987 assert_eq!(get_hash_value(&hash_path) > 0, true);
1988
1989 verify_texture_size(&image_path, 64, 64);
1990
1991 remove_dir_all(&parent_path);
1992
1993 assert_eq!(exists_file(&hash_path), false);
1994 assert_eq!(exists_file(&json_path), false);
1995 assert_eq!(exists_file(&image_path), false);
1996
1997 Ok(())
1998 }
1999
2000 #[test]
2001 fn cli_success_input_defaults_load_filter_tiff() -> Result<(), Box<dyn std::error::Error>> {
2002 let mut cmd = cargo_bin_cmd!("flow-texpack");
2003 let out_file_path = "test_data/cli_success_input_defaults_load_filter_tiff/atlas";
2004 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
2005
2006 cmd.arg("-i")
2007 .arg("test_data/white_32x32.tiff")
2008 .arg("test_data/white_128x128.png")
2009 .arg("-o")
2010 .arg(out_file_path)
2011 .arg("--load-filter")
2012 .arg("tiff");
2013 cmd.assert().success();
2014
2015 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
2016 let json_path = PathBuf::from(format!("{}.json", out_file_path));
2017 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
2018
2019 assert_eq!(exists_file(&hash_path), true);
2020 assert_eq!(exists_file(&json_path), true);
2021 assert_eq!(exists_file(&image_path), true);
2022 assert_eq!(get_hash_value(&hash_path) > 0, true);
2023
2024 verify_texture_size(&image_path, 64, 64);
2025
2026 remove_dir_all(&parent_path);
2027
2028 assert_eq!(exists_file(&hash_path), false);
2029 assert_eq!(exists_file(&json_path), false);
2030 assert_eq!(exists_file(&image_path), false);
2031
2032 Ok(())
2033 }
2034
2035 #[test]
2036 fn cli_success_input_defaults_load_filter_webp() -> Result<(), Box<dyn std::error::Error>> {
2037 let mut cmd = cargo_bin_cmd!("flow-texpack");
2038 let out_file_path = "test_data/cli_success_input_defaults_load_filter_webp/atlas";
2039 let parent_path = PathBuf::from(PathBuf::from(out_file_path).parent().unwrap());
2040
2041 cmd.arg("-i")
2042 .arg("test_data/white_32x32.webp")
2043 .arg("test_data/white_128x128.png")
2044 .arg("-o")
2045 .arg(out_file_path)
2046 .arg("--load-filter")
2047 .arg("webp");
2048 cmd.assert().success();
2049
2050 let hash_path = PathBuf::from(format!("{}.hash", out_file_path));
2051 let json_path = PathBuf::from(format!("{}.json", out_file_path));
2052 let image_path = PathBuf::from(format!("{}0.png", out_file_path));
2053
2054 assert_eq!(exists_file(&hash_path), true);
2055 assert_eq!(exists_file(&json_path), true);
2056 assert_eq!(exists_file(&image_path), true);
2057 assert_eq!(get_hash_value(&hash_path) > 0, true);
2058
2059 verify_texture_size(&image_path, 64, 64);
2060
2061 remove_dir_all(&parent_path);
2062
2063 assert_eq!(exists_file(&hash_path), false);
2064 assert_eq!(exists_file(&json_path), false);
2065 assert_eq!(exists_file(&image_path), false);
2066
2067 Ok(())
2068 }