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 b733cbd
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
#! /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
@@ -87,6 +101,16 @@ def crunch(input_path, output_path, options=[]):
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")

png_known_sum="6238f9678cd9fa774e6d50ee6638f316d0b1148ade344c06b4ddebac4738ea90e93c19d5cca405fccdabfdb37898bc7f9bccce1f0d974f9cbd18ab54b66adaa3"
check_file("build/test/tga-to-png/raw-bottom-left.png", png_known_sum)
check_file("build/test/tga-to-png/raw-bottom-right.png", png_known_sum)
check_file("build/test/tga-to-png/raw-top-left.png", png_known_sum)
check_file("build/test/tga-to-png/raw-top-right.png", png_known_sum)
check_file("build/test/tga-to-png/rle-bottom-left.png", png_known_sum)
check_file("build/test/tga-to-png/rle-bottom-right.png", png_known_sum)
check_file("build/test/tga-to-png/rle-top-left.png", png_known_sum)
check_file("build/test/tga-to-png/rle-top-right.png", 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")
@@ -97,6 +121,16 @@ def crunch(input_path, output_path, options=[]):
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")

crn_known_sum="fcf1da3fc69f6b05935deafacb1c637f44983b9992a7452f8f26a7787d5577c6548986366fae5fd6d300366de4acade853464e7656224b04673a7d129e006854"
check_file("build/test/tga-to-crn/raw-bottom-left.crn", crn_known_sum)
check_file("build/test/tga-to-crn/raw-bottom-right.crn", crn_known_sum)
check_file("build/test/tga-to-crn/raw-top-left.crn", crn_known_sum)
check_file("build/test/tga-to-crn/raw-top-right.crn", crn_known_sum)
check_file("build/test/tga-to-crn/rle-bottom-left.crn", crn_known_sum)
check_file("build/test/tga-to-crn/rle-bottom-right.crn", crn_known_sum)
check_file("build/test/tga-to-crn/rle-top-left.crn", crn_known_sum)
check_file("build/test/tga-to-crn/rle-top-right.crn", 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")
@@ -111,5 +145,9 @@ def crunch(input_path, output_path, options=[]):
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")

crn_known_sum="119f0f756811e56ba688c402ea317923d9665017aed19022ad19fc8396e45d3ca3bb7b5383f3edc00e859e31558a0865de88af71110529b16b89ded731070925"
check_file("build/test/bmp-to-crn/sample-default.crn", crn_known_sum)
check_file("build/test/bmp-to-crn/sample-vertical-flip.crn", crn_known_sum)

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

0 comments on commit b733cbd

Please sign in to comment.