Testing (and fixed) SysEx codec.
Now conforms to Somascape specs.
This commit is contained in:
parent
22d6bb8cf2
commit
d42acc0cbb
|
|
@ -55,7 +55,7 @@ unsigned encodeSysEx(const byte* inData, byte* outSysEx, unsigned inLength)
|
|||
const byte msb = data >> 7;
|
||||
const byte body = data & 0x7f;
|
||||
|
||||
outSysEx[0] |= (msb << count);
|
||||
outSysEx[0] |= (msb << (6 - count));
|
||||
outSysEx[1 + count] = body;
|
||||
|
||||
if (count++ == 6)
|
||||
|
|
@ -84,17 +84,20 @@ unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLength)
|
|||
{
|
||||
unsigned count = 0;
|
||||
byte msbStorage = 0;
|
||||
byte byteIndex = 0;
|
||||
|
||||
for (unsigned i = 0; i < inLength; ++i)
|
||||
{
|
||||
if ((i % 8) == 0)
|
||||
{
|
||||
msbStorage = inSysEx[i];
|
||||
byteIndex = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
outData[count++] = inSysEx[i] | ((msbStorage & 1) << 7);
|
||||
msbStorage >>= 1;
|
||||
const byte body = inSysEx[i];
|
||||
const byte msb = ((msbStorage >> byteIndex--) & 1) << 7;
|
||||
outData[count++] = msb | body;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ project(unit-tests)
|
|||
include_directories(
|
||||
${unit-tests_SOURCE_DIR}
|
||||
${gtest_SOURCE_DIR}/include
|
||||
${gmock_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
add_executable(unit-tests
|
||||
|
|
@ -13,10 +14,12 @@ add_executable(unit-tests
|
|||
|
||||
tests/unit-tests_MidiMessage.cpp
|
||||
tests/unit-tests_Settings.cpp
|
||||
tests/unit-tests_SysExCodec.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(unit-tests
|
||||
gtest
|
||||
gmock
|
||||
midi
|
||||
test-mocks
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,103 @@
|
|||
#include "unit-tests.h"
|
||||
#include <src/MIDI.h>
|
||||
|
||||
BEGIN_MIDI_NAMESPACE
|
||||
|
||||
END_MIDI_NAMESPACE
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
BEGIN_UNNAMED_NAMESPACE
|
||||
|
||||
using namespace testing;
|
||||
|
||||
TEST(SysExCodec, Encoder)
|
||||
{
|
||||
// ASCII content
|
||||
{
|
||||
const byte input[] = "Hello, World!";
|
||||
byte buffer[32];
|
||||
memset(buffer, 0, 32 * sizeof(byte));
|
||||
const unsigned encodedSize = midi::encodeSysEx(input, buffer, 13);
|
||||
EXPECT_EQ(encodedSize, 15);
|
||||
const byte expected[32] = {
|
||||
0, 'H', 'e', 'l', 'l', 'o', ',', ' ',
|
||||
0, 'W', 'o', 'r', 'l', 'd', '!', 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
EXPECT_THAT(buffer, Each(Le(0x7f))); // All elements are <= 127
|
||||
EXPECT_THAT(buffer, ContainerEq(expected));
|
||||
}
|
||||
// Non-ASCII content
|
||||
{
|
||||
const byte input[] = {
|
||||
182, 236, 167, 177, 61, 91, 120, // 01111000 -> 120
|
||||
107, 94, 209, 87, 94 // 000100xx -> 16
|
||||
};
|
||||
byte buffer[32];
|
||||
memset(buffer, 0, 32 * sizeof(byte));
|
||||
const unsigned encodedSize = midi::encodeSysEx(input, buffer, 12);
|
||||
EXPECT_EQ(encodedSize, 14);
|
||||
const byte expected[32] = {
|
||||
// MSB Data
|
||||
120, 54, 108, 39, 49, 61, 91, 120,
|
||||
16, 107, 94, 81, 87, 94, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
EXPECT_THAT(buffer, Each(Le(0x7f))); // All elements are <= 127
|
||||
EXPECT_THAT(buffer, ContainerEq(expected));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SysExCodec, Decoder)
|
||||
{
|
||||
// ASCII content
|
||||
{
|
||||
const byte input[] = {
|
||||
0, 'H', 'e', 'l', 'l', 'o', ',', ' ',
|
||||
0, 'W', 'o', 'r', 'l', 'd', '!',
|
||||
};
|
||||
byte buffer[32];
|
||||
memset(buffer, 0, 32 * sizeof(byte));
|
||||
const unsigned decodedSize = midi::decodeSysEx(input, buffer, 15);
|
||||
EXPECT_EQ(decodedSize, 13);
|
||||
const byte expected[32] = {
|
||||
'H', 'e', 'l', 'l', 'o', ',', ' ', 'W',
|
||||
'o', 'r', 'l', 'd', '!', 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
EXPECT_THAT(buffer, Each(Le(0x7f))); // All elements are <= 127
|
||||
EXPECT_THAT(buffer, ContainerEq(expected));
|
||||
}
|
||||
// Non-ASCII content
|
||||
{
|
||||
const byte input[] = {
|
||||
// MSB Data
|
||||
120, 54, 108, 39, 49, 61, 91, 120,
|
||||
16, 107, 94, 81, 87, 94,
|
||||
};
|
||||
byte buffer[32];
|
||||
memset(buffer, 0, 32 * sizeof(byte));
|
||||
const unsigned encodedSize = midi::decodeSysEx(input, buffer, 14);
|
||||
EXPECT_EQ(encodedSize, 12);
|
||||
const byte expected[32] = {
|
||||
182, 236, 167, 177, 61, 91, 120,
|
||||
107, 94, 209, 87, 94, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0
|
||||
};
|
||||
EXPECT_THAT(input, Each(Le(0x7f))); // All elements are <= 127
|
||||
EXPECT_THAT(buffer, ContainerEq(expected));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SysExCodec, Codec)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
END_UNNAMED_NAMESPACE
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "unit-tests_Namespace.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
BEGIN_UNIT_TESTS_NAMESPACE
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue