Skip to content
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

[draft] add a test for reading imported union values #193

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
4 changes: 2 additions & 2 deletions backends/open62541/src/DataTypeImporter.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ static void setPaddingMemsize(UA_DataType *type,
}
else
{
// add the switchfield to the padding of the first datatype member
if (type->typeKind == UA_DATATYPEKIND_UNION && tm == type->members)
// add the switchfield to the padding of all datatype members
if (type->typeKind == UA_DATATYPEKIND_UNION)
{
#ifdef USE_MEMBERTYPE_INDEX
tm->padding = (UA_Byte)sizeof(UA_Int32);
Expand Down
2 changes: 1 addition & 1 deletion backends/open62541/tests/dataTypeImport/union.bsd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
<opc:Field SwitchField="SwitchField" TypeName="opc:Int32" SwitchValue="1" Name="NoOffield1"/>
<opc:Field LengthField="NoOffield1" SwitchField="SwitchField" TypeName="opc:Double" SwitchValue="1" Name="field1"/>
</opc:StructuredType>
</opc:TypeDictionary>
</opc:TypeDictionary>
2 changes: 2 additions & 0 deletions backends/open62541/tests/dataTypeImport/union.csv
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ Server_Namespaces_http___yourorganisation_org_union__StaticNumericNodeIdRange,60
Server_Namespaces_http___yourorganisation_org_union__StaticStringNodeIdPattern,6013,Variable
TypeDictionary_BinarySchema_MyUnion,6014,Variable
TypeDictionary_XmlSchema_MyUnion,6015,Variable
Union_Field1,6018,Variable
Union_Field2,6021,Variable
44 changes: 43 additions & 1 deletion backends/open62541/tests/dataTypeImport/union.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Alias Alias="String">i=12</Alias>
<Alias Alias="DateTime">i=13</Alias>
<Alias Alias="ByteString">i=15</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="HasEncoding">i=38</Alias>
<Alias Alias="HasDescription">i=39</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
Expand All @@ -24,10 +25,11 @@
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="IdType">i=256</Alias>
<Alias Alias="NumericRange">i=291</Alias>
<Alias Alias="MyUnion">ns=1;i=3003</Alias>
</Aliases>
<Extensions>
<Extension>
<ua:ModelInfo Tool="UaModeler" Hash="VbBlrcnI0A9jOzMXGCCxQw==" Version="1.6.7"/>
<ua:ModelInfo Tool="UaModeler" Hash="dYZboYJ20Cvgqv5AiQIR6g==" Version="1.6.7"/>
</Extension>
</Extensions>
<UADataType NodeId="ns=1;i=3003" BrowseName="1:MyUnion">
Expand Down Expand Up @@ -272,6 +274,46 @@
<Reference ReferenceType="HasProperty" IsForward="false">ns=1;i=5004</Reference>
</References>
</UAVariable>
<UAVariable DataType="MyUnion" NodeId="ns=1;i=6018" BrowseName="1:Union_Field1" AccessLevel="3">
<DisplayName>Union_Field1</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
</References>
<Value>
<uax:ExtensionObject>
<uax:TypeId>
<uax:Identifier>ns=1;i=5006</uax:Identifier>
</uax:TypeId>
<uax:Body>
<MyUnion xmlns="http://yourorganisation.org/union/Types.xsd">
<SwitchField>1</SwitchField>
<x>70000</x>
</MyUnion>
</uax:Body>
</uax:ExtensionObject>
</Value>
</UAVariable>
<UAVariable DataType="MyUnion" NodeId="ns=1;i=6021" BrowseName="1:Union_Field2" AccessLevel="3">
<DisplayName>Union_Field2</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
</References>
<Value>
<uax:ExtensionObject>
<uax:TypeId>
<uax:Identifier>ns=1;i=5006</uax:Identifier>
</uax:TypeId>
<uax:Body>
<MyUnion xmlns="http://yourorganisation.org/union/Types.xsd">
<SwitchField>2</SwitchField>
<y>-1000</y>
</MyUnion>
</uax:Body>
</uax:ExtensionObject>
</Value>
</UAVariable>
<UAObject SymbolicName="DefaultBinary" NodeId="ns=1;i=5001" BrowseName="Default Binary">
<DisplayName>Default Binary</DisplayName>
<References>
Expand Down
30 changes: 30 additions & 0 deletions backends/open62541/tests/dataTypeImport/union2.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,42 @@ START_TEST(compareUnion)
}
END_TEST

START_TEST(readUnionValue)
{
UA_Variant var;
UA_Variant_init(&var);

UA_StatusCode status =
UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6018), &var);
ck_assert(status == UA_STATUSCODE_GOOD);

UA_MyUnion u;
u = *(UA_MyUnion*)var.data;

ck_assert(u.switchField==UA_MYUNIONSWITCH_X);
ck_assert_int_eq(u.fields.x, 70000);

UA_Variant_clear(&var);

status =
UA_Server_readValue(server, UA_NODEID_NUMERIC(2, 6021), &var);
ck_assert(status == UA_STATUSCODE_GOOD);

u = *(UA_MyUnion *)var.data;

ck_assert(u.switchField == UA_MYUNIONSWITCH_Y);
ck_assert_int_eq(u.fields.y, -1000);
UA_Variant_clear(&var);
}
END_TEST

static Suite *testSuite_Client(void)
{
Suite *s = suite_create("datatype Import");
TCase *tc_server = tcase_create("server nodeset import");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, compareUnion);
tcase_add_test(tc_server, readUnionValue);
suite_add_tcase(s, tc_server);
return s;
}
Expand Down
4 changes: 0 additions & 4 deletions backends/open62541/tests/testHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ void typesAreMatching(const UA_DataType *t1, const UA_DataType *t2, const UA_Dat
ck_assert(!strcmp(t1->typeName, t2->typeName));
size_t cnt =0;
UA_UInt32 mSize = t1->membersSize;
if (t1->typeKind == UA_DATATYPEKIND_UNION)
{
mSize--;
}
for(const UA_DataTypeMember* m = t1->members; m!=t1->members+mSize; m++)
{
memberTypeMatching(m, &t2->members[cnt], generatedTypes, customTypes);
Expand Down