From 693f59749d8f5e1f12a5e763fc2613a77360b724 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 11 Jul 2024 05:28:50 +0200 Subject: [PATCH] test: add more tests and check some output --- test/test.py | 137 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 35 deletions(-) diff --git a/test/test.py b/test/test.py index 721db6a1..23f30871 100755 --- a/test/test.py +++ b/test/test.py @@ -1,19 +1,34 @@ #! /usr/bin/env python3 +import hashlib import os import subprocess import sys +def print_status(message): + print(message, file=sys.stderr) + +def print_error(message): + print(message, file=sys.stderr) + exit(1) + def print_command(command_list): - print("running: " + " ".join(command_list), file=sys.stderr) + print_status("Running command: {}".format(" ".join(command_list))) def convert_path(path): return path.replace("/", os.path.sep) +def check_file(file_path, known_sum): + print_status("Checking file: {}".format(file_path)) + check_sum = hashlib.blake2b(open(file_path, "rb").read()).hexdigest() + if check_sum != known_sum: + print_error("Error: {}'s checksum {} doesn't match known {}".format(file_path, check_sum, known_sum)) + def run(command_list): print_command(command_list) returncode = subprocess.run(command_list).returncode if returncode: + print_error("Command failed: {}".format(" ".join(command_list))) exit(returncode) def mkdir(path): @@ -39,67 +54,119 @@ def crunch(input_path, output_path, options=[]): run(command_list) +def crunch_check(input_path, output_path, known_sum): + crunch(input_path, output_path) + check_file(output_path, known_sum) + crunch(None, None, ["--help"]) +tga_sum="34434170b06843b2d4fb5964a4b8751ec3a151a7d03e351e45a5967508f6a21f6e40ffc214bb46640105c4058bc35e196ecb5dd3261528a64acfeff52034fb40" +bmp_sum="1c5f28be8151a8125346e9cf17b1bf6e3f9fe27f6947b164b7eefa8fd3732a2e4dff173c354a0cd4ed599cd604d4b8f916c0575b0a4b4b508acc68dc9b4067ae" +png_sum="71bb28da97cd778b99f131acaeb1c28ea37bae295a9e9934bed339508d8428587120c0da8f5bbc7963cdb77741ef789414f9d0d2c1e0da46026336efde147cc5" +crn_sum="a3b526e95f44b6a4c919bc8eb79f4debf592f0bccc163c900cd1b6f9add0ce58c3db9fc8dac1828d350bbcd915823d7743a0c114a533fbc08c163fcb4846d2f5" +dds_sum="ce98b21c574b4883e4aff4a0b92fd0f533f22e00ab753686f353111fa7503287c2c4dba25f2c2670508630d79b59464578e094461bad81ad803e1d58ed5e69f8" +ktx_sum="d82eab591163d802231722ef325571735971b6a9b0703ed8ea59b4a4144189825d96d3455605426453fb3ad8d7cc61f931c52b3e73df2bb6787f7408baeb4ac7" +jpg_sum="6cd22de7e2e5baced5ef16e84f816dde3049f822459d552ced4dcd4e3f9a16be82ee0747ed1479fe8339991176004b4ccc90380b7ef51292c7d9b518503a348d" + mkdir("build/test/png-to-all") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png") -crunch("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg") +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.tga", tga_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.png", png_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.crn", crn_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.dds", dds_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("test/unvanquished_64.png", "build/test/png-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/tga-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.tga", "build/test/tga-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/bmp-to-all") +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.tga", tga_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.bmp", bmp_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.png", png_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.crn", crn_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.dds", dds_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.ktx", ktx_sum) +crunch_check("build/test/png-to-all/unvanquished_64.bmp", "build/test/bmp-to-all/unvanquished_64.jpg", jpg_sum) + +mkdir("build/test/jpg-to-all") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.tga") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.bmp") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.ktx") +crunch("build/test/png-to-all/unvanquished_64.jpg", "build/test/jpg-to-all/unvanquished_64.jpg") mkdir("build/test/crn-to-all") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.crn", "build/test/crn-to-all/unvanquished_64.jpg") mkdir("build/test/dds-to-all") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.crn") +crunch_check("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.dds", dds_sum) +crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.dds", "build/test/dds-to-all/unvanquished_64.jpg") mkdir("build/test/ktx-to-all") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") -crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.tga") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.bmp") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.png") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.crn") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.dds") +crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.ktx") crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.jpg") +mkdir("build/test/tga-to-png") +tga_png_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png", tga_png_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png", tga_png_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png", tga_png_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png", tga_png_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png", tga_png_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png", tga_png_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png", tga_png_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png", tga_png_sum) + mkdir("build/test/tga-to-crn") -crunch("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn") -crunch("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn") -crunch("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn") -crunch("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn") -crunch("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn") -crunch("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn") -crunch("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn") -crunch("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn") +tga_crn_sum="fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854" +crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn", tga_crn_sum) +crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn", tga_crn_sum) +crunch_check("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn", tga_crn_sum) +crunch_check("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn", tga_crn_sum) +crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn", tga_crn_sum) +crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn", tga_crn_sum) +crunch_check("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn", tga_crn_sum) +crunch_check("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn", tga_crn_sum) mkdir("build/test/png-to-crn") -crunch("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn") -crunch("test/test-colormap2-alpha1.png", "build/test/png-to-crn/test-colormap2-alpha1.crn") -crunch("test/test-colormap4-alpha1.png", "build/test/png-to-crn/test-colormap4-alpha1.crn") -crunch("test/test-colormap8-alpha1.png", "build/test/png-to-crn/test-colormap8-alpha1.crn") -crunch("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn") -crunch("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn") -crunch("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn") -crunch("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn") +crunch_check("test/test-colormap1-alpha1.png", "build/test/png-to-crn/test-colormap1-alpha1.crn", "c331744f6d683cbe18718e2b74ab7bdce5561fcf51321a8b778e848712129964ae78dcb7204c3f6e736a7f3d42e9f52af9f0c170a62243e9c71520709710bdae") +crunch_check("test/test-colormap2-alpha1.png", "build/test/png-to-crn/test-colormap2-alpha1.crn", "ef06c38192e6b6baa7b9c368f604cf86da0b3ee3307eb670492ec18bcf7622fe9565f98f8f764f7dcc6bf84fb824acb28582f1cca7301438e9d19f513931a9a9") +crunch_check("test/test-colormap4-alpha1.png", "build/test/png-to-crn/test-colormap4-alpha1.crn", "12e36ebb68d603282120a92fc8a184d6505bb316bedadf56f7cb9828f878f475bb055f569f73c54046d36410d502e8bd4e9200d26d94053ead52b720c272be6d") +crunch_check("test/test-colormap8-alpha1.png", "build/test/png-to-crn/test-colormap8-alpha1.crn", "657eb9b7ec4c3d21c4a02d235af04b0f1626267a38f1519afb0c8e374a6ac8e4bf2024aebe738d33a3b35c12dcd277d27de1743a86ac61ed58f809047b03d682") +crunch_check("test/test-grayscale1-alpha1.png", "build/test/png-to-crn/test-grayscale1-alpha1.crn", "31906b0368d7d009954917597066b21813db53a13d01290153a064623db48ad3a1617a0af8a47178fc303f598b8d757547c31ad74dac9899feaa258546a8810a") +crunch_check("test/test-grayscale1-alpha8.png", "build/test/png-to-crn/test-grayscale1-alpha8.crn", "22d6726ef894102eb95f00199c90dc2c675751b884560b65176f5a9ee4b57b148793144c08ef63aa4ea5f064378423f3ca805c4ca05f8e1f18033522a9658582") +crunch_check("test/test-grayscale8-alpha1.png", "build/test/png-to-crn/test-grayscale8-alpha1.crn", "3b7ecf85212aca71cd3a36e5e3578f44ffaf61c53614edc60c3a7a591995856202c2b4f6792520060c2256c62eafd99b5999ae9e7ffeab3719bdc93c670bc236") +crunch_check("test/test-rgb8-alpha8.png", "build/test/png-to-crn/test-rgb8-alpha8.crn", "87dcb6922f2f8ee8cab69d5f9a36e8e3b94ae0603fddd8e04c588128a006507af9475fa469cf1483b49a40a1a9cfb5cc9338de5b3085f6366b5b237d40c47fc1") mkdir("build/test/bmp-to-crn") -crunch("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn") -crunch("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn") +bmp_crn_sum="119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925" +crunch_check("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn", bmp_crn_sum) +crunch_check("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn", bmp_crn_sum) mkdir("build/test/jpg-to-crn") crunch("test/black.jpg", "build/test/jpg-to-crn/black.crn")