From 03707964ee9a5bd6281181fa23d2878263a1e00c Mon Sep 17 00:00:00 2001 From: lathoub Date: Mon, 23 Mar 2020 21:19:01 +0100 Subject: [PATCH] setting the CMake env --- src/CMakeLists.txt | 1 + test/mocks/CMakeLists.txt | 2 + test/mocks/midi_RingBuffer.h | 62 +++++++++ test/mocks/midi_RingBuffer.hpp | 121 ++++++++++++++++++ test/mocks/test-mocks_SerialMock.h | 2 +- test/unit-tests/CMakeLists.txt | 5 +- test/unit-tests/tests/unit-tests_Platform.cpp | 15 +++ test/unit-tests/tests/unit-tests_Platform.h | 12 ++ test/unit-tests/tests/unit-tests_Settings.cpp | 1 - 9 files changed, 216 insertions(+), 5 deletions(-) create mode 100644 test/mocks/midi_RingBuffer.h create mode 100644 test/mocks/midi_RingBuffer.hpp create mode 100644 test/unit-tests/tests/unit-tests_Platform.cpp create mode 100644 test/unit-tests/tests/unit-tests_Platform.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b2a7169..b9672fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(midi STATIC midi_Namespace.h midi_Defs.h midi_Message.h + midi_Platform.h midi_Settings.h MIDI.cpp MIDI.hpp diff --git a/test/mocks/CMakeLists.txt b/test/mocks/CMakeLists.txt index 5322dfb..fd07022 100644 --- a/test/mocks/CMakeLists.txt +++ b/test/mocks/CMakeLists.txt @@ -7,6 +7,8 @@ add_library(test-mocks STATIC test-mocks_SerialMock.cpp test-mocks_SerialMock.hpp test-mocks_SerialMock.h + midi_RingBuffer.h + midi_RingBuffer.hpp ) target_link_libraries(test-mocks diff --git a/test/mocks/midi_RingBuffer.h b/test/mocks/midi_RingBuffer.h new file mode 100644 index 0000000..da2266c --- /dev/null +++ b/test/mocks/midi_RingBuffer.h @@ -0,0 +1,62 @@ +/*! + * @file midi_RingBuffer.h + * Project Arduino MIDI Library + * @brief MIDI Library for Arduino - Ring Buffer + * @author Francois Best + * @date 10/10/2016 + * @license MIT - Copyright (c) 2016 Francois Best + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include "midi_Namespace.h" + +BEGIN_MIDI_NAMESPACE + +template +class RingBuffer +{ +public: + RingBuffer(); + ~RingBuffer(); + +public: + int getLength() const; + bool isEmpty() const; + +public: + void write(DataType inData); + void write(const DataType* inData, int inSize); + void clear(); + +public: + DataType read(); + void read(DataType* outData, int inSize); + +private: + DataType mData[Size]; + DataType* mWriteHead; + DataType* mReadHead; +}; + +END_MIDI_NAMESPACE + +#include "midi_RingBuffer.hpp" diff --git a/test/mocks/midi_RingBuffer.hpp b/test/mocks/midi_RingBuffer.hpp new file mode 100644 index 0000000..9c273c9 --- /dev/null +++ b/test/mocks/midi_RingBuffer.hpp @@ -0,0 +1,121 @@ +/*! + * @file midi_RingBuffer.hpp + * Project Arduino MIDI Library + * @brief MIDI Library for Arduino - Ring Buffer + * @author Francois Best + * @date 10/10/2016 + * @license MIT - Copyright (c) 2016 Francois Best + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +BEGIN_MIDI_NAMESPACE + +template +RingBuffer::RingBuffer() + : mWriteHead(mData) + , mReadHead(mData) +{ + memset(mData, DataType(0), Size * sizeof(DataType)); +} + +template +RingBuffer::~RingBuffer() +{ +} + +// ----------------------------------------------------------------------------- + +template +int RingBuffer::getLength() const +{ + if (mReadHead == mWriteHead) + { + return 0; + } + else if (mWriteHead > mReadHead) + { + return int(mWriteHead - mReadHead); + } + else + { + return int(mWriteHead - mData) + Size - int(mReadHead - mData); + } +} + +template +bool RingBuffer::isEmpty() const +{ + return mReadHead == mWriteHead; +} + +// ----------------------------------------------------------------------------- + +template +void RingBuffer::write(DataType inData) +{ + *mWriteHead++ = inData; + if (mWriteHead >= mData + Size) + { + mWriteHead = mData; + } +} + +template +void RingBuffer::write(const DataType* inData, int inSize) +{ + for (int i = 0; i < inSize; ++i) + { + write(inData[i]); + } +} + +template +void RingBuffer::clear() +{ + memset(mData, DataType(0), Size * sizeof(DataType)); + mReadHead = mData; + mWriteHead = mData; +} + +// ----------------------------------------------------------------------------- + +template +DataType RingBuffer::read() +{ + const DataType data = *mReadHead++; + if (mReadHead >= mData + Size) + { + mReadHead = mData; + } + return data; +} + +template +void RingBuffer::read(DataType* outData, int inSize) +{ + for (int i = 0; i < inSize; ++i) + { + outData[i] = read(); + } +} + +END_MIDI_NAMESPACE diff --git a/test/mocks/test-mocks_SerialMock.h b/test/mocks/test-mocks_SerialMock.h index f3ab833..c739e0b 100644 --- a/test/mocks/test-mocks_SerialMock.h +++ b/test/mocks/test-mocks_SerialMock.h @@ -2,7 +2,7 @@ #include "test-mocks.h" #include -#include +#include BEGIN_TEST_MOCKS_NAMESPACE diff --git a/test/unit-tests/CMakeLists.txt b/test/unit-tests/CMakeLists.txt index a63cbd4..2c8ff85 100644 --- a/test/unit-tests/CMakeLists.txt +++ b/test/unit-tests/CMakeLists.txt @@ -6,7 +6,6 @@ include_directories( "${unit-tests_SOURCE_DIR}" "${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include" - "${ROOT_SOURCE_DIR}/external/midi-usb/src" ) add_executable(unit-tests @@ -17,14 +16,14 @@ add_executable(unit-tests tests/unit-tests_MidiMessage.cpp tests/unit-tests_Settings.cpp tests/unit-tests_Settings.h + tests/unit-tests_Platform.cpp + tests/unit-tests_Platform.h tests/unit-tests_SysExCodec.cpp tests/unit-tests_RingBuffer.cpp tests/unit-tests_MidiInput.cpp tests/unit-tests_MidiInputCallbacks.cpp tests/unit-tests_MidiOutput.cpp tests/unit-tests_MidiThru.cpp - tests/unit-tests_MidiUsbDefs.cpp - tests/unit-tests_MidiUsbPacketInterface.cpp ) target_link_libraries(unit-tests diff --git a/test/unit-tests/tests/unit-tests_Platform.cpp b/test/unit-tests/tests/unit-tests_Platform.cpp new file mode 100644 index 0000000..f4a5b6b --- /dev/null +++ b/test/unit-tests/tests/unit-tests_Platform.cpp @@ -0,0 +1,15 @@ +#include "unit-tests_Platform.h" + +BEGIN_MIDI_NAMESPACE + +END_MIDI_NAMESPACE + +// ----------------------------------------------------------------------------- + +BEGIN_UNNAMED_NAMESPACE + +TEST(Platform, hasTheRightDefaultValues) +{ +} + +END_UNNAMED_NAMESPACE diff --git a/test/unit-tests/tests/unit-tests_Platform.h b/test/unit-tests/tests/unit-tests_Platform.h new file mode 100644 index 0000000..0f90660 --- /dev/null +++ b/test/unit-tests/tests/unit-tests_Platform.h @@ -0,0 +1,12 @@ +#pragma once + +#include "unit-tests.h" +#include + +BEGIN_UNIT_TESTS_NAMESPACE + +struct VariablePlatform : public midi::DefaultPlatform +{ +}; + +END_UNIT_TESTS_NAMESPACE diff --git a/test/unit-tests/tests/unit-tests_Settings.cpp b/test/unit-tests/tests/unit-tests_Settings.cpp index cfb1326..859db19 100644 --- a/test/unit-tests/tests/unit-tests_Settings.cpp +++ b/test/unit-tests/tests/unit-tests_Settings.cpp @@ -5,7 +5,6 @@ BEGIN_MIDI_NAMESPACE const bool DefaultSettings::UseRunningStatus; const bool DefaultSettings::HandleNullVelocityNoteOnAsNoteOff; const bool DefaultSettings::Use1ByteParsing; -const long DefaultSettings::BaudRate; const unsigned DefaultSettings::SysExMaxSize; END_MIDI_NAMESPACE