Skip to content

Commit

Permalink
test: check some crunch output
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 11, 2024
1 parent 0e90ebf commit 0c96cd5
Showing 1 changed file with 49 additions and 27 deletions.
76 changes: 49 additions & 27 deletions test/test.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -39,6 +54,10 @@ 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"])

mkdir("build/test/png-to-all")
Expand Down Expand Up @@ -78,38 +97,41 @@ def crunch(input_path, output_path, options=[]):
crunch("build/test/png-to-all/unvanquished_64.ktx", "build/test/ktx-to-all/unvanquished_64.jpg")

mkdir("build/test/tga-to-png")
crunch("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png")
crunch("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png")
crunch("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png")
crunch("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png")
crunch("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png")
crunch("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png")
crunch("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png")
crunch("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png")
known_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3"
crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-png/raw-bottom-left.png", known_sum)
crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-png/raw-bottom-right.png", known_sum)
crunch_check("test/raw-top-left.tga", "build/test/tga-to-png/raw-top-left.png", known_sum)
crunch_check("test/raw-top-right.tga", "build/test/tga-to-png/raw-top-right.png", known_sum)
crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-png/rle-bottom-left.png", known_sum)
crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-png/rle-bottom-right.png", known_sum)
crunch_check("test/rle-top-left.tga", "build/test/tga-to-png/rle-top-left.png", known_sum)
crunch_check("test/rle-top-right.tga", "build/test/tga-to-png/rle-top-right.png", known_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")
known_sum="fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854"
crunch_check("test/raw-bottom-left.tga", "build/test/tga-to-crn/raw-bottom-left.crn", known_sum)
crunch_check("test/raw-bottom-right.tga", "build/test/tga-to-crn/raw-bottom-right.crn", known_sum)
crunch_check("test/raw-top-left.tga", "build/test/tga-to-crn/raw-top-left.crn", known_sum)
crunch_check("test/raw-top-right.tga", "build/test/tga-to-crn/raw-top-right.crn", known_sum)
crunch_check("test/rle-bottom-left.tga", "build/test/tga-to-crn/rle-bottom-left.crn", known_sum)
crunch_check("test/rle-bottom-right.tga", "build/test/tga-to-crn/rle-bottom-right.crn", known_sum)
crunch_check("test/rle-top-left.tga", "build/test/tga-to-crn/rle-top-left.crn", known_sum)
crunch_check("test/rle-top-right.tga", "build/test/tga-to-crn/rle-top-right.crn", known_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")
known_sum="119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925"
crunch_check("test/sample-default.bmp", "build/test/bmp-to-crn/sample-default.crn", known_sum)
crunch_check("test/sample-vertical-flip.bmp", "build/test/bmp-to-crn/sample-vertical-flip.crn", known_sum)

mkdir("build/test/jpg-to-crn")
crunch("test/black.jpg", "build/test/jpg-to-crn/black.crn")

0 comments on commit 0c96cd5

Please sign in to comment.