Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization #99

Open
wants to merge 140 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 114 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
3b8a2b8
Started writing tests for Java, ported 3 specs
GreyCat Mar 24, 2017
e0e3626
Better var name
GreyCat Mar 24, 2017
9639693
Extra check to see if any data was generated at all
GreyCat Mar 24, 2017
8e1d1d0
Ported fixed_struct to writing tests in Java
GreyCat Mar 24, 2017
490fc26
Write test: ported enum_0 and str_encodings
GreyCat Mar 24, 2017
d5d03b4
Ported repeat_n_strz and str_eos to Java write specs
GreyCat Mar 24, 2017
704aa17
Merge branch 'master' into serialization
GreyCat Mar 27, 2017
11a9819
Ported bytes_pad_term and nested_types to Java writing tests
GreyCat Mar 27, 2017
cfa0219
Ported process_rotate test for Java writing
GreyCat Mar 27, 2017
f3050e0
Ported repeat_n_struct to Java writing tests
GreyCat Mar 27, 2017
579b19b
Optimize imports
GreyCat Mar 28, 2017
757a425
Ported buffered_struct to Java writing
GreyCat Mar 28, 2017
afe2501
Rewrote all Java writing tests using new KaitaiStruct.Writable API
GreyCat Mar 28, 2017
156a3c7
Added process_to_user Java writing port
GreyCat Mar 28, 2017
f0cfc1c
Use new toByteArray API
GreyCat Mar 28, 2017
b15aaf4
Fix assertEqualToFile to work again
GreyCat Mar 28, 2017
a5d07e9
Added repeat_eos_u4 Java writing port
GreyCat Mar 28, 2017
790e89e
More assertion helper functions
GreyCat Mar 29, 2017
c5c8465
Modified BufferedStruct tests to fit both read/write
GreyCat Mar 29, 2017
4c8845d
Ported if_struct to Java writing
GreyCat Mar 29, 2017
a4a7909
Replaced interfaces with new abstract classes
GreyCat Mar 29, 2017
301d3ac
Added SwitchManualInt to Java writing tests
GreyCat Mar 29, 2017
d311bd4
Ported switch_manual_str to Java writing
GreyCat Mar 29, 2017
97a7c1f
Added _check call before every writing attempt
GreyCat Mar 30, 2017
a00d702
Added tests for _check number of members in array mismatch + NPE
GreyCat Mar 30, 2017
803209f
specwrite/TestStrEncodings: added string size _check testing
GreyCat Mar 30, 2017
99b1753
Added byte array limited length check test
GreyCat Mar 30, 2017
2cc29ff
Added more byte limited type consistency check tests
GreyCat Mar 30, 2017
2b9f369
Merge branch 'master' into serialization
GreyCat Apr 4, 2017
0f2c659
Merge branch 'master' into serialization
GreyCat Apr 5, 2017
7d4520a
Merge branch 'master' into serialization
GreyCat Apr 26, 2017
e23a38b
Merge branch 'master' into serialization
generalmimon Nov 15, 2019
08e9728
Merge pull request #67 from generalmimon/serialization
GreyCat Nov 16, 2019
166d222
Port bits_simple to Java writing test
generalmimon Feb 1, 2020
a9ceae4
Merge branch 'master' into serialization
generalmimon Aug 1, 2022
5a45be2
Fix compiling for Java to `/src` folder (not implicit since 0.9)
generalmimon Aug 1, 2022
c6d48cc
Rename Test{FixedStruct => Integers}, because that's what it is
generalmimon Aug 2, 2022
99c39a6
Add universal read-write roundtrip test, port existing manual tests
generalmimon Aug 12, 2022
8732152
KST translator: add --read-write mode for Java roundtrip tests
generalmimon Aug 13, 2022
80b5da0
Regen applicable Java read-write tests from KST
generalmimon Aug 13, 2022
0b61180
Fix 2 bugs in read-write roundtrip code
generalmimon Aug 13, 2022
98a275a
Use HelloWorld (not TermStrz) as an opaque type in tests
generalmimon Aug 13, 2022
07c1327
Add tests {Bytes,Str,Struct}*PadTerm based on BytesPadTerm
generalmimon Aug 14, 2022
09b3ba0
Add Term{Bytes,Strz}2 as a variation of existing Term{Bytes,Strz}
generalmimon Aug 14, 2022
3b0e57a
Add TermStruct{,2} based on TermBytes{,2}
generalmimon Aug 14, 2022
458fdd6
KST translator: fix JavaTranslator instantiation for read-write KSC
generalmimon Aug 28, 2022
911ccb0
Add KST specs for Debug{ArrayUser,EnumName}, regen for Java write
generalmimon Aug 28, 2022
2d19543
Add KST spec for OptionalId (semi-automatic), regen for Java write
generalmimon Aug 28, 2022
04352a5
Add KST for Debug0 (semi-automatic), regen for Java write
generalmimon Aug 28, 2022
65376ff
Add Term{Bytes,Struct,Strz}3 as a variation of TermBytes
generalmimon Sep 4, 2022
53e92fb
Add Repeat{Eos,N,Until}Bytes for a repeated fixed-size byte array
generalmimon Sep 5, 2022
0335f10
Add Repeat{Eos,N,Until}{BytesPad{,Term},TermBytes}
generalmimon Sep 5, 2022
6789fdf
Add {Bytes,Str{Eos,},Struct}PadTermEqual (`terminator` == `pad-right`)
generalmimon Sep 8, 2022
0c07f4c
Add new BytesPadTerm* tests and asserts for _check() correctness
generalmimon Sep 10, 2022
2be6f4b
Add StrPadTerm{Roundtrip,ZeroSize} (BytesPadTerm* equivalents)
generalmimon Sep 11, 2022
fda09a9
Add Term{Bytes,Struct,Strz}4 for `eos-error: false`
generalmimon Sep 11, 2022
5ab822d
Add test cases to RepeatUntilS4 for `repeat-until` checks
generalmimon Sep 12, 2022
f6a61f6
Add/adjust ExprIfInt{Eq,Ops} + FloatToI for Java casting issues
generalmimon Sep 15, 2022
895a025
dumpStructValue: exclude _invalidate* and _raw_* from struct dumps
generalmimon Sep 16, 2022
fdba97c
Add Expr2 subtest for _invalidate*() method of value instances
generalmimon Sep 16, 2022
14424f3
dumpStructValue: call all _check*() (both `seq` and `instances`)
generalmimon Sep 17, 2022
0596437
Add InstanceStd subtests for _check{Inst}() and _write{Inst}()
generalmimon Sep 17, 2022
fe66a13
Add InstanceInRepeat{Expr,Until}
generalmimon Nov 17, 2022
79b1861
dumpStructValue: exclude _fetchInstances* from dumps
generalmimon Nov 26, 2022
b9cf221
Add Instance{InSized,IoUserEarlier} for instances in substreams
generalmimon Nov 26, 2022
b16605c
Implement encode() in custom processing classes
generalmimon Dec 19, 2022
436e742
Enable Zlib{WithHeader78,Surrounded} write tests
generalmimon Dec 20, 2022
99df2b1
Add ProcessRepeatUsertypeDynarg{Xor,Rotate,Custom}
generalmimon Dec 20, 2022
b0fe2e9
Add Repeat{Eos,N,Until}TermStruct
generalmimon Dec 23, 2022
53440a9
Add ProcessTermStruct
generalmimon Dec 23, 2022
010efd1
Remove unneeded alignToByte() calls in write tests
generalmimon Dec 25, 2022
0fb06a5
Add test case to ProcessRotate for a size check in _write()
generalmimon Dec 31, 2022
1986891
Add a test case to StrEos for residual bytes after `size-eos: true`
generalmimon Dec 31, 2022
6a537fb
Add a case to RepeatEosBytes on residual bytes after `repeat: eos`
generalmimon Dec 31, 2022
c5a451e
Add a case to TermBytes4 for EOF after `include: true` without term
generalmimon Jan 1, 2023
218127f
Add test case to SwitchManualIntSize for byte size mismatch check
generalmimon Jan 1, 2023
a3d967d
Add ParamsPass{,Array}Io
generalmimon Jan 1, 2023
9bbbc1a
Fix tests with wrong `_root`/`_parent` now checked by _check()
generalmimon Jan 2, 2023
4825dfc
Bump KST translator to 0.11-SNAPSHOT, use KSC 0.11-SNAPSHOT
generalmimon Feb 13, 2023
1e1035c
Regen existing Python tests from KST
generalmimon Feb 17, 2023
85c5a8e
Regen newly added tests from KST to Python
generalmimon Feb 17, 2023
56575bc
Fix unclosed files in manual Python tests
generalmimon Feb 17, 2023
61b967b
Generate Python EOF error tests from KST
generalmimon Feb 19, 2023
6223ab4
Move Python tests to `spec/python/spec/` (from `spec/python/`)
generalmimon Feb 17, 2023
56b337f
Generate .py modules to `testformats` and `testwrite` packages
generalmimon Feb 17, 2023
c7062c3
Port read-write roundtrip test code to specwrite/common_spec.py
generalmimon Feb 26, 2023
c50da9a
Add PythonWriteSG to KST translator
generalmimon Feb 26, 2023
ef856ba
Regen Python write tests from KST
generalmimon Feb 26, 2023
d4ba103
specwrite/common_spec.py: fix Python 2 compatibility
generalmimon Mar 4, 2023
a7fd288
Python: implement encode() in custom processors
generalmimon Mar 4, 2023
f53b1ba
Add ExprIo{Eof,Pos}Bits
generalmimon Mar 6, 2023
f8483a7
Port {Eof,Eos}Exception{Bytes,U4} to Java, Python writing tests
generalmimon Mar 6, 2023
619a1c3
specwrite/common_spec.py: remove maximum length of diffs
generalmimon Mar 6, 2023
1a9c268
Java specwrite: only write to streams with expected size
generalmimon Mar 11, 2023
c166c87
Java: add assertThrowsEofError supporting both BB and RAF streams
generalmimon Mar 11, 2023
5c2ba6e
JavaSG: delete redundant empty line in output, regen Java from KST
generalmimon Mar 11, 2023
3d5cc8a
Java: simplify reading all bytes from a file in assertEqualToFullFile
generalmimon Apr 1, 2023
edd6a44
Add EofExceptionBits{Be,Le}{,2}, add Python read+write specs for it
generalmimon Jul 21, 2023
9a950cf
Simplify ExprIoEofBits, adjust Python test specs
generalmimon Jul 21, 2023
8bc02aa
Fix EofExceptionBits{Be,Le}{,2} Python specs
generalmimon Jul 25, 2023
03939b6
Port EofExceptionBits{Be,Le}{,2} and regen ExprIoEofBits to Java
generalmimon Jul 26, 2023
4c04172
Remove "Autogenerated from KST" from modified Java write specs
generalmimon Jul 26, 2023
4901dea
Java specwrite: minor improvements in manual tests
generalmimon Jul 27, 2023
6a3c0f1
Port manual Java specwrite tests to Python
generalmimon Jul 27, 2023
cc36a88
Add BitsByteAlignedEof{Be,Le} + regen from KST to Java and Python
generalmimon Jul 28, 2023
59ce923
JavaWriteSG: throw a `SkipException` for skipped roundtrip tests
generalmimon Jul 28, 2023
d0fb3f9
Regen Java specwrite tests from KST: remove useless newline
generalmimon Jul 28, 2023
c49776f
Regen Java specwrite tests from KST: skip roundtrip properly
generalmimon Jul 28, 2023
6eccb6b
Java specwrite: don't print format class in testReadWriteRoundtrip()
generalmimon Jul 31, 2023
d3fe5b6
Java specwrite: make sure all test methods are named `test*()`
generalmimon Jul 31, 2023
aa79aa8
Support Python serialization tests when generating `ci.json`
generalmimon Jul 30, 2023
cbcc400
Support Java serialization tests when generating `ci.json`
generalmimon Jul 31, 2023
14309eb
Merge pull request #100 from kaitai-io/serialization-tests-to-ci-json
generalmimon Jul 31, 2023
8ff9923
Merge branch 'master' into serialization
generalmimon Jul 31, 2023
7a3fefa
build-formats: replace hardcoded `compiled` dir with config var
generalmimon Aug 1, 2023
f57b29d
Merge branch 'master' into serialization
generalmimon Aug 4, 2023
a50a038
Merge branch 'master' into serialization
generalmimon Aug 4, 2023
328239e
java_builder: fix `builder/spec` failure (make ctor args optional)
generalmimon Aug 4, 2023
c64152c
PythonWriteSG: simplify, extend `SpecGenerator` (fixes build error)
generalmimon Aug 4, 2023
f9deea2
Regen Python specwrite from KST: fix double final newline
generalmimon Aug 4, 2023
ec57e22
Move Python spec ExprToITrailing test to the correct location
generalmimon Aug 4, 2023
4b9beae
Merge branch 'master' into serialization
generalmimon Sep 13, 2023
55dbf81
junit_xml_parser: add support for `skipped` status
generalmimon Sep 14, 2023
64f7c89
junit_xml_parser: downgrade `classname` match error to warning
generalmimon Sep 14, 2023
57f1142
ValidFailRangeFloat: use values with exact representation
generalmimon Sep 16, 2023
e92fb33
Java specwrite: test that _check() uses no IO in ValidFail* tests
generalmimon Sep 23, 2023
e7869f0
Port tests for _check() not using IO from Java to Python
generalmimon Sep 23, 2023
d4d3870
Python specwrite: fix incompatibilities with Python 2
generalmimon Sep 24, 2023
2841eec
InstanceStd: fix incompatibility with Python 2
generalmimon Sep 28, 2023
ddd8086
Merge branch 'master' into serialization
generalmimon Oct 12, 2023
54b8ef2
Regen Java spec tests from KST (remove extra newline)
generalmimon Oct 12, 2023
2fc07b7
Regen EnumToIInvalid from KST for Java+Python specwrite
generalmimon Oct 12, 2023
6199fe0
Fix Java 7 compat: add `final` to local vars used in inner classes
generalmimon Oct 12, 2023
e0c5a67
Fix Java 7 compat: add explicit type args to empty collections
generalmimon Oct 12, 2023
bb10791
Fix Java 7 compat: replace `getParameterCount()` added in Java 8
generalmimon Oct 12, 2023
3714a69
java_builder: build only the sources that each suite needs
generalmimon Oct 13, 2023
2b80b8b
RepeatNStrz, StrEncodings: fix Java <17 compat of testCheckNull()
generalmimon Oct 14, 2023
a50ba2f
Merge branch 'master' into serialization
generalmimon Jan 2, 2024
b8da1cb
BytesEosPadTerm: add _check() cases for Java specwrite
generalmimon Mar 3, 2024
629484b
BytesEosPadTerm: port _check() cases to Python specwrite
generalmimon Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__/

