Skip to content

Commit

Permalink
Regen KST expr_bits
Browse files Browse the repository at this point in the history
  • Loading branch information
generalmimon committed Feb 22, 2020
1 parent ba26622 commit fff2200
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/construct/test_expr_bits.py
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions spec/cpp_stl_11/test_expr_bits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Autogenerated from KST: please remove this line if doing any edits by hand!

#include <boost/test/unit_test.hpp>
#include "expr_bits.h"
#include <iostream>
#include <fstream>
#include <vector>


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;
}
28 changes: 28 additions & 0 deletions spec/cpp_stl_98/test_expr_bits.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Autogenerated from KST: please remove this line if doing any edits by hand!

#include <boost/test/unit_test.hpp>
#include "expr_bits.h"
#include <iostream>
#include <fstream>
#include <vector>


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;
}
28 changes: 28 additions & 0 deletions spec/csharp/kaitai_struct_csharp_tests/tests/SpecExprBits.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
50 changes: 50 additions & 0 deletions spec/go/expr_bits_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
25 changes: 25 additions & 0 deletions spec/java/src/io/kaitai/struct/spec/TestExprBits.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 19 additions & 0 deletions spec/javascript/test_expr_bits.js
Original file line number Diff line number Diff line change
@@ -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);
});
26 changes: 26 additions & 0 deletions spec/nim/src/io/kaitai/struct/spec/texpr_bits.nim
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions spec/perl/TestExprBits.t
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions spec/php/ExprBitsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
// Autogenerated from KST: please remove this line if doing any edits by hand!

namespace Kaitai\Struct\Tests;

class ExprBitsTest extends TestCase {
public function testExprBits() {
$r = ExprBits::fromFile(self::SRC_DIR_PATH . '/switch_opcodes.bin');


$this->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());
}
}
20 changes: 20 additions & 0 deletions spec/python/test_expr_bits.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions spec/ruby/expr_bits_spec.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions spec/rust/test_expr_bits.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit fff2200

Please sign in to comment.