From 03526b8f40980cb259c70c65dcbc49d6d4a5a962 Mon Sep 17 00:00:00 2001 From: Duncan McGreggor Date: Sat, 7 Aug 2021 02:07:27 -0500 Subject: [PATCH] Added mide msg tests. --- Makefile | 2 ++ test/erl/messages_midi_test.go | 59 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/erl/messages_midi_test.go diff --git a/Makefile b/Makefile index 47c8ace..5404f53 100644 --- a/Makefile +++ b/Makefile @@ -59,3 +59,5 @@ test: @export PATH=$$PATH:~/go/bin && richgo test -v ./... || echo "Uh-oh ... 🔥" rebuild: clean all + +.PHONY: test \ No newline at end of file diff --git a/test/erl/messages_midi_test.go b/test/erl/messages_midi_test.go new file mode 100644 index 0000000..986b47f --- /dev/null +++ b/test/erl/messages_midi_test.go @@ -0,0 +1,59 @@ +package erl + +// Basic imports +import ( + "testing" + + "github.com/stretchr/testify/suite" + + "github.com/geomyidia/midiserver/pkg/erl" + "github.com/geomyidia/midiserver/pkg/erl/messages" + "github.com/geomyidia/midiserver/pkg/erl/packets" + "github.com/geomyidia/midiserver/pkg/types" +) + +type MidiMessageTestSuite struct { + suite.Suite + batch interface{} + meter interface{} + tempo interface{} +} + +func (suite *MidiMessageTestSuite) SetupTest() { + batchBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x33, 0x36, 0x38, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x36, 0x36, 0x34, 0x36, 0x35, 0x37, 0x36, 0x36, 0x39, 0x36, 0x33, 0x36, 0x35, 0x36, 0x31, 0x30, 0x30, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x34, 0x36, 0x35, 0x37, 0x32, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x36, 0x45, 0x37, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x42, 0x36, 0x34, 0x36, 0x35, 0x36, 0x45, 0x36, 0x46, 0x36, 0x44, 0x36, 0x39, 0x36, 0x45, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x41, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x37, 0x34, 0x36, 0x35, 0x36, 0x44, 0x37, 0x30, 0x36, 0x46, 0x35, 0x46, 0x36, 0x32, 0x37, 0x30, 0x36, 0x44, 0x36, 0x31, 0x34, 0x34, 0x36, 0x41, 0xa} + meterBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x34, 0x36, 0x35, 0x37, 0x32, 0x36, 0x43, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x36, 0x45, 0x37, 0x35, 0x36, 0x44, 0x36, 0x35, 0x37, 0x32, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x42, 0x36, 0x34, 0x36, 0x35, 0x36, 0x45, 0x36, 0x46, 0x36, 0x44, 0x36, 0x39, 0x36, 0x45, 0x36, 0x31, 0x37, 0x34, 0x36, 0x46, 0x37, 0x32, 0x36, 0x31, 0x30, 0x34, 0x36, 0x41, 0xa} + tempoBytes := []byte{0x38, 0x33, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x34, 0x36, 0x44, 0x36, 0x39, 0x36, 0x34, 0x36, 0x39, 0x36, 0x38, 0x30, 0x32, 0x36, 0x34, 0x30, 0x30, 0x30, 0x39, 0x37, 0x34, 0x36, 0x35, 0x36, 0x44, 0x37, 0x30, 0x36, 0x46, 0x35, 0x46, 0x36, 0x32, 0x37, 0x30, 0x36, 0x44, 0x36, 0x31, 0x34, 0x34, 0xa} + opts := &erl.Opts{IsHexEncoded: true} + bPkt, _ := packets.NewPacket(batchBytes, opts) + suite.batch, _ = bPkt.Term() + mPkt, _ := packets.NewPacket(meterBytes, opts) + suite.meter, _ = mPkt.Term() + tPkt, _ := packets.NewPacket(tempoBytes, opts) + suite.tempo, _ = tPkt.Term() + +} + +func (suite *MidiMessageTestSuite) TestConvertTempo() { + converted, err := messages.Convert(suite.tempo) + suite.NoError(err) + suite.Equal(types.MidiTempo(), converted.Op) + suite.Equal(uint8(68), converted.Args.Tempo) +} + +func (suite *MidiMessageTestSuite) TestConvertMeter() { + // converted, err := messages.ConvertArgs(suite.meter) + // suite.NoError(err) + // suite.Equal(5, converted) +} + +func (suite *MidiMessageTestSuite) TestConvertBatch() { + // converted, err := messages.ConvertArgs(suite.batch) + // suite.NoError(err) + // suite.Equal(5, converted) +} + +// In order for 'go test' to run this suite, we need to create +// a normal test function and pass our suite to suite.Run +func TestMidiMessageTestSuite(t *testing.T) { + suite.Run(t, new(MidiMessageTestSuite)) +}