This is an automated email from the ASF dual-hosted git repository. sruehl pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 784678553eacd2442e10c0424e52dc591d72f740 Author: Sebastian Rühl <[email protected]> AuthorDate: Wed Apr 12 12:11:38 2023 +0200 test(plc4go/cbus): add assertions for message mapper --- plc4go/internal/cbus/CBusMessageMapper_test.go | 1086 +++++++++++++++++++++++- 1 file changed, 1074 insertions(+), 12 deletions(-) diff --git a/plc4go/internal/cbus/CBusMessageMapper_test.go b/plc4go/internal/cbus/CBusMessageMapper_test.go index d9987f2ed0..d97bd0ea96 100644 --- a/plc4go/internal/cbus/CBusMessageMapper_test.go +++ b/plc4go/internal/cbus/CBusMessageMapper_test.go @@ -25,6 +25,8 @@ import ( readWriteModel "github.com/apache/plc4x/plc4go/protocols/cbus/readwrite/model" "github.com/apache/plc4x/plc4go/spi" "github.com/apache/plc4x/plc4go/spi/utils" + spiValues "github.com/apache/plc4x/plc4go/spi/values" + "github.com/stretchr/testify/assert" "reflect" "testing" ) @@ -295,8 +297,8 @@ func TestMapEncodedReply(t *testing.T) { transaction spi.RequestTransaction encodedReply readWriteModel.EncodedReply tagName string - addResponseCode func(name string, responseCode apiModel.PlcResponseCode) - addPlcValue func(name string, plcValue apiValues.PlcValue) + addResponseCode func(t *testing.T) func(name string, responseCode apiModel.PlcResponseCode) + addPlcValue func(t *testing.T) func(name string, plcValue apiValues.PlcValue) } tests := []struct { name string @@ -314,10 +316,18 @@ func TestMapEncodedReply(t *testing.T) { }) return transaction }(), - encodedReply: nil, - tagName: "", - addResponseCode: nil, - addPlcValue: nil, + encodedReply: nil, + tagName: "", + addResponseCode: func(t *testing.T) func(name string, responseCode apiModel.PlcResponseCode) { + return func(name string, responseCode apiModel.PlcResponseCode) { + // NO-OP + } + }, + addPlcValue: func(t *testing.T) func(name string, plcValue apiValues.PlcValue) { + return func(name string, plcValue apiValues.PlcValue) { + // NO-OP + } + }, }, }, { @@ -332,23 +342,1075 @@ func TestMapEncodedReply(t *testing.T) { return transaction }(), encodedReply: func() readWriteModel.EncodedReplyCALReply { - calDataStatus := readWriteModel.NewCALDataStatus(readWriteModel.ApplicationIdContainer_LIGHTING_3A, 0, nil, readWriteModel.CALCommandTypeContainer_CALCommandStatus_0Bytes, nil, nil) + statusBytes := []readWriteModel.StatusByte{ + readWriteModel.NewStatusByte(readWriteModel.GAVState_ON, readWriteModel.GAVState_ERROR, readWriteModel.GAVState_DOES_NOT_EXIST, readWriteModel.GAVState_OFF), + readWriteModel.NewStatusByte(readWriteModel.GAVState_ON, readWriteModel.GAVState_ERROR, readWriteModel.GAVState_DOES_NOT_EXIST, readWriteModel.GAVState_OFF), + } + calDataStatus := readWriteModel.NewCALDataStatus(readWriteModel.ApplicationIdContainer_LIGHTING_3A, 0, statusBytes, readWriteModel.CALCommandTypeContainer_CALCommandStatus_0Bytes, nil, nil) calReplyShort := readWriteModel.NewCALReplyShort(0, calDataStatus, nil, nil) return readWriteModel.NewEncodedReplyCALReply(calReplyShort, 0, nil, nil) }(), tagName: "someTag", - addResponseCode: func(name string, responseCode apiModel.PlcResponseCode) { - // TODO: add assertions + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct( + map[string]apiValues.PlcValue{ + "application": spiValues.NewPlcSTRING("LIGHTING_3A"), + "blockStart": spiValues.NewPlcBYTE(0x0), + "values": spiValues.NewPlcList([]apiValues.PlcValue{ + spiValues.NewPlcSTRING("OFF"), + spiValues.NewPlcSTRING("DOES_NOT_EXIST"), + spiValues.NewPlcSTRING("ERROR"), + spiValues.NewPlcSTRING("ON"), + spiValues.NewPlcSTRING("OFF"), + spiValues.NewPlcSTRING("DOES_NOT_EXIST"), + spiValues.NewPlcSTRING("ERROR"), + spiValues.NewPlcSTRING("ON"), + }), + }, + ), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataStatusExtendedExactly (binary)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + statusBytes := []readWriteModel.StatusByte{ + readWriteModel.NewStatusByte(readWriteModel.GAVState_ON, readWriteModel.GAVState_ERROR, readWriteModel.GAVState_DOES_NOT_EXIST, readWriteModel.GAVState_OFF), + readWriteModel.NewStatusByte(readWriteModel.GAVState_ON, readWriteModel.GAVState_ERROR, readWriteModel.GAVState_DOES_NOT_EXIST, readWriteModel.GAVState_OFF), + } + calDataStatus := readWriteModel.NewCALDataStatusExtended(readWriteModel.StatusCoding_BINARY_BY_THIS_SERIAL_INTERFACE, readWriteModel.ApplicationIdContainer_LIGHTING_3A, 0, statusBytes, nil, readWriteModel.CALCommandTypeContainer_CALCommandStatus_0Bytes, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataStatus, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct( + map[string]apiValues.PlcValue{ + "application": spiValues.NewPlcSTRING("LIGHTING_3A"), + "blockStart": spiValues.NewPlcBYTE(0x0), + "values": spiValues.NewPlcList([]apiValues.PlcValue{ + spiValues.NewPlcSTRING("OFF"), + spiValues.NewPlcSTRING("DOES_NOT_EXIST"), + spiValues.NewPlcSTRING("ERROR"), + spiValues.NewPlcSTRING("ON"), + spiValues.NewPlcSTRING("OFF"), + spiValues.NewPlcSTRING("DOES_NOT_EXIST"), + spiValues.NewPlcSTRING("ERROR"), + spiValues.NewPlcSTRING("ON"), + }), + }, + ), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataStatusExtendedExactly (level)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + levelInformation := []readWriteModel.LevelInformation{ + readWriteModel.NewLevelInformationNormal(readWriteModel.LevelInformationNibblePair_Value_A, readWriteModel.LevelInformationNibblePair_Value_F, 13), + readWriteModel.NewLevelInformationAbsent(13), + readWriteModel.NewLevelInformationCorrupted(13, 14, 15, 16, 17), + } + calDataStatus := readWriteModel.NewCALDataStatusExtended(readWriteModel.StatusCoding_LEVEL_BY_THIS_SERIAL_INTERFACE, readWriteModel.ApplicationIdContainer_LIGHTING_3A, 0, nil, levelInformation, readWriteModel.CALCommandTypeContainer_CALCommandStatus_0Bytes, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataStatus, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcList( + []apiValues.PlcValue{ + spiValues.NewPlcUSINT(250), + spiValues.NewPlcSTRING("is absent"), + spiValues.NewPlcSTRING("corrupted"), + }, + ), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (sense levels)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandCurrentSenseLevels([]byte{1, 2, 3, 4}, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_CurrentSenseLevels, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (delays)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandDelays([]byte{1, 2, 3, 4}, 5, 5) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_Delays, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "reStrikeDelay": spiValues.NewPlcUSINT(5), + "terminalLevel": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (dsi status)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandDSIStatus( + readWriteModel.ChannelStatus_OK, + readWriteModel.ChannelStatus_LAMP_FAULT, + readWriteModel.ChannelStatus_CURRENT_LIMIT_OR_SHORT, + readWriteModel.ChannelStatus_OK, + readWriteModel.ChannelStatus_OK, + readWriteModel.ChannelStatus_OK, + readWriteModel.ChannelStatus_OK, + readWriteModel.ChannelStatus_OK, + readWriteModel.UnitStatus_OK, + 12, + 9, + ) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "channelStatus1": spiValues.NewPlcSTRING("OK"), + "channelStatus2": spiValues.NewPlcSTRING("LAMP_FAULT"), + "channelStatus3": spiValues.NewPlcSTRING("CURRENT_LIMIT_OR_SHORT"), + "channelStatus4": spiValues.NewPlcSTRING("OK"), + "channelStatus5": spiValues.NewPlcSTRING("OK"), + "channelStatus6": spiValues.NewPlcSTRING("OK"), + "channelStatus7": spiValues.NewPlcSTRING("OK"), + "channelStatus8": spiValues.NewPlcSTRING("OK"), + "dimmingUCRevisionNumber": spiValues.NewPlcUSINT(12), + "unitStatus": spiValues.NewPlcSTRING("OK"), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (extended diagnostic summary)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandExtendedDiagnosticSummary( + readWriteModel.ApplicationIdContainer_LIGHTING_3B, + readWriteModel.ApplicationIdContainer_LIGHTING_3C, + 12, + 13, + 14, + 15, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + true, + 8, + ) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "lowApplication": spiValues.NewPlcSTRING("LIGHTING_3B"), + "highApplication": spiValues.NewPlcSTRING("LIGHTING_3C"), + "area": spiValues.NewPlcUSINT(12), + "crc": spiValues.NewPlcUINT(13), + "serialNumber": spiValues.NewPlcUDINT(14), + "networkVoltage": spiValues.NewPlcUSINT(15), + "unitInLearnMode": spiValues.NewPlcBOOL(true), + "networkVoltageLow": spiValues.NewPlcBOOL(true), + "networkVoltageMarginal": spiValues.NewPlcBOOL(true), + "enableChecksumAlarm": spiValues.NewPlcBOOL(true), + "outputUnit": spiValues.NewPlcBOOL(true), + "installationMMIError": spiValues.NewPlcBOOL(true), + "EEWriteError": spiValues.NewPlcBOOL(true), + "EEChecksumError": spiValues.NewPlcBOOL(true), + "EEDataError": spiValues.NewPlcBOOL(true), + "microReset": spiValues.NewPlcBOOL(true), + "commsTxError": spiValues.NewPlcBOOL(true), + "internalStackOverflow": spiValues.NewPlcBOOL(true), + "microPowerReset": spiValues.NewPlcBOOL(true), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (summary)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandSummary("pineapple", 1, "13", 3) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "partName": spiValues.NewPlcSTRING("pineapple"), + "unitServiceType": spiValues.NewPlcUSINT(1), + "version": spiValues.NewPlcSTRING("13"), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (firmware version)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandFirmwareVersion("13", 1) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcSTRING("13"), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (GAV physical addresses)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandGAVPhysicalAddresses([]byte{1, 2, 3, 4}, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (GAV values current)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandGAVValuesCurrent([]byte{1, 2, 3, 4}, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (GAV values stored)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandGAVValuesStored([]byte{1, 2, 3, 4}, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (logical assignment)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandLogicalAssignment([]readWriteModel.LogicAssignment{ + readWriteModel.NewLogicAssignment(true, true, true, true, true, true), + readWriteModel.NewLogicAssignment(true, true, true, true, true, true), + }, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcList([]apiValues.PlcValue{ + spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "greaterOfOrLogic": spiValues.NewPlcBOOL(true), + "reStrikeDelay": spiValues.NewPlcBOOL(true), + "assignedToGav16": spiValues.NewPlcBOOL(true), + "assignedToGav15": spiValues.NewPlcBOOL(true), + "assignedToGav14": spiValues.NewPlcBOOL(true), + "assignedToGav13": spiValues.NewPlcBOOL(true), + }), + spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "greaterOfOrLogic": spiValues.NewPlcBOOL(true), + "reStrikeDelay": spiValues.NewPlcBOOL(true), + "assignedToGav16": spiValues.NewPlcBOOL(true), + "assignedToGav15": spiValues.NewPlcBOOL(true), + "assignedToGav14": spiValues.NewPlcBOOL(true), + "assignedToGav13": spiValues.NewPlcBOOL(true), + }), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (manufacturer)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandManufacturer("Apache", 13) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcSTRING("Apache"), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (maximum levels)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandMaximumLevels([]byte{1, 2, 3, 4}, 1) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (minimum levels)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandMinimumLevels([]byte{1, 2, 3, 4}, 1) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (terminal levels)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandTerminalLevels([]byte{1, 2, 3, 4}, 1) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (network voltage)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandNetworkVoltage("13.3", "3", 3) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcLREAL(13.600000000000001), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (output unit summary)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + gavStoreEnabledByte1 := byte(2) + gavStoreEnabledByte2 := byte(3) + command := readWriteModel.NewIdentifyReplyCommandOutputUnitSummary(readWriteModel.NewIdentifyReplyCommandUnitSummary(true, true, true, true, true, true, true, true), &gavStoreEnabledByte1, &gavStoreEnabledByte2, 13, 13) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "unitFlags": spiValues.NewPlcStruct(map[string]apiValues.PlcValue{ + "assertingNetworkBurden": spiValues.NewPlcBOOL(true), + "restrikeTimingActive": spiValues.NewPlcBOOL(true), + "remoteOFFInputAsserted": spiValues.NewPlcBOOL(true), + "remoteONInputAsserted": spiValues.NewPlcBOOL(true), + "localToggleEnabled": spiValues.NewPlcBOOL(true), + "localToggleActiveState": spiValues.NewPlcBOOL(true), + "clockGenerationEnabled": spiValues.NewPlcBOOL(true), + "unitGeneratingClock": spiValues.NewPlcBOOL(true), + }), + "timeFromLastRecoverOfMainsInSeconds": spiValues.NewPlcUSINT(13), + "gavStoreEnabledByte1": spiValues.NewPlcUSINT(2), + "gavStoreEnabledByte2": spiValues.NewPlcUSINT(3), + }), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (terminal levels)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandTerminalLevels([]byte{1, 2, 3, 4}, 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } + }, + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcRawByteArray([]byte{1, 2, 3, 4}), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } + }, + }, + }, + { + name: "CALDataIdentifyReplyExactly (type)", + args: args{ + transaction: func() spi.RequestTransaction { + transactionManager := spi.NewRequestTransactionManager(1) + transaction := transactionManager.StartTransaction() + transaction.Submit(func() { + // NO-OP + }) + return transaction + }(), + encodedReply: func() readWriteModel.EncodedReplyCALReply { + command := readWriteModel.NewIdentifyReplyCommandType("chonkers", 4) + calDataIdentify := readWriteModel.NewCALDataIdentifyReply(readWriteModel.Attribute_DSIStatus, command, readWriteModel.CALCommandTypeContainer_CALCommandIdentify, nil, nil) + calReplyLong := readWriteModel.NewCALReplyLong(0, readWriteModel.NewUnitAddress(1), readWriteModel.NewBridgeAddress(2), readWriteModel.NewSerialInterfaceAddress(3), nil, nil, 0, calDataIdentify, nil, nil) + return readWriteModel.NewEncodedReplyCALReply(calReplyLong, 0, nil, nil) + }(), + tagName: "someTag", + addResponseCode: func(t *testing.T) func(string, apiModel.PlcResponseCode) { + codes := map[string]apiModel.PlcResponseCode{ + "someTag": apiModel.PlcResponseCode_OK, + } + return func(name string, responseCode apiModel.PlcResponseCode) { + if code, ok := codes[name]; ok { + assert.Equal(t, code, responseCode) + } else { + t.Errorf("code for %s not found", name) + } + } }, - addPlcValue: func(name string, plcValue apiValues.PlcValue) { - // TODO: add assertions + addPlcValue: func(t *testing.T) func(string, apiValues.PlcValue) { + values := map[string]apiValues.PlcValue{ + "someTag": spiValues.NewPlcSTRING("chonkers"), + } + return func(name string, plcValue apiValues.PlcValue) { + if value, ok := values[name]; ok { + assert.Equal(t, value, plcValue) + } else { + t.Errorf("value for %s not found", name) + } + } }, }, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := MapEncodedReply(tt.args.transaction, tt.args.encodedReply, tt.args.tagName, tt.args.addResponseCode, tt.args.addPlcValue); (err != nil) != tt.wantErr { + if err := MapEncodedReply(tt.args.transaction, tt.args.encodedReply, tt.args.tagName, tt.args.addResponseCode(t), tt.args.addPlcValue(t)); (err != nil) != tt.wantErr { t.Errorf("MapEncodedReply() error = %v, wantErr %v", err, tt.wantErr) } })