# Nim
_*
!_*.py
spec/nim/bin

# Rust compiled code, cargo and rls data
Expand Down
32 changes: 24 additions & 8 deletions aggregate/convert_to_json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,27 @@ def add_fails(first, *seconds)
end

def add_kst_adoption(tests, log_dir)
kst_tests = File.readlines("#{log_dir}/kst_adoption.log")
kst_tests = File.readlines("#{log_dir}/kst_adoption.log").map { |name| name.chomp }
kst_test_used = {}
kst_tests.each { |name| kst_test_used[name] = false }
tests.each_pair { |name, test_result|
kst_name = nil
if kst_test_used.has_key?(name)
kst_name = name
elsif name =~ /^(.+?)\./ && kst_test_used.has_key?($1)
kst_name = $1
end

if kst_name
test_result['is_kst'] = true
kst_test_used[kst_name] = true
end
}
kst_tests.each { |name|
name.chomp!
tests[name] ||= {}
tests[name]['is_kst'] = true
if !kst_test_used.fetch(name)
tests[name] ||= {}
tests[name]['is_kst'] = true
end
}
tests
end
Expand Down Expand Up @@ -72,10 +88,10 @@ when 'cpp_stl'
),
infile
)
when 'java'
when 'java', 'java-write'
add_kst_adoption(
add_fails(
JUnitXMLParser.new("#{infile}/junitreports").to_h,
JUnitXMLParser.new("#{infile}/junitreports", lang == 'java-write').to_h,
BuildFailedParser.new("#{infile}/build_failed_tests.txt").to_h
),
infile
Expand All @@ -97,9 +113,9 @@ when 'javascript'
JUnitXMLParser.new("#{infile}/test-output-javascript.xml").to_h,
infile
)
when 'php', 'python', 'construct'
when 'php', 'python', 'python-write', 'construct'
add_kst_adoption(
JUnitXMLParser.new(infile).to_h,
JUnitXMLParser.new(infile, lang == 'python-write').to_h,
infile
)
when 'ruby'
Expand Down
16 changes: 12 additions & 4 deletions aggregate/junit_xml_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'rexml/document'

class JUnitXMLParser < TestParser
def initialize(fn)
def initialize(fn, include_classname = false)
@include_classname = include_classname
@docs = if not File.exist?(fn)
[]
elsif File.directory?(fn)
Expand Down Expand Up @@ -35,10 +36,17 @@ def each_test
name = underscore_to_ucamelcase($1)
else
raise "Unable to parse name: \"#{name}\"" unless name =~ /^[Tt]est(.*?)$/
if $1[0] == '_'
name = underscore_to_ucamelcase($1)
name = $1
if name[0] == '_'
name = underscore_to_ucamelcase(name[1..-1])
end

if @include_classname
classname = tc.attribute('classname').value
raise "Unable to parse classname: \"#{classname}\"" unless classname =~ /\.Test([^.]*)$/
classname = $1
name = "#{classname}.#{name}"
else
name = $1
end
end

Expand Down
33 changes: 32 additions & 1 deletion build-formats
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
#!/bin/sh
#!/bin/sh -e

. ./config

rm -rf "$FORMATS_COMPILED_DIR"
mkdir -p "$FORMATS_COMPILED_DIR"

# --java-from-file-class io.kaitai.struct.RandomAccessFileKaitaiStream \

"$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \
--verbose all -t all -d "$FORMATS_COMPILED_DIR" \
--import-path "$FORMATS_REPO_DIR" \
--import-path "$FORMATS_KSY_DIR/ks_path" \
--java-package io.kaitai.struct.testformats \
--php-namespace 'Kaitai\Struct\Tests' \
--python-package testformats \
--go-package test_formats \
--nim-module "kaitai_struct_nim_runtime" \
--nim-opaque "../../tests/spec/nim/opaque/" \
"$FORMATS_KSY_DIR"/*.ksy || :

