Skip to content

Commit e7c1c2c

Browse files
authored
[C] add test to ensure generated C code properly compiles when versions are set (#1011)
1 parent 23e0147 commit e7c1c2c

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

sbe-tool/src/test/c/CComplianceTest.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
#include "group_with_data/testMessage3.h"
2222
#include "group_with_data/testMessage4.h"
2323

24-
int main()
24+
int main(void)
2525
{
2626
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2013-2024 Real Logic Limited.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "code_generation_test_version/car.h"
17+
#include "code_generation_test_version/messageHeader.h"
18+
19+
int main(void)
20+
{
21+
}

sbe-tool/src/test/c/CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ endfunction()
3434
find_package(Java REQUIRED)
3535

3636
set(CODE_GENERATION_SCHEMA ${CODEC_SCHEMA_DIR}/code-generation-schema.xml)
37+
set(CODE_GENERATION_SCHEMA_WITH_VERSION ${CODEC_SCHEMA_DIR}/code-generation-schema-with-version.xml)
3738
set(GROUP_WITH_DATA_SCHEMA ${CODEC_SCHEMA_DIR}/group-with-data-schema.xml)
3839
set(ISSUE889_SCHEMA ${CODEC_SCHEMA_DIR}/issue889.xml)
3940

@@ -43,13 +44,14 @@ set(GENERATED_CODECS
4344

4445
add_custom_command(
4546
OUTPUT ${GENERATED_CODECS}
46-
DEPENDS sbe-jar ${SBE_JAR} ${CODE_GENERATION_SCHEMA} ${GROUP_WITH_DATA_SCHEMA} ${ISSUE889_SCHEMA}
47+
DEPENDS sbe-jar ${SBE_JAR} ${CODE_GENERATION_SCHEMA} ${CODE_GENERATION_SCHEMA_WITH_VERSION} ${GROUP_WITH_DATA_SCHEMA} ${ISSUE889_SCHEMA}
4748
COMMAND
4849
${Java_JAVA_EXECUTABLE}
4950
-Dsbe.output.dir=${C_CODEC_TARGET_DIR}
5051
-Dsbe.target.language="C"
5152
-jar ${SBE_JAR}
5253
${CODE_GENERATION_SCHEMA}
54+
${CODE_GENERATION_SCHEMA_WITH_VERSION}
5355
${GROUP_WITH_DATA_SCHEMA}
5456
${ISSUE889_SCHEMA}
5557
)
@@ -70,3 +72,11 @@ target_include_directories(CComplianceTest
7072
)
7173

7274
add_dependencies(CComplianceTest c_codecs)
75+
76+
add_executable(CComplianceWithVersionTest CComplianceWithVersionTest.c)
77+
78+
target_include_directories(CComplianceWithVersionTest
79+
PRIVATE ${C_CODEC_TARGET_DIR}
80+
)
81+
82+
add_dependencies(CComplianceWithVersionTest c_codecs)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<sbe:messageSchema xmlns:sbe="http://fixprotocol.io/2016/sbe"
3+
package="code.generation.test.version"
4+
id="6"
5+
version="1"
6+
semanticVersion="5.2"
7+
description="Example schema"
8+
byteOrder="littleEndian">
9+
<types>
10+
<composite name="BoosterT">
11+
<enum name="BoostType" encodingType="char">
12+
<validValue name="TURBO">T</validValue>
13+
<validValue name="SUPERCHARGER">S</validValue>
14+
<validValue name="NITROUS">N</validValue>
15+
<validValue name="KERS">K</validValue>
16+
</enum>
17+
<type name="horsePower" primitiveType="uint8"/>
18+
</composite>
19+
<composite name="messageHeader" description="Message identifiers and length of message root">
20+
<type name="blockLength" primitiveType="uint16"/>
21+
<type name="templateId" primitiveType="uint16"/>
22+
<type name="schemaId" primitiveType="uint16"/>
23+
<type name="version" primitiveType="uint16"/>
24+
</composite>
25+
<composite name="groupSizeEncoding" description="Repeating group dimensions">
26+
<type name="blockLength" primitiveType="uint16"/>
27+
<type name="numInGroup" primitiveType="uint16"/>
28+
</composite>
29+
<composite name="varStringEncoding">
30+
<type name="length" primitiveType="uint16"/>
31+
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-8"/>
32+
</composite>
33+
<composite name="varAsciiStringEncoding">
34+
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
35+
<type name="varData" primitiveType="uint8" length="0" characterEncoding="ASCII"/>
36+
</composite>
37+
</types>
38+
<types>
39+
<type name="ModelYear" primitiveType="uint16"/>
40+
<type name="VehicleCode" primitiveType="char" length="6" characterEncoding="ASCII"/>
41+
<type name="someNumbers" primitiveType="int32" length="5"/>
42+
<type name="Ron" primitiveType="uint8" minValue="90" maxValue="110"/>
43+
<composite name="Engine">
44+
<type name="capacity" primitiveType="uint16"/>
45+
<type name="numCylinders" primitiveType="uint8"/>
46+
<type name="maxRpm" primitiveType="uint16" presence="constant">9000</type>
47+
<type name="manufacturerCode" primitiveType="char" length="3"/>
48+
<type name="fuel" primitiveType="char" presence="constant">Petrol</type>
49+
<ref name="booster" type="BoosterT"/>
50+
</composite>
51+
<enum name="BooleanType" encodingType="uint8">
52+
<validValue name="F">0</validValue>
53+
<validValue name="T">1</validValue>
54+
</enum>
55+
<enum name="Model" encodingType="char">
56+
<validValue name="A">A</validValue>
57+
<validValue name="B">B</validValue>
58+
<validValue name="C">C</validValue>
59+
</enum>
60+
<set name="OptionalExtras" encodingType="uint8">
61+
<choice name="sunRoof">0</choice>
62+
<choice name="sportsPack">1</choice>
63+
<choice name="cruiseControl">2</choice>
64+
</set>
65+
</types>
66+
<sbe:message name="Car" id="1" description="Description of a basic Car">
67+
<field name="serialNumber" id="1" type="uint64" sinceVersion="1"/>
68+
<field name="modelYear" id="2" type="ModelYear" sinceVersion="1"/>
69+
<field name="available" id="3" type="BooleanType" sinceVersion="1"/>
70+
<field name="code" id="4" type="Model" sinceVersion="1"/>
71+
<field name="someNumbers" id="5" type="someNumbers" sinceVersion="1"/>
72+
<field name="vehicleCode" id="6" type="VehicleCode" sinceVersion="1"/>
73+
<field name="extras" id="7" type="OptionalExtras" sinceVersion="1"/>
74+
<field name="discountedModel" id="8" type="Model" presence="constant" valueRef="Model.C" sinceVersion="1"/>
75+
<field name="engine" id="9" type="Engine" sinceVersion="1"/>
76+
<group name="fuelFigures" id="10" dimensionType="groupSizeEncoding" sinceVersion="1">
77+
<field name="speed" id="11" type="uint16" sinceVersion="1"/>
78+
<field name="mpg" id="12" type="float" sinceVersion="1"/>
79+
<data name="usageDescription" id="200" type="varStringEncoding" sinceVersion="1"/>
80+
</group>
81+
<group name="performanceFigures" id="13" dimensionType="groupSizeEncoding" sinceVersion="1">
82+
<field name="octaneRating" id="14" type="Ron" sinceVersion="1"/>
83+
<group name="acceleration" id="15" dimensionType="groupSizeEncoding" sinceVersion="1">
84+
<field name="mph" id="16" type="uint16" sinceVersion="1"/>
85+
<field name="seconds" id="17" type="float" sinceVersion="1"/>
86+
</group>
87+
</group>
88+
<data name="manufacturer" id="18" type="varStringEncoding" sinceVersion="1"/>
89+
<data name="model" id="19" type="varStringEncoding" sinceVersion="1"/>
90+
<data name="activationCode" id="20" type="varStringEncoding" sinceVersion="1"/>
91+
<data name="color" id="21" type="varAsciiStringEncoding" sinceVersion="1"/>
92+
</sbe:message>
93+
</sbe:messageSchema>

0 commit comments

Comments
 (0)