Merge branch 'master' into tlsf-allocator

This commit is contained in:
Jeroen van Rijn
2024-06-09 16:42:23 +02:00
100 changed files with 2649 additions and 999 deletions
-14
View File
@@ -1,14 +0,0 @@
ODIN=../../odin
COMMON=-no-bounds-check -vet -strict-style -define:ODIN_TEST_FANCY=false
all: crypto_bench \
hash_bench
crypto_bench:
$(ODIN) test crypto $(COMMON) -o:speed -out:bench_crypto
hash_bench:
$(ODIN) test hash $(COMMON) -o:speed -out:bench_hash
clean:
rm bench_*
+4
View File
@@ -0,0 +1,4 @@
package benchmarks
@(require) import "crypto"
@(require) import "hash"
-13
View File
@@ -1,13 +0,0 @@
@echo off
set COMMON=-no-bounds-check -vet -strict-style -define:ODIN_TEST_FANCY=false
set PATH_TO_ODIN==..\..\odin
echo ---
echo Running core:crypto benchmarks
echo ---
%PATH_TO_ODIN% test crypto %COMMON% -o:speed -out:bench_crypto.exe || exit /b
echo ---
echo Running core:hash benchmarks
echo ---
%PATH_TO_ODIN% test hash %COMMON% -o:speed -out:bench_hash.exe || exit /b
+1
View File
@@ -1,3 +1,4 @@
*.bmp
*.zip
*.png
math_big_test_library.*
-115
View File
@@ -1,115 +0,0 @@
ODIN=../../odin
PYTHON=$(shell which python3)
COMMON=-no-bounds-check -vet -strict-style -define:ODIN_TEST_FANCY=false
all: all_bsd \
net_test
all_bsd: download_test_assets \
c_libc_test \
compress_test \
container_test \
crypto_test \
encoding_test \
filepath_test \
fmt_test \
hash_test \
i18n_test \
image_test \
linalg_glsl_math_test \
match_test \
math_test \
mem_test \
noise_test \
odin_test \
os_exit_test \
reflect_test \
runtime_test \
slice_test \
strings_test \
thread_test \
time_test
download_test_assets:
$(PYTHON) download_assets.py
c_libc_test:
$(ODIN) test c/libc $(COMMON) -out:test_core_libc
compress_test:
$(ODIN) test compress $(COMMON) -out:test_core_compress
container_test:
$(ODIN) test container $(COMMON) -out:test_core_container
crypto_test:
$(ODIN) test crypto $(COMMON) -o:speed -out:test_crypto
encoding_test:
$(ODIN) test encoding/base64 $(COMMON) -out:test_base64
$(ODIN) test encoding/cbor $(COMMON) -out:test_cbor
$(ODIN) test encoding/hex $(COMMON) -out:test_hex
$(ODIN) test encoding/hxa $(COMMON) -out:test_hxa
$(ODIN) test encoding/json $(COMMON) -out:test_json
$(ODIN) test encoding/varint $(COMMON) -out:test_varint
$(ODIN) test encoding/xml $(COMMON) -out:test_xml
filepath_test:
$(ODIN) test path/filepath $(COMMON) -out:test_core_filepath
fmt_test:
$(ODIN) test fmt $(COMMON) -out:test_core_fmt
hash_test:
$(ODIN) test hash $(COMMON) -o:speed -out:test_hash
image_test:
$(ODIN) test image $(COMMON) -out:test_core_image
i18n_test:
$(ODIN) test text/i18n $(COMMON) -out:test_core_i18n
match_test:
$(ODIN) test text/match $(COMMON) -out:test_core_match
math_test:
$(ODIN) test math $(COMMON) -out:test_core_math
linalg_glsl_math_test:
$(ODIN) test math/linalg/glsl $(COMMON) -out:test_linalg_glsl_math
noise_test:
$(ODIN) test math/noise $(COMMON) -out:test_noise
mem_test:
$(ODIN) test mem $(COMMON) -out:test_core_mem
net_test:
$(ODIN) test net $(COMMON) -out:test_core_net
os_exit_test:
$(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0
odin_test:
$(ODIN) test odin $(COMMON) -out:test_core_odin
reflect_test:
$(ODIN) test reflect $(COMMON) -out:test_core_reflect
runtime_test:
$(ODIN) test runtime $(COMMON) -out:test_core_runtime
slice_test:
$(ODIN) test slice $(COMMON) -out:test_core_slice
strings_test:
$(ODIN) test strings $(COMMON) -out:test_core_strings
thread_test:
$(ODIN) test thread $(COMMON) -out:test_core_thread
time_test:
$(ODIN) test time $(COMMON) -out:test_core_time
clean:
rm test_*
-124
View File
@@ -1,124 +0,0 @@
@echo off
set COMMON=-no-bounds-check -vet -strict-style -define:ODIN_TEST_FANCY=false
set PATH_TO_ODIN==..\..\odin
python3 download_assets.py
echo ---
echo Running core:c/libc tests
echo ---
%PATH_TO_ODIN% test c\libc %COMMON% -out:test_libc.exe || exit /b
echo ---
echo Running core:compress tests
echo ---
%PATH_TO_ODIN% test compress %COMMON% -out:test_core_compress.exe || exit /b
echo ---
echo Running core:container tests
echo ---
%PATH_TO_ODIN% test container %COMMON% -out:test_core_container.exe || exit /b
echo ---
echo Running core:crypto tests
echo ---
%PATH_TO_ODIN% test crypto %COMMON% -o:speed -out:test_crypto.exe || exit /b
echo ---
echo Running core:encoding tests
echo ---
%PATH_TO_ODIN% test encoding/base64 %COMMON% -out:test_base64.exe || exit /b
%PATH_TO_ODIN% test encoding/cbor %COMMON% -out:test_cbor.exe || exit /b
%PATH_TO_ODIN% test encoding/hex %COMMON% -out:test_hex.exe || exit /b
%PATH_TO_ODIN% test encoding/hxa %COMMON% -out:test_hxa.exe || exit /b
%PATH_TO_ODIN% test encoding/json %COMMON% -out:test_json.exe || exit /b
%PATH_TO_ODIN% test encoding/varint %COMMON% -out:test_varint.exe || exit /b
%PATH_TO_ODIN% test encoding/xml %COMMON% -out:test_xml.exe || exit /b
echo ---
echo Running core:path/filepath tests
echo ---
%PATH_TO_ODIN% test path/filepath %COMMON% -out:test_core_filepath.exe || exit /b
echo ---
echo Running core:fmt tests
echo ---
%PATH_TO_ODIN% test fmt %COMMON% -out:test_core_fmt.exe || exit /b
echo ---
echo Running core:hash tests
echo ---
%PATH_TO_ODIN% test hash %COMMON% -o:speed -out:test_core_hash.exe || exit /b
echo ---
echo Running core:image tests
echo ---
%PATH_TO_ODIN% test image %COMMON% -out:test_core_image.exe || exit /b
echo ---
echo Running core:text/i18n tests
echo ---
%PATH_TO_ODIN% test text\i18n %COMMON% -out:test_core_i18n.exe || exit /b
echo ---
echo Running text:match tests
echo ---
%PATH_TO_ODIN% test text/match %COMMON% -out:test_core_match.exe || exit /b
echo ---
echo Running core:math tests
echo ---
%PATH_TO_ODIN% test math %COMMON% -out:test_core_math.exe || exit /b
echo ---
echo Running core:math/linalg/glsl tests
echo ---
%PATH_TO_ODIN% test math/linalg/glsl %COMMON% -out:test_linalg_glsl.exe || exit /b
echo ---
echo Running core:math/noise tests
echo ---
%PATH_TO_ODIN% test math/noise %COMMON% -out:test_noise.exe || exit /b
echo ---
echo Running core:mem tests
echo ---
%PATH_TO_ODIN% test mem %COMMON% -out:test_core_mem.exe || exit /b
echo ---
echo Running core:net
echo ---
%PATH_TO_ODIN% test net %COMMON% -out:test_core_net.exe || exit /b
echo ---
echo Running core:odin tests
echo ---
%PATH_TO_ODIN% test odin %COMMON% -o:size -out:test_core_odin.exe || exit /b
echo ---
echo Running core:reflect tests
echo ---
%PATH_TO_ODIN% test reflect %COMMON% -out:test_core_reflect.exe || exit /b
echo ---
echo Running core:runtime tests
echo ---
%PATH_TO_ODIN% test runtime %COMMON% -out:test_core_runtime.exe || exit /b
echo ---
echo Running core:slice tests
echo ---
%PATH_TO_ODIN% test slice %COMMON% -out:test_core_slice.exe || exit /b
echo ---
echo Running core:strings tests
echo ---
%PATH_TO_ODIN% test strings %COMMON% -out:test_core_strings.exe || exit /b
echo ---
echo Running core:thread tests
echo ---
%PATH_TO_ODIN% test thread %COMMON% -out:test_core_thread.exe || exit /b
echo ---
echo Running core:time tests
echo ---
%PATH_TO_ODIN% test time %COMMON% -out:test_core_time.exe || exit /b
+91 -2
View File
@@ -7,8 +7,8 @@ import zipfile
import hashlib
import hmac
TEST_SUITES = ['PNG', 'XML']
DOWNLOAD_BASE_PATH = "assets/{}"
TEST_SUITES = ['PNG', 'XML', 'BMP']
DOWNLOAD_BASE_PATH = sys.argv[1] + "/{}"
ASSETS_BASE_URL = "https://raw.githubusercontent.com/odin-lang/test-assets/master/{}/{}"
HMAC_KEY = "https://odin-lang.org"
HMAC_HASH = hashlib.sha3_512
@@ -192,6 +192,94 @@ HMAC_DIGESTS = {
'z06n2c08.png': "94268c1998de1f4304d24219e31175def7375cc26e2bbfc7d1ac20465a42fae49bcc8ff7626873138b537588e8bce21b6d5e1373efaade1f83cae455334074aa",
'z09n2c08.png': "3cbb1bb58d78ecc9dd5568a8e9093ba020b63449ef3ab102f98fac4220fc9619feaa873336a25f3c1ad99cfb3e5d32bcfe52d966bc8640d1d5ba4e061741743e",
'ba-bm.bmp': "2f76d46b1b9bea62e08e7fc5306452a495616cb7af7a0cbb79237ed457b083418d5859c9e6cfd0d9fbf1fe24495319b6f206135f36f2bd19330de01a8eaf20c8",
'badbitcount.bmp': "2d37e22aa2e659416c950815841e5a402f2e9c21eb677390fc026eefaeb5be64345a7ef0fac2965a2cae8abe78c1e12086a7d93d8e62cc8659b35168c82f6d5f",
'badbitssize.bmp': "f59cc30827bcb56f7e946dcffcaab22a5e197f2e3884cf80a2e596f5653f5203b3927674d9d5190486239964e65228f4e3f359cdd2f7d061b09846f5f26bfaa9",
'baddens1.bmp': "aa84bebc41b3d50329269da9ee61fd7e1518ffd0e8f733af6872323bc46ace6ed1c9931a65a367d97b8b2cb2aa772ccd94fd3def0a79fd1c0baf185d669c386f",
'baddens2.bmp': "5c254a8cde716fae77ebf20294a404383fd6afc705d783c5418762e7c4138aa621625bc6d08a8946ee3f1e8c40c767681a39806735bb3b3026fee5eb91d8fadc",
'badfilesize.bmp': "9019b6853a91f69bd246f9b28da47007aec871c0e46fea7cd6ab5c30460a6938a1b09da8fa7ba8895650e37ce14a79d4183e9f2401eb510f60455410e2266eb5",
'badheadersize.bmp': "90412d7c3bff7336d5e0c7ae899d8a53b82235072034f00783fb2403479447cd2959644f7ec70ae0988f99cc49b63356c8710b808ddd2280e19dca484f34074e",
'badpalettesize.bmp': "d914a89f7b78fcdd6ab4433c176355755687b65c3cfc23db57de9d04447c440fa31d993db184940c1dc09b37e8e044324d8237877d3d1b1ad5657c4929d8435a",
'badplanes.bmp': "46f583d4a43ef0c9964765b9d8820369955f0568a4eae0bf215434f508e8e03457bd759b73c344c2f88de7f33fc5379517ce3cf5b2e5a16ebc20c05df73aa723",
'badrle.bmp': "a64e1551fd60159ff469ce25e1f5b4575dc462684f4ff66c7ea69b2990c7c9d2547b72237020e2d001f69dfd31f1ac45e0a9630d0ddd11c77584881f3e25609e",
'badrle4.bmp': "2bd22418010b1ac3eac50932ed06e578411ac2741bfa50a9edd1b360686efa28c74df8b14d92e05b711eeb88a5e826256c6a5cf5a0176a29369fb92b336efb93",
'badrle4bis.bmp': "d7a24ab095e1ca5e888dd1bcb732b19bb1983f787c64c1eb5a273da0f58c4b8cd137197df9ac47572a74c3026aab5af1f08551a2121af37b8941cffa71df1951",
'badrle4ter.bmp': "825cc5361378d44524205b117825f95228c4d093d39ac2fc2ab755be743df78784529f2019418deca31059f3e46889a66658e7424b4f896668ee4cfa281574bc",
'badrlebis.bmp': "f41acfd4f989302bb5ec42a2e759a56f71a5ecac5a814842e32542742ca015464f8579ebeec0e7e9cea45e2aafe51456cfe18b48b509bc3704f992bcc9d321af",
'badrleter.bmp': "a8f3e0b0668fc4f43353028d5fca87d6cac6ff0c917c4e7a61c624918360ff598ec9eaa32f5c6a070da9bf6e90c58426f5a901fdab9dfb0a4fdca0c72ba67de4",
'badwidth.bmp': "68f192a55b8de66f8e13fe316647262a5e4641365eb77d4987c84ab1eae35b7cba20827277cd569583543819de70ec75f383367f72cd229e48743ad1e45bfa9e",
'pal1.bmp': "0194c9b501ac7e043fab78746e6f142e0c880917d0fd6dbb7215765b8fc1ce4403ad85146c555665ba6e37d3b47edad5e687b9260e7a61a27d8a059bc81bb525",
'pal1bg.bmp': "3aafc29122bd6e97d88d740be1f61cb9febe8373d19ae6d731f4af776c868dd489260287bf0cf1c960f9d9afcbc7448e83e45435d3e42e913823c0f5c2a80d9f",
'pal1huffmsb.bmp': "4e122f602c3556f4f5ab45f9e13a617d8210d81f587d08cbd6c2110dc6231573aec92a6344aeb4734c00d3dcf380130f53a887002756811d8edd6bc5aabbafc0",
'pal1p1.bmp': "33e2b2b1c1bed43ba64888d7739eb830c7789857352513de08b6e35718ac0e421afcdae0e7bab97c25d1ad972eb4f09e2c6556c416d4d7367c545330c4123df0",
'pal1wb.bmp': "bc583ad4eaae40f5d2e3a6280aeb3c62ee11b2cf05ba7c8386f9578587e29b66819293992bdcd31c2750c21cd9bf97daa603ce1051fbfdd40fadbc1860156853",
'pal2.bmp': "7b560ba972cf58ca1ed01910fa4f630ca74e657d46d134e2ac0df733eb5773d0a1788e745d5240efa18f182bd8dce22c7ac7cee6f99ddc946a27b65297762764",
'pal2color.bmp': "b868a8aaa22fac3aa86bbd5270eb5ffee06959461be8177880829d838be0391d9617d11d73fab1643520a92364dc333c25c0510bb2628c8fb945719518d2675f",
'pal4.bmp': "53a39fdb86630c828d9003a1e95dbd59c47524c4ec044d8ce72e1b643166b4c2b6ec06ab5191cb25d17be2fcb18bd7a9e0b7ec169722e6d89b725609a15b1df1",
'pal4gs.bmp': "ab4c2078943afdf19bcc02b1ebbe5a69cfa93d1152f7882db6176c39b917191a2760fbb2127e5207b0bfb3dafd711593a6aed61d312807605913062aa1ce9c2f",
'pal4rle.bmp': "c86c86280b75a252ccf484e4bba2df45d3747dc1e4879795e925613959a0c451e2fc4890532e8aef9911e38e45e7d6a8baf29d57e573d26c20923a5823700443",
'pal4rlecut.bmp': "f38d485dbb8e67bdeaefba181f9a05556a986ed3f834edca723c088e813764bb2b42240d4fbb938a1775370b79b9ea2f14277ffe9c7247c1e0e77766fec27189",
'pal4rletrns.bmp': "b81e7fed38854d201a3199ce50ca05e92ca287c860797142857ac20b4a2f28952b058e21687c0fae60712f5784cd2c950ce70148ba1316efe31d4f3fc4006817",
'pal8-0.bmp': "f39a4f1827c52bb620d975f8c72f5e95f90ac6c65ae0a6776ff1ad95808c090de17cbd182188a85157396fd9649ea4b5d84bb7c9175ab49ce2845da214c16bff",
'pal8.bmp': "be27e55a866cbb655fdd917435cd6a5b62c20ae0d6ef7c1533c5a01dd9a893f058cc4ba2d902ab9315380009808e06b7f180116c9b790587cf62aa770c7a4a07",
'pal8badindex.bmp': "bd5fc036985ae705182915a560dee2e5dfb3bd8b50932337b9085e190259c66e6bae5fbc813a261d352a60dcb0755798bdc251d6c2a0b638a7e337ba58811811",
'pal8gs.bmp': "228f944b3e45359f62a2839d4e7b94d7f3a1074ad9e25661fdb9e8fff4c15581c85a7bb0ac75c92b95c7537ececc9d80b835cfe55bc7560a513118224a9ed36f",
'pal8nonsquare.bmp': "b8adc9b03880975b232849ea1e8f87705937929d743df3d35420902b32557065354ab71d0d8176646bf0ad72c583c884cfcd1511017260ffca8c41d5a358a3eb",
'pal8offs.bmp': "c92f1e1835d753fd8484be5198b2b8a2660d5e54117f6c4fc6d2ebc8d1def72a8d09cd820b1b8dcee15740b47151d62b8b7aca0b843e696252e28226b51361cf",
'pal8os2-hs.bmp': "477c04048787eb412f192e7fe47ae96f14d7995391e78b10cc4c365f8c762f60c54cad7ef9d1705a78bd490a578fb346ee0a383c3a3fdf790558a12589eb04eb",
'pal8os2-sz.bmp': "fd0eeb733be9b39f492d0f67dd28fc67207149e41691c206d4de4c693b5dea9458b88699a781383e7050a3b343259659aae64fec0616c98f3f8555cbf5c9e46c",
'pal8os2.bmp': "cdab3ed7bc9f38d89117332a21418b3c916a99a8d8fb6b7ce456d54288c96152af12c0380293b04e96594a7867b83be5c99913d224c9750c7d38295924e0735a",
'pal8os2sp.bmp': "f6e595a6db992ab7d1f79442d31f39f648061e7de13e51b07933283df065ce405c0208e6101ac916e4eb0613e412116f008510021a2d17543aa7f0a32349c96f",
'pal8os2v2-16.bmp': "f52877d434218aa6b772a7aa0aaba4c2ae6ce35ecfa6876943bb350fdf9554f1f763a8d5bb054362fb8f9848eb71ce14a371f4a76da4b9475cdcee4f286109a4",
'pal8os2v2-40sz.bmp': "9481691ada527df1f529316d44b5857c6a840c5dafa7e9795c9cb92dac02c6cc35739d3f6ce33d4ab6ff6bcd6b949741e89dc8c42cf52ad4546ff58cd3b5b66a",
'pal8os2v2-sz.bmp': "99cd2836f90591cd27b0c8696ecff1e7a1debcef284bbe5d21e68759270c1bfe1f32ee8f576c49f3e64d8f4e4d9096574f3c8c79bfdae0545689da18364de3e7",
'pal8os2v2.bmp': "7859b265956c7d369db7a0a357ce09bcda74e98954de88f454cae5e7cb021222146687a7770ce0cc2c58f1439c7c21c45c0c27464944e73913e1c88afc836c8a",
'pal8oversizepal.bmp': "e778864e0669a33fce27c0ccd5b6460b572a5db01975e8d56acec8a9447e1c58d6051ad3516cfa96a39f4eb7f2576154188ea62ec187bcf4ae323883499383c0",
'pal8rle.bmp': "88942a1cd2e36d1e0f0e2748a888034057919c7ec0f8d9b2664deb1daf1a6e45ed3e722dff5d810f413d6fc182e700a16d6563dd25f67dc6d135d751cd736dea",
'pal8rlecut.bmp': "cda9fa274cde590aeaca81516e0465684cfae84e934eb983301801e978e6e2e9c590d22af992d9912e51bb9c2761945276bdbe0b6c47f3a021514414e1f3f455",
'pal8rletrns.bmp': "0b2d5618dc9c81caa72c070070a4245dd9cd3de5d344b76ce9c15d0eeb72e2675efc264201f8709dfcffd234df09e76d6f328f16f2ad873ba846f870cadfa486",
'pal8topdown.bmp': "d470a2b7556fa88eac820427cb900f59a121732cdb4a7f3530ed457798139c946a884a34ab79d822feb84c2ca6f4d9a65f6e792994eafc3a189948b9e4543546",
'pal8v4.bmp': "0382610e32c49d5091a096cb48a54ebbf44d9ba1def96e2f30826fd3ddf249f5aed70ca5b74c484b6cdc3924f4d4bfed2f5194ad0bcf1d99bfaa3a619e299d86",
'pal8v5.bmp': "50fadaa93aac2a377b565c4dc852fd4602538863b913cb43155f5ad7cf79928127ca28b33e5a3b0230076ea4a6e339e3bf57f019333f42c4e9f003a8f2376325",
'pal8w124.bmp': "e54a901b9badda655cad828d226b381831aea7e36aec8729147e9e95a9f2b21a9d74d93756e908e812902a01197f1379fe7e35498dbafed02e27c853a24097b7",
'pal8w125.bmp': "d7a04d45ef5b3830da071ca598f1e2a413c46834968b2db7518985cf8d8c7380842145899e133e71355b6b7d040ee9e97adec1e928ce4739282e0533058467c0",
'pal8w126.bmp': "4b93845a98797679423c669c541a248b4cdfee80736f01cec29d8b40584bf55a27835c80656a2bf5c7ad3ed211c1f7d3c7d5831a6726904b39f10043a76b658d",
'reallybig.bmp': "babbf0335bac63fd2e95a89210c61ae6bbaaeeab5f07974034e76b4dc2a5c755f77501e3d056479357445aac442e2807d7170ec44067bab8fd35742f0e7b8440",
'rgb16-231.bmp': "611a87cb5d29f16ef71971714a3b0e3863a6df51fff16ce4d4df8ee028442f9ce03669fb5d7a6a838a12a75d8a887b56b5a2e44a3ad62f4ef3fc2e238c33f6a1",
'rgb16-3103.bmp': "7fdff66f4d94341da522b4e40586b3b8c327be9778e461bca1600e938bfbaa872b484192b35cd84d9430ca20aa922ec0301567a74fb777c808400819db90b09d",
'rgb16-565.bmp': "777883f64b9ae80d77bf16c6d062082b7a4702f8260c183680afee6ec26e48681bcca75f0f81c470be1ac8fcb55620b3af5ce31d9e114b582dfd82300a3d6654",
'rgb16-565pal.bmp': "57e9dcf159415b3574a1b343a484391b0859ab2f480e22157f2a84bc188fde141a48826f960c6f30b1d1f17ef6503ec3afc883a2f25ff09dd50c437244f9ae7f",
'rgb16-880.bmp': "8d61183623002da4f7a0a66b42aa58a120e3a91578bb0c4a5e2c5ba7d08b875d43a22f2b5b3a449d3caf4cc303cb05111dd1d5169953f288493b7ea3c2423d24",
'rgb16.bmp': "1c0fe56661d4998edd76efedda520a441171d42ae4dad95b350e3b61deda984c3a3255392481fe1903e5e751357da3f35164935e323377f015774280036ba39e",
'rgb16bfdef.bmp': "ed55d086e27ba472076df418be0046b740944958afeb84d05aa2bbe578dec27ced122ffefb6d549e1d07e05eb608979b3ac9b1bd809f8237cf0984ffdaa24716",
'rgb16faketrns.bmp': "9cd4a8e05fe125649e360715851ef912e78a56d30e0ea1b1cfb6eaafd386437d45de9c1e1a845dd8d63ff5a414832355b8ae0e2a96d72a42a7205e8a2742d37c",
'rgb24.bmp': "4f0ce2978bbfea948798b2fdcc4bdbe8983a6c94d1b7326f39daa6059368e08ebf239260984b64eeb0948f7c8089a523e74b7fa6b0437f9205d8af8891340389",
'rgb24largepal.bmp': "b377aee1594c5d9fc806a70bc62ee83cf8d1852b4a2b18fd3e9409a31aa3b5a4cf5e3b4af2cbdebcef2b5861b7985a248239684a72072437c50151adc524e9df",
'rgb24pal.bmp': "f40bb6e01f6ecb3d55aa992bf1d1e2988ea5eb11e3e58a0c59a4fea2448de26f231f45e9f378b7ee1bdd529ec57a1de38ea536e397f5e1ac6998921e066ab427",
'rgb24png.bmp': "c60890bbd79c12472205665959eb6e2dd2103671571f80117b9e963f897cffca103181374a4797f53c7768af01a705e830a0de4dd8fab7241d24c17bee4a4dbe",
'rgb24rle24.bmp': "ea0ff3f512dd04176d14b43dfbee73ac7f1913aa1b77587e187e271781c7dacec880cec73850c4127ea9f8dd885f069e281f159bb5232e93cbb2d1ee9cb50438",
'rgb32-111110.bmp': "732884e300d4edbcf31556a038947beefc0c5e749131a66d2d7aa1d4ec8c8eba07833133038a03bbe4c4fa61a805a5df1f797b5853339ee6a8140478f5f70a76",
'rgb32-7187.bmp': "4c55aab2e4ecf63dc30b04e5685c5d9fba7354ca0e1327d7c4b15d6da10ac66ca1cea6f0303f9c5f046da3bcd2566275384e0e7bb14fcc5196ec39ca90fac194",
'rgb32-xbgr.bmp': "1e9f240eaec6ac2833f8c719f1fb53cc7551809936620e871ccacfab26402e1afc6503b9f707e4ec25f15529e3ce6433c7f999d5714af31dfb856eb67e772f64",
'rgb32.bmp': "32033dbf9462e5321b1182ba739624ed535aa4d33b775ffeeaf09d2d4cb663e4c3505e8c05489d940f754dde4b50a2e0b0688b21d06755e717e6e511b0947525",
'rgb32bf.bmp': "7243c215827a9b4a1d7d52d67fb04ffb43b0b176518fbdab43d413e2a0c18883b106797f1acd85ba68d494ec939b0caab8789564670d058caf0e1175ce7983fb",
'rgb32bfdef.bmp': "a81433babb67ce714285346a77bfccd19cf6203ac1d8245288855aff20cf38146a783f4a7eac221db63d1ee31345da1329e945b432f0e7bcf279ea88ff5bb302",
'rgb32fakealpha.bmp': "abecaf1b5bfad322de7aec897efe7aa6525f2a77a0af86cc0a0a366ed1650da703cf4b7b117a7ba34f21d03a8a0045e5821248cdefa00b0c78e01d434b55e746",
'rgb32h52.bmp': "707d734393c83384bc75720330075ec9ffefc69167343259ebf95f9393948364a40f33712619f962e7056483b73334584570962c16da212cd5291f764b3f2cd1",
'rgba16-1924.bmp': "3e41a5d8d951bac580c780370ca21e0783de8154f4081106bc58d1185bb2815fc5b7f08f2a1c75cd205fc52c888e9d07c91856651603a2d756c9cfc392585598",
'rgba16-4444.bmp': "a6662186b23bd434a7e019d2a71cd95f53a47b64a1afea4c27ae1120685d041a9ff98800a43a9d8f332682670585bdb2fa77ff77b6def65139fe725323f91561",
'rgba16-5551.bmp': "a7d9f8ae7f8349cd6df651ab9d814411939fa2a235506ddfdd0df5a8f8abcf75552c32481ea035ff29e683bdcd34da68eb23730857e0716b79af51d69a60757b",
'rgba32-1.bmp': "3958d18d2a7f32ada69cb11e0b4397821225a5c40acc7b6d36ff28ee4565e150cc508971278a2ddf8948aaff86f66ec6a0c24513db44962d81b79c4239b3e612",
'rgba32-1010102.bmp': "59a28db5563caf954d31b20a1d1cc59366fcfd258b7ba2949f7281978460a3d94bedcc314c089243dd7463bb18d36a9473355158a7d903912cb25b98eab6b068",
'rgba32-2.bmp': "9b7e5965ff9888f011540936ab6b3022edf9f6c5d7e541d6882cb81820cf1d68326d65695a6f0d01999ac10a496a504440906aa45e413da593405563c54c1a05",
'rgba32-61754.bmp': "784ae0a32b19fa925e0c86dbff3bd38d80904d0fa7dc3b03e9d4f707d42b1604c1f54229e901ccc249cab8c2976d58b1e16980157d9bf3dbc4e035e2b2fd1779",
'rgba32-81284.bmp': "fcfca645017c0d15d44b08598a90d238d063763fd06db665d9a8e36ef5099ce0bf4d440e615c6d6b1bf99f38230d4848318bfa1e6d9bfdd6dfd521cc633ba110",
'rgba32abf.bmp': "2883d676966d298d235196f102e044e52ef18f3cb5bb0dd84738c679f0a1901181483ca2df1cccf6e4b3b4e98be39e81de69c9a58f0d70bc3ebb0fcea80daa0c",
'rgba32h56.bmp': "507d0caf29ccb011c83c0c069c21105ea1d58e06b92204f9c612f26102123a7680eae53fef023c701952d903e11b61f8aa07618c381ea08f6808c523f5a84546",
'rgba64.bmp': "d01f14f649c1c33e3809508cc6f089dd2ab0a538baf833a91042f2e54eca3f8e409908e15fa8763b059d7fa022cf5c074d9f5720eed5293a4c922e131c2eae68",
'rletopdown.bmp': "37500893aad0b40656aa80fd5c7c5f9b35d033018b8070d8b1d7baeb34c90f90462288b13295204b90aa3e5c9be797d22a328e3714ab259334e879a09a3de175",
'shortfile.bmp': "be3ffade7999304f00f9b7d152b5b27811ad1166d0fd43004392467a28f44b6a4ec02a23c0296bacd4f02f8041cd824b9ca6c9fc31fed27e36e572113bb47d73",
'unicode.xml': "e0cdc94f07fdbb15eea811ed2ae6dcf494a83d197dafe6580c740270feb0d8f5f7146d4a7d4c2d2ea25f8bd9678bc986123484b39399819a6b7262687959d1ae",
}
@@ -233,6 +321,7 @@ def try_download_and_unpack_zip(suite):
hmac_digest = hmac.new(HMAC_KEY.encode(), file_data, HMAC_HASH).hexdigest()
print("{} *{}".format(hmac_digest, file.filename))
if not hmac.compare_digest(hmac_digest, HMAC_DIGESTS[file.filename]):
print("FAIL! Expected: {}".format(HMAC_DIGESTS[file.filename]))
return 4
+40 -3
View File
@@ -221,8 +221,45 @@ test_fmt_python_syntax :: proc(t: ^testing.T) {
check(t, "%!(MISSING CLOSE BRACE)%!(EXTRA 1)", "{0", 1 )
}
@(test)
test_pointers :: proc(t: ^testing.T) {
S :: struct { i: int }
a: rawptr
b: ^int
c: ^S
d: ^S = cast(^S)cast(uintptr)0xFFFF
check(t, "0x0", "%p", a)
check(t, "0x0", "%p", b)
check(t, "0x0", "%p", c)
check(t, "0xFFFF", "%p", d)
check(t, "0x0", "%#p", a)
check(t, "0x0", "%#p", b)
check(t, "0x0", "%#p", c)
check(t, "0xFFFF", "%#p", d)
check(t, "0x0", "%v", a)
check(t, "0x0", "%v", b)
check(t, "<nil>", "%v", c)
check(t, "0x0", "%#v", a)
check(t, "0x0", "%#v", b)
check(t, "<nil>", "%#v", c)
check(t, "0x0000", "%4p", a)
check(t, "0x0000", "%4p", b)
check(t, "0x0000", "%4p", c)
check(t, "0xFFFF", "%4p", d)
check(t, "0x0000", "%#4p", a)
check(t, "0x0000", "%#4p", b)
check(t, "0x0000", "%#4p", c)
check(t, "0xFFFF", "%#4p", d)
}
@(private)
check :: proc(t: ^testing.T, exp: string, format: string, args: ..any) {
check :: proc(t: ^testing.T, exp: string, format: string, args: ..any, loc := #caller_location) {
got := fmt.tprintf(format, ..args)
testing.expectf(t, got == exp, "(%q, %v): %q != %q", format, args, got, exp)
}
testing.expectf(t, got == exp, "(%q, %v): %q != %q", format, args, got, exp, loc = loc)
}
-2
View File
@@ -1,2 +0,0 @@
@echo off
odin test . -define:ODIN_TEST_TRACK_MEMORY=true -define:ODIN_TEST_PROGRESS_WIDTH=12 -vet -strict-style
+597 -72
View File
@@ -1,11 +1,11 @@
/*
Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.
Copyright 2021-2024 Jeroen van Rijn <nom@duclavier.com>.
Made available under Odin's BSD-3 license.
List of contributors:
Jeroen van Rijn: Initial implementation.
A test suite for PNG + QOI.
A test suite for PNG, TGA, NetPBM, QOI and BMP.
*/
package test_core_image
@@ -13,6 +13,7 @@ import "core:testing"
import "core:compress"
import "core:image"
import "core:image/bmp"
import pbm "core:image/netpbm"
import "core:image/png"
import "core:image/qoi"
@@ -24,16 +25,17 @@ import "core:strings"
import "core:mem"
import "core:time"
TEST_SUITE_PATH :: ODIN_ROOT + "tests/core/assets/PNG/"
TEST_SUITE_PATH_PNG :: ODIN_ROOT + "tests/core/assets/PNG"
TEST_SUITE_PATH_BMP :: ODIN_ROOT + "tests/core/assets/BMP"
I_Error :: image.Error
PNG_Test :: struct {
Test :: struct {
file: string,
tests: []struct {
options: image.Options,
expected_error: image.Error,
dims: PNG_Dims,
dims: Dims,
hash: u32,
},
}
@@ -46,19 +48,18 @@ Blend_BG_Keep :: image.Options{.blend_background, .alpha_add_if_missing}
Return_Metadata :: image.Options{.return_metadata}
No_Channel_Expansion :: image.Options{.do_not_expand_channels, .return_metadata}
PNG_Dims :: struct {
Dims :: struct {
width: int,
height: int,
channels: int,
depth: int,
}
Basic_PNG_Tests := []PNG_Test{
Basic_PNG_Tests := []Test{
/*
Basic format tests:
http://www.schaik.com/pngsuite/pngsuite_bas_png.html
*/
{
"basn0g01", // Black and white.
{
@@ -166,7 +167,7 @@ Basic_PNG_Tests := []PNG_Test{
},
}
Interlaced_PNG_Tests := []PNG_Test{
Interlaced_PNG_Tests := []Test{
/*
Interlaced format tests:
http://www.schaik.com/pngsuite/pngsuite_int_png.html
@@ -284,9 +285,9 @@ Interlaced_PNG_Tests := []PNG_Test{
},
}
Odd_Sized_PNG_Tests := []PNG_Test{
Odd_Sized_PNG_Tests := []Test{
/*
" PngSuite", // Odd sizes / PNG-files:
"PngSuite", // Odd sizes / PNG-files:
http://www.schaik.com/pngsuite/pngsuite_siz_png.html
This tests curious sizes with and without interlacing.
@@ -510,7 +511,7 @@ Odd_Sized_PNG_Tests := []PNG_Test{
},
}
PNG_bKGD_Tests := []PNG_Test{
PNG_bKGD_Tests := []Test{
/*
" PngSuite", // Background colors / PNG-files:
http://www.schaik.com/pngsuite/pngsuite_bck_png.html
@@ -597,7 +598,7 @@ PNG_bKGD_Tests := []PNG_Test{
},
}
PNG_tRNS_Tests := []PNG_Test{
PNG_tRNS_Tests := []Test{
/*
PngSuite - Transparency:
http://www.schaik.com/pngsuite/pngsuite_trn_png.html
@@ -759,7 +760,7 @@ PNG_tRNS_Tests := []PNG_Test{
},
}
PNG_Filter_Tests := []PNG_Test{
PNG_Filter_Tests := []Test{
/*
PngSuite - Image filtering:
@@ -838,7 +839,7 @@ PNG_Filter_Tests := []PNG_Test{
},
}
PNG_Varied_IDAT_Tests := []PNG_Test{
PNG_Varied_IDAT_Tests := []Test{
/*
PngSuite - Chunk ordering:
@@ -897,7 +898,7 @@ PNG_Varied_IDAT_Tests := []PNG_Test{
},
}
PNG_ZLIB_Levels_Tests := []PNG_Test{
PNG_ZLIB_Levels_Tests := []Test{
/*
PngSuite - Zlib compression:
@@ -938,7 +939,7 @@ PNG_ZLIB_Levels_Tests := []PNG_Test{
},
}
PNG_sPAL_Tests := []PNG_Test{
PNG_sPAL_Tests := []Test{
/*
PngSuite - Additional palettes:
@@ -985,7 +986,7 @@ PNG_sPAL_Tests := []PNG_Test{
},
}
PNG_Ancillary_Tests := []PNG_Test{
PNG_Ancillary_Tests := []Test{
/*
PngSuite" - Ancillary chunks:
@@ -1153,7 +1154,7 @@ PNG_Ancillary_Tests := []PNG_Test{
}
Corrupt_PNG_Tests := []PNG_Test{
Corrupt_PNG_Tests := []Test{
/*
PngSuite - Corrupted files / PNG-files:
@@ -1249,7 +1250,7 @@ Corrupt_PNG_Tests := []PNG_Test{
}
No_Postprocesing_Tests := []PNG_Test{
No_Postprocesing_Tests := []Test{
/*
These are some custom tests where we skip expanding to RGB(A).
*/
@@ -1273,8 +1274,6 @@ No_Postprocesing_Tests := []PNG_Test{
},
}
Text_Title :: "PngSuite"
Text_Software :: "Created on a NeXTstation color using \"pnmtopng\"."
Text_Descrption :: "A compilation of a set of images created to test the\nvarious color-types of the PNG format. Included are\nblack&white, color, paletted, with alpha channel, with\ntransparency formats. All bit-depths allowed according\nto the spec are present."
@@ -1453,9 +1452,9 @@ png_test_no_postproc :: proc(t: ^testing.T) {
run_png_suite(t, No_Postprocesing_Tests)
}
run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
run_png_suite :: proc(t: ^testing.T, suite: []Test) {
for file in suite {
test_file := strings.concatenate({TEST_SUITE_PATH, file.file, ".png"})
test_file := strings.concatenate({TEST_SUITE_PATH_PNG, "/", file.file, ".png"}, context.allocator)
defer delete(test_file)
img: ^png.Image
@@ -1468,20 +1467,18 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
img, err = png.load(test_file, test.options)
passed := (test.expected_error == nil && err == nil) || (test.expected_error == err)
testing.expectf(t, passed, "%v failed with %v.", test_file, 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)
// This struct compare fails at -opt:2 if PNG_Dims is not #packed.
dims := PNG_Dims{img.width, img.height, img.channels, img.depth}
dims := Dims{img.width, img.height, img.channels, img.depth}
dims_pass := test.dims == dims
testing.expectf(t, dims_pass, "%v has %v, expected: %v.", file.file, dims, test.dims)
testing.expectf(t, dims_pass, "%v has %v, expected: %v", file.file, dims, test.dims)
passed &= dims_pass
png_hash := hash.crc32(pixels)
testing.expectf(t, test.hash == png_hash, "%v test %v hash is %08x, expected %08x with %v.", file.file, count, png_hash, test.hash, test.options)
testing.expectf(t, test.hash == png_hash, "%v test %v hash is %08x, expected %08x with %v", file.file, count, png_hash, test.hash, test.options)
passed &= test.hash == png_hash
@@ -1492,16 +1489,16 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
defer bytes.buffer_destroy(&qoi_buffer)
qoi_save_err := qoi.save(&qoi_buffer, img)
testing.expectf(t, qoi_save_err == nil, "%v test %v QOI save failed with %v.", file.file, count, qoi_save_err)
testing.expectf(t, qoi_save_err == nil, "%v test %v QOI save failed with %v", file.file, count, qoi_save_err)
if qoi_save_err == nil {
qoi_img, qoi_load_err := qoi.load(qoi_buffer.buf[:])
defer qoi.destroy(qoi_img)
testing.expectf(t, qoi_load_err == nil, "%v test %v QOI load failed with %v.", file.file, count, qoi_load_err)
testing.expectf(t, qoi_load_err == nil, "%v test %v QOI load failed with %v", file.file, count, qoi_load_err)
qoi_hash := hash.crc32(qoi_img.pixels.buf[:])
testing.expectf(t, qoi_hash == png_hash, "%v test %v QOI load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, qoi_hash, png_hash, test.options)
testing.expectf(t, qoi_hash == png_hash, "%v test %v QOI load hash is %08x, expected it match PNG's %08x with %v", file.file, count, qoi_hash, png_hash, test.options)
}
}
@@ -1511,15 +1508,15 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
defer bytes.buffer_destroy(&tga_buffer)
tga_save_err := tga.save(&tga_buffer, img)
testing.expectf(t, tga_save_err == nil, "%v test %v TGA save failed with %v.", file.file, count, tga_save_err)
testing.expectf(t, tga_save_err == nil, "%v test %v TGA save failed with %v", file.file, count, tga_save_err)
if tga_save_err == nil {
tga_img, tga_load_err := tga.load(tga_buffer.buf[:])
defer tga.destroy(tga_img)
testing.expectf(t, tga_load_err == nil, "%v test %v TGA load failed with %v.", file.file, count, tga_load_err)
testing.expectf(t, tga_load_err == nil, "%v test %v TGA load failed with %v", file.file, count, tga_load_err)
tga_hash := hash.crc32(tga_img.pixels.buf[:])
testing.expectf(t, tga_hash == png_hash, "%v test %v TGA load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, tga_hash, png_hash, test.options)
testing.expectf(t, tga_hash == png_hash, "%v test %v TGA load hash is %08x, expected it match PNG's %08x with %v", file.file, count, tga_hash, png_hash, test.options)
}
}
@@ -1528,18 +1525,18 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
pbm_buf, pbm_save_err := pbm.save_to_buffer(img)
defer delete(pbm_buf)
testing.expectf(t, pbm_save_err == nil, "%v test %v PBM save failed with %v.", file.file, count, pbm_save_err)
testing.expectf(t, pbm_save_err == nil, "%v test %v PBM save failed with %v", file.file, count, pbm_save_err)
if pbm_save_err == nil {
// Try to load it again.
pbm_img, pbm_load_err := pbm.load(pbm_buf)
defer pbm.destroy(pbm_img)
testing.expectf(t, pbm_load_err == nil, "%v test %v PBM load failed with %v.", file.file, count, pbm_load_err)
testing.expectf(t, pbm_load_err == nil, "%v test %v PBM load failed with %v", file.file, count, pbm_load_err)
if pbm_load_err == nil {
pbm_hash := hash.crc32(pbm_img.pixels.buf[:])
testing.expectf(t, pbm_hash == png_hash, "%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, pbm_hash, png_hash, test.options)
testing.expectf(t, pbm_hash == png_hash, "%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v", file.file, count, pbm_hash, png_hash, test.options)
}
}
}
@@ -1553,18 +1550,18 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
pbm_buf, pbm_save_err := pbm.save_to_buffer(img, pbm_info)
defer delete(pbm_buf)
testing.expectf(t, pbm_save_err == nil, "%v test %v PBM save failed with %v.", file.file, count, pbm_save_err)
testing.expectf(t, pbm_save_err == nil, "%v test %v PBM save failed with %v", file.file, count, pbm_save_err)
if pbm_save_err == nil {
// Try to load it again.
pbm_img, pbm_load_err := pbm.load(pbm_buf)
defer pbm.destroy(pbm_img)
testing.expectf(t, pbm_load_err == nil, "%v test %v PBM load failed with %v.", file.file, count, pbm_load_err)
testing.expectf(t, pbm_load_err == nil, "%v test %v PBM load failed with %v", file.file, count, pbm_load_err)
if pbm_load_err == nil {
pbm_hash := hash.crc32(pbm_img.pixels.buf[:])
testing.expectf(t, pbm_hash == png_hash, "%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v.", file.file, count, pbm_hash, png_hash, test.options)
testing.expectf(t, pbm_hash == png_hash, "%v test %v PBM load hash is %08x, expected it match PNG's %08x with %v", file.file, count, pbm_hash, png_hash, test.options)
}
}
}
@@ -1653,7 +1650,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
case "pp0n2c16", "pp0n6a08":
gamma, gamma_ok := png.gamma(c)
expected_gamma := f32(1.0)
testing.expectf(t, gamma == expected_gamma && gamma_ok, "%v test %v gAMA is %v, expected %v.", file.file, count, gamma, expected_gamma)
testing.expectf(t, gamma == expected_gamma && gamma_ok, "%v test %v gAMA is %v, expected %v", file.file, count, gamma, expected_gamma)
}
case .PLTE:
switch(file.file) {
@@ -1661,7 +1658,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
plte, plte_ok := png.plte(c)
expected_plte_len := u16(216)
testing.expectf(t, expected_plte_len == plte.used && plte_ok, "%v test %v PLTE length is %v, expected %v.", file.file, count, plte.used, expected_plte_len)
testing.expectf(t, expected_plte_len == plte.used && plte_ok, "%v test %v PLTE length is %v, expected %v", file.file, count, plte.used, expected_plte_len)
}
case .sPLT:
switch(file.file) {
@@ -1669,10 +1666,10 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
splt, splt_ok := png.splt(c)
expected_splt_len := u16(216)
testing.expectf(t, expected_splt_len == splt.used && splt_ok, "%v test %v sPLT length is %v, expected %v.", file.file, count, splt.used, expected_splt_len)
testing.expectf(t, expected_splt_len == splt.used && splt_ok, "%v test %v sPLT length is %v, expected %v", file.file, count, splt.used, expected_splt_len)
expected_splt_name := "six-cube"
testing.expectf(t, expected_splt_name == splt.name && splt_ok, "%v test %v sPLT name is %v, expected %v.", file.file, count, splt.name, expected_splt_name)
testing.expectf(t, expected_splt_name == splt.name && splt_ok, "%v test %v sPLT name is %v, expected %v", file.file, count, splt.name, expected_splt_name)
png.splt_destroy(splt)
}
@@ -1686,31 +1683,31 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
g = png.CIE_1931{x = 0.3000, y = 0.6000},
b = png.CIE_1931{x = 0.1500, y = 0.0600},
}
testing.expectf(t, expected_chrm == chrm && chrm_ok, "%v test %v cHRM is %v, expected %v.", file.file, count, chrm, expected_chrm)
testing.expectf(t, expected_chrm == chrm && chrm_ok, "%v test %v cHRM is %v, expected %v", file.file, count, chrm, expected_chrm)
}
case .pHYs:
phys, phys_ok := png.phys(c)
switch (file.file) {
case "cdfn2c08":
expected_phys := png.pHYs{ppu_x = 1, ppu_y = 4, unit = .Unknown}
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v.", file.file, count, phys, expected_phys)
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v", file.file, count, phys, expected_phys)
case "cdhn2c08":
expected_phys := png.pHYs{ppu_x = 4, ppu_y = 1, unit = .Unknown}
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v.", file.file, count, phys, expected_phys)
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v", file.file, count, phys, expected_phys)
case "cdsn2c08":
expected_phys := png.pHYs{ppu_x = 1, ppu_y = 1, unit = .Unknown}
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v.", file.file, count, phys, expected_phys)
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v", file.file, count, phys, expected_phys)
case "cdun2c08":
expected_phys := png.pHYs{ppu_x = 1000, ppu_y = 1000, unit = .Meter}
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v.", file.file, count, phys, expected_phys)
testing.expectf(t, expected_phys == phys && phys_ok, "%v test %v cHRM is %v, expected %v", file.file, count, phys, expected_phys)
}
case .hIST:
hist, hist_ok := png.hist(c)
switch (file.file) {
case "ch1n3p04":
testing.expectf(t, hist.used == 15 && hist_ok, "%v test %v hIST has %v entries, expected %v.", file.file, count, hist.used, 15)
testing.expectf(t, hist.used == 15 && hist_ok, "%v test %v hIST has %v entries, expected %v", file.file, count, hist.used, 15)
case "ch2n3p08":
testing.expectf(t, hist.used == 256 && hist_ok, "%v test %v hIST has %v entries, expected %v.", file.file, count, hist.used, 256)
testing.expectf(t, hist.used == 256 && hist_ok, "%v test %v hIST has %v entries, expected %v", file.file, count, hist.used, 256)
}
case .tIME:
png_time, png_time_ok := png.time(c)
@@ -1731,8 +1728,8 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
expected_core = time.Time{_nsec = 946684799000000000}
}
testing.expectf(t, png_time == expected_time && png_time_ok, "%v test %v tIME was %v, expected %v.", file.file, count, png_time, expected_time)
testing.expectf(t, core_time == expected_core && core_time_ok, "%v test %v tIME->core:time is %v, expected %v.", file.file, count, core_time, expected_core)
testing.expectf(t, png_time == expected_time && png_time_ok, "%v test %v tIME was %v, expected %v", file.file, count, png_time, expected_time)
testing.expectf(t, core_time == expected_core && core_time_ok, "%v test %v tIME->core:time is %v, expected %v", file.file, count, core_time, expected_core)
case .sBIT:
sbit, sbit_ok := png.sbit(c)
expected_sbit: [4]u8
@@ -1753,7 +1750,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
case "cdfn2c08", "cdhn2c08", "cdsn2c08", "cdun2c08", "ch1n3p04", "basn3p04":
expected_sbit = [4]u8{ 4, 4, 4, 0}
}
testing.expectf(t, sbit == expected_sbit && sbit_ok, "%v test %v sBIT was %v, expected %v.", file.file, count, sbit, expected_sbit)
testing.expectf(t, sbit == expected_sbit && sbit_ok, "%v test %v sBIT was %v, expected %v", file.file, count, sbit, expected_sbit)
case .tEXt, .zTXt:
text, text_ok := png.text(c)
defer png.text_destroy(text)
@@ -1765,7 +1762,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test_text := Expected_Text[file.file][text.keyword].text
testing.expectf(t, text.text == test_text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text.text, test_text)
testing.expectf(t, text.text == test_text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text.text, test_text)
}
}
}
@@ -1778,44 +1775,44 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test := Expected_Text[file.file][text.keyword]
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
}
}
case "ctfn0g04": // international UTF-8, finnish
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test := Expected_Text[file.file][text.keyword]
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
}
}
case "ctgn0g04": // international UTF-8, greek
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test := Expected_Text[file.file][text.keyword]
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
}
}
case "cthn0g04": // international UTF-8, hindi
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test := Expected_Text[file.file][text.keyword]
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
}
}
case "ctjn0g04": // international UTF-8, japanese
if file.file in Expected_Text {
if text.keyword in Expected_Text[file.file] {
test := Expected_Text[file.file][text.keyword]
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'.", file.file, count, text.keyword, text, test)
testing.expectf(t, text.text == test.text && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.language == test.language && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
testing.expectf(t, text.keyword_localized == test.keyword_localized && text_ok, "%v test %v text keyword {{%v}}:'%v', expected '%v'", file.file, count, text.keyword, text, test)
}
}
}
@@ -1823,7 +1820,7 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
if file.file == "exif2c08" { // chunk with jpeg exif data
exif, exif_ok := png.exif(c)
testing.expectf(t, exif.byte_order == .big_endian && exif_ok, "%v test %v eXIf byte order '%v', expected 'big_endian'.", file.file, count, exif.byte_order)
testing.expectf(t, len(exif.data) == 978 && exif_ok, "%v test %v eXIf data length '%v', expected '%v'.", file.file, len(exif.data), 978)
testing.expectf(t, len(exif.data) == 978 && exif_ok, "%v test %v eXIf data length '%v', expected '%v'", file.file, len(exif.data), 978)
}
}
}
@@ -1833,4 +1830,532 @@ run_png_suite :: proc(t: ^testing.T, suite: []PNG_Test) {
png.destroy(img)
}
}
return
}
/*
Basic format tests:
https://entropymine.com/jason/bmpsuite/bmpsuite/html/bmpsuite.html - Version 2.8; 2023-11-28
The BMP Suite image generator itself is GPL, and isn't included, nor did it have its code referenced.
We do thank the author for the well-researched test suite, which we are free to include:
"Image files generated by this program are not covered by this license, and are
in the public domain (except for the embedded ICC profiles)."
The files with embedded ICC profiles aren't part of Odin's test assets. We don't support BMP metadata.
We don't support all "possibly correct" images, and thus only ship a subset of these from the BMP Suite.
*/
Basic_BMP_Tests := []Test{
{
"pal1", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"pal1wb", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"pal1bg", {
{Default, nil, {127, 64, 3, 8}, 0x_9e91_174a},
},
},
{
"pal4", {
{Default, nil, {127, 64, 3, 8}, 0x_288e_4371},
},
},
{
"pal4gs", {
{Default, nil, {127, 64, 3, 8}, 0x_452d_a01a},
},
},
{
"pal4rle", {
{Default, nil, {127, 64, 3, 8}, 0x_288e_4371},
},
},
{
"pal8", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8-0", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8gs", {
{Default, nil, {127, 64, 3, 8}, 0x_09c2_7834},
},
},
{
"pal8rle", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8w126", {
{Default, nil, {126, 63, 3, 8}, 0x_bb66_4cda},
},
},
{
"pal8w125", {
{Default, nil, {125, 62, 3, 8}, 0x_3ab8_f7c5},
},
},
{
"pal8w124", {
{Default, nil, {124, 61, 3, 8}, 0x_b53e_e6c8},
},
},
{
"pal8topdown", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8nonsquare", {
{Default, nil, {127, 32, 3, 8}, 0x_8409_c689},
},
},
{
"pal8v4", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8v5", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"rgb16", {
{Default, nil, {127, 64, 3, 8}, 0x_8b6f_81a2},
},
},
{
"rgb16bfdef", {
{Default, nil, {127, 64, 3, 8}, 0x_8b6f_81a2},
},
},
{
"rgb16-565", {
{Default, nil, {127, 64, 3, 8}, 0x_8c73_a2ff},
},
},
{
"rgb16-565pal", {
{Default, nil, {127, 64, 3, 8}, 0x_8c73_a2ff},
},
},
{
"rgb24", {
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb24pal", {
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb32", {
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb32bf", {
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb32bfdef", {
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
}
OS2_Tests := []Test{
{
"pal8os2", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2-sz", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2-hs", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2sp", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2v2", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2v2-16", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2v2-sz", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8os2v2-40sz", { // An OS/2-style bitmap. This format can be called OS/2 BMPv1, or Windows BMPv2.
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
}
// BMP files that aren't 100% to spec. Some we support, some we don't.
Questionable_BMP_Tests := []Test{
{
"pal1p1", { // Spec says 1-bit image has 2 palette entries. This one has 1.
{Default, nil, {127, 64, 3, 8}, 0x_2b54_2560},
},
},
{
"pal2", { // 2-bit. Allowed on Windows CE. Irfanview doesn't support it.
{Default, nil, {127, 64, 3, 8}, 0x_0da2_7594},
},
},
{
"pal2color", { // 2-bit, with color palette.
{Default, nil, {127, 64, 3, 8}, 0x_f0d8_c5d6},
},
},
{
"pal8offs", { // 300 palette entries (yes, only 256 can be used)
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal8oversizepal", { // Some padding between palette and image data
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"pal4rletrns", { // Using palette tricks to skip pixels
{Default, nil, {127, 64, 3, 8}, 0x_eed4_e744},
},
},
{
"pal4rlecut", { // Using palette tricks to skip pixels
{Default, nil, {127, 64, 3, 8}, 0x_473fbc7d},
},
},
{
"pal8rletrns", { // Using palette tricks to skip pixels
{Default, nil, {127, 64, 3, 8}, 0x_fe1f_e560},
},
},
{
"pal8rlecut", { // Using palette tricks to skip pixels
{Default, nil, {127, 64, 3, 8}, 0x_bd04_3619},
},
},
{
"rgb16faketrns", { // Using palette tricks to skip pixels
{Default, nil, {127, 64, 3, 8}, 0x_8b6f_81a2},
},
},
{
"rgb16-231", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_7393_a163},
},
},
{
"rgb16-3103", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_3b66_2189},
},
},
{
"rgba16-4444", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_b785_1f9f},
},
},
{
"rgba16-5551", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_8b6f_81a2},
},
},
{
"rgba16-1924", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_f038_2bed},
},
},
{
"rgb32-xbgr", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb32fakealpha", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgb32-111110", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_b2c7_a8ff},
},
},
{
"rgb32-7187", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_b93a_4291},
},
},
{
"rgba32-1", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_7b67_823d},
},
},
{
"rgba32-2", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_7b67_823d},
},
},
{
"rgba32-1010102", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_aa42_0b16},
},
},
{
"rgba32-81284", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_28a2_4c16},
},
},
{
"rgba32-61754", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_4aae_26ed},
},
},
{
"rgba32abf", { // Custom bit fields
{Default, nil, {127, 64, 3, 8}, 0x_7b67_823d},
},
},
{
"rgb32h52", { // Truncated header (RGB bit fields included)
{Default, nil, {127, 64, 3, 8}, 0x_025b_ba0a},
},
},
{
"rgba32h56", { // Truncated header (RGBA bit fields included)
{Default, nil, {127, 64, 3, 8}, 0x_7b67_823d},
},
},
}
// Unsupported BMP features, or malformed images.
Unsupported_BMP_Tests := []Test{
{
"ba-bm", { // An OS/2 Bitmap array. We don't support this BA format.
{Default, .Unsupported_OS2_File, {127, 32, 3, 8}, 0x_0000_0000},
},
},
{
"pal1huffmsb", { // An OS/2 file with Huffman 1D compression
{Default, .Unsupported_Compression, {127, 32, 3, 8}, 0x_0000_0000},
},
},
{
"rgb24rle24", { // An OS/2 file with RLE24 compression
{Default, .Unsupported_Compression, {127, 64, 3, 8}, 0x_0000_0000},
},
},
{
"rgba64", { // An OS/2 file with RLE24 compression
{Default, .Unsupported_BPP, {127, 64, 3, 8}, 0x_0000_0000},
},
},
}
// Malformed / malicious files
Known_Bad_BMP_Tests := []Test{
{
"badbitcount", {
{Default, .Unsupported_BPP, {127, 64, 3, 8}, 0x_3ce81fae},
},
},
{
"badbitssize", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"baddens1", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"baddens2", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"badfilesize", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"badheadersize", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"badpalettesize", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"badplanes", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"badrle", {
{Default, nil, {127, 64, 3, 8}, 0x_1457_aae4},
},
},
{
"badrle4", {
{Default, nil, {127, 64, 3, 8}, 0x_6764_d2ac},
},
},
{
"badrle4bis", {
{Default, nil, {127, 64, 3, 8}, 0x_935d_bb37},
},
},
{
"badrle4ter", {
{Default, nil, {127, 64, 3, 8}, 0x_f2ba_5b08},
},
},
{
"badrlebis", {
{Default, nil, {127, 64, 3, 8}, 0x_07e2_d730},
},
},
{
"badrleter", {
{Default, nil, {127, 64, 3, 8}, 0x_a874_2742},
},
},
{
"badwidth", {
{Default, nil, {127, 64, 3, 8}, 0x_3ce8_1fae},
},
},
{
"pal8badindex", {
{Default, nil, {127, 64, 3, 8}, 0x_0450_0d02},
},
},
{
"reallybig", {
{Default, .Image_Dimensions_Too_Large, {3000000, 2000000, 1, 24}, 0x_0000_0000},
},
},
{
"rgb16-880", {
{Default, nil, {127, 64, 3, 8}, 0x_f1c2_0c73},
},
},
{
"rletopdown", {
{Default, nil, {127, 64, 3, 8}, 0x_3845_4155},
},
},
{
"shortfile", {
{Default, .Short_Buffer, {127, 64, 1, 1}, 0x_0000_0000},
},
},
}
@test
bmp_test_basic :: proc(t: ^testing.T) {
run_bmp_suite(t, Basic_BMP_Tests)
}
@test
bmp_test_os2 :: proc(t: ^testing.T) {
run_bmp_suite(t, OS2_Tests)
}
@test
bmp_test_questionable :: proc(t: ^testing.T) {
run_bmp_suite(t, Questionable_BMP_Tests)
}
@test
bmp_test_unsupported :: proc(t: ^testing.T) {
run_bmp_suite(t, Unsupported_BMP_Tests)
}
@test
bmp_test_known_bad :: proc(t: ^testing.T) {
run_bmp_suite(t, Known_Bad_BMP_Tests)
}
run_bmp_suite :: proc(t: ^testing.T, suite: []Test) {
for file in suite {
test_file := strings.concatenate({TEST_SUITE_PATH_BMP, "/", file.file, ".bmp"}, context.allocator)
defer delete(test_file)
for test in file.tests {
img, err := bmp.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 in memory
buf: bytes.Buffer
save_err := bmp.save(&buf, img)
testing.expectf(t, save_err == nil, "expected saving to BMP in memory not to raise error, got %v", save_err)
// Reload BMP from memory
reload_img, reload_err := bmp.load(buf.buf[:])
testing.expectf(t, reload_err == nil, "expected reloading BMP from memory not to raise error, got %v", reload_err)
testing.expect(t, img.width == reload_img.width && img.height == reload_img.height, "expected saved BMP to have the same dimensions")
testing.expect(t, img.channels == reload_img.channels && img.depth == reload_img.depth, "expected saved BMP to have the same dimensions")
reload_pixels := bytes.buffer_to_bytes(&reload_img.pixels)
reload_hash := hash.crc32(reload_pixels)
testing.expectf(t, img_hash == reload_hash, "expected saved BMP to have the same pixel hash (%08x), got %08x", img_hash, reload_hash)
bytes.buffer_destroy(&buf)
bmp.destroy(reload_img)
}
bmp.destroy(img)
}
}
return
}
+2 -1
View File
@@ -8,6 +8,7 @@
A test suite for `core:net`
*/
//+build !netbsd
package test_core_net
import "core:testing"
@@ -552,4 +553,4 @@ binstr_to_address :: proc(t: ^testing.T, binstr: string) -> (address: net.Addres
return nil
}
panic("Invalid test case")
}
}
+40
View File
@@ -0,0 +1,40 @@
package tests_core
import rlibc "core:c/libc"
@(init)
download_assets :: proc() {
if rlibc.system("python3 " + ODIN_ROOT + "tests/core/download_assets.py " + ODIN_ROOT + "tests/core/assets") != 0 {
panic("downloading test assets failed!")
}
}
@(require) import "c/libc"
@(require) import "compress"
@(require) import "container"
@(require) import "encoding/base64"
@(require) import "encoding/cbor"
@(require) import "encoding/hex"
@(require) import "encoding/hxa"
@(require) import "encoding/json"
@(require) import "encoding/varint"
@(require) import "encoding/xml"
@(require) import "fmt"
@(require) import "image"
@(require) import "math"
@(require) import "math/big"
@(require) import "math/linalg/glsl"
@(require) import "math/noise"
@(require) import "mem"
@(require) import "net"
@(require) import "odin"
@(require) import "path/filepath"
@(require) import "reflect"
@(require) import "runtime"
@(require) import "slice"
@(require) import "strconv"
@(require) import "strings"
@(require) import "text/i18n"
@(require) import "text/match"
@(require) import "thread"
@(require) import "time"
-10
View File
@@ -1,10 +0,0 @@
// Tests that Odin run returns exit code of built executable on Unix
// Needs exit status to be inverted to return 0 on success, e.g.
// $(./odin run tests/core/os/test_core_os_exit.odin && exit 1 || exit 0)
package test_core_os_exit
import "core:os"
main :: proc() {
os.exit(1)
}
+5
View File
@@ -0,0 +1,5 @@
// Tests intended to be ran with optimizations on
package tests_core
@(require) import "crypto"
@(require) import "hash"
+145
View File
@@ -0,0 +1,145 @@
package test_core_strconv
import "core:math"
import "core:strconv"
import "core:testing"
@(test)
test_float :: proc(t: ^testing.T) {
n: int
f: f64
ok: bool
f, ok = strconv.parse_f64("1.2", &n)
testing.expect_value(t, f, 1.2)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, true)
f, ok = strconv.parse_f64("1.2a", &n)
testing.expect_value(t, f, 1.2)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, false)
f, ok = strconv.parse_f64("+", &n)
testing.expect_value(t, f, 0)
testing.expect_value(t, n, 0)
testing.expect_value(t, ok, false)
f, ok = strconv.parse_f64("-", &n)
testing.expect_value(t, f, 0)
testing.expect_value(t, n, 0)
testing.expect_value(t, ok, false)
}
@(test)
test_nan :: proc(t: ^testing.T) {
n: int
f: f64
ok: bool
f, ok = strconv.parse_f64("nan", &n)
testing.expect_value(t, math.classify(f), math.Float_Class.NaN)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, true)
f, ok = strconv.parse_f64("nAN", &n)
testing.expect_value(t, math.classify(f), math.Float_Class.NaN)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, true)
f, ok = strconv.parse_f64("Nani", &n)
testing.expect_value(t, math.classify(f), math.Float_Class.NaN)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, false)
}
@(test)
test_infinity :: proc(t: ^testing.T) {
pos_inf := math.inf_f64(+1)
neg_inf := math.inf_f64(-1)
n: int
s := "infinity"
for i in 0 ..< len(s) + 1 {
ss := s[:i]
f, ok := strconv.parse_f64(ss, &n)
if i >= 3 { // "inf" .. "infinity"
expected_n := 8 if i == 8 else 3
expected_ok := i == 3 || i == 8
testing.expect_value(t, f, pos_inf)
testing.expect_value(t, n, expected_n)
testing.expect_value(t, ok, expected_ok)
testing.expect_value(t, math.classify(f), math.Float_Class.Inf)
} else { // invalid substring
testing.expect_value(t, f, 0)
testing.expect_value(t, n, 0)
testing.expect_value(t, ok, false)
testing.expect_value(t, math.classify(f), math.Float_Class.Zero)
}
}
s = "+infinity"
for i in 0 ..< len(s) + 1 {
ss := s[:i]
f, ok := strconv.parse_f64(ss, &n)
if i >= 4 { // "+inf" .. "+infinity"
expected_n := 9 if i == 9 else 4
expected_ok := i == 4 || i == 9
testing.expect_value(t, f, pos_inf)
testing.expect_value(t, n, expected_n)
testing.expect_value(t, ok, expected_ok)
testing.expect_value(t, math.classify(f), math.Float_Class.Inf)
} else { // invalid substring
testing.expect_value(t, f, 0)
testing.expect_value(t, n, 0)
testing.expect_value(t, ok, false)
testing.expect_value(t, math.classify(f), math.Float_Class.Zero)
}
}
s = "-infinity"
for i in 0 ..< len(s) + 1 {
ss := s[:i]
f, ok := strconv.parse_f64(ss, &n)
if i >= 4 { // "-inf" .. "infinity"
expected_n := 9 if i == 9 else 4
expected_ok := i == 4 || i == 9
testing.expect_value(t, f, neg_inf)
testing.expect_value(t, n, expected_n)
testing.expect_value(t, ok, expected_ok)
testing.expect_value(t, math.classify(f), math.Float_Class.Neg_Inf)
} else { // invalid substring
testing.expect_value(t, f, 0)
testing.expect_value(t, n, 0)
testing.expect_value(t, ok, false)
testing.expect_value(t, math.classify(f), math.Float_Class.Zero)
}
}
// Make sure odd casing works.
batch := [?]string {"INFiniTY", "iNfInItY", "InFiNiTy"}
for ss in batch {
f, ok := strconv.parse_f64(ss, &n)
testing.expect_value(t, f, pos_inf)
testing.expect_value(t, n, 8)
testing.expect_value(t, ok, true)
testing.expect_value(t, math.classify(f), math.Float_Class.Inf)
}
// Explicitly check how trailing characters are handled.
s = "infinityyyy"
f, ok := strconv.parse_f64(s, &n)
testing.expect_value(t, f, pos_inf)
testing.expect_value(t, n, 8)
testing.expect_value(t, ok, false)
testing.expect_value(t, math.classify(f), math.Float_Class.Inf)
s = "inflippity"
f, ok = strconv.parse_f64(s, &n)
testing.expect_value(t, f, pos_inf)
testing.expect_value(t, n, 3)
testing.expect_value(t, ok, false)
testing.expect_value(t, math.classify(f), math.Float_Class.Inf)
}
-22
View File
@@ -1,22 +0,0 @@
ODIN=../../odin
COMMON=-file -vet -strict-style -o:minimal
all: asan_test rtti_test map_test pow_test 128_test string_compare_test
rtti_test:
$(ODIN) test test_rtti.odin $(COMMON)
map_test:
$(ODIN) test test_map.odin $(COMMON)
pow_test:
$(ODIN) test test_pow.odin $(COMMON)
128_test:
$(ODIN) test test_128.odin $(COMMON)
asan_test:
$(ODIN) test test_asan.odin $(COMMON) -sanitize:address -debug
string_compare_test:
$(ODIN) test test_string_compare.odin $(COMMON)
-9
View File
@@ -1,9 +0,0 @@
@echo off
set PATH_TO_ODIN==..\..\odin
set COMMON=-file -vet -strict-style -o:minimal
%PATH_TO_ODIN% test test_rtti.odin %COMMON% || exit /b
%PATH_TO_ODIN% test test_map.odin %COMMON% || exit /b
%PATH_TO_ODIN% test test_pow.odin %COMMON% || exit /b
%PATH_TO_ODIN% test test_asan.odin %COMMON% || exit /b
%PATH_TO_ODIN% test test_128.odin %COMMON% || exit /b
%PATH_TO_ODIN% test test_string_compare.odin %COMMON% || exit /b
+1 -1
View File
@@ -1,4 +1,4 @@
package test_128
package test_internal
import "core:testing"
+1 -1
View File
@@ -1,5 +1,5 @@
// Intended to contain code that would trigger asan easily if the abi was set up badly.
package test_asan
package test_internal
import "core:testing"
+2 -2
View File
@@ -1,4 +1,4 @@
package test_internal_map
package test_internal
import "core:log"
import "base:intrinsics"
@@ -309,4 +309,4 @@ set_delete_random_key_value :: proc(t: ^testing.T) {
}
seed_incr += 1
}
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
package test_internal_math_pow
package test_internal
@(require) import "core:log"
import "core:math"
@@ -42,4 +42,4 @@ pow_test :: proc(t: ^testing.T) {
testing.expectf(t, _v1 == _v2, "Expected math.pow2_f16(%d) == math.pow(2, %d) (= %04x), got %04x", exp, exp, _v1, _v2)
}
}
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
package test_internal_rtti
package test_internal
import "core:fmt"
import "core:testing"
@@ -43,4 +43,4 @@ rtti_test :: proc(t: ^testing.T) {
l_s := fmt.tprintf("%s", l_buggy)
testing.expectf(t, g_s == EXPECTED_REPR, "Expected fmt.tprintf(\"%%s\", g_s)) to return \"%v\", got \"%v\"", EXPECTED_REPR, g_s)
testing.expectf(t, l_s == EXPECTED_REPR, "Expected fmt.tprintf(\"%%s\", l_s)) to return \"%v\", got \"%v\"", EXPECTED_REPR, l_s)
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
package test_internal_string_compare
package test_internal
import "core:testing"
@@ -54,4 +54,4 @@ string_compare :: proc(t: ^testing.T) {
}
}
}
}
}
-1
View File
@@ -10,7 +10,6 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
..\..\..\odin test ..\test_issue_829.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_1592.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2056.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2087.odin %COMMON% || exit /b
..\..\..\odin build ..\test_issue_2113.odin %COMMON% -debug || exit /b
..\..\..\odin test ..\test_issue_2466.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b
+3 -5
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -eu
mkdir -p build
@@ -6,23 +6,21 @@ pushd build
ODIN=../../../odin
COMMON="-define:ODIN_TEST_FANCY=false -file -vet -strict-style"
NO_NIL_ERR="Error: "
set -x
$ODIN test ../test_issue_829.odin $COMMON
$ODIN test ../test_issue_1592.odin $COMMON
$ODIN test ../test_issue_2056.odin $COMMON
$ODIN test ../test_issue_2087.odin $COMMON
$ODIN build ../test_issue_2113.odin $COMMON -debug
$ODIN test ../test_issue_2466.odin $COMMON
$ODIN test ../test_issue_2615.odin $COMMON
$ODIN test ../test_issue_2637.odin $COMMON
$ODIN test ../test_issue_2666.odin $COMMON
if [[ $($ODIN build ../test_issue_2395.odin $COMMON 2>&1 >/dev/null | grep -c "$NO_NIL_ERR") -eq 2 ]] ; then
if [[ $($ODIN build ../test_issue_2395.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 2 ]] ; then
echo "SUCCESSFUL 1/1"
else
echo "SUCCESSFUL 0/1"
exit 1
fi
set +x
-62
View File
@@ -1,62 +0,0 @@
// Tests issue #2087 https://github.com/odin-lang/Odin/issues/2087
package test_issues
import "core:math"
import "core:strconv"
import "core:testing"
@(test)
test_parse_float :: proc(t: ^testing.T) {
{
f, ok := strconv.parse_f64("1.2")
testing.expect(t, ok && f == 1.2, "expected f64(1.2), fully consumed")
f, ok = strconv.parse_f64("1.2a")
testing.expect(t, !ok && f == 1.2, "expected f64(1.2), partially consumed")
f, ok = strconv.parse_f64("+")
testing.expect(t, !ok && f == 0.0, "expected f64(0.0), with ok=false")
f, ok = strconv.parse_f64("-")
testing.expect(t, !ok && f == 0.0, "expected f64(0.0), with ok=false")
f, ok = strconv.parse_f64("inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Inf, "expected f64(+inf), fully consumed")
f, ok = strconv.parse_f64("+inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Inf, "expected f64(+inf), fully consumed")
f, ok = strconv.parse_f64("-inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Neg_Inf, "expected f64(-inf), fully consumed")
f, ok = strconv.parse_f64("inFinity")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Inf, "expected f64(+inf), partially consumed")
f, ok = strconv.parse_f64("+InFinity")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Inf, "expected f64(+inf), partially consumed")
f, ok = strconv.parse_f64("-InfiniTy")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Neg_Inf, "expected f64(-inf), partially consumed")
f, ok = strconv.parse_f64("nan")
testing.expect(t, ok && math.classify(f) == math.Float_Class.NaN, "expected f64(nan), fully consumed")
f, ok = strconv.parse_f64("nAN")
testing.expect(t, ok && math.classify(f) == math.Float_Class.NaN, "expected f64(nan), fully consumed")
}
{
f, ok := strconv.parse_f32("1.2")
testing.expect(t, ok && f == 1.2, "expected f32(1.2), fully consumed")
f, ok = strconv.parse_f32("1.2a")
testing.expect(t, !ok && f == 1.2, "expected f32(1.2), partially consumed")
f, ok = strconv.parse_f32("inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Inf, "expected f32(+inf), fully consumed")
f, ok = strconv.parse_f32("+inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Inf, "expected f32(+inf), fully consumed")
f, ok = strconv.parse_f32("-inf")
testing.expect(t, ok && math.classify(f) == math.Float_Class.Neg_Inf, "expected f32(-inf), fully consumed")
f, ok = strconv.parse_f32("inFinity")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Inf, "expected f32(+inf), partially consumed")
f, ok = strconv.parse_f32("+InFinity")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Inf, "expected f32(+inf), partially consumed")
f, ok = strconv.parse_f32("-InfiniTy")
testing.expect(t, !ok && math.classify(f) == math.Float_Class.Neg_Inf, "expected f32(-inf), partially consumed")
f, ok = strconv.parse_f32("nan")
testing.expect(t, ok && math.classify(f) == math.Float_Class.NaN, "expected f32(nan), fully consumed")
f, ok = strconv.parse_f32("nAN")
testing.expect(t, ok && math.classify(f) == math.Float_Class.NaN, "expected f32(nan), fully consumed")
}
}
-2
View File
@@ -5,8 +5,6 @@
// exactly 2 errors from the invalid unions
package test_issues
import "core:testing"
ValidUnion :: union($T: typeid) #no_nil {
T,
f32,
-10
View File
@@ -1,10 +0,0 @@
ODIN=../../odin
ODINFLAGS=
OS=$(shell uname)
ifeq ($(OS), OpenBSD)
ODINFLAGS:=$(ODINFLAGS) -extra-linker-flags:-L/usr/local/lib
endif
all:
+3
View File
@@ -0,0 +1,3 @@
package tests_vendor
@(require) import "glfw"
-8
View File
@@ -1,8 +0,0 @@
@echo off
set COMMON=-show-timings -no-bounds-check -vet -strict-style -define:ODIN_TEST_FANCY=false
set PATH_TO_ODIN==..\..\odin
echo ---
echo Running vendor:glfw tests
echo ---
%PATH_TO_ODIN% test glfw %COMMON% -out:vendor_glfw.exe || exit /b
+1
View File
@@ -1,3 +1,4 @@
//+build darwin, windows
package test_vendor_glfw
import "core:testing"