<commit_before>#ifdef UART_INTERFACES
#if UART_INTERFACES > 0

#include "unity/src/unity.h"
#include "unity/Helpers.h"
#include "board/Board.h"
#include "common/OpenDeckMIDIformat/OpenDeckMIDIformat.h"
#include "core/src/general/RingBuffer.h"

#define TEST_MIDI_CHANNEL 0
#define BUFFER_SIZE       50

namespace
{
    auto                                   rebootType = Board::rebootType_t::rebootApp;
    core::RingBuffer<uint8_t, BUFFER_SIZE> buffer;
}    // namespace

namespace Board
{
    void reboot(Board::rebootType_t type)
    {
        rebootType = type;
    }

    namespace UART
    {
        bool read(uint8_t channel, uint8_t& data)
        {
            return buffer.remove(data);
        }

        bool write(uint8_t channel, uint8_t data)
        {
            TEST_ASSERT(buffer.insert(data) == true);
            return true;
        }
    }    // namespace UART
}    // namespace Board

TEST_CASE(MIDI)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(MIDI::messageType_t::noteOn);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    TEST_ASSERT(OpenDeckMIDIformat::write(TEST_MIDI_CHANNEL, sending, OpenDeckMIDIformat::packetType_t::midi) == true);
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    TEST_ASSERT(receivedPacketType == OpenDeckMIDIformat::packetType_t::midi);

    TEST_ASSERT(receiving.Event == static_cast<uint8_t>(MIDI::messageType_t::noteOn));
    TEST_ASSERT(receiving.Data1 == 0x10);
    TEST_ASSERT(receiving.Data2 == 0x20);
    TEST_ASSERT(receiving.Data3 == 0x30);

    //nothing left in the buffer - read should return false
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
}

TEST_CASE(InternalCMD)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(OpenDeckMIDIformat::command_t::btldrReboot);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    //change the state to app reboot first - after reading this should be switched to rebootBtldr
    rebootType = Board::rebootType_t::rebootApp;

    TEST_ASSERT(OpenDeckMIDIformat::write(TEST_MIDI_CHANNEL, sending, OpenDeckMIDIformat::packetType_t::internalCommand) == true);
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    TEST_ASSERT(receivedPacketType == OpenDeckMIDIformat::packetType_t::internalCommand);

    //in case of internal commands, Event, Data1, Data2 and Data3 are fully ignored - only the
    //specific function is called
    TEST_ASSERT(rebootType == Board::rebootType_t::rebootBtldr);

    //nothing left in the buffer - read should return false
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
}

TEST_CASE(ManualPacketBuilding)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(OpenDeckMIDIformat::command_t::btldrReboot);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    uint8_t dataXor = sending.Event ^ sending.Data1 ^ sending.Data2 ^ sending.Data3;

    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, dataXor));

    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    //now send the same packet but with XOR byte being wrong
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, 0x00));

    rebootType = Board::rebootType_t::rebootApp;

    //read should return false and btldr reboot function shouldn't be called
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
    TEST_ASSERT(rebootType == Board::rebootType_t::rebootApp);

    //try building valid packet, and then start another one in the middle without first one being finished properly
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    //now start another one
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));<commit_msg>tests: change wrong value for open deck midi format test<commit_after>#ifdef UART_INTERFACES
#if UART_INTERFACES > 0

#include "unity/src/unity.h"
#include "unity/Helpers.h"
#include "board/Board.h"
#include "common/OpenDeckMIDIformat/OpenDeckMIDIformat.h"
#include "core/src/general/RingBuffer.h"

#define TEST_MIDI_CHANNEL 0
#define BUFFER_SIZE       50

namespace
{
    auto                                   rebootType = Board::rebootType_t::rebootApp;
    core::RingBuffer<uint8_t, BUFFER_SIZE> buffer;
}    // namespace

namespace Board
{
    void reboot(Board::rebootType_t type)
    {
        rebootType = type;
    }

    namespace UART
    {
        bool read(uint8_t channel, uint8_t& data)
        {
            return buffer.remove(data);
        }

        bool write(uint8_t channel, uint8_t data)
        {
            TEST_ASSERT(buffer.insert(data) == true);
            return true;
        }
    }    // namespace UART
}    // namespace Board

TEST_CASE(MIDI)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(MIDI::messageType_t::noteOn);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    TEST_ASSERT(OpenDeckMIDIformat::write(TEST_MIDI_CHANNEL, sending, OpenDeckMIDIformat::packetType_t::midi) == true);
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    TEST_ASSERT(receivedPacketType == OpenDeckMIDIformat::packetType_t::midi);

    TEST_ASSERT(receiving.Event == static_cast<uint8_t>(MIDI::messageType_t::noteOn));
    TEST_ASSERT(receiving.Data1 == 0x10);
    TEST_ASSERT(receiving.Data2 == 0x20);
    TEST_ASSERT(receiving.Data3 == 0x30);

    //nothing left in the buffer - read should return false
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
}

TEST_CASE(InternalCMD)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(OpenDeckMIDIformat::command_t::btldrReboot);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    //change the state to app reboot first - after reading this should be switched to rebootBtldr
    rebootType = Board::rebootType_t::rebootApp;

    TEST_ASSERT(OpenDeckMIDIformat::write(TEST_MIDI_CHANNEL, sending, OpenDeckMIDIformat::packetType_t::internalCommand) == true);
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    TEST_ASSERT(receivedPacketType == OpenDeckMIDIformat::packetType_t::internalCommand);

    //in case of internal commands, Event, Data1, Data2 and Data3 are fully ignored - only the
    //specific function is called
    TEST_ASSERT(rebootType == Board::rebootType_t::rebootBtldr);

    //nothing left in the buffer - read should return false
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
}

TEST_CASE(ManualPacketBuilding)
{
    MIDI::USBMIDIpacket_t            sending;
    MIDI::USBMIDIpacket_t            receiving;
    OpenDeckMIDIformat::packetType_t receivedPacketType;

    sending.Event = static_cast<uint8_t>(OpenDeckMIDIformat::command_t::btldrReboot);
    sending.Data1 = 0x10;
    sending.Data2 = 0x20;
    sending.Data3 = 0x30;

    uint8_t dataXor = sending.Event ^ sending.Data1 ^ sending.Data2 ^ sending.Data3;

    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, dataXor));

    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == true);

    //now send the same packet but with XOR byte being wrong
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, 0xFF));

    rebootType = Board::rebootType_t::rebootApp;

    //read should return false and btldr reboot function shouldn't be called
    TEST_ASSERT(OpenDeckMIDIformat::read(TEST_MIDI_CHANNEL, receiving, receivedPacketType) == false);
    TEST_ASSERT(rebootType == Board::rebootType_t::rebootApp);

    //try building valid packet, and then start another one in the middle without first one being finished properly
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    //now start another one
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, static_cast<uint8_t>(OpenDeckMIDIformat::packetType_t::internalCommand)));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Event));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data1));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data2));
    TEST_ASSERT(true == Board::UART::write(TEST_MIDI_CHANNEL, sending.Data3));
{'fraction_non_alphanumeric': 0.11517834340682727, 'fraction_numerical': 0.0141312675576743, 'mean_word_length': 4.787192118226601, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '485323', 'n_tokens_mistral': 4076, 'n_tokens_neox': 3942, 'n_words': 636}