Skip to content

Commit

Permalink
completed test of eds -> protobuffer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrof committed Nov 30, 2024
1 parent 2c75776 commit fb80862
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 27 deletions.
37 changes: 19 additions & 18 deletions Tests/EDSMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,6 @@ public void Test_ToProtobufferAssertConfig()
MappingEDS.MapToProtobuffer(eds);
}
[Fact]
public void Test_FromProtobufferAssertConfig()
{
var d = new CanOpenDevice
{
FileInfo = new CanOpen_FileInfo(),
DeviceInfo = new CanOpen_DeviceInfo(),
DeviceCommissioning = new CanOpen_DeviceCommissioning()
};

//Assert is called inside the map function
MappingEDS.MapFromProtobuffer(d);
}
[Fact]
public void Test_ToProtobufferFileInfo()
{
var eds = new EDSsharp
Expand Down Expand Up @@ -150,7 +137,7 @@ public void Test_ToProtobufferDeviceCommissioning()
[InlineData(OdObject.Types.ObjectType.Unspecified, ObjectType.DOMAIN)]
[InlineData(OdObject.Types.ObjectType.Unspecified, ObjectType.NULL)]
[InlineData(OdObject.Types.ObjectType.Unspecified, ObjectType.UNKNOWN)]
void Test_ToProtobufferODObject(OdObject.Types.ObjectType objTypeProto, ObjectType objTypeEDS)
public void Test_ToProtobufferODObject(OdObject.Types.ObjectType objTypeProto, ObjectType objTypeEDS)
{
var eds = new EDSsharp
{
Expand Down Expand Up @@ -194,7 +181,7 @@ void Test_ToProtobufferODObject(OdObject.Types.ObjectType objTypeProto, ObjectTy
[InlineData(OdSubObject.Types.DataType.Unsigned48, DataType.UNSIGNED48)]
[InlineData(OdSubObject.Types.DataType.Unsigned56, DataType.UNSIGNED56)]
[InlineData(OdSubObject.Types.DataType.Unsigned64, DataType.UNSIGNED64)]
void Test_ToProtobufferSubODObjectDatatype(OdSubObject.Types.DataType datatypeProto, DataType datatypeEDS)
public void Test_ToProtobufferSubODObjectDatatype(OdSubObject.Types.DataType datatypeProto, DataType datatypeEDS)
{
var eds = new EDSsharp
{
Expand All @@ -216,15 +203,16 @@ void Test_ToProtobufferSubODObjectDatatype(OdSubObject.Types.DataType datatypePr
var tmp = MappingEDS.MapToProtobuffer(eds);
Assert.Equal(datatypeProto, tmp.Objects[od.Index.ToString()].SubObjects["0"].Type);
}

[Theory]
[InlineData(OdSubObject.Types.AccessPDO.Tr, OdSubObject.Types.AccessSDO.Rw, EDSsharp.AccessType.rw)]
[InlineData(OdSubObject.Types.AccessPDO.T, OdSubObject.Types.AccessSDO.Ro, EDSsharp.AccessType.ro)]
[InlineData(OdSubObject.Types.AccessPDO.R, OdSubObject.Types.AccessSDO.Wo, EDSsharp.AccessType.wo)]
[InlineData(OdSubObject.Types.AccessPDO.No, OdSubObject.Types.AccessSDO.Ro, EDSsharp.AccessType.ro)]
[InlineData(OdSubObject.Types.AccessPDO.No, OdSubObject.Types.AccessSDO.Wo, EDSsharp.AccessType.wo)]
[InlineData(OdSubObject.Types.AccessPDO.T, OdSubObject.Types.AccessSDO.Rw, EDSsharp.AccessType.rwr)]
[InlineData(OdSubObject.Types.AccessPDO.R, OdSubObject.Types.AccessSDO.Rw, EDSsharp.AccessType.rww)]
[InlineData(OdSubObject.Types.AccessPDO.R, OdSubObject.Types.AccessSDO.Ro, EDSsharp.AccessType.@const)]
[InlineData(OdSubObject.Types.AccessPDO.No, OdSubObject.Types.AccessSDO.No, EDSsharp.AccessType.UNKNOWN)]
void Test_ToProtobufferSubODObjectAccesstype(OdSubObject.Types.AccessPDO accessPDOProto, OdSubObject.Types.AccessSDO accessSDOProto, EDSsharp.AccessType datatypeEDS)
public void Test_ToProtobufferSubODObjectAccesstype(OdSubObject.Types.AccessPDO accessPDOProto, OdSubObject.Types.AccessSDO accessSDOProto, EDSsharp.AccessType datatypeEDS)
{
var eds = new EDSsharp
{
Expand Down Expand Up @@ -279,5 +267,18 @@ public void Test_ToProtobufferSubODObjectMembers()
Assert.Equal(sub.LowLimit, tmp.Objects[od.Index.ToString()].SubObjects["0"].LowLimit);
Assert.Equal(sub.defaultvalue, tmp.Objects[od.Index.ToString()].SubObjects["0"].DefaultValue);
}
[Fact]
public void Test_FromProtobufferAssertConfig()
{
var d = new CanOpenDevice
{
FileInfo = new CanOpen_FileInfo(),
DeviceInfo = new CanOpen_DeviceInfo(),
DeviceCommissioning = new CanOpen_DeviceCommissioning()
};

//Assert is called inside the map function
MappingEDS.MapFromProtobuffer(d);
}
}
}
80 changes: 71 additions & 9 deletions libEDSsharp/CanOpenEDSMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ public static CanOpenDevice MapToProtobuffer(EDSsharp source)
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.objecttype))

Check failure on line 150 in libEDSsharp/CanOpenEDSMapping.cs

View workflow job for this annotation

GitHub Actions / build (net481, Debug)

'OdObject' does not contain a definition for 'Type' and no accessible extension method 'Type' accepting a first argument of type 'OdObject' could be found (are you missing a using directive or an assembly reference?)
.ForMember(dest => dest.CountLabel, opt => opt.MapFrom(src => src.Label));
cfg.CreateMap<ObjectType, OdObject.Types.ObjectType>().ConvertUsing<ODTypeResolver>();
cfg.CreateMap<EDSsharp.AccessType, OdSubObject.Types.AccessSDO>().ConvertUsing<ODSDOAccessTypeResolver>();
cfg.CreateMap<EDSsharp.AccessType, OdSubObject.Types.AccessPDO>().ConvertUsing<ODPDOAccessTypeResolver>();
cfg.CreateMap<ODentry, OdSubObject>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.parameter_name))
.ForMember(dest => dest.Alias, opt => opt.Ignore())
.ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.datatype))

