diff --git a/.github/ISSUE_TEMPLATE/api-deprecation.md b/.github/ISSUE_TEMPLATE/api-deprecation.md new file mode 100644 index 00000000..74e4c785 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/api-deprecation.md @@ -0,0 +1,25 @@ +--- +name: API deprecation +about: Suggest the deprecation of an API component defined by ArduinoCore-API. +title: "" +labels: enhancement +assignees: "" +--- + +### API component + + + +### Description + + + + +### Replacement API component + + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/api-improvement.md b/.github/ISSUE_TEMPLATE/api-improvement.md new file mode 100644 index 00000000..1cfa43bb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/api-improvement.md @@ -0,0 +1,24 @@ +--- +name: API improvement +about: Suggest an improvement to an existing API component. +title: "" +labels: enhancement +assignees: "" +--- + +### API component + + + +### Description + + + +### Is this a breaking change? + + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..cc410ae0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Report problems with the code in this repository. +title: "" +labels: bug +assignees: "" +--- + +### Description + + + +### Environment + +- Boards platform name: +- Boards platform version (as shown in Boards Manager): +- ArduinoCore-API version (if you manually installed it): + +### Current behavior + + + +### Expected behavior + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..af023790 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,10 @@ +contact_links: + - name: Learn about the Arduino language + url: https://www.arduino.cc/reference/en + about: User documentation is available at the Arduino language reference. + - name: Support request + url: https://forum.arduino.cc/ + about: We can help you out on the Arduino Forum! + - name: Discuss ArduinoCore-API development + url: https://groups.google.com/a/arduino.cc/g/developers + about: Arduino Developers Mailing List diff --git a/.github/ISSUE_TEMPLATE/new-api-component.md b/.github/ISSUE_TEMPLATE/new-api-component.md new file mode 100644 index 00000000..15991f46 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new-api-component.md @@ -0,0 +1,15 @@ +--- +name: New API component +about: Suggest the addition of a new API component to ArduinoCore-API. +title: "" +labels: enhancement +assignees: "" +--- + +### Description + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/other-enhancement.md b/.github/ISSUE_TEMPLATE/other-enhancement.md new file mode 100644 index 00000000..c72cea49 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other-enhancement.md @@ -0,0 +1,22 @@ +--- +name: Other enhancement +about: + Suggest an improvement for this project that doesn't fit in the specific categories + above. +title: "" +labels: enhancement +assignees: "" +--- + +### Description + + + +### Is this a breaking change? + + + + +### Additional information + + diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f72d58b1..55d5b650 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -38,8 +38,9 @@ jobs: coverage-data-path: ${{ env.COVERAGE_DATA_PATH }} # See: https://github.com/codecov/codecov-action/blob/master/README.md - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v1 + - name: Code coverage + uses: codecov/codecov-action@v3 with: - file: ${{ env.COVERAGE_DATA_PATH }} + token: ${{ secrets.CODECOV_TOKEN }} + files: ${{ env.COVERAGE_DATA_PATH }} fail_ci_if_error: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..93c700e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +.idea/ diff --git a/README.md b/README.md index 16367ce5..506569a8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ As of now, the following official cores are utilising ArduinoCore-API: * [megaavr](https://github.com/arduino/ArduinoCore-megaAVR) * [mbed](https://github.com/arduino/ArduinoCore-mbed) * [samd](https://github.com/arduino/ArduinoCore-samd) +* [renesas](https://github.com/arduino/ArduinoCore-renesas) There's an ongoing effort to port the others, while maintainers of third-party cores are strongly invited to follow the same route in order to stay up-to-date with the new language features. For backwards compatibility, every revision of this repo will increase the `ARDUINO_API_VERSION` define. @@ -77,6 +78,8 @@ In order to compile a core which is implementing ArduinoCore-API you'll need to tar --exclude='*.git*' -cjhvf $yourcore-$version.tar.bz2 $yourcore/ ``` +The API is coded to the C++11 standard and the core's compiler must be able to support that version of the language. + Documentation for how to integrate with a Arduino core (which is necessary if you do not download the Arduino core via the Boards Manager) can be found here: * [ArduinoCore-megaavr](https://github.com/arduino/ArduinoCore-megaavr#developing) * [ArduinoCore-mbed](https://github.com/arduino/ArduinoCore-mbed#clone-the-repository-in-sketchbookhardwarearduino-git) diff --git a/api/ArduinoAPI.h b/api/ArduinoAPI.h index edc04918..eae69497 100644 --- a/api/ArduinoAPI.h +++ b/api/ArduinoAPI.h @@ -20,8 +20,8 @@ #ifndef ARDUINO_API_H #define ARDUINO_API_H -// version 1.4.0 -#define ARDUINO_API_VERSION 10400 +// version 1.5.0 +#define ARDUINO_API_VERSION 10500 #include "Binary.h" diff --git a/api/CanMsg.cpp b/api/CanMsg.cpp new file mode 100644 index 00000000..1137f066 --- /dev/null +++ b/api/CanMsg.cpp @@ -0,0 +1,34 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsg.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * STATIC CONST DEFINITION + **************************************************************************************/ + +uint8_t const CanMsg::MAX_DATA_LENGTH; +uint32_t const CanMsg::CAN_EFF_FLAG; +uint32_t const CanMsg::CAN_SFF_MASK; +uint32_t const CanMsg::CAN_EFF_MASK; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ diff --git a/api/CanMsg.h b/api/CanMsg.h new file mode 100644 index 00000000..3e103c0b --- /dev/null +++ b/api/CanMsg.h @@ -0,0 +1,144 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef ARDUINOCORE_API_CAN_MSG_H_ +#define ARDUINOCORE_API_CAN_MSG_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include +#include + +#include "Print.h" +#include "Printable.h" +#include "Common.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class CanMsg : public Printable +{ +public: + static uint8_t constexpr MAX_DATA_LENGTH = 8; + + static uint32_t constexpr CAN_EFF_FLAG = 0x80000000U; + static uint32_t constexpr CAN_SFF_MASK = 0x000007FFU; /* standard frame format (SFF) */ + static uint32_t constexpr CAN_EFF_MASK = 0x1FFFFFFFU; /* extended frame format (EFF) */ + + + CanMsg(uint32_t const can_id, uint8_t const can_data_len, uint8_t const * can_data_ptr) + : id{can_id} + , data_length{min(can_data_len, MAX_DATA_LENGTH)} + , data{0} + { + if (data_length && can_data_ptr) + memcpy(data, can_data_ptr, data_length); + } + + CanMsg() : CanMsg(0, 0, nullptr) { } + + CanMsg(CanMsg const & other) + { + id = other.id; + data_length = other.data_length; + if (data_length > 0) + memcpy(data, other.data, data_length); + } + + virtual ~CanMsg() { } + + CanMsg & operator = (CanMsg const & other) + { + if (this != &other) + { + id = other.id; + data_length = other.data_length; + if (data_length > 0) + memcpy(data, other.data, data_length); + } + return (*this); + } + + virtual size_t printTo(Print & p) const override + { + char buf[20] = {0}; + size_t len = 0; + + /* Print the header. */ + if (isStandardId()) + len = snprintf(buf, sizeof(buf), "[%03" PRIX32 "] (%d) : ", getStandardId(), data_length); + else + len = snprintf(buf, sizeof(buf), "[%08" PRIX32 "] (%d) : ", getExtendedId(), data_length); + size_t n = p.write(buf, len); + + /* Print the data. */ + for (size_t d = 0; d < data_length; d++) + { + len = snprintf(buf, sizeof(buf), "%02X", data[d]); + n += p.write(buf, len); + } + + /* Wrap up. */ + return n; + } + + + uint32_t getStandardId() const { + return (id & CAN_SFF_MASK); + } + uint32_t getExtendedId() const { + return (id & CAN_EFF_MASK); + } + bool isStandardId() const { + return ((id & CAN_EFF_FLAG) == 0); + } + bool isExtendedId() const { + return ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG); + } + + + /* + * CAN ID semantics (mirroring definition by linux/can.h): + * |- Bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) + * |- Bit 30 : reserved (future remote transmission request flag) + * |- Bit 29 : reserved (future error frame flag) + * |- Bit 0-28 : CAN identifier (11/29 bit) + */ + uint32_t id; + uint8_t data_length; + uint8_t data[MAX_DATA_LENGTH]; +}; + +/************************************************************************************** + * FREE FUNCTIONS + **************************************************************************************/ + +inline uint32_t CanStandardId(uint32_t const id) { + return (id & CanMsg::CAN_SFF_MASK); +} + +inline uint32_t CanExtendedId(uint32_t const id) { + return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK)); +} + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_CAN_MSG_H_ */ diff --git a/api/CanMsgRingbuffer.cpp b/api/CanMsgRingbuffer.cpp new file mode 100644 index 00000000..e62db89a --- /dev/null +++ b/api/CanMsgRingbuffer.cpp @@ -0,0 +1,62 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsgRingbuffer.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CTOR/DTOR + **************************************************************************************/ + +CanMsgRingbuffer::CanMsgRingbuffer() +: _head{0} +, _tail{0} +, _num_elems{0} +{ +} + +/************************************************************************************** + * PUBLIC MEMBER FUNCTIONS + **************************************************************************************/ + +void CanMsgRingbuffer::enqueue(CanMsg const & msg) +{ + if (isFull()) + return; + + _buf[_head] = msg; + _head = next(_head); + _num_elems = _num_elems + 1; +} + +CanMsg CanMsgRingbuffer::dequeue() +{ + if (isEmpty()) + return CanMsg(); + + CanMsg const msg = _buf[_tail]; + _tail = next(_tail); + _num_elems = _num_elems - 1; + + return msg; +} + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ diff --git a/api/CanMsgRingbuffer.h b/api/CanMsgRingbuffer.h new file mode 100644 index 00000000..461df450 --- /dev/null +++ b/api/CanMsgRingbuffer.h @@ -0,0 +1,60 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ +#define ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include "CanMsg.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class CanMsgRingbuffer +{ +public: + static size_t constexpr RING_BUFFER_SIZE = 32U; + + CanMsgRingbuffer(); + + inline bool isFull() const { return (_num_elems == RING_BUFFER_SIZE); } + void enqueue(CanMsg const & msg); + + inline bool isEmpty() const { return (_num_elems == 0); } + CanMsg dequeue(); + + inline size_t available() const { return _num_elems; } + +private: + CanMsg _buf[RING_BUFFER_SIZE]; + volatile size_t _head; + volatile size_t _tail; + volatile size_t _num_elems; + + inline size_t next(size_t const idx) const { return ((idx + 1) % RING_BUFFER_SIZE); } +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ */ diff --git a/api/HardwareCAN.h b/api/HardwareCAN.h new file mode 100644 index 00000000..a5b87604 --- /dev/null +++ b/api/HardwareCAN.h @@ -0,0 +1,106 @@ +/* + * This file is free software; you can redistribute it and/or modify + * it under the terms of either the GNU General Public License version 2 + * or the GNU Lesser General Public License version 2.1, both as + * published by the Free Software Foundation. + */ + +#ifndef ARDUINOCORE_API_HARDWARECAN_H +#define ARDUINOCORE_API_HARDWARECAN_H + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsg.h" +#include "CanMsgRingbuffer.h" + +/************************************************************************************** + * TYPEDEF + **************************************************************************************/ + +enum class CanBitRate : int +{ + BR_125k = 125000, + BR_250k = 250000, + BR_500k = 500000, + BR_1000k = 1000000, +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class HardwareCAN +{ +public: + virtual ~HardwareCAN() {} + + + /** + * Initialize the CAN controller. + * + * @param can_bitrate the bus bit rate + * @return true if initialization succeeded and the controller is operational + */ + virtual bool begin(CanBitRate const can_bitrate) = 0; + + /** + * Disable the CAN controller. + * + * Whether any messages that are buffered will be sent is _implementation defined_. + */ + virtual void end() = 0; + + /** + * Enqueue a message for transmission to the CAN bus. + * + * This call returns when the message has been enqueued for transmission. + * Due to bus arbitration and error recovery there may be a substantial delay + * before the message is actually sent. + * + * An implementation must ensure that all messages with the same CAN priority + * are sent in the order in which they are enqueued. + * + * It is _implementation defined_ whether multiple messages can be enqueued + * for transmission, and if messages with higher CAN priority can preempt the + * transmission of previously enqueued messages. The default configuration for + * and implementation should not allow multiple messages to be enqueued. + * + * @param msg the message to send + * @return 1 if the message was enqueued, an _implementation defined_ error code < 0 if there was an error + * @todo define specific error codes, especially "message already pending" + */ + virtual int write(CanMsg const &msg) = 0; + + /** + * Determine if any messages have been received and buffered. + * + * @return the number of unread messages that have been received + */ + virtual size_t available() = 0; + + /** + * Returns the first message received, or an empty message if none are available. + * + * Messages must be returned in the order received. + * + * @return the first message in the receive buffer + */ + virtual CanMsg read() = 0; +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_HARDWARECAN_H */ diff --git a/api/IPAddress.cpp b/api/IPAddress.cpp index 4b729319..05b41bc1 100644 --- a/api/IPAddress.cpp +++ b/api/IPAddress.cpp @@ -94,6 +94,33 @@ IPAddress::IPAddress(const char *address) fromString(address); } +String IPAddress::toString4() const +{ + char szRet[16]; + snprintf(szRet, sizeof(szRet), "%u.%u.%u.%u", _address.bytes[IPADDRESS_V4_BYTES_INDEX], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3]); + return String(szRet); +} + +String IPAddress::toString6() const +{ + char szRet[40]; + snprintf(szRet, sizeof(szRet), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", + _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3], + _address.bytes[4], _address.bytes[5], _address.bytes[6], _address.bytes[7], + _address.bytes[8], _address.bytes[9], _address.bytes[10], _address.bytes[11], + _address.bytes[12], _address.bytes[13], _address.bytes[14], _address.bytes[15]); + return String(szRet); +} + +String IPAddress::toString() const +{ + if (_type == IPv4) { + return toString4(); + } else { + return toString6(); + } +} + bool IPAddress::fromString(const char *address) { if (!fromString4(address)) { return fromString6(address); diff --git a/api/IPAddress.h b/api/IPAddress.h index 964faa67..31a2d06d 100644 --- a/api/IPAddress.h +++ b/api/IPAddress.h @@ -96,8 +96,9 @@ class IPAddress : public Printable { IPAddress& operator=(const char *address); virtual size_t printTo(Print& p) const; + String toString() const; - IPType type() { return _type; } + IPType type() const { return _type; } friend class UDP; friend class Client; @@ -110,6 +111,8 @@ class IPAddress : public Printable { protected: bool fromString4(const char *address); bool fromString6(const char *address); + String toString4() const; + String toString6() const; }; extern const IPAddress IN6ADDR_ANY; diff --git a/api/Print.cpp b/api/Print.cpp index 8c3e1930..f1e82469 100644 --- a/api/Print.cpp +++ b/api/Print.cpp @@ -287,6 +287,12 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base) uint8_t i = 0; uint8_t innerLoops = 0; + // Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178 + if (n64 == 0) { + write('0'); + return 1; + } + // prevent crash if called with base == 1 if (base < 2) base = 10; diff --git a/api/RingBuffer.h b/api/RingBuffer.h index 833350d1..8665cf6a 100644 --- a/api/RingBuffer.h +++ b/api/RingBuffer.h @@ -77,7 +77,7 @@ void RingBufferN::store_char( uint8_t c ) { _aucBuffer[_iHead] = c ; _iHead = nextIndex(_iHead); - _numElems++; + _numElems = _numElems + 1; } } @@ -97,7 +97,7 @@ int RingBufferN::read_char() uint8_t value = _aucBuffer[_iTail]; _iTail = nextIndex(_iTail); - _numElems--; + _numElems = _numElems - 1; return value; } @@ -138,4 +138,4 @@ bool RingBufferN::isFull() } #endif /* _RING_BUFFER_ */ -#endif /* __cplusplus */ \ No newline at end of file +#endif /* __cplusplus */ diff --git a/api/String.cpp b/api/String.cpp index 0a5c11fe..4f176374 100644 --- a/api/String.cpp +++ b/api/String.cpp @@ -63,7 +63,6 @@ String::String(const __FlashStringHelper *pstr) *this = pstr; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String::String(String &&rval) : buffer(rval.buffer) , capacity(rval.capacity) @@ -73,7 +72,6 @@ String::String(String &&rval) rval.capacity = 0; rval.len = 0; } -#endif String::String(char c) { @@ -213,7 +211,6 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) return *this; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { if (this != &rhs) @@ -229,31 +226,28 @@ void String::move(String &rhs) rhs.capacity = 0; } } -#endif String & String::operator = (const String &rhs) { if (this == &rhs) return *this; - + if (rhs.buffer) copy(rhs.buffer, rhs.len); else invalidate(); - + return *this; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & String::operator = (String &&rval) { move(rval); return *this; } -#endif String & String::operator = (const char *cstr) { if (cstr) copy(cstr, strlen(cstr)); else invalidate(); - + return *this; } @@ -484,7 +478,7 @@ bool String::equalsIgnoreCase( const String &s2 ) const const char *p2 = s2.buffer; while (*p1) { if (tolower(*p1++) != tolower(*p2++)) return false; - } + } return true; } @@ -515,7 +509,7 @@ char String::charAt(unsigned int loc) const return operator[](loc); } -void String::setCharAt(unsigned int loc, char c) +void String::setCharAt(unsigned int loc, char c) { if (loc < len) buffer[loc] = c; } @@ -652,9 +646,9 @@ void String::replace(const String& find, const String& replace) } } else if (diff < 0) { unsigned int size = len; // compute size needed for result + diff = 0 - diff; while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { readFrom = foundAt + find.len; - diff = 0 - diff; size -= diff; } if (size == len) return; diff --git a/api/String.h b/api/String.h index 03ecf442..0bafd35a 100644 --- a/api/String.h +++ b/api/String.h @@ -72,9 +72,7 @@ class String String(const uint8_t *cstr, unsigned int length) : String((const char*)cstr, length) {} String(const String &str); String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); - #endif explicit String(char c); explicit String(unsigned char, unsigned char base=10); explicit String(int, unsigned char base=10); @@ -91,6 +89,7 @@ class String // invalid string (i.e., "if (s)" will be true afterwards) bool reserve(unsigned int size); inline unsigned int length(void) const {return len;} + inline bool isEmpty(void) const { return length() == 0; } // creates a copy of the assigned value. if the value is null or // invalid, or if the memory allocation fails, the string will be @@ -98,9 +97,7 @@ class String String & operator = (const String &rhs); String & operator = (const char *cstr); String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); - #endif // concatenate (works w/ built-in types) @@ -231,9 +228,7 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); String & copy(const __FlashStringHelper *pstr, unsigned int length); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); - #endif }; class StringSumHelper : public String diff --git a/api/WCharacter.h b/api/WCharacter.h index e3642ccb..d0508424 100644 --- a/api/WCharacter.h +++ b/api/WCharacter.h @@ -70,7 +70,7 @@ inline bool isAscii(int c) // Checks for a blank character, that is, a space or a tab. inline bool isWhitespace(int c) { - return ( isblank (c) == 0 ? false : true); + return ( c == '\t' || c == ' '); } @@ -98,7 +98,7 @@ inline bool isGraph(int c) // Checks for a lower-case character. inline bool isLowerCase(int c) { - return (islower (c) == 0 ? false : true); + return ( c >= 'a' && c <= 'z' ); } @@ -113,7 +113,7 @@ inline bool isPrintable(int c) // or an alphanumeric character. inline bool isPunct(int c) { - return ( ispunct (c) == 0 ? false : true); + return ( isPrintable(c) && !isSpace(c) && !isAlphaNumeric(c) ); } diff --git a/api/deprecated-avr-comp/avr/dtostrf.c.impl b/api/deprecated-avr-comp/avr/dtostrf.c.impl index 96987a8f..f410886c 100644 --- a/api/deprecated-avr-comp/avr/dtostrf.c.impl +++ b/api/deprecated-avr-comp/avr/dtostrf.c.impl @@ -29,9 +29,12 @@ char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { asm(".global _printf_float"); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" char fmt[20]; sprintf(fmt, "%%%d.%df", width, prec); sprintf(sout, fmt, val); return sout; +#pragma GCC diagnostic pop } diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/api/deprecated-avr-comp/avr/pgmspace.h index 95897d75..a80e4a51 100644 --- a/api/deprecated-avr-comp/avr/pgmspace.h +++ b/api/deprecated-avr-comp/avr/pgmspace.h @@ -30,7 +30,9 @@ #include #define PROGMEM +#define __ATTR_PROGMEM__ #define PGM_P const char * +#define PGM_VOID_P const void * #define PSTR(str) (str) #define _SFR_BYTE(n) (n) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0f6200b2..f6bcc123 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,7 @@ project(test-ArduinoCore-API) ########################################################################## -include_directories(../api) +include_directories(..) include_directories(include) include_directories(external/catch/v2.13.9/include) @@ -25,10 +25,20 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME}) ########################################################################## set(TEST_SRCS + src/CanMsg/test_CanMsg.cpp + src/CanMsg/test_CanMsg_CopyCtor.cpp + src/CanMsg/test_CanExtendedId.cpp + src/CanMsg/test_CanStandardId.cpp + src/CanMsg/test_isExtendedId.cpp + src/CanMsg/test_isStandardId.cpp + src/CanMsg/test_operator_assignment.cpp + src/CanMsg/test_printTo.cpp + src/CanMsgRingbuffer/test_available.cpp src/Common/test_makeWord.cpp src/Common/test_map.cpp src/Common/test_max.cpp src/Common/test_min.cpp + src/IPAddress/test_toString.cpp src/IPAddress/test_fromString.cpp src/IPAddress/test_fromString6.cpp src/IPAddress/test_IPAddress.cpp @@ -94,6 +104,8 @@ set(TEST_SRCS ) set(TEST_DUT_SRCS + ../api/CanMsg.cpp + ../api/CanMsgRingbuffer.cpp ../api/Common.cpp ../api/IPAddress.cpp ../api/String.cpp @@ -120,8 +132,8 @@ add_compile_definitions(HOST) add_compile_options(-Wall -Wextra -Wpedantic -Werror) add_compile_options(-Wno-cast-function-type) -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -Wno-deprecated-copy") ########################################################################## diff --git a/test/include/MillisFake.h b/test/include/MillisFake.h index da21049b..be078bd0 100644 --- a/test/include/MillisFake.h +++ b/test/include/MillisFake.h @@ -9,7 +9,7 @@ * INCLUDE **************************************************************************************/ -#include +#include /************************************************************************************** * FUNCTION DECLARATION diff --git a/test/include/PrintMock.h b/test/include/PrintMock.h index 87c83313..d41e78fa 100644 --- a/test/include/PrintMock.h +++ b/test/include/PrintMock.h @@ -11,7 +11,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/include/PrintableMock.h b/test/include/PrintableMock.h index cfc00555..39121928 100644 --- a/test/include/PrintableMock.h +++ b/test/include/PrintableMock.h @@ -11,7 +11,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/include/StreamMock.h b/test/include/StreamMock.h index 91eb3c26..a7d9da1a 100644 --- a/test/include/StreamMock.h +++ b/test/include/StreamMock.h @@ -11,7 +11,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/src/CanMsg/test_CanExtendedId.cpp b/test/src/CanMsg/test_CanExtendedId.cpp new file mode 100644 index 00000000..a812f08b --- /dev/null +++ b/test/src/CanMsg/test_CanExtendedId.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for lowest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-01]") +{ + REQUIRE(CanExtendedId(0) == (CanMsg::CAN_EFF_FLAG | 0U)); +} + +TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for highest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-02]") +{ + REQUIRE(CanExtendedId(0x1FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); +} + +TEST_CASE ("Verify capping of CAN IDs exceeding 29-Bit CAN ID range", "[CanMsg-CanExtendedId-03]") +{ + REQUIRE(CanExtendedId(0x2FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); + REQUIRE(CanExtendedId(0x3FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); + REQUIRE(CanExtendedId(0x4FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); + REQUIRE(CanExtendedId(0x5FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); + /* ... */ + REQUIRE(CanExtendedId(0xFFFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); +} diff --git a/test/src/CanMsg/test_CanMsg.cpp b/test/src/CanMsg/test_CanMsg.cpp new file mode 100644 index 00000000..03704623 --- /dev/null +++ b/test/src/CanMsg/test_CanMsg.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]") +{ + CanMsg const msg(CanStandardId(0x20), 0, nullptr); + + REQUIRE(msg.data_length == 0); + for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++) + REQUIRE(msg.data[i] == 0); +} + +TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]") +{ + uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; + + CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); + + REQUIRE(msg.data_length == 4); + for (size_t i = 0; i < msg.data_length; i++) + REQUIRE(msg.data[i] == msg_data[i]); +} + +TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]") +{ + uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + + CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); + + REQUIRE(msg.data_length == 8); + for (size_t i = 0; i < msg.data_length; i++) + REQUIRE(msg.data[i] == msg_data[i]); +} + +TEST_CASE ("Test constructor constructing a CAN frame with standard ID", "[CanMsg-CanMsg-04]") +{ + CanMsg const msg(CanStandardId(0x20), 0, nullptr); + + REQUIRE(msg.id == 0x20); +} + +TEST_CASE ("Test constructor constructing a CAN frame with extended ID", "[CanMsg-CanMsg-05]") +{ + CanMsg const msg(CanExtendedId(0x20), 0, nullptr); + + REQUIRE(msg.id == (CanMsg::CAN_EFF_FLAG | 0x20)); +} diff --git a/test/src/CanMsg/test_CanMsg_CopyCtor.cpp b/test/src/CanMsg/test_CanMsg_CopyCtor.cpp new file mode 100644 index 00000000..ccf62931 --- /dev/null +++ b/test/src/CanMsg/test_CanMsg_CopyCtor.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Test copy constructor", "[CanMsg-CopyCtor-01]") +{ + uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; + + CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); + CanMsg const msg_2(msg_1); + + REQUIRE(msg_1.data_length == msg_2.data_length); + + for (size_t i = 0; i < msg_1.data_length; i++) + { + REQUIRE(msg_1.data[i] == msg_data[i]); + REQUIRE(msg_2.data[i] == msg_data[i]); + } +} diff --git a/test/src/CanMsg/test_CanStandardId.cpp b/test/src/CanMsg/test_CanStandardId.cpp new file mode 100644 index 00000000..81d2301d --- /dev/null +++ b/test/src/CanMsg/test_CanStandardId.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for lowest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-01]") +{ + REQUIRE(CanStandardId(0) == 0U); +} + +TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for highest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-02]") +{ + REQUIRE(CanStandardId(0x7FF) == 0x7FF); +} + +TEST_CASE ("Verify capping of CAN IDs exceeding 11-Bit CAN ID range", "[CanMsg-CanStandardId-03]") +{ + REQUIRE(CanStandardId(0x800U) == 0x000U); + REQUIRE(CanStandardId(0x801U) == 0x001U); + REQUIRE(CanStandardId(0x8FFU) == 0x0FFU); + REQUIRE(CanStandardId(0x1FFFFFFFU) == 0x7FFU); + REQUIRE(CanStandardId(0xFFFFFFFFU) == 0x7FFU); +} diff --git a/test/src/CanMsg/test_isExtendedId.cpp b/test/src/CanMsg/test_isExtendedId.cpp new file mode 100644 index 00000000..242866e9 --- /dev/null +++ b/test/src/CanMsg/test_isExtendedId.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("\"isExtendedId\" should return true for extended CAN ID", "[CanMsg-isExtendedId-01]") +{ + CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); + REQUIRE(msg_ext_id.isExtendedId() == true); +} + +TEST_CASE ("\"isExtendedId\" should return false for standard CAN ID", "[CanMsg-isExtendedId-02]") +{ + CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); + REQUIRE(msg_std_id.isExtendedId() == false); +} diff --git a/test/src/CanMsg/test_isStandardId.cpp b/test/src/CanMsg/test_isStandardId.cpp new file mode 100644 index 00000000..a73bf7c1 --- /dev/null +++ b/test/src/CanMsg/test_isStandardId.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("\"isStandardId\" should return true for standard CAN ID", "[CanMsg-isStandardId-01]") +{ + CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); + REQUIRE(msg_std_id.isStandardId() == true); +} + +TEST_CASE ("\"isStandardId\" should return false for extended CAN ID", "[CanMsg-isStandardId-02]") +{ + CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); + REQUIRE(msg_ext_id.isStandardId() == false); +} diff --git a/test/src/CanMsg/test_operator_assignment.cpp b/test/src/CanMsg/test_operator_assignment.cpp new file mode 100644 index 00000000..0dd35543 --- /dev/null +++ b/test/src/CanMsg/test_operator_assignment.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Testing CanMsg::operator = (CanMsg const &)", "[CanMsg-Operator-=-1]") +{ + uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; + + CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); + CanMsg msg_2(CanStandardId(0x21), 0, nullptr); + + msg_2 = msg_1; + + REQUIRE(msg_1.data_length == msg_2.data_length); + + for (size_t i = 0; i < msg_1.data_length; i++) + { + REQUIRE(msg_1.data[i] == msg_data[i]); + REQUIRE(msg_2.data[i] == msg_data[i]); + } +} diff --git a/test/src/CanMsg/test_printTo.cpp b/test/src/CanMsg/test_printTo.cpp new file mode 100644 index 00000000..bf532c81 --- /dev/null +++ b/test/src/CanMsg/test_printTo.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include +#include + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +using namespace arduino; + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Print CAN frame with standard ID", "[CanMsg-printTo-1]") +{ + uint8_t const std_msg_data[] = {0xBE, 0xEF}; + CanMsg const std_msg(CanStandardId(0x20), sizeof(std_msg_data), std_msg_data); + + PrintMock mock; + mock.print(std_msg); + + REQUIRE(mock._str == "[020] (2) : BEEF"); +} + +TEST_CASE ("Print CAN frame with extended ID", "[CanMsg-printTo-2]") +{ + uint8_t const ext_msg_data[] = {0xDE, 0xAD, 0xC0, 0xDE}; + CanMsg const ext_msg(CanExtendedId(0x20), sizeof(ext_msg_data), ext_msg_data); + + PrintMock mock; + mock.print(ext_msg); + + REQUIRE(mock._str == "[00000020] (4) : DEADC0DE"); +} diff --git a/test/src/CanMsgRingbuffer/test_available.cpp b/test/src/CanMsgRingbuffer/test_available.cpp new file mode 100644 index 00000000..684eaeec --- /dev/null +++ b/test/src/CanMsgRingbuffer/test_available.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("'available' should return 0 for empty CanMsg ring buffer", "[CanMsgRingbuffer-available-01]") +{ + arduino::CanMsgRingbuffer ringbuffer; + REQUIRE(ringbuffer.available() == 0); +} + +TEST_CASE ("'available' should return number of elements in CanMsg ringbuffer", "[CanMsgRingbuffer-available-02]") +{ + arduino::CanMsgRingbuffer ringbuffer; + arduino::CanMsg msg; + ringbuffer.enqueue(msg); + REQUIRE(ringbuffer.available() == 1); + ringbuffer.enqueue(msg); + REQUIRE(ringbuffer.available() == 2); + ringbuffer.dequeue(); + REQUIRE(ringbuffer.available() == 1); +} diff --git a/test/src/Common/test_makeWord.cpp b/test/src/Common/test_makeWord.cpp index 2e0a29dc..dcb3ea33 100644 --- a/test/src/Common/test_makeWord.cpp +++ b/test/src/Common/test_makeWord.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Common/test_map.cpp b/test/src/Common/test_map.cpp index aef3e72a..59441cac 100644 --- a/test/src/Common/test_map.cpp +++ b/test/src/Common/test_map.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Common/test_max.cpp b/test/src/Common/test_max.cpp index 6612cc95..ccb5e5e1 100644 --- a/test/src/Common/test_max.cpp +++ b/test/src/Common/test_max.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE @@ -53,7 +53,7 @@ TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") { uint32_t const a = 32; uint64_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(unsigned long)); + REQUIRE(typeid(max(a,b)) == typeid(uint64_t)); } WHEN("type(A) = int8_t, type(b) = int16_t") { @@ -71,6 +71,6 @@ TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") { int32_t const a = -32; int64_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(long)); + REQUIRE(typeid(max(a,b)) == typeid(int64_t)); } } diff --git a/test/src/Common/test_min.cpp b/test/src/Common/test_min.cpp index 2298dc6c..750f41ae 100644 --- a/test/src/Common/test_min.cpp +++ b/test/src/Common/test_min.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE @@ -53,7 +53,7 @@ TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") { uint32_t const a = 32; uint64_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(unsigned long)); + REQUIRE(typeid(min(a,b)) == typeid(uint64_t)); } WHEN("type(A) = int8_t, type(b) = int16_t") { @@ -71,6 +71,6 @@ TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") { int32_t const a = -32; int64_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(long)); + REQUIRE(typeid(min(a,b)) == typeid(int64_t)); } } diff --git a/test/src/IPAddress/test_IPAddress.cpp b/test/src/IPAddress/test_IPAddress.cpp index d12db0f3..6b66e118 100644 --- a/test/src/IPAddress/test_IPAddress.cpp +++ b/test/src/IPAddress/test_IPAddress.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_IPAddress6.cpp b/test/src/IPAddress/test_IPAddress6.cpp index a6941b71..3a8a5315 100644 --- a/test/src/IPAddress/test_IPAddress6.cpp +++ b/test/src/IPAddress/test_IPAddress6.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_fromString.cpp b/test/src/IPAddress/test_fromString.cpp index 2c918052..d058b529 100644 --- a/test/src/IPAddress/test_fromString.cpp +++ b/test/src/IPAddress/test_fromString.cpp @@ -8,8 +8,8 @@ #include -#include -#include +#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_fromString6.cpp b/test/src/IPAddress/test_fromString6.cpp index a0f09c73..deb54458 100644 --- a/test/src/IPAddress/test_fromString6.cpp +++ b/test/src/IPAddress/test_fromString6.cpp @@ -8,8 +8,8 @@ #include -#include -#include +#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_assignment.cpp b/test/src/IPAddress/test_operator_assignment.cpp index e9fc8691..fdf641d4 100644 --- a/test/src/IPAddress/test_operator_assignment.cpp +++ b/test/src/IPAddress/test_operator_assignment.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_comparison.cpp b/test/src/IPAddress/test_operator_comparison.cpp index c3283b71..3978c8e2 100644 --- a/test/src/IPAddress/test_operator_comparison.cpp +++ b/test/src/IPAddress/test_operator_comparison.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_comparison6.cpp b/test/src/IPAddress/test_operator_comparison6.cpp index a5e1b87c..da03a0b3 100644 --- a/test/src/IPAddress/test_operator_comparison6.cpp +++ b/test/src/IPAddress/test_operator_comparison6.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_parentheses.cpp b/test/src/IPAddress/test_operator_parentheses.cpp index 27fce3a5..c1c2e375 100644 --- a/test/src/IPAddress/test_operator_parentheses.cpp +++ b/test/src/IPAddress/test_operator_parentheses.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_parentheses6.cpp b/test/src/IPAddress/test_operator_parentheses6.cpp index 5b4740c8..b4575f4e 100644 --- a/test/src/IPAddress/test_operator_parentheses6.cpp +++ b/test/src/IPAddress/test_operator_parentheses6.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_printTo.cpp b/test/src/IPAddress/test_printTo.cpp index 05e43fa5..a0ed7c16 100644 --- a/test/src/IPAddress/test_printTo.cpp +++ b/test/src/IPAddress/test_printTo.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/test/src/IPAddress/test_printTo6.cpp b/test/src/IPAddress/test_printTo6.cpp index 621008af..7d924b63 100644 --- a/test/src/IPAddress/test_printTo6.cpp +++ b/test/src/IPAddress/test_printTo6.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/test/src/IPAddress/test_toString.cpp b/test/src/IPAddress/test_toString.cpp new file mode 100644 index 00000000..f36ae549 --- /dev/null +++ b/test/src/IPAddress/test_toString.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include +#include + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Extract valid string from IPv4address", "[IPAddress-toString-01]") +{ + arduino::IPAddress ip(129,168,1,2); + + REQUIRE(ip.toString().equals("129.168.1.2") == true); +} + +TEST_CASE ("Extract valid ipv6 string from IPv6address", "[IPAddress-toString-02]") +{ + arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); + + REQUIRE(ip.toString().equals("2001:0db8:0102:0304:0506:0708:090a:0b0c") == true); +} + +TEST_CASE ("Extract 0.0.0.0 string from uninitialized IP address", "[IPAddress-toString-03]") +{ + arduino::IPAddress ip; + + REQUIRE(ip.toString().equals("0.0.0.0") == true); +} diff --git a/test/src/Print/test_availableForWrite.cpp b/test/src/Print/test_availableForWrite.cpp index 47f599cf..c5dfbcda 100644 --- a/test/src/Print/test_availableForWrite.cpp +++ b/test/src/Print/test_availableForWrite.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_clearWriteError.cpp b/test/src/Print/test_clearWriteError.cpp index 295f4984..720a1210 100644 --- a/test/src/Print/test_clearWriteError.cpp +++ b/test/src/Print/test_clearWriteError.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_getWriteError.cpp b/test/src/Print/test_getWriteError.cpp index ef2b1435..3b616411 100644 --- a/test/src/Print/test_getWriteError.cpp +++ b/test/src/Print/test_getWriteError.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_print.cpp b/test/src/Print/test_print.cpp index 92e9c083..2598b7f7 100644 --- a/test/src/Print/test_print.cpp +++ b/test/src/Print/test_print.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include @@ -110,12 +110,24 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr { PrintMock mock; - unsigned long long const val = 17; + GIVEN("a value of zero ...") + { + unsigned long long const val = 0; - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } + WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); } + WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); } + WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); } + WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); } + } + GIVEN("a non-zero value ...") + { + unsigned long long const val = 17; + + WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } + WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } + WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } + WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } + } } TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]") diff --git a/test/src/Print/test_println.cpp b/test/src/Print/test_println.cpp index 977ed532..2d2d7306 100644 --- a/test/src/Print/test_println.cpp +++ b/test/src/Print/test_println.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include #include diff --git a/test/src/Ringbuffer/test_available.cpp b/test/src/Ringbuffer/test_available.cpp index 3a79e5bc..75b86a7f 100644 --- a/test/src/Ringbuffer/test_available.cpp +++ b/test/src/Ringbuffer/test_available.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_availableForStore.cpp b/test/src/Ringbuffer/test_availableForStore.cpp index 7d73d8da..5b8415f6 100644 --- a/test/src/Ringbuffer/test_availableForStore.cpp +++ b/test/src/Ringbuffer/test_availableForStore.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_clear.cpp b/test/src/Ringbuffer/test_clear.cpp index 165a5bbb..93da03a2 100644 --- a/test/src/Ringbuffer/test_clear.cpp +++ b/test/src/Ringbuffer/test_clear.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_isFull.cpp b/test/src/Ringbuffer/test_isFull.cpp index 8d9c4aaa..c575981e 100644 --- a/test/src/Ringbuffer/test_isFull.cpp +++ b/test/src/Ringbuffer/test_isFull.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_peek.cpp b/test/src/Ringbuffer/test_peek.cpp index 3811dd39..9efe28ea 100644 --- a/test/src/Ringbuffer/test_peek.cpp +++ b/test/src/Ringbuffer/test_peek.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_read_char.cpp b/test/src/Ringbuffer/test_read_char.cpp index de754275..babc27df 100644 --- a/test/src/Ringbuffer/test_read_char.cpp +++ b/test/src/Ringbuffer/test_read_char.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_store_char.cpp b/test/src/Ringbuffer/test_store_char.cpp index 6e127b28..0becdc0f 100644 --- a/test/src/Ringbuffer/test_store_char.cpp +++ b/test/src/Ringbuffer/test_store_char.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/String/StringPrinter.h b/test/src/String/StringPrinter.h index f338a902..1ddee147 100644 --- a/test/src/String/StringPrinter.h +++ b/test/src/String/StringPrinter.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace Catch { /** diff --git a/test/src/String/test_String.cpp b/test/src/String/test_String.cpp index 461f2d08..6d1b8152 100644 --- a/test/src/String/test_String.cpp +++ b/test/src/String/test_String.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_characterAccessFunc.cpp b/test/src/String/test_characterAccessFunc.cpp index 329cca43..49d257af 100644 --- a/test/src/String/test_characterAccessFunc.cpp +++ b/test/src/String/test_characterAccessFunc.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -45,10 +45,11 @@ TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)" WHEN("Valid operation") { arduino::String str("Hello"); - unsigned char buf[2]; + unsigned char buf[3]; str.getBytes(buf, 5, 3); REQUIRE(buf[0] == 'l'); REQUIRE(buf[1] == 'o'); + REQUIRE(buf[2] == '\0'); } } diff --git a/test/src/String/test_compareTo.cpp b/test/src/String/test_compareTo.cpp index 9aef1ee7..74a3da7b 100644 --- a/test/src/String/test_compareTo.cpp +++ b/test/src/String/test_compareTo.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -27,13 +27,13 @@ TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]") WHEN ("str2 is empty") { arduino::String str1("Hello"), str2; - REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); + REQUIRE(str1.compareTo(str2) > 0); } WHEN ("str1 is empty") { arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); + REQUIRE(str1.compareTo(str2) < 0); } } @@ -47,14 +47,14 @@ TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") WHEN ("Passed string is empty") { - arduino::String str1("Hello"), str2(""); - REQUIRE(str1.compareTo("") == strcmp(str1.c_str(), str2.c_str())); + arduino::String str("Hello"); + REQUIRE(str.compareTo("") > 0); } WHEN ("Passed string is compared with empty string") { - arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str())); + arduino::String str; + REQUIRE(str.compareTo("") == 0); } } @@ -64,8 +64,8 @@ TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String { char *buffer = NULL; - arduino::String str1("Hello"); - REQUIRE(str1.compareTo(buffer) != 0); + arduino::String str("Hello"); + REQUIRE(str.compareTo(buffer) != 0); } WHEN ("First string does NOT have a valid buffer") @@ -73,8 +73,8 @@ TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String char *buffer1 = NULL; char *buffer2 = NULL; - arduino::String str1(buffer1); - REQUIRE(str1.compareTo(buffer2) == 0); + arduino::String str(buffer1); + REQUIRE(str.compareTo(buffer2) == 0); } } diff --git a/test/src/String/test_comparisonFunc.cpp b/test/src/String/test_comparisonFunc.cpp index 89a7f3be..3b49bacc 100644 --- a/test/src/String/test_comparisonFunc.cpp +++ b/test/src/String/test_comparisonFunc.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_concat.cpp b/test/src/String/test_concat.cpp index b7390b64..ef6c6fa1 100644 --- a/test/src/String/test_concat.cpp +++ b/test/src/String/test_concat.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_indexOf.cpp b/test/src/String/test_indexOf.cpp index bcaf65ef..9f32a07e 100644 --- a/test/src/String/test_indexOf.cpp +++ b/test/src/String/test_indexOf.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp new file mode 100644 index 00000000..9f70f26d --- /dev/null +++ b/test/src/String/test_isEmpty.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Arduino. All rights reserved. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include + +#include "StringPrinter.h" + +/************************************************************************************** + * TEST CODE + **************************************************************************************/ + +TEST_CASE ("Testing String::isEmpty when string is empty", "[String-isEmpty-01]") +{ + arduino::String str; + REQUIRE(str.isEmpty()); +} + +TEST_CASE ("Testing String::isEmpty when string contains characters", "[String-isEmpty-02]") +{ + arduino::String str("Testing String::isEmpty"); + REQUIRE(!str.isEmpty()); +} diff --git a/test/src/String/test_lastIndexOf.cpp b/test/src/String/test_lastIndexOf.cpp index 2ae95f54..7f776fa6 100644 --- a/test/src/String/test_lastIndexOf.cpp +++ b/test/src/String/test_lastIndexOf.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_length.cpp b/test/src/String/test_length.cpp index 3b47faed..fae358fa 100644 --- a/test/src/String/test_length.cpp +++ b/test/src/String/test_length.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_move.cpp b/test/src/String/test_move.cpp index d37630c4..a2529b50 100644 --- a/test/src/String/test_move.cpp +++ b/test/src/String/test_move.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include "StringPrinter.h" @@ -31,7 +31,14 @@ TEST_CASE("Testing String move assignment", "[String-move-02]") TEST_CASE("Testing String move self assignment", "[String-move-03]") { +#if (defined(GCC_VERSION) && GCC_VERSION >= 13) || (defined(__clang_major__) && __clang_major__ >= 14) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wself-move" +#endif arduino::String a("src"); a = std::move(a); REQUIRE(a == "src"); +#if defined(GCC_VERSION) && GCC_VERSION >= 13 +#pragma GCC diagnostic pop +#endif } diff --git a/test/src/String/test_operators.cpp b/test/src/String/test_operators.cpp index 67cb39be..5a3b677c 100644 --- a/test/src/String/test_operators.cpp +++ b/test/src/String/test_operators.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_remove.cpp b/test/src/String/test_remove.cpp index e8c19536..17b8dabb 100644 --- a/test/src/String/test_remove.cpp +++ b/test/src/String/test_remove.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_replace.cpp b/test/src/String/test_replace.cpp index 5d46fafb..cfcaead0 100644 --- a/test/src/String/test_replace.cpp +++ b/test/src/String/test_replace.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -66,3 +66,24 @@ TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than ' str.replace(arduino::String("ll"), arduino::String("111")); REQUIRE(str == "He111o Arduino!"); } + +TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]") +{ + arduino::String str("Hello Arduino! Hello, Hello, Hello"); + str.replace(arduino::String("ll"), arduino::String("lll")); + REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo"); +} + +TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]") +{ + arduino::String str("Hello Arduino! Hello, Hello, Hello"); + str.replace(arduino::String("ll"), arduino::String("11")); + REQUIRE(str == "He11o Arduino! He11o, He11o, He11o"); +} + +TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]") +{ + arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo"); + str.replace(arduino::String("lll"), arduino::String("ll")); + REQUIRE(str == "Hello Arduino! Hello, Hello, Hello"); +} diff --git a/test/src/String/test_substring.cpp b/test/src/String/test_substring.cpp index 8fa43086..bb05d439 100644 --- a/test/src/String/test_substring.cpp +++ b/test/src/String/test_substring.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toDouble.cpp b/test/src/String/test_toDouble.cpp index 246f25d4..af6960e9 100644 --- a/test/src/String/test_toDouble.cpp +++ b/test/src/String/test_toDouble.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toFloat.cpp b/test/src/String/test_toFloat.cpp index afef02c5..75cf94b2 100644 --- a/test/src/String/test_toFloat.cpp +++ b/test/src/String/test_toFloat.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toInt.cpp b/test/src/String/test_toInt.cpp index 43397b76..060fdd27 100644 --- a/test/src/String/test_toInt.cpp +++ b/test/src/String/test_toInt.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toLowerCase.cpp b/test/src/String/test_toLowerCase.cpp index 1ff81e91..9f6f7c9d 100644 --- a/test/src/String/test_toLowerCase.cpp +++ b/test/src/String/test_toLowerCase.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toUpperCase.cpp b/test/src/String/test_toUpperCase.cpp index b8ae6aaf..1bcf93fb 100644 --- a/test/src/String/test_toUpperCase.cpp +++ b/test/src/String/test_toUpperCase.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_trim.cpp b/test/src/String/test_trim.cpp index 539d6568..c5168ecd 100644 --- a/test/src/String/test_trim.cpp +++ b/test/src/String/test_trim.cpp @@ -8,7 +8,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/WCharacter/test_isAscii.cpp b/test/src/WCharacter/test_isAscii.cpp index 8c2763c4..c6792719 100644 --- a/test/src/WCharacter/test_isAscii.cpp +++ b/test/src/WCharacter/test_isAscii.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isControl.cpp b/test/src/WCharacter/test_isControl.cpp index 157c8bc8..adb41ccf 100644 --- a/test/src/WCharacter/test_isControl.cpp +++ b/test/src/WCharacter/test_isControl.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isDigit.cpp b/test/src/WCharacter/test_isDigit.cpp index 58b1808a..146a863b 100644 --- a/test/src/WCharacter/test_isDigit.cpp +++ b/test/src/WCharacter/test_isDigit.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isHexadecimalDigit.cpp b/test/src/WCharacter/test_isHexadecimalDigit.cpp index 0eba5846..486a3e44 100644 --- a/test/src/WCharacter/test_isHexadecimalDigit.cpp +++ b/test/src/WCharacter/test_isHexadecimalDigit.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isLowerCase.cpp b/test/src/WCharacter/test_isLowerCase.cpp index 79e1dbc4..9b05b458 100644 --- a/test/src/WCharacter/test_isLowerCase.cpp +++ b/test/src/WCharacter/test_isLowerCase.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_isPunct.cpp b/test/src/WCharacter/test_isPunct.cpp index 5f6875d1..7e6b49dc 100644 --- a/test/src/WCharacter/test_isPunct.cpp +++ b/test/src/WCharacter/test_isPunct.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isSpace.cpp b/test/src/WCharacter/test_isSpace.cpp index c96557d6..29ed8107 100644 --- a/test/src/WCharacter/test_isSpace.cpp +++ b/test/src/WCharacter/test_isSpace.cpp @@ -10,7 +10,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isUpperCase.cpp b/test/src/WCharacter/test_isUpperCase.cpp index e21e33db..598bb55b 100644 --- a/test/src/WCharacter/test_isUpperCase.cpp +++ b/test/src/WCharacter/test_isUpperCase.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_isWhitespace.cpp b/test/src/WCharacter/test_isWhitespace.cpp index 6eb3f7a6..483c6477 100644 --- a/test/src/WCharacter/test_isWhitespace.cpp +++ b/test/src/WCharacter/test_isWhitespace.cpp @@ -8,7 +8,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_toAscii.cpp b/test/src/WCharacter/test_toAscii.cpp index b071702f..96a2cfb9 100644 --- a/test/src/WCharacter/test_toAscii.cpp +++ b/test/src/WCharacter/test_toAscii.cpp @@ -6,13 +6,11 @@ * INCLUDE **************************************************************************************/ -#undef _GNU_SOURCE - #include #include -#include +#include /************************************************************************************** * CONSTANTS @@ -47,4 +45,4 @@ TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toA TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]") { REQUIRE(arduino::toAscii(0x3030) == 0x30); -} \ No newline at end of file +} diff --git a/test/src/dtostrf.cpp b/test/src/dtostrf.cpp index 0635b492..0700debb 100644 --- a/test/src/dtostrf.cpp +++ b/test/src/dtostrf.cpp @@ -6,7 +6,7 @@ * INCLUDE **************************************************************************************/ -#include +#include #include @@ -18,7 +18,7 @@ extern "C" { #endif -#include +#include #ifdef __cplusplus } // extern "C" diff --git a/test/src/itoa.cpp b/test/src/itoa.cpp index 84d640c3..292d0ef0 100644 --- a/test/src/itoa.cpp +++ b/test/src/itoa.cpp @@ -6,7 +6,7 @@ * INCLUDE **************************************************************************************/ -#include +#include #include #include @@ -27,24 +27,36 @@ std::string radixToFmtString(int const radix) char * itoa(int value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * ltoa(long value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * utoa(unsigned value, char *str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * ultoa(unsigned long value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; }