mv -n compiled/python compiled/python-tmp
mkdir compiled/python
mv -n compiled/python-tmp compiled/python/testformats
# __init__.py is needed in Python 2
touch compiled/python/testformats/__init__.py

"$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \
--verbose file -t java -d "$FORMATS_COMPILED_DIR/java/src" \
--no-auto-read \
--read-write \
--import-path "$FORMATS_REPO_DIR" \
--import-path "$FORMATS_KSY_DIR/ks_path" \
--java-package io.kaitai.struct.testwrite \
"$FORMATS_KSY_DIR"/*.ksy || :

"$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \
--verbose file -t python -d "$FORMATS_COMPILED_DIR/python/testwrite" \
--no-auto-read \
--read-write \
--import-path "$FORMATS_REPO_DIR" \
--import-path "$FORMATS_KSY_DIR/ks_path" \
--python-package testwrite \
"$FORMATS_KSY_DIR"/*.ksy || :

# __init__.py is needed in Python 2
touch compiled/python/testwrite/__init__.py
14 changes: 8 additions & 6 deletions builder/java_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
require_relative 'shellconfig'

class JavaBuilder < PartialBuilder
def initialize
super
def initialize(suite_names, test_out_dir)
super()

@suite_names = suite_names || 'spec,specwrite'
@test_out_dir = File.absolute_path(test_out_dir || "#{@config['TEST_OUT_DIR']}/java")

