Skip to content
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
3 changes: 3 additions & 0 deletions EDSEditor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libEDSsharp", "libEDSsharp\libEDSsharp.csproj", "{CC0FA4B1-2BFC-43B3-8C56-B428DF2D24E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{2A479BF3-7628-409B-8A29-9314C308445E}"
ProjectSection(ProjectDependencies) = postProject
{8B7A7545-6257-44BF-8868-F429E1B72C77} = {8B7A7545-6257-44BF-8868-F429E1B72C77}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDSSharp", "EDSSharp\EDSSharp.csproj", "{8B7A7545-6257-44BF-8868-F429E1B72C77}"
EndProject
Expand Down
3 changes: 2 additions & 1 deletion EDSEditorGUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ private void exportCanOpenNode(DeviceView dv, string FileName, ExporterFactory.E
{
string savePath = Path.GetDirectoryName(FileName);
string baseFileName = Path.GetFileNameWithoutExtension(FileName);
exporter.export(savePath, baseFileName, this.gitVersion, dv.eds, baseFileName);
var filepath = $"{savePath}/{baseFileName}";
exporter.export(filepath, this.gitVersion, dv.eds);
}
catch (Exception ex)
{
Expand Down
5 changes: 2 additions & 3 deletions EDSSharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ private static void openEDSfile(string infile, string outfile, InfoSection.Filet

private static void exportCOOD(string outpath,ExporterFactory.Exporter type)
{
string odname = outpath;

outpath = Path.GetFullPath(outpath);

string savePath = Path.GetDirectoryName(outpath);
Expand All @@ -103,8 +101,9 @@ private static void exportCOOD(string outpath,ExporterFactory.Exporter type)
Warnings.warning_list.Clear();

IExporter exporter = ExporterFactory.getExporter(type);
var filepath = Path.Combine(savePath, Path.GetFileNameWithoutExtension(outpath));

exporter.export(savePath, Path.GetFileNameWithoutExtension(outpath), gitversion, eds, odname);
exporter.export(filepath, gitversion, eds);

foreach(string warning in Warnings.warning_list)
{
Expand Down
37 changes: 37 additions & 0 deletions Tests/CLITest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Diagnostics;
using System.IO;
using Xunit;

namespace Tests
{
public class CliTest : libEDSsharp.EDSsharp
{
string RunEDSSharp(string arguments)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "EDSSharp.exe";
p.StartInfo.Arguments = arguments;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
return output;
}

[Fact]
public void XddToCanOpenNodeLegacy()
{
RunEDSSharp("--type CanOpenNode --infile minimal_project.xdd --outfile Legacy");
string[] files = Directory.GetFiles(".", "Legacy.*");
Assert.Equal(2, files.Length);
}
[Fact]
public void XddToCanOpenNodeV4()
{
RunEDSSharp("--type CanOpenNodeV4 --infile minimal_project.xdd --outfile V4");
string[] files = Directory.GetFiles(".", "V4.*");
Assert.Equal(2, files.Length);
}
}
}
63 changes: 32 additions & 31 deletions Tests/ExporterTestsV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ public ExporterTestsV4()
_eds = new EDSsharp();
}

void GetExportResult(EDSsharp eds, out IEnumerable<String> cfile, out IEnumerable<String> hfile)
void GetExportResult(EDSsharp eds, out IEnumerable<String> cfile, out IEnumerable<String> hfile, out string odname)
{
var fullPath = Path.GetTempFileName();
var tempfile = Path.GetFileName(fullPath);
var path = Path.GetTempPath();

var cfilePath = fullPath + ".c";
var hfilePath = fullPath + ".h";
export(path, tempfile, ".", eds, "OD_Test");
export(cfilePath, ".", eds);
cfile = File.ReadLines(cfilePath);
hfile = File.ReadLines(hfilePath);
odname = tempfile;
}

bool FindExpectedLines(IEnumerable<String> lines, List<String> expectedLines)
Expand Down Expand Up @@ -85,12 +86,12 @@ public void TestVariableStringZeroData()

_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
Assert.True(FindExpectedLines(hfile, new List<string> { "#define OD_Test_ENTRY_H2000 &OD_Test->list[0]" }));
Assert.True(FindExpectedLines(hfile, new List<string> { "#define OD_Test_ENTRY_H2000_testString &OD_Test->list[0]" }));
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> { $"#define {odname}_ENTRY_H2000 &{odname}->list[0]" }));
Assert.True(FindExpectedLines(hfile, new List<string> { $"#define {odname}_ENTRY_H2000_testString &{odname}->list[0]" }));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testString = {",
" .dataOrig = NULL,",
" .attribute = ODA_SDO_R | ODA_STR,",
Expand All @@ -99,8 +100,8 @@ public void TestVariableStringZeroData()
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x01, ODT_VAR, &OD_TestObjs.o_2000_testString, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x01, ODT_VAR, &{odname}Objs.o_2000_testString, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -123,25 +124,25 @@ public void TestVariableString(string defaultValue, uint stringLengthMin, int ex

_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var _);
GetExportResult(_eds, out var cfile, out var _, out var odname);

Assert.True(FindExpectedLines(cfile, new List<string> {
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
$" .x2000_testString = {{{expectedInitialValues}}}",
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testString = {",
" .dataOrig = &OD_Test_RAM.x2000_testString[0],",
$" .dataOrig = &{odname}_RAM.x2000_testString[0],",
" .attribute = ODA_SDO_R | ODA_STR,",
$" .dataLength = {expectedLength}",
" }",
"};"}));

Assert.True(FindExpectedLines(cfile, new List<string> {
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x01, ODT_VAR, &OD_TestObjs.o_2000_testString, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x01, ODT_VAR, &{odname}Objs.o_2000_testString, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -165,18 +166,18 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int
od.subobjects[1].prop.CO_stringLengthMin = stringLengthMin;
_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> {
"typedef struct {",
" struct {",
" uint8_t numElements;",
$" char str[{expectedLength+1}];",
" } x2000_testRec;",
"} OD_Test_RAM_t;"}));
$"}} {odname}_RAM_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
" .x2000_testRec = {",
" .numElements = 0x00,",
$" .str = {{{expectedInitialValues}}}",
Expand All @@ -187,20 +188,20 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int
{
"typedef struct {",
" OD_obj_record_t o_2000_testRec[2];",
"} OD_TestObjs_t;"}));
$"}} {odname}Objs_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testRec = {",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.numElements,",
$" .dataOrig = &{odname}_RAM.x2000_testRec.numElements,",
" .subIndex = 0,",
" .attribute = ODA_SDO_RW | ODA_TRPDO,",
" .dataLength = 1",
" },",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.str[0],",
$" .dataOrig = &{odname}_RAM.x2000_testRec.str[0],",
" .subIndex = 1,",
" .attribute = ODA_SDO_RW | ODA_TRPDO | ODA_STR,",
$" .dataLength = {expectedLength}",
Expand All @@ -210,8 +211,8 @@ public void TestRecordWithString(string defaultValue, uint stringLengthMin, int

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x02, ODT_REC, &OD_TestObjs.o_2000_testRec, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x02, ODT_REC, &{odname}Objs.o_2000_testRec, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand All @@ -231,17 +232,17 @@ public void TestRecordWithZeroLengthString()
od.addsubobject(1, new ODentry("str", 0x2000, DataType.VISIBLE_STRING, "", EDSsharp.AccessType.rw, PDOMappingType.optional));
_eds.ods.Add(0x2000, od);

GetExportResult(_eds, out var cfile, out var hfile);
GetExportResult(_eds, out var cfile, out var hfile, out var odname);
Assert.True(FindExpectedLines(hfile, new List<string> {
"typedef struct {",
" struct {",
" uint8_t numElements;",
" } x2000_testRec;",
"} OD_Test_RAM_t;"}));
$"}} {odname}_RAM_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"OD_Test_ATTR_RAM OD_Test_RAM_t OD_Test_RAM = {",
$"{odname}_ATTR_RAM {odname}_RAM_t {odname}_RAM = {{",
" .x2000_testRec = {",
" .numElements = 0x00",
" }",
Expand All @@ -251,14 +252,14 @@ public void TestRecordWithZeroLengthString()
{
"typedef struct {",
" OD_obj_record_t o_2000_testRec[2];",
"} OD_TestObjs_t;"}));
$"}} {odname}Objs_t;"}));

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static CO_PROGMEM OD_TestObjs_t OD_TestObjs = {",
$"static CO_PROGMEM {odname}Objs_t {odname}Objs = {{",
" .o_2000_testRec = {",
" {",
" .dataOrig = &OD_Test_RAM.x2000_testRec.numElements,",
$" .dataOrig = &{odname}_RAM.x2000_testRec.numElements,",
" .subIndex = 0,",
" .attribute = ODA_SDO_RW | ODA_TRPDO,",
" .dataLength = 1",
Expand All @@ -274,8 +275,8 @@ public void TestRecordWithZeroLengthString()

Assert.True(FindExpectedLines(cfile, new List<string>
{
"static OD_Test_ATTR_OD OD_entry_t OD_TestList[] = {",
" {0x2000, 0x02, ODT_REC, &OD_TestObjs.o_2000_testRec, NULL},",
$"static {odname}_ATTR_OD OD_entry_t {odname}List[] = {{",
$" {{0x2000, 0x02, ODT_REC, &{odname}Objs.o_2000_testRec, NULL}},",
" {0x0000, 0x00, 0, NULL, NULL}",
"};"}));
}
Expand Down
11 changes: 11 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
<ItemGroup>
<ProjectReference Include="..\libEDSsharp\libEDSsharp.csproj" />
</ItemGroup>
<Target Name="CopyEDSSharpToTestOutDir" AfterTargets="Build">
<ItemGroup>
<EDSSharpFiles Include="..\EDSSharp\bin\$(Configuration)\$(TargetFramework)\*"/>
</ItemGroup>
<Copy SourceFiles="@(EDSSharpFiles)" DestinationFolder="$(OutDir)" />
</Target>
<ItemGroup>
<None Include="minimal_project.xdd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
Expand Down
Loading