diff --git a/spec/cpp_stl_11/test_nested_types_import.cpp b/spec/cpp_stl_11/test_nested_types_import.cpp index 35dbfe1e9..1ba039da6 100644 --- a/spec/cpp_stl_11/test_nested_types_import.cpp +++ b/spec/cpp_stl_11/test_nested_types_import.cpp @@ -1,3 +1,5 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "nested_types_import.h" #include diff --git a/spec/cpp_stl_11/test_switch_manual_enum_invalid.cpp b/spec/cpp_stl_11/test_switch_manual_enum_invalid.cpp index 9345c016d..31a723355 100644 --- a/spec/cpp_stl_11/test_switch_manual_enum_invalid.cpp +++ b/spec/cpp_stl_11/test_switch_manual_enum_invalid.cpp @@ -1,20 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "switch_manual_enum_invalid.h" #include #include #include - BOOST_AUTO_TEST_CASE(test_switch_manual_enum_invalid) { std::ifstream ifs("src/enum_negative.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); switch_manual_enum_invalid_t* r = new switch_manual_enum_invalid_t(&ks); - BOOST_CHECK_EQUAL(r->opcodes()->size(), 2); - BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), static_cast(255)); + BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), 255); BOOST_CHECK(r->opcodes()->at(0)->_is_null_body()); - BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), static_cast(1)); + BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), 1); BOOST_CHECK(r->opcodes()->at(1)->_is_null_body()); delete r; diff --git a/spec/cpp_stl_11/test_switch_manual_enum_invalid_else.cpp b/spec/cpp_stl_11/test_switch_manual_enum_invalid_else.cpp index 2445d0156..df686e170 100644 --- a/spec/cpp_stl_11/test_switch_manual_enum_invalid_else.cpp +++ b/spec/cpp_stl_11/test_switch_manual_enum_invalid_else.cpp @@ -1,20 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "switch_manual_enum_invalid_else.h" #include #include #include - BOOST_AUTO_TEST_CASE(test_switch_manual_enum_invalid_else) { std::ifstream ifs("src/enum_negative.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); switch_manual_enum_invalid_else_t* r = new switch_manual_enum_invalid_else_t(&ks); - BOOST_CHECK_EQUAL(r->opcodes()->size(), 2); - BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), static_cast(255)); + BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), 255); BOOST_CHECK_EQUAL(static_cast(r->opcodes()->at(0)->body())->value(), 123); - BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), static_cast(1)); + BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), 1); BOOST_CHECK_EQUAL(static_cast(r->opcodes()->at(1)->body())->value(), 123); delete r; diff --git a/spec/cpp_stl_98/test_nested_types_import.cpp b/spec/cpp_stl_98/test_nested_types_import.cpp index b0721ad79..5d359b76b 100644 --- a/spec/cpp_stl_98/test_nested_types_import.cpp +++ b/spec/cpp_stl_98/test_nested_types_import.cpp @@ -1,3 +1,5 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "nested_types_import.h" #include diff --git a/spec/cpp_stl_98/test_switch_manual_enum_invalid.cpp b/spec/cpp_stl_98/test_switch_manual_enum_invalid.cpp index 9345c016d..31a723355 100644 --- a/spec/cpp_stl_98/test_switch_manual_enum_invalid.cpp +++ b/spec/cpp_stl_98/test_switch_manual_enum_invalid.cpp @@ -1,20 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "switch_manual_enum_invalid.h" #include #include #include - BOOST_AUTO_TEST_CASE(test_switch_manual_enum_invalid) { std::ifstream ifs("src/enum_negative.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); switch_manual_enum_invalid_t* r = new switch_manual_enum_invalid_t(&ks); - BOOST_CHECK_EQUAL(r->opcodes()->size(), 2); - BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), static_cast(255)); + BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), 255); BOOST_CHECK(r->opcodes()->at(0)->_is_null_body()); - BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), static_cast(1)); + BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), 1); BOOST_CHECK(r->opcodes()->at(1)->_is_null_body()); delete r; diff --git a/spec/cpp_stl_98/test_switch_manual_enum_invalid_else.cpp b/spec/cpp_stl_98/test_switch_manual_enum_invalid_else.cpp index 2445d0156..df686e170 100644 --- a/spec/cpp_stl_98/test_switch_manual_enum_invalid_else.cpp +++ b/spec/cpp_stl_98/test_switch_manual_enum_invalid_else.cpp @@ -1,20 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #include #include "switch_manual_enum_invalid_else.h" #include #include #include - BOOST_AUTO_TEST_CASE(test_switch_manual_enum_invalid_else) { std::ifstream ifs("src/enum_negative.bin", std::ifstream::binary); kaitai::kstream ks(&ifs); switch_manual_enum_invalid_else_t* r = new switch_manual_enum_invalid_else_t(&ks); - BOOST_CHECK_EQUAL(r->opcodes()->size(), 2); - BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), static_cast(255)); + BOOST_CHECK_EQUAL(r->opcodes()->at(0)->code(), 255); BOOST_CHECK_EQUAL(static_cast(r->opcodes()->at(0)->body())->value(), 123); - BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), static_cast(1)); + BOOST_CHECK_EQUAL(r->opcodes()->at(1)->code(), 1); BOOST_CHECK_EQUAL(static_cast(r->opcodes()->at(1)->body())->value(), 123); delete r; diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/CppStlSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/CppStlSG.scala index c2b9fe6b1..1d9aca95d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/CppStlSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/CppStlSG.scala @@ -2,6 +2,7 @@ package io.kaitai.struct.testtranslator.specgenerators import io.kaitai.struct.datatype.{DataType, KSError} import io.kaitai.struct.exprlang.Ast +import io.kaitai.struct.format.Identifier import io.kaitai.struct.languages.CppCompiler import io.kaitai.struct.testtranslator.{Main, TestAssert, TestEquals, TestSpec} import io.kaitai.struct.translators.CppTranslator @@ -75,9 +76,19 @@ class CppStlSG(spec: TestSpec, provider: ClassTypeProvider, cppConfig: CppRuntim override def nullAssert(actual: Ast.expr): Unit = { val nullCheckStr = actual match { case Ast.expr.Attribute(x, Ast.identifier(attrName)) => - translateAct(x) + s"->_is_null_$attrName()" + val expr = translateAct(x) + attrName match { + case Identifier.PARENT | Identifier.ROOT => + config.cppConfig.pointers match { + case CppRuntimeConfig.UniqueAndRawPointers => + out.puts(s"BOOST_CHECK_EQUAL($expr->$attrName(), nullptr);") + case CppRuntimeConfig.RawPointers => + out.puts(s"BOOST_CHECK(!$expr->$attrName());") + } + case _ => + out.puts(s"BOOST_CHECK($expr->_is_null_$attrName());") + } } - out.puts(s"BOOST_CHECK($nullCheckStr);") } override def trueArrayEquality(check: TestEquals, elType: DataType, elts: Seq[Ast.expr]): Unit = {