Skip to content

Commit

Permalink
test: also test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Jul 7, 2024
1 parent 2b06fbb commit 9ca3203
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions crnlib/crnlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ bool crn_decompress_dds_to_images(const void* pDDS_file_data, crn_uint32 dds_fil
for (uint32 l = 0; l < tex.get_num_levels(); l++) {
mip_level* pLevel = tex.get_level(f, l);
image_u8* pImg = pLevel->get_image();
printf("===== %p\n", pImg->get_pixel_buf().assume_ownership());
ppImages[l + tex.get_num_levels() * f] = static_cast<crn_uint32*>(pImg->get_pixel_buf().assume_ownership());
}
}
Expand Down
51 changes: 45 additions & 6 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ def mkdir(path):
print_command(["mkdir", path])
os.makedirs(path, exist_ok=True)

def crunch(input_path, output_path, options=[]):
executable_extension = ["", ".exe"][sys.platform == 'win32']
executable_name = "crunch" + executable_extension

def get_build_dir():
build_dir = "build"
windows_build_dir = os.path.join(build_dir, "Release")
if os.path.exists(windows_build_dir):
build_dir = windows_build_dir
return windows_build_dir
return build_dir

def get_executable_path(executable_name):
executable_extension = ["", ".exe"][sys.platform == 'win32']
executable_name += executable_extension
build_dir = get_build_dir()
return os.path.join(build_dir, executable_name)

executable_path = os.path.join(build_dir, executable_name)
def crunch(input_path, output_path, options=[]):
executable_path = get_executable_path("crunch")
command_list = [executable_path] + options

if input_path:
Expand All @@ -39,6 +44,26 @@ def crunch(input_path, output_path, options=[]):

run(command_list)

def example(num, input_path, output_path, options=[]):
executable_path = get_executable_path("example" + str(num))
command_list = [executable_path]

if (num == 1):
command_list += [options[0]]
options = options[1:]

if input_path:
input_path = convert_path(input_path)
command_list += [input_path]

command_list += options

if output_path:
output_path = convert_path(output_path)
command_list += ["-out", output_path]

run(command_list)

crunch(None, None, ["--help"])

mkdir("build/test/0")
Expand Down Expand Up @@ -99,3 +124,17 @@ def crunch(input_path, output_path, options=[]):

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

mkdir("build/test/8")
example(1, "test/unvanquished_64.png", None, ["i"])
example(1, "test/unvanquished_64.png", "build/test/8/unvanquished_64.dds", ["c"])

mkdir("build/test/9")
example(1, "test/unvanquished_64.png", "build/test/9/unvanquished_64.crn", ["c", "-crn"])
example(1, "build/test/9/unvanquished_64.crn", "build/test/9/unvanquished_64.dds", ["d"])

mkdir("build/test/10")
example(2, "build/test/9/unvanquished_64.crn", "build/test/10/unvanquished_64.dds")

mkdir("build/test/11")
example(3, "test/unvanquished_64.png", "build/test/11/unvanquished_64.dds")

0 comments on commit 9ca3203

Please sign in to comment.