@spec_dir = File.join('spec', 'java', 'src')
@compiled_dir = File.join("#{@config['FORMATS_COMPILED_DIR']}", 'java')
Expand All @@ -22,9 +25,6 @@ def initialize
@java_classes_dir = "#{@compiled_dir}/bin"
@java_classes_dir = File.absolute_path(@java_classes_dir)
@java_classpath = [@java_classes_dir, @java_testng_jar].join(File::PATH_SEPARATOR)

@test_out_dir = "#{@config['TEST_OUT_DIR']}/java"
@test_out_dir = File.absolute_path(@test_out_dir)
end

def list_mandatory_files
Expand Down Expand Up @@ -92,7 +92,9 @@ def run_tests
'java',
'-cp', @java_classpath,
'org.testng.TestNG',
'-d', @test_out_dir, File.absolute_path(File.join('spec', 'java', 'testng.xml'))
'-d', @test_out_dir,
'-testnames', @suite_names,
File.absolute_path(File.join('spec', 'java', 'testng.xml'))
]
out_log = File.join(@test_out_dir, 'test_run.stdout')

Expand Down
6 changes: 5 additions & 1 deletion ci-java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

. ./config

./run-java
rm -rf "$TEST_OUT_DIR/java" "$TEST_OUT_DIR/java-write"
./run-java spec "$TEST_OUT_DIR/java"
./run-java specwrite "$TEST_OUT_DIR/java-write"

