aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-09-08 18:18:08 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-09-08 18:18:08 +0200
commit2de4918fb321c746570af831f9cab713bd48ecad (patch)
tree8a9a4d27a6d8fd773e11ea8897bcda6873c2ab26 /tests
parent2f59e0175eba5efc8c5f1360f3c87e3dc3c20b93 (diff)
Add basic test for JPG using Odin emblem
Diffstat (limited to 'tests')
-rw-r--r--tests/core/download_assets.py6
-rw-r--r--tests/core/image/test_core_image.odin48
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/core/download_assets.py b/tests/core/download_assets.py
index fc4a71cdc..f6f5396c8 100644
--- a/tests/core/download_assets.py
+++ b/tests/core/download_assets.py
@@ -7,7 +7,7 @@ import zipfile
import hashlib
import hmac
-TEST_SUITES = ['PNG', 'XML', 'BMP']
+TEST_SUITES = ['PNG', 'XML', 'BMP', 'JPG']
DOWNLOAD_BASE_PATH = sys.argv[1] + "/{}"
ASSETS_BASE_URL = "https://raw.githubusercontent.com/odin-lang/test-assets/master/{}/{}"
HMAC_KEY = "https://odin-lang.org"
@@ -280,7 +280,9 @@ HMAC_DIGESTS = {
'rletopdown.bmp': "37500893aad0b40656aa80fd5c7c5f9b35d033018b8070d8b1d7baeb34c90f90462288b13295204b90aa3e5c9be797d22a328e3714ab259334e879a09a3de175",
'shortfile.bmp': "be3ffade7999304f00f9b7d152b5b27811ad1166d0fd43004392467a28f44b6a4ec02a23c0296bacd4f02f8041cd824b9ca6c9fc31fed27e36e572113bb47d73",
- 'unicode.xml': "e0cdc94f07fdbb15eea811ed2ae6dcf494a83d197dafe6580c740270feb0d8f5f7146d4a7d4c2d2ea25f8bd9678bc986123484b39399819a6b7262687959d1ae",
+ 'emblem-1024.jpg': "d7b7e3ffaa5cda04c667e3742752091d78e02aa2d3c7a63406af679ce810a0a86666b10fcab12cc7ead2fadf2f6c2e1237bc94f892a62a4c218e18a20f96dbe4",
+
+ 'unicode.xml': "e0cdc94f07fdbb15eea811ed2ae6dcf494a83d197dafe6580c740270feb0d8f5f7146d4a7d4c2d2ea25f8bd9678bc986123484b39399819a6b7262687959d1ae",
}
def try_download_file(url, out_file):
diff --git a/tests/core/image/test_core_image.odin b/tests/core/image/test_core_image.odin
index 8f6091481..ca737973d 100644
--- a/tests/core/image/test_core_image.odin
+++ b/tests/core/image/test_core_image.odin
@@ -19,6 +19,7 @@ import pbm "core:image/netpbm"
import "core:image/png"
import "core:image/qoi"
import "core:image/tga"
+import "core:image/jpeg"
import "core:bytes"
import "core:hash"
@@ -28,6 +29,7 @@ import "core:time"
TEST_SUITE_PATH_PNG :: ODIN_ROOT + "tests/core/assets/PNG"
TEST_SUITE_PATH_BMP :: ODIN_ROOT + "tests/core/assets/BMP"
+TEST_SUITE_PATH_JPG :: ODIN_ROOT + "tests/core/assets/JPG"
I_Error :: image.Error
@@ -2360,6 +2362,52 @@ run_bmp_suite :: proc(t: ^testing.T, suite: []Test) {
return
}
+// JPG test image
+Basic_JPG_Tests := []Test{
+ {
+ "emblem-1024", {
+ {Default, nil, {1024, 1024, 3, 8}, 0x_46a29e0f},
+ },
+ },
+}
+
+@test
+jpeg_test_basic :: proc(t: ^testing.T) {
+ run_jpg_suite(t, Basic_JPG_Tests)
+}
+
+run_jpg_suite :: proc(t: ^testing.T, suite: []Test) {
+ for file in suite {
+ test_file := strings.concatenate({TEST_SUITE_PATH_JPG, "/", file.file, ".jpg"}, context.allocator)
+ defer delete(test_file)
+
+ for test in file.tests {
+ img, err := jpeg.load(test_file, test.options)
+
+ passed := (test.expected_error == nil && err == nil) || (test.expected_error == err)
+ testing.expectf(t, passed, "%q failed to load with error %v.", file.file, err)
+
+ if err == nil { // No point in running the other tests if it didn't load.
+ pixels := bytes.buffer_to_bytes(&img.pixels)
+
+ dims := Dims{img.width, img.height, img.channels, img.depth}
+ testing.expectf(t, test.dims == dims, "%v has %v, expected: %v.", file.file, dims, test.dims)
+
+ img_hash := hash.crc32(pixels)
+ testing.expectf(t, test.hash == img_hash, "%v test #1's hash is %08x, expected %08x with %v.", file.file, img_hash, test.hash, test.options)
+
+ // Save to BMP file to check load
+ test_bmp := strings.concatenate({TEST_SUITE_PATH_JPG, "/", file.file, ".bmp"}, context.temp_allocator)
+
+ save_err := bmp.save(test_bmp, img)
+ testing.expectf(t, save_err == nil, "expected saving to BMP in memory not to raise error, got %v", save_err)
+ }
+ bmp.destroy(img)
+ }
+ }
+ return
+}
+
@test
will_it_blend :: proc(t: ^testing.T) {
Pixel :: image.RGB_Pixel