My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

zstd: test errors

+31 -4
+4 -1
test/dune
··· 1 1 (test 2 2 (name test_zstd) 3 3 (package zstd-test) 4 - (libraries zstd alcotest)) 4 + (libraries zstd alcotest) 5 + (deps 6 + (source_tree ../vendor/git/zstd-c/tests/golden-decompression) 7 + (source_tree ../vendor/git/zstd-c/tests/golden-decompression-errors))) 5 8
+27 -3
test/test_zstd.ml
··· 1 1 (** Tests for the pure OCaml zstd implementation *) 2 2 3 - (* Use absolute path for test data - handles running from _build directory *) 4 - let golden_dir = "/workspace/mymatrix/project/ocaml-zstd/vendor/git/zstd-c/tests/golden-decompression" 5 - let _error_dir = "/workspace/mymatrix/project/ocaml-zstd/vendor/git/zstd-c/tests/golden-decompression-errors" 3 + (* Test data paths - relative to test directory, resolved via dune deps *) 4 + let golden_dir = "../vendor/git/zstd-c/tests/golden-decompression" 5 + let error_dir = "../vendor/git/zstd-c/tests/golden-decompression-errors" 6 6 7 7 let read_file path = 8 8 let ic = open_in_bin path in ··· 89 89 (* Truncated frame *) 90 90 begin match Zstd.decompress "\x28\xb5\x2f\xfd" with 91 91 | Ok _ -> Alcotest.fail "Should reject truncated frame" 92 + | Error _ -> () 93 + end 94 + 95 + (** Test that malformed golden error files are rejected *) 96 + let test_golden_errors () = 97 + (* off0.bin.zst - invalid offset *) 98 + let off0 = read_file (error_dir ^ "/off0.bin.zst") in 99 + begin match Zstd.decompress off0 with 100 + | Ok _ -> Alcotest.fail "Should reject off0.bin.zst" 101 + | Error _ -> () 102 + end; 103 + 104 + (* truncated_huff_state.zst - truncated huffman state *) 105 + let truncated = read_file (error_dir ^ "/truncated_huff_state.zst") in 106 + begin match Zstd.decompress truncated with 107 + | Ok _ -> Alcotest.fail "Should reject truncated_huff_state.zst" 108 + | Error _ -> () 109 + end; 110 + 111 + (* zeroSeq_extraneous.zst - extraneous data *) 112 + let extraneous = read_file (error_dir ^ "/zeroSeq_extraneous.zst") in 113 + begin match Zstd.decompress extraneous with 114 + | Ok _ -> Alcotest.fail "Should reject zeroSeq_extraneous.zst" 92 115 | Error _ -> () 93 116 end 94 117 ··· 217 240 ]; 218 241 "error handling", [ 219 242 Alcotest.test_case "invalid inputs" `Quick test_invalid_inputs; 243 + Alcotest.test_case "golden errors" `Quick test_golden_errors; 220 244 ]; 221 245 "utilities", [ 222 246 Alcotest.test_case "get_decompressed_size" `Quick test_get_decompressed_size;