Skip to content

Commit

Permalink
Added mide msg tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Aug 7, 2021
1 parent 5b5e308 commit 03526b8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ test:
@export PATH=$$PATH:~/go/bin && richgo test -v ./... || echo "Uh-oh ... 🔥"

rebuild: clean all

.PHONY: test
59 changes: 59 additions & 0 deletions test/erl/messages_midi_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 03526b8

Please sign in to comment.