From fff22009e2e311e3a684367e357dba8c71b1f949 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 22 Feb 2020 16:35:44 +0100 Subject: [PATCH] Regen KST expr_bits --- spec/construct/test_expr_bits.py | 20 ++++++++ spec/cpp_stl_11/test_expr_bits.cpp | 28 +++++++++++ spec/cpp_stl_98/test_expr_bits.cpp | 28 +++++++++++ .../tests/SpecExprBits.cs | 28 +++++++++++ spec/go/expr_bits_test.go | 50 +++++++++++++++++++ .../io/kaitai/struct/spec/TestExprBits.java | 25 ++++++++++ spec/javascript/test_expr_bits.js | 19 +++++++ .../src/io/kaitai/struct/spec/texpr_bits.nim | 26 ++++++++++ spec/perl/TestExprBits.t | 27 ++++++++++ spec/php/ExprBitsTest.php | 22 ++++++++ spec/python/test_expr_bits.py | 20 ++++++++ spec/ruby/expr_bits_spec.rb | 20 ++++++++ spec/rust/test_expr_bits.rs | 24 +++++++++ 13 files changed, 337 insertions(+) create mode 100644 spec/construct/test_expr_bits.py create mode 100644 spec/cpp_stl_11/test_expr_bits.cpp create mode 100644 spec/cpp_stl_98/test_expr_bits.cpp create mode 100644 spec/csharp/kaitai_struct_csharp_tests/tests/SpecExprBits.cs create mode 100644 spec/go/expr_bits_test.go create mode 100644 spec/java/src/io/kaitai/struct/spec/TestExprBits.java create mode 100644 spec/javascript/test_expr_bits.js create mode 100644 spec/nim/src/io/kaitai/struct/spec/texpr_bits.nim create mode 100644 spec/perl/TestExprBits.t create mode 100644 spec/php/ExprBitsTest.php create mode 100644 spec/python/test_expr_bits.py create mode 100644 spec/ruby/expr_bits_spec.rb create mode 100644 spec/rust/test_expr_bits.rs diff --git a/spec/construct/test_expr_bits.py b/spec/construct/test_expr_bits.py new file mode 100644 index 000000000..8b9ed7319 --- /dev/null +++ b/spec/construct/test_expr_bits.py @@ -0,0 +1,20 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest + +from expr_bits import _schema + +class TestExprBits(unittest.TestCase): + def test_expr_bits(self): + r = _schema.parse_file('src/switch_opcodes.bin') + + self.assertEqual(r.a, 2) + self.assertEqual(r.enum_seq, self._root.Items.foo) + self.assertEqual(r.byte_size, b"\x66\x6F") + self.assertEqual(len(r.repeat_expr), 2) + self.assertEqual(r.repeat_expr[0], 111) + self.assertEqual(r.repeat_expr[1], 98) + self.assertEqual(r.switch_on_type, 97) + self.assertEqual(r.switch_on_endian.foo, 29184) + self.assertEqual(r.enum_inst, self._root.Items.bar) + self.assertEqual(r.inst_pos, 111) diff --git a/spec/cpp_stl_11/test_expr_bits.cpp b/spec/cpp_stl_11/test_expr_bits.cpp new file mode 100644 index 000000000..6bbdfe409 --- /dev/null +++ b/spec/cpp_stl_11/test_expr_bits.cpp @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#include +#include "expr_bits.h" +#include +#include +#include + + +BOOST_AUTO_TEST_CASE(test_expr_bits) { + std::ifstream ifs("src/switch_opcodes.bin", std::ifstream::binary); + kaitai::kstream ks(&ifs); + expr_bits_t* r = new expr_bits_t(&ks); + + + BOOST_CHECK_EQUAL(r->a(), 2); + BOOST_CHECK_EQUAL(r->enum_seq(), expr_bits_t::ITEMS_FOO); + BOOST_CHECK_EQUAL(r->byte_size(), std::string("\x66\x6F", 2)); + BOOST_CHECK_EQUAL(r->repeat_expr()->size(), 2); + BOOST_CHECK_EQUAL(r->repeat_expr()->at(0), 111); + BOOST_CHECK_EQUAL(r->repeat_expr()->at(1), 98); + BOOST_CHECK_EQUAL(r->switch_on_type(), 97); + BOOST_CHECK_EQUAL(r->switch_on_endian()->foo(), 29184); + BOOST_CHECK_EQUAL(r->enum_inst(), expr_bits_t::ITEMS_BAR); + BOOST_CHECK_EQUAL(r->inst_pos(), 111); + + delete r; +} diff --git a/spec/cpp_stl_98/test_expr_bits.cpp b/spec/cpp_stl_98/test_expr_bits.cpp new file mode 100644 index 000000000..6bbdfe409 --- /dev/null +++ b/spec/cpp_stl_98/test_expr_bits.cpp @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#include +#include "expr_bits.h" +#include +#include +#include + + +BOOST_AUTO_TEST_CASE(test_expr_bits) { + std::ifstream ifs("src/switch_opcodes.bin", std::ifstream::binary); + kaitai::kstream ks(&ifs); + expr_bits_t* r = new expr_bits_t(&ks); + + + BOOST_CHECK_EQUAL(r->a(), 2); + BOOST_CHECK_EQUAL(r->enum_seq(), expr_bits_t::ITEMS_FOO); + BOOST_CHECK_EQUAL(r->byte_size(), std::string("\x66\x6F", 2)); + BOOST_CHECK_EQUAL(r->repeat_expr()->size(), 2); + BOOST_CHECK_EQUAL(r->repeat_expr()->at(0), 111); + BOOST_CHECK_EQUAL(r->repeat_expr()->at(1), 98); + BOOST_CHECK_EQUAL(r->switch_on_type(), 97); + BOOST_CHECK_EQUAL(r->switch_on_endian()->foo(), 29184); + BOOST_CHECK_EQUAL(r->enum_inst(), expr_bits_t::ITEMS_BAR); + BOOST_CHECK_EQUAL(r->inst_pos(), 111); + + delete r; +} diff --git a/spec/csharp/kaitai_struct_csharp_tests/tests/SpecExprBits.cs b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecExprBits.cs new file mode 100644 index 000000000..33adb0292 --- /dev/null +++ b/spec/csharp/kaitai_struct_csharp_tests/tests/SpecExprBits.cs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +using NUnit.Framework; + +namespace Kaitai +{ + [TestFixture] + public class SpecExprBits : CommonSpec + { + [Test] + public void TestExprBits() + { + var r = ExprBits.FromFile(SourceFile("switch_opcodes.bin")); + + + Assert.AreEqual(r.A, 2); + Assert.AreEqual(r.EnumSeq, ExprBits.Items.Foo); + Assert.AreEqual(r.ByteSize, new byte[] { 102, 111 }); + Assert.AreEqual(r.RepeatExpr.Count, 2); + Assert.AreEqual(r.RepeatExpr[0], 111); + Assert.AreEqual(r.RepeatExpr[1], 98); + Assert.AreEqual(r.SwitchOnType, 97); + Assert.AreEqual(r.SwitchOnEndian.Foo, 29184); + Assert.AreEqual(r.EnumInst, ExprBits.Items.Bar); + Assert.AreEqual(r.InstPos, 111); + } + } +} diff --git a/spec/go/expr_bits_test.go b/spec/go/expr_bits_test.go new file mode 100644 index 000000000..532fdd23f --- /dev/null +++ b/spec/go/expr_bits_test.go @@ -0,0 +1,50 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +package spec + +import ( + "runtime/debug" + "os" + "testing" + "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai" + . "test_formats" + "github.com/stretchr/testify/assert" +) + +func TestExprBits(t *testing.T) { + defer func() { + if r := recover(); r != nil { + debug.PrintStack() + t.Fatal("unexpected panic:", r) + } + }() + f, err := os.Open("../../src/switch_opcodes.bin") + if err != nil { + t.Fatal(err) + } + s := kaitai.NewStream(f) + var r ExprBits + err = r.Read(s, &r, &r) + if err != nil { + t.Fatal(err) + } + + assert.EqualValues(t, 2, r.A) + assert.EqualValues(t, ExprBits_Items__Foo, r.EnumSeq) + assert.EqualValues(t, []uint8{102, 111}, r.ByteSize) + assert.EqualValues(t, 2, len(r.RepeatExpr)) + assert.EqualValues(t, 111, r.RepeatExpr[0]) + assert.EqualValues(t, 98, r.RepeatExpr[1]) + assert.EqualValues(t, 97, r.SwitchOnType) + assert.EqualValues(t, 29184, r.SwitchOnEndian.Foo) + tmp1, err := r.EnumInst() + if err != nil { + t.Fatal(err) + } + assert.EqualValues(t, ExprBits_Items__Bar, tmp1) + tmp2, err := r.InstPos() + if err != nil { + t.Fatal(err) + } + assert.EqualValues(t, 111, tmp2) +} diff --git a/spec/java/src/io/kaitai/struct/spec/TestExprBits.java b/spec/java/src/io/kaitai/struct/spec/TestExprBits.java new file mode 100644 index 000000000..46dcbb1e5 --- /dev/null +++ b/spec/java/src/io/kaitai/struct/spec/TestExprBits.java @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +package io.kaitai.struct.spec; + +import io.kaitai.struct.testformats.ExprBits; +import org.testng.annotations.Test; +import static org.testng.Assert.*; +public class TestExprBits extends CommonSpec { + + @Test + public void testExprBits() throws Exception { + ExprBits r = ExprBits.fromFile(SRC_DIR + "switch_opcodes.bin"); + + assertIntEquals(r.a(), 2); + assertEquals(r.enumSeq(), ExprBits.Items.FOO); + assertEquals(r.byteSize(), new byte[] { 102, 111 }); + assertIntEquals(r.repeatExpr().size(), 2); + assertIntEquals(r.repeatExpr().get((int) 0), 111); + assertIntEquals(r.repeatExpr().get((int) 1), 98); + assertIntEquals(r.switchOnType(), 97); + assertIntEquals(r.switchOnEndian().foo(), 29184); + assertEquals(r.enumInst(), ExprBits.Items.BAR); + assertIntEquals(r.instPos(), 111); + } +} diff --git a/spec/javascript/test_expr_bits.js b/spec/javascript/test_expr_bits.js new file mode 100644 index 000000000..ad86e62af --- /dev/null +++ b/spec/javascript/test_expr_bits.js @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +var assert = require('assert'); +var testHelper = require('testHelper'); +var hexString = require('hexString'); + +testHelper('ExprBits', 'src/switch_opcodes.bin', function(r, ExprBits) { + + assert.strictEqual(r.a, 2); + assert.strictEqual(r.enumSeq, ExprBits.Items.FOO); + assert.strictEqual(hexString(r.byteSize), hexString([102, 111])); + assert.strictEqual(r.repeatExpr.length, 2); + assert.strictEqual(r.repeatExpr[0], 111); + assert.strictEqual(r.repeatExpr[1], 98); + assert.strictEqual(r.switchOnType, 97); + assert.strictEqual(r.switchOnEndian.foo, 29184); + assert.strictEqual(r.enumInst, ExprBits.Items.BAR); + assert.strictEqual(r.instPos, 111); +}); diff --git a/spec/nim/src/io/kaitai/struct/spec/texpr_bits.nim b/spec/nim/src/io/kaitai/struct/spec/texpr_bits.nim new file mode 100644 index 000000000..9a0c41dff --- /dev/null +++ b/spec/nim/src/io/kaitai/struct/spec/texpr_bits.nim @@ -0,0 +1,26 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest, os, streams, options, sequtils, ../testhelpers +import ../../../compiled/nim/expr_bits + +var + stream = newFileStream("test_out/nim/junitreports/expr_bits.xml", fmWrite) + outputFormatter = newJUnitOutputFormatter(stream) +addOutputFormatter(outputFormatter) + +suite "Kaitai Struct Compiler Test Suite": + test "Nim: ExprBits": + let r = ExprBits.fromFile("src/switch_opcodes.bin") + + check(r.a == uint64(2)) + check(r.enumSeq == Items()) + check(r.byteSize == seq[byte](@[102, 111].mapIt(toByte(it)))) + check(len(r.repeatExpr) == int(2)) + check(r.repeatExpr[0] == int8(111)) + check(r.repeatExpr[1] == int8(98)) + check(r.switchOnType == int8(97)) + check(r.switchOnEndian.foo == int16(29184)) + check(r.enumInst == Items()) + check(r.instPos == int8(111)) + +close(outputFormatter) diff --git a/spec/perl/TestExprBits.t b/spec/perl/TestExprBits.t new file mode 100644 index 000000000..70cfd9ef5 --- /dev/null +++ b/spec/perl/TestExprBits.t @@ -0,0 +1,27 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +package spec::perl::TestExprBits; + +use strict; +use warnings; +use base qw(Test::Class); +use Test::More; +use ExprBits; + +sub test_expr_bits: Test(10) { + my $r = ExprBits->from_file('src/switch_opcodes.bin'); + + + is($r->a(), 2, 'Equals'); + is($r->enum_seq(), $ExprBits::ITEMS_FOO, 'Equals'); + is($r->byte_size(), pack('C*', (102, 111)), 'Equals'); + is(scalar(@{$r->repeat_expr()}), 2, 'Equals'); + is(@{$r->repeat_expr()}[0], 111, 'Equals'); + is(@{$r->repeat_expr()}[1], 98, 'Equals'); + is($r->switch_on_type(), 97, 'Equals'); + is($r->switch_on_endian()->foo(), 29184, 'Equals'); + is($r->enum_inst(), $ExprBits::ITEMS_BAR, 'Equals'); + is($r->inst_pos(), 111, 'Equals'); +} + +Test::Class->runtests; diff --git a/spec/php/ExprBitsTest.php b/spec/php/ExprBitsTest.php new file mode 100644 index 000000000..630d40998 --- /dev/null +++ b/spec/php/ExprBitsTest.php @@ -0,0 +1,22 @@ +assertEquals(2, $r->a()); + $this->assertEquals(\Kaitai\Struct\Tests\ExprBits\Items::FOO, $r->enumSeq()); + $this->assertEquals("\x66\x6F", $r->byteSize()); + $this->assertEquals(2, count($r->repeatExpr())); + $this->assertEquals(111, $r->repeatExpr()[0]); + $this->assertEquals(98, $r->repeatExpr()[1]); + $this->assertEquals(97, $r->switchOnType()); + $this->assertEquals(29184, $r->switchOnEndian()->foo()); + $this->assertEquals(\Kaitai\Struct\Tests\ExprBits\Items::BAR, $r->enumInst()); + $this->assertEquals(111, $r->instPos()); + } +} diff --git a/spec/python/test_expr_bits.py b/spec/python/test_expr_bits.py new file mode 100644 index 000000000..42ad46543 --- /dev/null +++ b/spec/python/test_expr_bits.py @@ -0,0 +1,20 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +import unittest + +from expr_bits import ExprBits + +class TestExprBits(unittest.TestCase): + def test_expr_bits(self): + with ExprBits.from_file('src/switch_opcodes.bin') as r: + + self.assertEqual(r.a, 2) + self.assertEqual(r.enum_seq, ExprBits.Items.foo) + self.assertEqual(r.byte_size, b"\x66\x6F") + self.assertEqual(len(r.repeat_expr), 2) + self.assertEqual(r.repeat_expr[0], 111) + self.assertEqual(r.repeat_expr[1], 98) + self.assertEqual(r.switch_on_type, 97) + self.assertEqual(r.switch_on_endian.foo, 29184) + self.assertEqual(r.enum_inst, ExprBits.Items.bar) + self.assertEqual(r.inst_pos, 111) diff --git a/spec/ruby/expr_bits_spec.rb b/spec/ruby/expr_bits_spec.rb new file mode 100644 index 000000000..3575ce238 --- /dev/null +++ b/spec/ruby/expr_bits_spec.rb @@ -0,0 +1,20 @@ +# Autogenerated from KST: please remove this line if doing any edits by hand! + +require 'expr_bits' + +RSpec.describe ExprBits do + it 'parses test properly' do + r = ExprBits.from_file('src/switch_opcodes.bin') + + expect(r.a).to eq 2 + expect(r.enum_seq).to eq :items_foo + expect(r.byte_size).to eq [102, 111].pack('C*') + expect(r.repeat_expr.length).to eq 2 + expect(r.repeat_expr[0]).to eq 111 + expect(r.repeat_expr[1]).to eq 98 + expect(r.switch_on_type).to eq 97 + expect(r.switch_on_endian.foo).to eq 29184 + expect(r.enum_inst).to eq :items_bar + expect(r.inst_pos).to eq 111 + end +end diff --git a/spec/rust/test_expr_bits.rs b/spec/rust/test_expr_bits.rs new file mode 100644 index 000000000..316b4a9b6 --- /dev/null +++ b/spec/rust/test_expr_bits.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprBits; + +#[test] +fn test_expr_bits() { + if let Ok(r) = ExprBits::from_file("src/switch_opcodes.bin") { + + assert_eq!(r.a, 2); + assert_eq!(r.enum_seq, ExprBits__Items::FOO); + assert_eq!(r.byte_size, vec!([0x66, 0x6f])); + assert_eq!(r.repeat_expr.len(), 2); + assert_eq!(r.repeat_expr[0], 111); + assert_eq!(r.repeat_expr[1], 98); + assert_eq!(r.switch_on_type, 97); + assert_eq!(r.switch_on_endian.foo, 29184); + assert_eq!(r.enum_inst, ExprBits__Items::BAR); + assert_eq!(r.inst_pos, 111); + } +}