Fix some of the old tests

- add new examples
- fix struct builder
- complete array interfaces
This commit is contained in:
Felix Weiß
2023-07-20 23:28:58 +02:00
parent 3a7b787949
commit 9bcffad77b
59 changed files with 2190 additions and 2101 deletions

View File

@@ -13,113 +13,22 @@ namespace MewtocolTests {
this.output = output;
}
[Fact(DisplayName = "Numeric mewtocol query building")]
public void NumericRegisterMewtocolIdentifiers() {
List<IRegisterInternal> registers = new List<IRegisterInternal> {
new NumberRegister<short>(50),
new NumberRegister<ushort>(50),
new NumberRegister<int>(50),
new NumberRegister<uint>(50),
new NumberRegister<float>(50),
new NumberRegister<TimeSpan>(50),
new BytesRegister(50, (uint)30),
new BytesRegister(50, (uint)31),
};
List<string> expectedIdents = new List<string> {
"D0005000050", //single word register
"D0005000050", //single word register
"D0005000051", //double word register
"D0005000051", //double word register
"D0005000051", //double word register
"D0005000051", //double word register
"D0005000064", //variable len register even bytes
"D0005000065", //variable len register odd bytes
};
//test mewtocol idents
for (int i = 0; i < registers.Count; i++) {
IRegisterInternal? reg = registers[i];
string expect = expectedIdents[i];
Assert.Equal(expect, reg.BuildMewtocolQuery());
}
}
[Fact(DisplayName = "PLC register naming convention test")]
public void PLCRegisterIdentifiers() {
List<IRegisterInternal> registers = new List<IRegisterInternal> {
//numeric ones
new NumberRegister<short>(50, _name: null),
new NumberRegister<ushort>(60, _name : null),
new NumberRegister<int>(70, _name : null),
new NumberRegister<uint>(80, _name : null),
new NumberRegister<float>(90, _name : null),
new NumberRegister<TimeSpan>(100, _name : null),
//boolean
new BoolRegister(IOType.R, 0, 100),
new BoolRegister(IOType.R, 0, 0),
new BoolRegister(IOType.X, 5),
new BoolRegister(IOType.X, 0xA),
new BoolRegister(IOType.X, 0xF, 109),
new BoolRegister(IOType.Y, 0xC, 75),
//string
new BytesRegister(999, 5),
};
List<string> expcectedIdents = new List<string> {
//numeric ones
"DT50",
"DT60",
"DDT70",
"DDT80",
"DDT90",
"DDT100",
//boolean
"R100",
"R0",
"X5",
"XA",
"X109F",
"Y75C",
//string
"DT999"
};
//test mewtocol idents
for (int i = 0; i < registers.Count; i++) {
IRegisterInternal? reg = registers[i];
string expect = expcectedIdents[i];
Assert.Equal(expect, reg.GetMewName());
}
}
[Fact(DisplayName = "Non allowed (Overflow address)")]
public void OverFlowRegisterAddress() {
[Fact(DisplayName = "Non allowed Struct Address (Overflow address)")]
public void OverFlowStructRegister() {
var ex = Assert.Throws<NotSupportedException>(() => {
new NumberRegister<short>(100000, _name: null);
new StructRegister<short>(100000, 2);
});
output.WriteLine(ex.Message.ToString());
}
[Fact(DisplayName = "Non allowed Boolean Address (Overflow address )")]
public void OverFlowBoolRegister() {
var ex1 = Assert.Throws<NotSupportedException>(() => {
new BoolRegister(IOType.R, _areaAdress: 512);
@@ -136,27 +45,6 @@ namespace MewtocolTests {
output.WriteLine(ex2.Message.ToString());
var ex3 = Assert.Throws<NotSupportedException>(() => {
new BytesRegister(100000, 5);
});
output.WriteLine(ex3.Message.ToString());
}
[Fact(DisplayName = "Non allowed (Wrong data type)")]
public void WrongDataTypeRegister() {
var ex = Assert.Throws<NotSupportedException>(() => {
new NumberRegister<double>(100, _name: null);
});
output.WriteLine(ex.Message.ToString());
}
}