./kst-adoption-report java
./kst-adoption-report java-write
aggregate/convert_to_json java "$TEST_OUT_DIR/java" "$TEST_OUT_DIR/java/ci.json"
aggregate/convert_to_json java-write "$TEST_OUT_DIR/java-write" "$TEST_OUT_DIR/java-write/ci.json"
7 changes: 5 additions & 2 deletions ci-python
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

. ./config

rm -rf "$TEST_OUT_DIR/python"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python/extra" PYTHONDONTWRITEBYTECODE=1 PYTHONDEVMODE=1 python ./run-python-xml.py spec/python "$TEST_OUT_DIR/python"
rm -rf "$TEST_OUT_DIR/python" "$TEST_OUT_DIR/python-write"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python/extra" PYTHONDONTWRITEBYTECODE=1 PYTHONDEVMODE=1 python ./run-python-xml.py spec/python/spec "$TEST_OUT_DIR/python"
PYTHONPATH="$PYTHON_RUNTIME_DIR:compiled/python:spec/python:spec/python/extra" PYTHONDONTWRITEBYTECODE=1 PYTHONDEVMODE=1 python ./run-python-xml.py spec/python/specwrite "$TEST_OUT_DIR/python-write"

./kst-adoption-report python
./kst-adoption-report python-write
aggregate/convert_to_json python "$TEST_OUT_DIR/python" "$TEST_OUT_DIR/python/ci.json"
aggregate/convert_to_json python-write "$TEST_OUT_DIR/python-write" "$TEST_OUT_DIR/python-write/ci.json"
16 changes: 16 additions & 0 deletions formats/bits_byte_aligned_eof_be.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
meta:
id: bits_byte_aligned_eof_be
bit-endian: be
seq:
- id: prebuf
size: 8
- id: bits
type: b31
# 1 bit left until the end of file. This means that during serialization, when
# the stream is closed / `seek()` is called by the test code, the stream
# position must be "aligned" to a byte boundary so that the buffered bits are
# written into the final byte.
#
# We're specifically testing the alignment right before the EOF here to ensure
# that the EOF check in the implicitly called "write_align_to_byte()" method
# works properly, i.e. that it doesn't wrongly throw an EOF error here.
11 changes: 11 additions & 0 deletions formats/bits_byte_aligned_eof_le.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Like "bits_byte_aligned_eof_be", but for little-endian order.
meta:
id: bits_byte_aligned_eof_le
bit-endian: le
seq:
- id: prebuf
size: 8
- id: bits
type: b31
# 1 bit left until the end of file. (... - see "bits_byte_aligned_eof_be"
# for more details)
39 changes: 39 additions & 0 deletions formats/bytes_eos_pad_term.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Tests "pad-right" and "terminator" functionality in fixed-length "size-eos: true" byte arrays
meta:
id: bytes_eos_pad_term
seq:
- id: str_pad
size: 20
type: str_pad_type
- id: str_term
size: 20
type: str_term_type
- id: str_term_and_pad
size: 20
type: str_term_and_pad_type
- id: str_term_include
size: 20
type: str_term_include_type
types:
str_pad_type:
seq:
- id: value
size-eos: true
pad-right: 0x40
str_term_type:
seq:
- id: value
size-eos: true
terminator: 0x40
str_term_and_pad_type:
seq:
- id: value
size-eos: true
terminator: 0x40
pad-right: 0x2b
str_term_include_type:
seq:
- id: value
size-eos: true
terminator: 0x40
include: true
19 changes: 19 additions & 0 deletions formats/bytes_pad_term_empty.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Same as "bytes_pad_term", but used with different input file that is
# meant to test fully empty byte arrays (see "str_pad_term_empty")
meta:
id: bytes_pad_term_empty
seq:
- id: str_pad
size: 20
pad-right: 0x40
- id: str_term
size: 20
terminator: 0x40
- id: str_term_and_pad
size: 20
terminator: 0x40
pad-right: 0x2b
- id: str_term_include
size: 20
terminator: 0x40
include: true
23 changes: 23 additions & 0 deletions formats/bytes_pad_term_equal.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Tests "pad-right" and "terminator" functionality in fixed-length byte arrays
# with `terminator` == `pad-right`
meta:
id: bytes_pad_term_equal
seq:
- id: s1
size: 20
terminator: 0x40
pad-right: 0x40
- id: s2
size: 20
terminator: 0x40
include: true
pad-right: 0x2b
- id: s3
size: 20
terminator: 0x2b
pad-right: 0x2b
- id: s4
size: 20
terminator: 0x2e
include: true
pad-right: 0x2e
21 changes: 21 additions & 0 deletions formats/bytes_pad_term_roundtrip.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Like "bytes_pad_term", but with added `pad-right`s to be able to test for an
# exact match with the original file after serialization
meta:
id: bytes_pad_term_roundtrip
seq:
- id: str_pad
size: 20
pad-right: 0x40
- id: str_term
size: 20
terminator: 0x40
pad-right: 0x2b
- id: str_term_and_pad
size: 20
terminator: 0x40
pad-right: 0x2b
- id: str_term_include
size: 20
terminator: 0x40
include: true
pad-right: 0x2e
19 changes: 19 additions & 0 deletions formats/bytes_pad_term_zero_size.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Like "bytes_pad_term", but all `size`s are set to 0 (to make sure we don't
# fail in this case)
meta:
id: bytes_pad_term_zero_size
seq:
- id: str_pad
size: 0
pad-right: 0x40
- id: str_term
size: 0
terminator: 0x40
- id: str_term_and_pad
size: 0
terminator: 0x40
pad-right: 0x2b
- id: str_term_include
size: 0
terminator: 0x40
include: true
11 changes: 11 additions & 0 deletions formats/eof_exception_bits_be.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta:
id: eof_exception_bits_be
bit-endian: be
ks-debug: true
seq:
- id: pre_bits
type: b7
# only 2 full bytes (17 bits) available in the stream, should fail with EOF
# exception
- id: fail_bits
type: b18
11 changes: 11 additions & 0 deletions formats/eof_exception_bits_be2.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta:
id: eof_exception_bits_be2
bit-endian: be
ks-debug: true
seq:
- id: pre_bits
type: b8
# only 2 full bytes (16 bits) available in the stream, should fail with EOF
# exception
- id: fail_bits
type: b17
12 changes: 12 additions & 0 deletions formats/eof_exception_bits_le.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Like "eof_exception_bits_be", but for little-endian order.
meta:
id: eof_exception_bits_le
bit-endian: le
ks-debug: true
seq:
- id: pre_bits
type: b7
# only 2 full bytes (17 bits) available in the stream, should fail with EOF
# exception
- id: fail_bits
type: b18
Loading