Check failure on line 158 in libEDSsharp/CanOpenEDSMapping.cs

View workflow job for this annotation

GitHub Actions / build (net481, Debug)

'OdSubObject' does not contain a definition for 'Type' and no accessible extension method 'Type' accepting a first argument of type 'OdSubObject' could be found (are you missing a using directive or an assembly reference?)
.ForMember(dest => dest.Sdo, opt => opt.MapFrom(src => src.AccessSDO()))
.ForMember(dest => dest.Pdo, opt => opt.MapFrom(src => src.AccessPDO()))
.ForMember(dest => dest.Sdo, opt => opt.MapFrom(src => src.accesstype))
.ForMember(dest => dest.Pdo, opt => opt.MapFrom(src => src.accesstype))
.ForMember(dest => dest.Srdo, opt => opt.Ignore())
.ForMember(dest => dest.StringLengthMin, opt => opt.MapFrom(src => src.Lengthofstring));
});
Expand All @@ -166,7 +168,6 @@ public static CanOpenDevice MapToProtobuffer(EDSsharp source)
}
}


/// <summary>
/// Helper class to convert EDS date and time into datetime used in the protobuffer timestand (datetime)
/// </summary>
Expand Down Expand Up @@ -233,16 +234,16 @@ public Timestamp Resolve(FileInfo source, CanOpen_FileInfo destination, Timestam
}

