Skip to content

C++: slightly tweak KST generator to generate more automatic tests #110

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions spec/cpp_stl_11/test_nested_types_import.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cpp_stl_11/test_switch_manual_enum_invalid.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cpp_stl_11/test_switch_manual_enum_invalid_else.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/cpp_stl_98/test_nested_types_import.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cpp_stl_98/test_switch_manual_enum_invalid.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/cpp_stl_98/test_switch_manual_enum_invalid_else.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down