Skip to content

[C] add test to ensure generated C code properly compiles when versio… #1011

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

Merged
merged 1 commit into from
Aug 22, 2024
Merged
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: 1 addition & 1 deletion sbe-tool/src/test/c/CComplianceTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
#include "group_with_data/testMessage3.h"
#include "group_with_data/testMessage4.h"

int main()
int main(void)
{
}
21 changes: 21 additions & 0 deletions sbe-tool/src/test/c/CComplianceWithVersionTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2013-2024 Real Logic Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "code_generation_test_version/car.h"
#include "code_generation_test_version/messageHeader.h"

int main(void)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this test access anything from car.h or messageHeader.h, i.e. what kind of compilation check will it be doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's validating that the code in the header files actually compiles. Without the fix that you merged earlier, this file would fail to compile. We'd see a bunch of this when running cppbuild:

/Users/natebradac/src/real-logic/simple-binary-encoding/cppbuild/Release/generated/c/code_generation_test_version/car.h:2705:16: error: expected expression
        return { NULL, 0 };
               ^

}
12 changes: 11 additions & 1 deletion sbe-tool/src/test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ endfunction()
find_package(Java REQUIRED)

set(CODE_GENERATION_SCHEMA ${CODEC_SCHEMA_DIR}/code-generation-schema.xml)
set(CODE_GENERATION_SCHEMA_WITH_VERSION ${CODEC_SCHEMA_DIR}/code-generation-schema-with-version.xml)
set(GROUP_WITH_DATA_SCHEMA ${CODEC_SCHEMA_DIR}/group-with-data-schema.xml)
set(ISSUE889_SCHEMA ${CODEC_SCHEMA_DIR}/issue889.xml)

Expand All @@ -43,13 +44,14 @@ set(GENERATED_CODECS

add_custom_command(
OUTPUT ${GENERATED_CODECS}
DEPENDS sbe-jar ${SBE_JAR} ${CODE_GENERATION_SCHEMA} ${GROUP_WITH_DATA_SCHEMA} ${ISSUE889_SCHEMA}
DEPENDS sbe-jar ${SBE_JAR} ${CODE_GENERATION_SCHEMA} ${CODE_GENERATION_SCHEMA_WITH_VERSION} ${GROUP_WITH_DATA_SCHEMA} ${ISSUE889_SCHEMA}
COMMAND
${Java_JAVA_EXECUTABLE}
-Dsbe.output.dir=${C_CODEC_TARGET_DIR}
-Dsbe.target.language="C"
-jar ${SBE_JAR}
${CODE_GENERATION_SCHEMA}
${CODE_GENERATION_SCHEMA_WITH_VERSION}
${GROUP_WITH_DATA_SCHEMA}
${ISSUE889_SCHEMA}
)
Expand All @@ -70,3 +72,11 @@ target_include_directories(CComplianceTest
)

add_dependencies(CComplianceTest c_codecs)

add_executable(CComplianceWithVersionTest CComplianceWithVersionTest.c)

target_include_directories(CComplianceWithVersionTest
PRIVATE ${C_CODEC_TARGET_DIR}
)

add_dependencies(CComplianceWithVersionTest c_codecs)
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
package="code.generation.test.version"
id="6"
version="1"
semanticVersion="5.2"
description="Example schema"
byteOrder="littleEndian">
<types>
<composite name="BoosterT">
<enum name="BoostType" encodingType="char">
<validValue name="TURBO">T</validValue>
<validValue name="SUPERCHARGER">S</validValue>
<validValue name="NITROUS">N</validValue>
<validValue name="KERS">K</validValue>
</enum>
<type name="horsePower" primitiveType="uint8"/>
</composite>
<composite name="messageHeader" description="Message identifiers and length of message root">
<type name="blockLength" primitiveType="uint16"/>
<type name="templateId" primitiveType="uint16"/>
<type name="schemaId" primitiveType="uint16"/>
<type name="version" primitiveType="uint16"/>
</composite>
<composite name="groupSizeEncoding" description="Repeating group dimensions">
<type name="blockLength" primitiveType="uint16"/>
<type name="numInGroup" primitiveType="uint16"/>
</composite>
<composite name="varStringEncoding">
<type name="length" primitiveType="uint16"/>
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
</composite>
<composite name="varAsciiStringEncoding">
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
<type name="varData" primitiveType="uint8" length="0" characterEncoding="ASCII"/>
</composite>
</types>
<types>
<type name="ModelYear" primitiveType="uint16"/>
<type name="VehicleCode" primitiveType="char" length="6" characterEncoding="ASCII"/>
<type name="someNumbers" primitiveType="int32" length="5"/>
<type name="Ron" primitiveType="uint8" minValue="90" maxValue="110"/>
<composite name="Engine">
<type name="capacity" primitiveType="uint16"/>
<type name="numCylinders" primitiveType="uint8"/>
<type name="maxRpm" primitiveType="uint16" presence="constant">9000</type>
<type name="manufacturerCode" primitiveType="char" length="3"/>
<type name="fuel" primitiveType="char" presence="constant">Petrol</type>
<ref name="booster" type="BoosterT"/>
</composite>
<enum name="BooleanType" encodingType="uint8">
<validValue name="F">0</validValue>
<validValue name="T">1</validValue>
</enum>
<enum name="Model" encodingType="char">
<validValue name="A">A</validValue>
<validValue name="B">B</validValue>
<validValue name="C">C</validValue>
</enum>
<set name="OptionalExtras" encodingType="uint8">
<choice name="sunRoof">0</choice>
<choice name="sportsPack">1</choice>
<choice name="cruiseControl">2</choice>
</set>
</types>
<sbe:message name="Car" id="1" description="Description of a basic Car">
<field name="serialNumber" id="1" type="uint64" sinceVersion="1"/>
<field name="modelYear" id="2" type="ModelYear" sinceVersion="1"/>
<field name="available" id="3" type="BooleanType" sinceVersion="1"/>
<field name="code" id="4" type="Model" sinceVersion="1"/>
<field name="someNumbers" id="5" type="someNumbers" sinceVersion="1"/>
<field name="vehicleCode" id="6" type="VehicleCode" sinceVersion="1"/>
<field name="extras" id="7" type="OptionalExtras" sinceVersion="1"/>
<field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C" sinceVersion="1"/>
<field name="engine" id="9" type="Engine" sinceVersion="1"/>
<group name="fuelFigures" id="10" dimensionType="groupSizeEncoding" sinceVersion="1">
<field name="speed" id="11" type="uint16" sinceVersion="1"/>
<field name="mpg" id="12" type="float" sinceVersion="1"/>
<data name="usageDescription" id="200" type="varStringEncoding" sinceVersion="1"/>
</group>
<group name="performanceFigures" id="13" dimensionType="groupSizeEncoding" sinceVersion="1">
<field name="octaneRating" id="14" type="Ron" sinceVersion="1"/>
<group name="acceleration" id="15" dimensionType="groupSizeEncoding" sinceVersion="1">
<field name="mph" id="16" type="uint16" sinceVersion="1"/>
<field name="seconds" id="17" type="float" sinceVersion="1"/>
</group>
</group>
<data name="manufacturer" id="18" type="varStringEncoding" sinceVersion="1"/>
<data name="model" id="19" type="varStringEncoding" sinceVersion="1"/>
<data name="activationCode" id="20" type="varStringEncoding" sinceVersion="1"/>
<data name="color" id="21" type="varAsciiStringEncoding" sinceVersion="1"/>
</sbe:message>
</sbe:messageSchema>
Loading