/// <summary>
/// Helper class to convert Enum types
/// Helper class to convert object type enum
/// </summary>
/// Checkout AutoMapper.Extensions.EnumMapping when .net framework is gone
public class ODTypeResolver : ITypeConverter<ObjectType, OdObject.Types.ObjectType>
{
/// <summary>
/// Resolver to convert eds date and time into protobuffer timestamp (datetime)
/// Resolver to convert object types
/// </summary>
/// <param name="source">source EDS fileinfo object</param>
/// <param name="destination">protobuffer fileinfo object</param>
/// <param name="source">EDS object type object</param>
/// <param name="destination">protobuffer object type</param>
/// <param name="member">result object</param>
/// <param name="context">resolve context</param>
/// <returns>result </returns>
Expand All @@ -264,7 +265,68 @@ public OdObject.Types.ObjectType Convert(ObjectType source, OdObject.Types.Objec
default:
return OdObject.Types.ObjectType.Unspecified;
}

}
}
}
/// <summary>
/// Helper class to convert Enum types
/// </summary>
/// Checkout AutoMapper.Extensions.EnumMapping when .net framework is gone
public class ODSDOAccessTypeResolver : ITypeConverter<EDSsharp.AccessType, OdSubObject.Types.AccessSDO>
{
/// <summary>
/// Resolver to convert eds access into SDO access type
/// </summary>
/// <param name="source">EDS accesstype</param>
/// <param name="destination">protobuffer sdo access type</param>
/// <param name="member">result object</param>
/// <param name="context">resolve context</param>
/// <returns>result </returns>
public OdSubObject.Types.AccessSDO Convert(EDSsharp.AccessType source, OdSubObject.Types.AccessSDO destination, ResolutionContext context)
{
switch (source)
{
case EDSsharp.AccessType.rw:
case EDSsharp.AccessType.rwr:
case EDSsharp.AccessType.rww:
return OdSubObject.Types.AccessSDO.Rw;
case EDSsharp.AccessType.ro:
case EDSsharp.AccessType.@const:
return OdSubObject.Types.AccessSDO.Ro;
case EDSsharp.AccessType.wo:
return OdSubObject.Types.AccessSDO.Wo;
case EDSsharp.AccessType.UNKNOWN:
default:
return OdSubObject.Types.AccessSDO.No;
}
}
}
public class ODPDOAccessTypeResolver : ITypeConverter<EDSsharp.AccessType, OdSubObject.Types.AccessPDO>
{
/// <summary>
/// Resolver to convert eds access into PDO access type
/// </summary>
/// <param name="source">EDS accesstype</param>
/// <param name="destination">protobuffer pdo access type</param>
/// <param name="member">result object</param>
/// <param name="context">resolve context</param>
/// <returns>result </returns>
public OdSubObject.Types.AccessPDO Convert(EDSsharp.AccessType source, OdSubObject.Types.AccessPDO destination, ResolutionContext context)
{
switch (source)
{
case EDSsharp.AccessType.rw:
return OdSubObject.Types.AccessPDO.Tr;
case EDSsharp.AccessType.rwr:
return OdSubObject.Types.AccessPDO.T;
case EDSsharp.AccessType.rww:
case EDSsharp.AccessType.@const:
return OdSubObject.Types.AccessPDO.R;
case EDSsharp.AccessType.ro:
case EDSsharp.AccessType.wo:
case EDSsharp.AccessType.UNKNOWN:
default:
return OdSubObject.Types.AccessPDO.No;
}
}
}
}

0 comments on commit fb80862

Please sign in to comment.