Skip to content

Commit

Permalink
test: check tga-to-png output
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 11, 2024
1 parent bad8716 commit 71e63b3
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 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 {}".format(file_path, check_sum, known_sum))

def run(command_list):
print_command(command_list)
returncode = subprocess.run(command_list).returncode
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 71e63b3

Please sign in to comment.