diff --git a/api/ArduinoAPI.h b/ArduinoAPI.h similarity index 100% rename from api/ArduinoAPI.h rename to ArduinoAPI.h diff --git a/api/Binary.h b/Binary.h similarity index 100% rename from api/Binary.h rename to Binary.h diff --git a/api/CanMsg.cpp b/CanMsg.cpp similarity index 100% rename from api/CanMsg.cpp rename to CanMsg.cpp diff --git a/api/CanMsg.h b/CanMsg.h similarity index 100% rename from api/CanMsg.h rename to CanMsg.h diff --git a/api/CanMsgRingbuffer.cpp b/CanMsgRingbuffer.cpp similarity index 100% rename from api/CanMsgRingbuffer.cpp rename to CanMsgRingbuffer.cpp diff --git a/api/CanMsgRingbuffer.h b/CanMsgRingbuffer.h similarity index 100% rename from api/CanMsgRingbuffer.h rename to CanMsgRingbuffer.h diff --git a/api/Client.h b/Client.h similarity index 100% rename from api/Client.h rename to Client.h diff --git a/api/Common.cpp b/Common.cpp similarity index 100% rename from api/Common.cpp rename to Common.cpp diff --git a/api/Common.h b/Common.h similarity index 100% rename from api/Common.h rename to Common.h diff --git a/api/Compat.h b/Compat.h similarity index 100% rename from api/Compat.h rename to Compat.h diff --git a/api/DMAPool.h b/DMAPool.h similarity index 100% rename from api/DMAPool.h rename to DMAPool.h diff --git a/api/HardwareCAN.h b/HardwareCAN.h similarity index 100% rename from api/HardwareCAN.h rename to HardwareCAN.h diff --git a/api/HardwareI2C.h b/HardwareI2C.h similarity index 100% rename from api/HardwareI2C.h rename to HardwareI2C.h diff --git a/api/HardwareSPI.h b/HardwareSPI.h similarity index 100% rename from api/HardwareSPI.h rename to HardwareSPI.h diff --git a/api/HardwareSerial.h b/HardwareSerial.h similarity index 100% rename from api/HardwareSerial.h rename to HardwareSerial.h diff --git a/api/IPAddress.cpp b/IPAddress.cpp similarity index 100% rename from api/IPAddress.cpp rename to IPAddress.cpp diff --git a/api/IPAddress.h b/IPAddress.h similarity index 100% rename from api/IPAddress.h rename to IPAddress.h diff --git a/api/Interrupts.h b/Interrupts.h similarity index 100% rename from api/Interrupts.h rename to Interrupts.h diff --git a/api/PluggableUSB.cpp b/PluggableUSB.cpp similarity index 100% rename from api/PluggableUSB.cpp rename to PluggableUSB.cpp diff --git a/api/PluggableUSB.h b/PluggableUSB.h similarity index 100% rename from api/PluggableUSB.h rename to PluggableUSB.h diff --git a/api/Print.cpp b/Print.cpp similarity index 100% rename from api/Print.cpp rename to Print.cpp diff --git a/api/Print.h b/Print.h similarity index 100% rename from api/Print.h rename to Print.h diff --git a/api/Printable.h b/Printable.h similarity index 100% rename from api/Printable.h rename to Printable.h diff --git a/api/RingBuffer.h b/RingBuffer.h similarity index 100% rename from api/RingBuffer.h rename to RingBuffer.h diff --git a/ST-README.md b/ST-README.md new file mode 100644 index 00000000..f87b5ad5 --- /dev/null +++ b/ST-README.md @@ -0,0 +1,110 @@ +# 📚 ArduinoCore-API for STM32duino + +> **Fork** of [`arduino/ArduinoCore-API`](https://github.com/arduino/ArduinoCore-API) — Designed to be used as a **Git submodule** in [`stm32duino/Arduino_Core_STM32`](https://github.com/stm32duino/Arduino_Core_STM32) + +--- + +## 🎯 Purpose + +This repository is a **fork** that contains **only** the official Arduino API and hardware-independent code. + +**Main Goal:** Simplify Arduino API integration into STM32duino via a **git submodule**. + +--- + +## 📦 What's Included? + +✅ Arduino API official files (`api/` folder) + +❌ Elements Removed +- Folders `test/` + +--- + +## 🚀 Using as a Submodule + +### 1️⃣ Add the Submodule + +In your `Arduino_Core_STM32` repository, run: + +```bash +# Add this repository as a submodule +git submodule add https://github.com/YOUR_USERNAME/ArduinoCore-API.git cores/arduino/ArduinoCore-API + +# Initialize and update +git submodule update --init --recursive +``` + +--- + +## 📋 Changelog + +### Version 1.0 (Initial) +- ✅ Extract `api/` folder from `arduino/ArduinoCore-API` +- ✅ Remove all non-API folders +- ✅ Prepare for use as submodule + +--- + +## 🔗 Official Resources + +| Resource | Link | +|----------|------| +| **Official ArduinoCore-API** | https://github.com/arduino/ArduinoCore-API | +| **STM32duino** | https://github.com/stm32duino/Arduino_Core_STM32 | + +--- + +## 📝 License + +This repository is a fork of `arduino/ArduinoCore-API` and maintains the **same license** (LGPL 2.1+). + +See the `LICENSE` file in the repository root for details. + +--- + +## 💡 Important Notes + +### ✅ Advantages of Using a Submodule + +- **Traceability**: Know exactly which version of the API you're using +- **Easy Updates**: Simple `git submodule update` to sync +- **Isolation**: API stays in its own code branch +- **Compatibility**: STM32-specific modifications remain separate + +### ⚠️ Points to Consider + +- **After Clone**: Run `git submodule update --init --recursive` + +--- + +## 📊 Project Information + +| Property | Value | +|----------|-------| +| **Type** | fork | +| **Use Case** | Submodule for STM32duino | +| **Language** | C/C++ | +| **License** | LGPL 2.1+ | +| **Original Repository** | https://github.com/arduino/ArduinoCore-API | +| **Compatible With** | | + +--- + +## ✨ Quick Start + +### Clone with Submodule + +```bash +git clone --recurse-submodules https://github.com/stm32duino/Arduino_Core_STM32.git +``` + +### Update Submodule + +```bash +git submodule update --remote +``` + +--- + +**Last Updated:** December 15, 2025 \ No newline at end of file diff --git a/api/Server.h b/Server.h similarity index 100% rename from api/Server.h rename to Server.h diff --git a/api/Stream.cpp b/Stream.cpp similarity index 100% rename from api/Stream.cpp rename to Stream.cpp diff --git a/api/Stream.h b/Stream.h similarity index 100% rename from api/Stream.h rename to Stream.h diff --git a/api/String.cpp b/String.cpp similarity index 100% rename from api/String.cpp rename to String.cpp diff --git a/api/String.h b/String.h similarity index 100% rename from api/String.h rename to String.h diff --git a/api/USBAPI.h b/USBAPI.h similarity index 100% rename from api/USBAPI.h rename to USBAPI.h diff --git a/api/Udp.h b/Udp.h similarity index 100% rename from api/Udp.h rename to Udp.h diff --git a/api/WCharacter.h b/WCharacter.h similarity index 100% rename from api/WCharacter.h rename to WCharacter.h diff --git a/api/deprecated-avr-comp/avr/dtostrf.c.impl b/deprecated-avr-comp/avr/dtostrf.c.impl similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.c.impl rename to deprecated-avr-comp/avr/dtostrf.c.impl diff --git a/api/deprecated-avr-comp/avr/dtostrf.h b/deprecated-avr-comp/avr/dtostrf.h similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.h rename to deprecated-avr-comp/avr/dtostrf.h diff --git a/api/deprecated-avr-comp/avr/interrupt.h b/deprecated-avr-comp/avr/interrupt.h similarity index 100% rename from api/deprecated-avr-comp/avr/interrupt.h rename to deprecated-avr-comp/avr/interrupt.h diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/deprecated-avr-comp/avr/pgmspace.h similarity index 100% rename from api/deprecated-avr-comp/avr/pgmspace.h rename to deprecated-avr-comp/avr/pgmspace.h diff --git a/api/deprecated/Client.h b/deprecated/Client.h similarity index 100% rename from api/deprecated/Client.h rename to deprecated/Client.h diff --git a/api/deprecated/HardwareSerial.h b/deprecated/HardwareSerial.h similarity index 100% rename from api/deprecated/HardwareSerial.h rename to deprecated/HardwareSerial.h diff --git a/api/deprecated/IPAddress.h b/deprecated/IPAddress.h similarity index 100% rename from api/deprecated/IPAddress.h rename to deprecated/IPAddress.h diff --git a/api/deprecated/Print.h b/deprecated/Print.h similarity index 100% rename from api/deprecated/Print.h rename to deprecated/Print.h diff --git a/api/deprecated/Printable.h b/deprecated/Printable.h similarity index 100% rename from api/deprecated/Printable.h rename to deprecated/Printable.h diff --git a/api/deprecated/Server.h b/deprecated/Server.h similarity index 100% rename from api/deprecated/Server.h rename to deprecated/Server.h diff --git a/api/deprecated/Stream.h b/deprecated/Stream.h similarity index 100% rename from api/deprecated/Stream.h rename to deprecated/Stream.h diff --git a/api/deprecated/Udp.h b/deprecated/Udp.h similarity index 100% rename from api/deprecated/Udp.h rename to deprecated/Udp.h diff --git a/api/deprecated/WString.h b/deprecated/WString.h similarity index 100% rename from api/deprecated/WString.h rename to deprecated/WString.h diff --git a/api/itoa.h b/itoa.h similarity index 100% rename from api/itoa.h rename to itoa.h diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index faa6a97b..00000000 --- a/test/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -build -### CMake ### -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -### CMake Patch ### -CMakeUserPresets.json - -# External projects -*-prefix/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index d8050249..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,158 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later - -########################################################################## - -cmake_minimum_required(VERSION 2.8) - -########################################################################## - -project(test-ArduinoCore-API) - -Include(FetchContent) - -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 -) - -FetchContent_MakeAvailable(Catch2) - -########################################################################## - -include_directories(..) -include_directories(include) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -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 - src/IPAddress/test_IPAddress6.cpp - src/IPAddress/test_operator_assignment.cpp - src/IPAddress/test_operator_comparison.cpp - src/IPAddress/test_operator_comparison6.cpp - src/IPAddress/test_operator_parentheses.cpp - src/IPAddress/test_operator_parentheses6.cpp - src/IPAddress/test_printTo.cpp - src/IPAddress/test_printTo6.cpp - src/Print/test_clearWriteError.cpp - src/Print/test_getWriteError.cpp - src/Print/test_print.cpp - src/Print/test_println.cpp - src/Print/test_availableForWrite.cpp - src/Ringbuffer/test_available.cpp - src/Ringbuffer/test_availableForStore.cpp - src/Ringbuffer/test_clear.cpp - src/Ringbuffer/test_isFull.cpp - src/Ringbuffer/test_peek.cpp - src/Ringbuffer/test_read_char.cpp - src/Ringbuffer/test_store_char.cpp - src/Stream/test_find.cpp - src/Stream/test_findUntil.cpp - src/Stream/test_getTimeout.cpp - src/Stream/test_parseFloat.cpp - src/Stream/test_parseInt.cpp - src/Stream/test_readBytes.cpp - src/Stream/test_readBytesUntil.cpp - src/Stream/test_readString.cpp - src/Stream/test_readStringUntil.cpp - src/Stream/test_setTimeout.cpp - src/String/test_concat.cpp - src/String/test_operators.cpp - src/String/test_compareTo.cpp - src/String/test_comparisonFunc.cpp - src/String/test_characterAccessFunc.cpp - src/String/test_substring.cpp - src/String/test_indexOf.cpp - src/String/test_lastIndexOf.cpp - src/String/test_length.cpp - src/String/test_move.cpp - src/String/test_remove.cpp - src/String/test_replace.cpp - src/String/test_String.cpp - src/String/test_toDouble.cpp - src/String/test_toFloat.cpp - src/String/test_toInt.cpp - src/String/test_toLowerCase.cpp - src/String/test_toUpperCase.cpp - src/String/test_trim.cpp - src/WCharacter/test_isAscii.cpp - src/WCharacter/test_isControl.cpp - src/WCharacter/test_isDigit.cpp - src/WCharacter/test_isHexadecimalDigit.cpp - src/WCharacter/test_isLowerCase.cpp - src/WCharacter/test_isPunct.cpp - src/WCharacter/test_isSpace.cpp - src/WCharacter/test_isUpperCase.cpp - src/WCharacter/test_isWhitespace.cpp - src/WCharacter/test_toAscii.cpp -) - -set(TEST_DUT_SRCS - ../api/CanMsg.cpp - ../api/CanMsgRingbuffer.cpp - ../api/Common.cpp - ../api/IPAddress.cpp - ../api/String.cpp - ../api/Stream.cpp - ../api/Print.cpp -) - -########################################################################## - -set(TEST_TARGET_SRCS - src/dtostrf.cpp - src/itoa.cpp - src/MillisFake.cpp - src/PrintMock.cpp - src/StreamMock.cpp - ${TEST_SRCS} - ${TEST_DUT_SRCS} -) - -########################################################################## - -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") - -########################################################################## - -add_executable( - ${TEST_TARGET} - ${TEST_TARGET_SRCS} -) - -target_link_libraries( ${TEST_TARGET} Catch2WithMain ) - -########################################################################## - diff --git a/test/include/MillisFake.h b/test/include/MillisFake.h deleted file mode 100644 index bdb3f14c..00000000 --- a/test/include/MillisFake.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef MILLIS_FAKE_H_ -#define MILLIS_FAKE_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * FUNCTION DECLARATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -void millis_autoOn(); -void millis_autoOff(); -void set_millis(unsigned long const val); - -#ifdef __cplusplus -} -#endif - -#endif /* MILLIS_FAKE_H_ */ \ No newline at end of file diff --git a/test/include/PrintMock.h b/test/include/PrintMock.h deleted file mode 100644 index 9a103848..00000000 --- a/test/include/PrintMock.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINT_MOCK_H_ -#define PRINT_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintMock : public Print -{ -public: - std::string _str; - virtual size_t write(uint8_t b) override; - void mock_setWriteError() { setWriteError(); } - void mock_setWriteError(int err) { setWriteError(err); } -}; - -#endif /* PRINT_MOCK_H_ */ diff --git a/test/include/PrintableMock.h b/test/include/PrintableMock.h deleted file mode 100644 index f55540d1..00000000 --- a/test/include/PrintableMock.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINTABLE_MOCK_H_ -#define PRINTABLE_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintableMock : public arduino::Printable -{ -public: - int _i; - virtual size_t printTo(arduino::Print& p) const override - { - size_t written = 0; - written += p.print("PrintableMock i = "); - written += p.print(_i); - return written; - } -}; - -#endif /* PRINTABLE_MOCK_H_ */ diff --git a/test/include/StreamMock.h b/test/include/StreamMock.h deleted file mode 100644 index afa4b487..00000000 --- a/test/include/StreamMock.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef STREAM_MOCK_H_ -#define STREAM_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class StreamMock : public arduino::Stream -{ -public: - - void operator << (char const * str); - - virtual size_t write(uint8_t ch) override; - virtual int available() override; - virtual int read() override; - virtual int peek() override; - -private: - std::deque _stream; - -}; - -#endif /* STREAM_MOCK_H_ */ diff --git a/test/src/CanMsg/test_CanExtendedId.cpp b/test/src/CanMsg/test_CanExtendedId.cpp deleted file mode 100644 index caf7bccc..00000000 --- a/test/src/CanMsg/test_CanExtendedId.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 1394eee4..00000000 --- a/test/src/CanMsg/test_CanMsg.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index c7878152..00000000 --- a/test/src/CanMsg/test_CanMsg_CopyCtor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 23b862fe..00000000 --- a/test/src/CanMsg/test_CanStandardId.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 7c3dd478..00000000 --- a/test/src/CanMsg/test_isExtendedId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 00fee646..00000000 --- a/test/src/CanMsg/test_isStandardId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 7bdde6c0..00000000 --- a/test/src/CanMsg/test_operator_assignment.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index a434bdf4..00000000 --- a/test/src/CanMsg/test_printTo.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index f843a673..00000000 --- a/test/src/CanMsgRingbuffer/test_available.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 2f1e706a..00000000 --- a/test/src/Common/test_makeWord.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'makeWord(w)'", "[makeWord-01]") -{ - REQUIRE(makeWord(0xDEAD) == 0xDEAD); - REQUIRE(makeWord(0xDE) == 0x00DE); -} - -TEST_CASE ("Calling 'makeWord(h,l)'", "[makeWord-02]") -{ - REQUIRE(makeWord(0xDE, 0xAD) == 0xDEAD); -} - -TEST_CASE ("Calling 'word(...)'", "[makeWord-03]") -{ - REQUIRE(word(0xDEAD) == 0xDEAD); - REQUIRE(word(0xDE, 0xAD) == 0xDEAD); -} diff --git a/test/src/Common/test_map.cpp b/test/src/Common/test_map.cpp deleted file mode 100644 index bd2b5845..00000000 --- a/test/src/Common/test_map.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with reduction of output", "[map-01]") -{ - REQUIRE(map(50, 0, 100, 0, 10) == 5); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with increase of output", "[map-02]") -{ - REQUIRE(map(5, 0, 10, 0, 100) == 50); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' where output is reduced to a value < 0", "[map-03]") -{ - REQUIRE(map(1, 0, 100, 0, 10) == 0); /* Would be 0.1 if we'd be using floating point. */ -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' default usage with negative values", "[map-04]") -{ - WHEN ("Negative 'from' values") - { - REQUIRE(map(0, 0, -256, 0, 1024) == 0); - REQUIRE(map(-256, 0, -256, 0, 1024) == 1024); - REQUIRE(map(-128, 0, -256, 0, 1024) == 512); - } - WHEN ("Negative 'to' values") - { - REQUIRE(map(0, 0, 256, 0, -1024) == 0); - REQUIRE(map(256, 0, 256, 0, -1024) == -1024); - REQUIRE(map(128, 0, 256, 0, -1024) == -512); - } -} diff --git a/test/src/Common/test_max.cpp b/test/src/Common/test_max.cpp deleted file mode 100644 index 815f0ec1..00000000 --- a/test/src/Common/test_max.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'max(a,b)' with a < b", "[max-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(1,5) == 5); - WHEN("a < 0 and b > 0") REQUIRE(max(-1,5) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-5,-1) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a > b", "[max-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(5,1) == 5); - WHEN("a > 0 and b < 0") REQUIRE(max(5,-1) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-1,-5) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a == b", "[max-03]") -{ - WHEN("a = b > 0") REQUIRE(max(5,5) == 5); - WHEN("a = b < 0") REQUIRE(max(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(max(0,0) == 0); -} - -TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int64_t)); - } -} diff --git a/test/src/Common/test_min.cpp b/test/src/Common/test_min.cpp deleted file mode 100644 index b37158ff..00000000 --- a/test/src/Common/test_min.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'min(a,b)' with a < b", "[min-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(1,5) == 1); - WHEN("a < 0 and b > 0") REQUIRE(min(-1,5) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-5,-1) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a > b", "[min-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(5,1) == 1); - WHEN("a > 0 and b < 0") REQUIRE(min(5,-1) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-1,-5) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a == b", "[min-03]") -{ - WHEN("a = b > 0") REQUIRE(min(5,5) == 5); - WHEN("a = b < 0") REQUIRE(min(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(min(0,0) == 0); -} - -TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int64_t)); - } -} diff --git a/test/src/IPAddress/test_IPAddress.cpp b/test/src/IPAddress/test_IPAddress.cpp deleted file mode 100644 index 848a2c75..00000000 --- a/test/src/IPAddress/test_IPAddress.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress() default constructor()", "[IPAddress-Ctor-01]") -{ - arduino::IPAddress ip; - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o) constructor", "[IPAddress-Ctor-02]") -{ - arduino::IPAddress ip(129,168,1,2); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a) constructor", "[IPAddress-Ctor-03]") -{ - arduino::IPAddress ip(129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a *) constructor", "[IPAddress-Ctor-04]") -{ - uint8_t const ip_addr_array[] = {129,168,1,2}; - - arduino::IPAddress ip(ip_addr_array); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} diff --git a/test/src/IPAddress/test_IPAddress6.cpp b/test/src/IPAddress/test_IPAddress6.cpp deleted file mode 100644 index fc48f4c0..00000000 --- a/test/src/IPAddress/test_IPAddress6.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress(type) constructor()", "[IPAddress6-Ctor-01]") -{ - arduino::IPAddress ip (arduino::IPType::IPv6); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o) constructor", "[IPAddress-Ctor6-02]") -{ - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Testing IPAddress(type, a *) constructor", "[IPAddress6-Ctor-03]") -{ - uint8_t const ip_addr_array[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - arduino::IPAddress ip(arduino::IPType::IPv6, ip_addr_array); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} diff --git a/test/src/IPAddress/test_fromString.cpp b/test/src/IPAddress/test_fromString.cpp deleted file mode 100644 index 1e7795a3..00000000 --- a/test/src/IPAddress/test_fromString.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IP address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("129.168.1.2") == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract valid IP address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("129.168.1.2"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract invalid IP address 'fromString(const char *)'", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("") == false); - REQUIRE(ip.fromString("1") == false); - REQUIRE(ip.fromString("1.") == false); - REQUIRE(ip.fromString("1.1") == false); - REQUIRE(ip.fromString("1.1.") == false); - REQUIRE(ip.fromString("1.1.1") == false); - REQUIRE(ip.fromString("1.1.1.") == false); - REQUIRE(ip.fromString("...") == false); - REQUIRE(ip.fromString("256.1.1.1") == false); - REQUIRE(ip.fromString("a.1.1.1") == false); - REQUIRE(ip.fromString("-.1.1.1") == false); - REQUIRE(ip.fromString("-1.1.1.1") == false); -} diff --git a/test/src/IPAddress/test_fromString6.cpp b/test/src/IPAddress/test_fromString6.cpp deleted file mode 100644 index bb9f01b0..00000000 --- a/test/src/IPAddress/test_fromString6.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IPv6 address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("2001:db8:102:304:506:708:90a:b0c"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 any address", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 localhost address", "[IPAddress-fromString-04]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::1") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 1); -} - -TEST_CASE ("Extract valid IPv6 different length segments", "[IPAddress-fromString-05]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("abcd:ef1:23:0:4::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0xab); - REQUIRE(ip[1] == 0xcd); - REQUIRE(ip[2] == 0xe); - REQUIRE(ip[3] == 0xf1); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0x23); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 4); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 zero start", "[IPAddress-fromString-06]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - - -TEST_CASE ("Extract valid IPv6 zero end", "[IPAddress-fromString-07]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1:2:3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero start", "[IPAddress-fromString-08]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero end", "[IPAddress-fromString-9]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -// Non-canonical - -TEST_CASE ("Extract valid IPv6 any full long form", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 upper case", "[IPAddress-fromString-11]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:DB8:102:304:506:708:90A:B0C") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 explicit start zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 explicit end zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 compression of one group of zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1::3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - -// Invalid cases - -TEST_CASE ("Extract invalid IPv6 address", "[IPAddress-fromString-12]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString(":::") == false); // three colons by self - REQUIRE(ip.fromString("::3:4:5:6::") == false); // two compressions - REQUIRE(ip.fromString("2001:db8:102:10304:506:708:90a:b0c") == false); // 5 character field - REQUIRE(ip.fromString("200x:db8:102:304:506:708:90a:b0c") == false); // invalid character - REQUIRE(ip.fromString("2001:db8:102:304::506:708:90a:b0c") == false); // double colon with 8 other fields (so not a compression) - REQUIRE(ip.fromString("2001:db8:102:304:::708:90a:b0c") == false); // three colons in middle - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c:d0e") == false); // 9 fields - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a") == false); // only seven groups - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:0") == false); // nine zeros - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:") == false); // extra colon - REQUIRE(ip.fromString("0:0:0:0:0:0:0:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("0:0:0:0:0:0:0") == false); // only seven groups -} diff --git a/test/src/IPAddress/test_operator_assignment.cpp b/test/src/IPAddress/test_operator_assignment.cpp deleted file mode 100644 index 0d4e0041..00000000 --- a/test/src/IPAddress/test_operator_assignment.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator = (const uint8_t * a)", "[IPAddress-Operator-=-01]") -{ - arduino::IPAddress ip1; - uint8_t const ip2[] = {192,168,1,2}; - - ip1 = ip2; - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} - -TEST_CASE ("Testing IPAddress::operator = (uint32_t a)", "[IPAddress-Operator-=-02]") -{ - arduino::IPAddress ip1; - uint32_t const ip2 = 192 | (168 << 8) | (1 << 16) | (2 << 24); - - ip1 = ip2; - // NOTE: Only correct on little-endian systems - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} diff --git a/test/src/IPAddress/test_operator_comparison.cpp b/test/src/IPAddress/test_operator_comparison.cpp deleted file mode 100644 index 75139bf3..00000000 --- a/test/src/IPAddress/test_operator_comparison.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 == ip2", "[IPAddress-Operator-==-01]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 != ip2", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {129,168,1,2}; - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {10,0,0,1}; - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 != ip2) == false); -} diff --git a/test/src/IPAddress/test_operator_comparison6.cpp b/test/src/IPAddress/test_operator_comparison6.cpp deleted file mode 100644 index 1a50f251..00000000 --- a/test/src/IPAddress/test_operator_comparison6.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing two basic constructs the same", "[IPAddress6-Operator-==-01]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing two addresses different", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing not equals different address is true", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing not equals same address is false", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 != ip2) == false); -} - -// IPv4 and IPv6 differ based on type (irrespective of bytes) - -TEST_CASE ("Testing IPv4 vs IPv6", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 equivalent IPv4-compatible address (deprecated)", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(127, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 equivalent compatible address vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(0, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv6 never matches as raw byte sequence assumed to be length 4", "[IPAddress6-Operator-==-06]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - uint8_t const ip2[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - REQUIRE((ip1 == ip2) == false); -} diff --git a/test/src/IPAddress/test_operator_parentheses.cpp b/test/src/IPAddress/test_operator_parentheses.cpp deleted file mode 100644 index b9ad65c7..00000000 --- a/test/src/IPAddress/test_operator_parentheses.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator uint32_t() const", "[IPAddress-Operator-()-01]") -{ - arduino::IPAddress ip(129,168,1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - // NOTE: Only correct on little-endian systems - REQUIRE(val_expected == val_actual); -} diff --git a/test/src/IPAddress/test_operator_parentheses6.cpp b/test/src/IPAddress/test_operator_parentheses6.cpp deleted file mode 100644 index d360f129..00000000 --- a/test/src/IPAddress/test_operator_parentheses6.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -// These comparisons should always return false, as you can't compare an IPv6 to an int32_t - -TEST_CASE ("Testing implicit cast of IPv6 compatible (little endian) to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems, considering only last four octets (ignoring the rest) - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 full little endian to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems (full value) - arduino::IPAddress ip(129,168, 1,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // Actual value of the 128-bit IPv6 address, which is network byte order - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = ((129 << 24) | (168 << 16) | (1 << 8) | 2); - REQUIRE((val_expected == val_actual) == false); -} diff --git a/test/src/IPAddress/test_printTo.cpp b/test/src/IPAddress/test_printTo.cpp deleted file mode 100644 index 68e2ea9f..00000000 --- a/test/src/IPAddress/test_printTo.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPAddress via print method", "[IPAddress-printTo-01]") -{ - PrintMock mock; - arduino::IPAddress const ip(192,168,1,2); - - mock.print(ip); - - REQUIRE(mock._str == "192.168.1.2"); -} diff --git a/test/src/IPAddress/test_printTo6.cpp b/test/src/IPAddress/test_printTo6.cpp deleted file mode 100644 index 71dea49f..00000000 --- a/test/src/IPAddress/test_printTo6.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPv6", "[IPAddress-printTo6-01]") -{ - PrintMock mock; - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - mock.print(ip); - - REQUIRE(mock._str == "2001:db8:102:304:506:708:90a:b0c"); -} - -TEST_CASE ("Print IPv6 any", "[IPAddress-printTo6-02]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::"); -} - -TEST_CASE ("Print IPv6 localhost", "[IPAddress-printTo6-03]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); - - mock.print(ip); - - REQUIRE(mock._str == "::1"); -} - -TEST_CASE ("Print IPv6 different length segments", "[IPAddress-printTo6-04]") -{ - PrintMock mock; - arduino::IPAddress const ip(0xab,0xcd, 0x0e,0xf1, 0x00,0x23, 0,0, 0x00,0x04, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "abcd:ef1:23:0:4::"); -} - -TEST_CASE ("Print IPv6 zero longest run end", "[IPAddress-printTo6-05]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,2, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1:0:0:2::"); -} - -TEST_CASE ("Print IPv6 zero longest run mid", "[IPAddress-printTo6-06]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,0, 0,2, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1::2:0:0"); -} - -TEST_CASE ("Print IPv6 start zero", "[IPAddress-printTo6-07]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6:7:8"); -} - -TEST_CASE ("Print IPv6 ending zero", "[IPAddress-printTo6-08]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "1:2:3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 start two zero", "[IPAddress-printTo6-09]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,0, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 ending two zero", "[IPAddress-printTo6-10]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6::"); -} - -TEST_CASE ("Print IPv6 first out of same length", "[IPAddress-printTo6-11]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,0, 0,4, 0,5, 0,0, 0,0, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1::4:5:0:0:8"); -} - - -TEST_CASE ("Print IPv6 single zeros not compressed", "[IPAddress-printTo6-12]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,3, 0,0, 0,5, 0,0, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1:0:3:0:5:0:7:8"); -} diff --git a/test/src/IPAddress/test_toString.cpp b/test/src/IPAddress/test_toString.cpp deleted file mode 100644 index 1bd8d749..00000000 --- a/test/src/IPAddress/test_toString.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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/MillisFake.cpp b/test/src/MillisFake.cpp deleted file mode 100644 index 293af87f..00000000 --- a/test/src/MillisFake.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TYPEDEF - **************************************************************************************/ - -enum class MillisFakeMode -{ - Auto, Manual -}; - -/************************************************************************************** - * GLOBAL VARIABLES - **************************************************************************************/ - -static unsigned long millis_val = 0; -static MillisFakeMode millis_fake_mode = MillisFakeMode::Auto; -static std::chrono::steady_clock::time_point const millis_begin = std::chrono::steady_clock::now(); - -/************************************************************************************** - * FUNCTION DEFINITION - **************************************************************************************/ - -void millis_autoOn() -{ - millis_fake_mode = MillisFakeMode::Auto; -} - -void millis_autoOff() -{ - millis_fake_mode = MillisFakeMode::Manual; -} - -void set_millis(unsigned long const val) -{ - millis_autoOff(); - millis_val = val; -} - -unsigned long millis() -{ - if (millis_fake_mode == MillisFakeMode::Manual) - return millis_val; - - if (millis_fake_mode == MillisFakeMode::Auto) - { - std::chrono::steady_clock::time_point millis_now = std::chrono::steady_clock::now(); - auto millis = std::chrono::duration_cast(millis_now - millis_begin).count(); - return static_cast(millis); - } - - return 0; -} diff --git a/test/src/Print/test_availableForWrite.cpp b/test/src/Print/test_availableForWrite.cpp deleted file mode 100644 index ab6647cb..00000000 --- a/test/src/Print/test_availableForWrite.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::availableForWrite() should return 0 if not overwritten by derived class", "[Print-availableForWrite-01]") -{ - PrintMock mock; - REQUIRE(mock.availableForWrite() == 0); -} diff --git a/test/src/Print/test_clearWriteError.cpp b/test/src/Print/test_clearWriteError.cpp deleted file mode 100644 index 5f674cb2..00000000 --- a/test/src/Print/test_clearWriteError.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Clear write error should set the error code back to 0", "[Print-clearWriteError-01]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - mock.clearWriteError(); - REQUIRE(mock.getWriteError() == 0); -} diff --git a/test/src/Print/test_getWriteError.cpp b/test/src/Print/test_getWriteError.cpp deleted file mode 100644 index ff9eb0df..00000000 --- a/test/src/Print/test_getWriteError.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("No write error has been set", "[Print-getWriteError-01]") -{ - PrintMock mock; - REQUIRE(mock.getWriteError() == 0); -} - -TEST_CASE ("A write error has been set", "[Print-getWriteError-02]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - REQUIRE(mock.getWriteError() == 5); -} diff --git a/test/src/Print/test_print.cpp b/test/src/Print/test_print.cpp deleted file mode 100644 index 1a41c462..00000000 --- a/test/src/Print/test_print.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::print(char)", "[Print-print-01]") -{ - PrintMock mock; - - mock.print('A'); - - REQUIRE(mock._str == "A"); -} - -TEST_CASE ("Print::print(const String &)", "[Print-print-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(const char str[])", "[Print-print-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(int, int = DEC|HEX|OCT|BIN)", "[Print-print-04]") -{ - PrintMock mock; - - int const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned int, int = DEC|HEX|OCT|BIN)", "[Print-print-05]") -{ - PrintMock mock; - - unsigned int 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(long, int = DEC|HEX|OCT|BIN)", "[Print-print-06]") -{ - PrintMock mock; - - long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long, int = DEC|HEX|OCT|BIN)", "[Print-print-07]") -{ - PrintMock mock; - - unsigned 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(long long, int = DEC|HEX|OCT|BIN)", "[Print-print-08]") -{ - PrintMock mock; - - long long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-print-09]") -{ - PrintMock mock; - - GIVEN("a value of zero ...") - { - unsigned long long const val = 0; - - 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]") -{ - PrintMock mock; - - WHEN ("val is a positive floating point value") - { - double const val = 3.1459; - WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); } - WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); } - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); } - WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); } - WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); } - WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); } - } - - WHEN ("digits are negative") - { - double const val = 3.1459; - WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); } - } - - WHEN ("val is a negative floating point value") - { - double const val = -3.1459; - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); } - } - - WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); } - WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); } -} - -TEST_CASE ("Print::print(Printable)", "[Print-print-11]") -{ - PrintMock mock; - - PrintableMock printable; - printable._i = 1; - - mock.print(printable); - - REQUIRE(mock._str == "PrintableMock i = 1"); -} - -TEST_CASE ("Print::print(unsigned char, int)", "[Print-print-12]") -{ - PrintMock mock; - - WHEN("DEC") { mock.print('A', DEC); REQUIRE(mock._str == "65"); } - WHEN("HEX") { mock.print('A', HEX); REQUIRE(mock._str == "41"); } - WHEN("OCT") { mock.print('A', OCT); REQUIRE(mock._str == "101"); } - WHEN("BIN") { mock.print('A', BIN); REQUIRE(mock._str == "1000001"); } -} - -TEST_CASE ("Testing Print::print(const __FlashStringHelper *)", "[Print-print-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.print(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string"); -} diff --git a/test/src/Print/test_println.cpp b/test/src/Print/test_println.cpp deleted file mode 100644 index e35814e0..00000000 --- a/test/src/Print/test_println.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::println(char)", "[Print-println-01]") -{ - PrintMock mock; - - mock.println('A'); - - REQUIRE(mock._str == "A\r\n"); -} - -TEST_CASE ("Print::println(const String &)", "[Print-println-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(const char str[])", "[Print-println-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(int, int = DEC (default))", "[Print-println-04]") -{ - PrintMock mock; - int const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned int, int = DEC (default))", "[Print-println-05]") -{ - PrintMock mock; - unsigned int const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long, int = DEC (default))", "[Print-println-06]") -{ - PrintMock mock; - long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long, int = DEC (default))", "[Print-println-07]") -{ - PrintMock mock; - unsigned long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long long, int = DEC (default))", "[Print-println-08]") -{ - PrintMock mock; - long long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-println-09]") -{ - PrintMock mock; - unsigned long long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(double, int = 2)", "[Print-println-10]") -{ - PrintMock mock; - double const val = 3.1459; - - mock.println(val); - - REQUIRE(mock._str == "3.15\r\n"); -} - -TEST_CASE ("Print::println(Printable)", "[Print-println-11]") -{ - PrintMock mock; - PrintableMock printable; - printable._i = 1; - - mock.println(printable); - - REQUIRE(mock._str == "PrintableMock i = 1\r\n"); -} - -TEST_CASE ("Print::println(unsigned char, int base = DEC (default))", "[Print-println-12]") -{ - PrintMock mock; - - mock.println('A', DEC); - - REQUIRE(mock._str == "65\r\n"); -} - -TEST_CASE ("Testing Print::println(const __FlashStringHelper *)", "[Print-println-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.println(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string\r\n"); -} diff --git a/test/src/PrintMock.cpp b/test/src/PrintMock.cpp deleted file mode 100644 index ffa7c58f..00000000 --- a/test/src/PrintMock.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -size_t PrintMock::write(uint8_t b) -{ - _str.append(1, static_cast(b)); - return 1; -} diff --git a/test/src/Ringbuffer/test_available.cpp b/test/src/Ringbuffer/test_available.cpp deleted file mode 100644 index 171dcbf6..00000000 --- a/test/src/Ringbuffer/test_available.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'available' should return 0 for empty ring buffer", "[Ringbuffer-available-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("'available' should return number of elements in ringbuffer", "[Ringbuffer-available-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.available() == 2); -} diff --git a/test/src/Ringbuffer/test_availableForStore.cpp b/test/src/Ringbuffer/test_availableForStore.cpp deleted file mode 100644 index 4a06e839..00000000 --- a/test/src/Ringbuffer/test_availableForStore.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'availableForStore' should return ring buffer size for empty ring buffer", "[Ringbuffer-availableForStore-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.availableForStore() == 2); -} - -TEST_CASE ("'availableForStore' should return number of free elements in ringbuffer", "[Ringbuffer-availableForStore-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.availableForStore() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.availableForStore() == 0); -} diff --git a/test/src/Ringbuffer/test_clear.cpp b/test/src/Ringbuffer/test_clear.cpp deleted file mode 100644 index e2868c16..00000000 --- a/test/src/Ringbuffer/test_clear.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'clear' on a empty ring buffer should have no effect", "[Ringbuffer-clear-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("Calling 'clear' on a partially filled ring buffer should \"remove\" all elements", "[Ringbuffer-clear-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} diff --git a/test/src/Ringbuffer/test_isFull.cpp b/test/src/Ringbuffer/test_isFull.cpp deleted file mode 100644 index a7208f85..00000000 --- a/test/src/Ringbuffer/test_isFull.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'isFull' should return false for empty ring buffer", "[Ringbuffer-isFull-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return false for a partial full ring buffer", "[Ringbuffer-isFull-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return true for full ring buffer", "[Ringbuffer-isFull-03]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.isFull() == true); -} diff --git a/test/src/Ringbuffer/test_peek.cpp b/test/src/Ringbuffer/test_peek.cpp deleted file mode 100644 index 145a7f37..00000000 --- a/test/src/Ringbuffer/test_peek.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is accessed but not removed from the ring buffer via 'peek'", "[Ringbuffer-peek-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'peek' should return -1") - REQUIRE(ringbuffer.peek() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'peek' should return first inserted element first (FIFO) and not remove it") - { - REQUIRE(ringbuffer.peek() == 'A'); - REQUIRE(ringbuffer.peek() == 'A'); - } - } -} diff --git a/test/src/Ringbuffer/test_read_char.cpp b/test/src/Ringbuffer/test_read_char.cpp deleted file mode 100644 index c6941adb..00000000 --- a/test/src/Ringbuffer/test_read_char.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is removed from the ring buffer via 'read_char'", "[Ringbuffer-read_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'read_char' should return -1") - REQUIRE(ringbuffer.read_char() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'read_char' should return first inserted element first (FIFO)") - { - REQUIRE(ringbuffer.read_char() == 'A'); - REQUIRE(ringbuffer.read_char() == 'B'); - } - } -} diff --git a/test/src/Ringbuffer/test_store_char.cpp b/test/src/Ringbuffer/test_store_char.cpp deleted file mode 100644 index 705d979a..00000000 --- a/test/src/Ringbuffer/test_store_char.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is put into the ring buffer via 'store_char'", "[Ringbuffer-store_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer._aucBuffer[0] == 'A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer._aucBuffer[1] == 'B'); -} diff --git a/test/src/Stream/test_find.cpp b/test/src/Stream/test_find.cpp deleted file mode 100644 index c3c69d04..00000000 --- a/test/src/Stream/test_find.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing find(const char *target)", "[Stream-find-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find("test") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(const char *target, size_t length)", "[Stream-find-02]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - /* 'length' should actually be '4' or strlen("test"). I'd rather - * think this API should not be exposed at all. - */ - REQUIRE(mock.find("test", 3) == true); - REQUIRE(mock.readString() == arduino::String("t string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test", 3) == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(char target)", "[Stream-find-03]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find('t') == true); - REQUIRE(mock.readString() == arduino::String("est string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find('!') == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_findUntil.cpp b/test/src/Stream/test_findUntil.cpp deleted file mode 100644 index acd5ea1e..00000000 --- a/test/src/Stream/test_findUntil.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing findUntil(const char *target, const char *terminator)", "[Stream-findUntil-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - WHEN ("'terminator' appears before 'target'") - { - mock << "This is a : test string"; - REQUIRE(mock.findUntil("test", ": ") == false); - REQUIRE(mock.readString() == arduino::String("test string")); - } - WHEN ("'terminator' appears after 'target'") - { - mock << "This is a test : string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" : string")); - } - WHEN ("'terminator' is not included in the string at all") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - } - - WHEN ("'target' is not contained in stream") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("abc", "def") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_getTimeout.cpp b/test/src/Stream/test_getTimeout.cpp deleted file mode 100644 index 9a9e6e1b..00000000 --- a/test/src/Stream/test_getTimeout.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if default timeout is returned correctly", "[Stream-getTimeout-01]") -{ - StreamMock mock; - REQUIRE(mock.getTimeout() == 1000); -} diff --git a/test/src/Stream/test_parseFloat.cpp b/test/src/Stream/test_parseFloat.cpp deleted file mode 100644 index 2c273370..00000000 --- a/test/src/Stream/test_parseFloat.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -using namespace Catch; - -#include - -#include - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-01]") -{ - StreamMock mock; - - WHEN ("Only a integer (no comma) is contained in stream") - { - mock << "12"; - REQUIRE(mock.parseFloat() == 12.0f); - } - WHEN ("A positive float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A negative float is contained in stream") - { - mock << "-12.34"; - REQUIRE(mock.parseFloat() == -12.34f); - } - WHEN ("A float is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A float is provided with too many digits after the decimal point") - { - mock << "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870064"; - REQUIRE(mock.parseFloat() == Approx(3.141592654f)); - } - WHEN ("A float is larger than LONG_MAX") - { - mock << "602200000000000000000000.00"; - REQUIRE(mock.parseFloat() == Approx(6.022e23f)); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-02]") -{ - StreamMock mock; - - WHEN ("Only a integer is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef12.34")); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 12.34")); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-03]") -{ - StreamMock mock; - - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_WHITESPACE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } -} - - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseFloat-04]") -{ - StreamMock mock; - - WHEN ("A float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The float contains only ignore char values") - { - mock << "12a.3a4a"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 1.0f); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/test/src/Stream/test_parseInt.cpp b/test/src/Stream/test_parseInt.cpp deleted file mode 100644 index 69cf5805..00000000 --- a/test/src/Stream/test_parseInt.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -using namespace arduino; - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-01]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A negative integer is contained in stream") - { - mock << "-1234"; - REQUIRE(mock.parseInt() == -1234); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt() == 1234); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-02]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef1234")); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 1234")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-03]") -{ - StreamMock mock; - - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_WHITESPACE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseInt-04]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains only ignore char values") - { - mock << "12a3a4a"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/test/src/Stream/test_readBytes.cpp b/test/src/Stream/test_readBytes.cpp deleted file mode 100644 index 814a602f..00000000 --- a/test/src/Stream/test_readBytes.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytes(char *buffer, size_t length)", "[Stream-readBytes-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains less data than we want to read") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - mock << str; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == strlen(str)); - REQUIRE(strncmp(buf, str, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } - - WHEN ("the stream contains more data than we want to read") - { - char buf[5] = {0}; - mock << "some stream content"; - char const EXPECTED_STR[] = "some "; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 5); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } -} diff --git a/test/src/Stream/test_readBytesUntil.cpp b/test/src/Stream/test_readBytesUntil.cpp deleted file mode 100644 index fa0cff10..00000000 --- a/test/src/Stream/test_readBytesUntil.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytesUntil(char terminator, char *buffer, size_t length)", "[Stream-readBytesUntil-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains the termination character") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - char const EXPECTED_STR[] = "some"; - mock << str; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == strlen("some")); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } - - WHEN ("the stream does not contain the termination character") - { - char buf[32] = {0}; - char const STR[] = "some stream content"; - mock << STR; - - REQUIRE(mock.readBytesUntil('!', buf, sizeof(buf)) == strlen(STR)); - REQUIRE(strncmp(buf, STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_readString.cpp b/test/src/Stream/test_readString.cpp deleted file mode 100644 index 996be6e7..00000000 --- a/test/src/Stream/test_readString.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readString' with data available within the stream", "[Stream-readString-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test stream content"; - - REQUIRE(mock.readString() == arduino::String("This is test stream content")); -} diff --git a/test/src/Stream/test_readStringUntil.cpp b/test/src/Stream/test_readStringUntil.cpp deleted file mode 100644 index c4f52b54..00000000 --- a/test/src/Stream/test_readStringUntil.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include -#include -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readStringUntil' with separator available within the stream", "[Stream-readStringUntil-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test! lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test")); -} - -TEST_CASE ("Testing 'readStringUntil' with separator not available within the stream", "[Stream-readStringUntil-02]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test ... lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test ... lorem ipsum lalala")); -} diff --git a/test/src/Stream/test_setTimeout.cpp b/test/src/Stream/test_setTimeout.cpp deleted file mode 100644 index 08840c97..00000000 --- a/test/src/Stream/test_setTimeout.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if calling 'setTimeout' is indeed modifying the timeout", "[Stream-setTimeout-01]") -{ - StreamMock mock; - - mock.setTimeout(100); - - REQUIRE(mock.getTimeout() == 100); -} diff --git a/test/src/StreamMock.cpp b/test/src/StreamMock.cpp deleted file mode 100644 index c1768859..00000000 --- a/test/src/StreamMock.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -void StreamMock::operator << (char const * str) -{ - for (size_t c = 0; c < strlen(str); c++) - _stream.push_back(str[c]); -} - -size_t StreamMock::write(uint8_t ch) -{ - _stream.push_back(static_cast(ch)); - return 1; -} - -int StreamMock::available() -{ - return _stream.size(); -} - -int StreamMock::read() -{ - if (available() == 0) - return -1; - - /* Extract first/oldest element. */ - char const c = _stream.at(0); - /* Erase first/oldest element. */ - _stream.pop_front(); - - return c; -} - -int StreamMock::peek() -{ - if (available() == 0) - return -1; - - return _stream.at(0); -} diff --git a/test/src/String/StringPrinter.h b/test/src/String/StringPrinter.h deleted file mode 100644 index 1785f983..00000000 --- a/test/src/String/StringPrinter.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#pragma once - -#include -#include - -namespace Catch { - /** - * Template specialization that makes sure Catch can properly print - * Arduino Strings when used in comparisons directly. - * - * Note that without this, String objects are printed as 0 and 1, - * because they are implicitly convertible to StringIfHelperType, - * which is a dummy pointer. - */ - template<> - struct StringMaker { - static std::string convert(const arduino::String& str) { - if (str) - return ::Catch::Detail::stringify(std::string(str.c_str(), str.length())); - else - return "{invalid String}"; - } - }; -} // namespace Catch diff --git a/test/src/String/test_String.cpp b/test/src/String/test_String.cpp deleted file mode 100644 index d6ef7254..00000000 --- a/test/src/String/test_String.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]") -{ - char const CSTR[] = "Hello Arduino String Class"; - arduino::String str(CSTR); - REQUIRE(str == CSTR); -} - -TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]") -{ - arduino::String str1("Hello Arduino String class"), - str2(str1); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-Ctor-03]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1(F("Hello")); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-04]") -{ - char const ch = 'A'; - arduino::String str(ch); - REQUIRE(str == "A"); -} - -TEST_CASE ("Testing String(unsigned char, unsigned char base = 10) constructor()", "[String-Ctor-05]") -{ - unsigned char const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-06]") -{ - int const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-07]") -{ - unsigned int const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-08]") -{ - long const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-09]") -{ - unsigned long const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]") -{ - WHEN ("String::String (some float value)") - { - arduino::String str(1.234f); - REQUIRE(str == "1.23"); - } - WHEN ("String::String (FLT_MAX)") - { - arduino::String str(FLT_MAX); - REQUIRE(str == "340282346638528859811704183484516925440.00"); - } - WHEN ("String::String (-FLT_MAX)") - { - arduino::String str(-FLT_MAX); - REQUIRE(str == "-340282346638528859811704183484516925440.00"); - } -} - -TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-11]") -{ - WHEN ("String::String (some double value)") - { - arduino::String str(5.678); - REQUIRE(str == "5.68"); - } - WHEN ("String::String (DBL_MAX)") - { - arduino::String str(DBL_MAX); - REQUIRE(str == "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } - WHEN ("String::String (-DBL_MAX)") - { - arduino::String str(-DBL_MAX); - REQUIRE(str == "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid buffer", "[String-Ctor-12]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - char *buffer = NULL; - - arduino::String str1(F(buffer)); - REQUIRE_FALSE(str1); -} - -TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1(static_cast(str+ch)); - REQUIRE(str1 == "Hello!"); -} - -TEST_CASE ("Testing String(String &&) constructor()", "[String-Ctor-14]") -{ - arduino::String str("Hello"); - arduino::String str1(static_cast(str)); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to larger buffer", "[String-Ctor-15]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smaller buffer", "[String-Ctor-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str = static_cast(str1); - REQUIRE(str == "Arduino"); -} diff --git a/test/src/String/test_characterAccessFunc.cpp b/test/src/String/test_characterAccessFunc.cpp deleted file mode 100644 index e191f1d0..00000000 --- a/test/src/String/test_characterAccessFunc.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::charAt(unsigned int)", "[String-charAt-01]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.charAt(2) == 'l'); -} - -TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-02]") -{ - arduino::String str1("Hello"); - str1.setCharAt(1, 'a'); - REQUIRE(str1 == "Hallo"); -} - -TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]") -{ - WHEN("No bufsize") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 0, 0); - } - - WHEN("Index >= len") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 5, 6); - } - - WHEN("Valid operation") { - arduino::String str("Hello"); - unsigned char buf[3]; - str.getBytes(buf, 5, 3); - REQUIRE(buf[0] == 'l'); - REQUIRE(buf[1] == 'o'); - REQUIRE(buf[2] == '\0'); - } -} - -TEST_CASE ("Testing & String::operator[]", "[String-&operator subscript-03]") -{ - arduino::String str("Hello"); - str[0] = 'M'; - REQUIRE(str == "Mello"); -} - -TEST_CASE ("Testing & String::operator[] with invalid buffer", "[String-&operator subscript-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - str[0] = 'M'; - REQUIRE(str[0] == 0); -} diff --git a/test/src/String/test_compareTo.cpp b/test/src/String/test_compareTo.cpp deleted file mode 100644 index b5673201..00000000 --- a/test/src/String/test_compareTo.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]") -{ - WHEN ("Strings are equal") - { - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.compareTo(str2) == 0); - } - - WHEN ("str2 is empty") - { - arduino::String str1("Hello"), str2; - REQUIRE(str1.compareTo(str2) > 0); - } - - WHEN ("str1 is empty") - { - arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo(str2) < 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") -{ - WHEN ("Strings are equal") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("Hello") == 0); - } - - WHEN ("Passed string is empty") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("") > 0); - } - - WHEN ("Passed string is compared with empty string") - { - arduino::String str; - REQUIRE(str.compareTo("") == 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String-compareTo-03]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str("Hello"); - REQUIRE(str.compareTo(buffer) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str(buffer1); - REQUIRE(str.compareTo(buffer2) == 0); - } -} - - -TEST_CASE ("Testing String::compareTo(const String &) with empty buffer", "[String-compareTo-04]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str1("Hello"); - arduino::String str2(buffer); - REQUIRE(str1.compareTo(str2) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str1(buffer1); - arduino::String str2(buffer2); - REQUIRE(str1.compareTo(str2) == 0); - } -} diff --git a/test/src/String/test_comparisonFunc.cpp b/test/src/String/test_comparisonFunc.cpp deleted file mode 100644 index 558012d1..00000000 --- a/test/src/String/test_comparisonFunc.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::equals(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equals(str2) == 1); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String::operator!=(const String &) with exit status FAIL", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE_FALSE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equals(str2) == 0); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE_FALSE(str1 == str2); -} - -TEST_CASE ("Testing String::operator !=(const String &) with exit status PASS", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("Hello") == 1); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status FAIL", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 != "Hello"); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("World") == 0); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 == "World"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status PASS", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 != "World"); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string", "[String-equalsIgnoreCase-05]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equalsIgnoreCase(str2) == 1); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with NON-empty string", "[String-equalsIgnoreCase-06]") -{ - arduino::String str1("Hello"), str2("Hel"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with different strings", "[String-equalsIgnoreCase-07]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with same string", "[String-equalsIgnoreCase-08]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equalsIgnoreCase(str1) == 1); -} - -TEST_CASE ("Testing String::startsWith(const String &)", "[String-startsWith-09]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.startsWith(str2) == 0); - } - WHEN ("str1 starts with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Hello"); - REQUIRE(str1.startsWith(str2) == 1); - } - WHEN ("str1 does NOT start with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.startsWith(str2) == 0); - } -} - -TEST_CASE ("Testing String::endsWith(const String &)", "[String-endsWith-10]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.endsWith(str2) == 0); - } - WHEN ("str1 ends with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("World"); - REQUIRE(str1.endsWith(str2) == 1); - } - WHEN ("str1 does NOT end with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.endsWith(str2) == 0); - } -} diff --git a/test/src/String/test_concat.cpp b/test/src/String/test_concat.cpp deleted file mode 100644 index 81136591..00000000 --- a/test/src/String/test_concat.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::concat(const String &)", "[String-concat-01]") -{ - arduino::String str1("Hello "), str2("Arduino!"); - REQUIRE(str1.concat(str2) == 1); - REQUIRE(str1 == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]") -{ - arduino::String str("Hello "); - REQUIRE(str.concat("Arduino!") == 1); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") -{ - arduino::String str("Hello "); - char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello A"); -} - -TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") -{ - arduino::String str("Hello "); - unsigned char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello 65"); /* ASCII['A'] = 65 */ -} - -TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") -{ - arduino::String str("Hello "); - int const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") -{ - arduino::String str("Hello "); - unsigned int const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") -{ - arduino::String str("Hello "); - long const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") -{ - arduino::String str("Hello "); - unsigned long const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") -{ - arduino::String str("Hello "); - float const num = 1.234f; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1.23"); -} - -TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") -{ - arduino::String str("Hello "); - double const num = 5.678; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 5.68"); -} - -TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-concat-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello"); - REQUIRE(str1.concat(F(" Arduino")) == 1); - REQUIRE(str1 == "Hello Arduino"); -} diff --git a/test/src/String/test_indexOf.cpp b/test/src/String/test_indexOf.cpp deleted file mode 100644 index 12de054c..00000000 --- a/test/src/String/test_indexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::indexOf(char ch)", "[String-indexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l') == 2); - } -} - -TEST_CASE ("Testing String::indexOf(char ch, unsigned int fromIndex)", "[String-indexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf('a', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::indexOf(const String &)", "[String-indexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str) == 6); - } -} - -TEST_CASE ("Testing String::indexOf(const String &, unsigned int fromIndex)", "[String-indexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 3) == 6); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 8) == -1); - } -} diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp deleted file mode 100644 index a6e30f94..00000000 --- a/test/src/String/test_isEmpty.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * 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 deleted file mode 100644 index 13e850cb..00000000 --- a/test/src/String/test_lastIndexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::lastIndexOf(char ch)", "[String-lastIndexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l') == 7); - } -} - -TEST_CASE ("Testing String::lastIndexOf(char ch, unsigned int fromIndex)", "[String-lastIndexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf('o', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &)", "[String-lastIndexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str) == 15); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &, unsigned int fromIndex)", "[String-lastIndexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 17) == 15); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } -} diff --git a/test/src/String/test_length.cpp b/test/src/String/test_length.cpp deleted file mode 100644 index 062ba819..00000000 --- a/test/src/String/test_length.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::length when string is empty", "[String-length-01]") -{ - arduino::String str; - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::length when string contains characters", "[String-length-02]") -{ - arduino::String str("Testing String::length"); - REQUIRE(str.length() == strlen("Testing String::length")); -} diff --git a/test/src/String/test_move.cpp b/test/src/String/test_move.cpp deleted file mode 100644 index fda0a0d2..00000000 --- a/test/src/String/test_move.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include - -#include - -#include "StringPrinter.h" - -#include - -TEST_CASE("Testing String move constructor", "[String-move-01]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b(std::move(a)); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b.c_str() == a_str); - REQUIRE(b.length() == 3); -} - -TEST_CASE("Testing String move assignment", "[String-move-02]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b; - b = std::move(a); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b == arduino::String("src")); - REQUIRE(b.c_str() == a_str); -} - -TEST_CASE("Testing String move self assignment", "[String-move-03]") -{ -#if (defined(GCC_VERSION) && GCC_VERSION >= 13) || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#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 || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#pragma GCC diagnostic pop -#endif -} diff --git a/test/src/String/test_operators.cpp b/test/src/String/test_operators.cpp deleted file mode 100644 index 14f826b0..00000000 --- a/test/src/String/test_operators.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", "[String-operator+-01]") -{ - arduino::String str1("Hello "); - arduino::String str2("Arduino"); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+str2); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const char *)", "[String-operator+-02]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+"Arduino"); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]") -{ - arduino::String str1("Hello"); - char ch='!'; - arduino::String str("Hello!"); - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]") -{ - arduino::String str1("Hello "); - unsigned char ch='A'; - arduino::String str("Hello 65"); /* ASCII['A'] = 65 */ - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, int)", "[String-operator+-05]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello 1"); - REQUIRE(str == str1+1); -} - -TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]") -{ - arduino::String str1("Hello "); - unsigned int const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]") -{ - arduino::String str1("Hello "); - long const num = -1; - arduino::String str("Hello -1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]") -{ - arduino::String str1("Hello "); - unsigned long const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]") -{ - arduino::String str1("Hello "); - float const num = 1.234f; - arduino::String str("Hello 1.23"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]") -{ - arduino::String str1("Hello "); - double const num = 5.678; - arduino::String str("Hello 5.68"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+F("Arduino")); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&rval)", "[String-operator+-12]") -{ - arduino::String str1("Hello "); - arduino::String str = (str1+"Arduino"); - REQUIRE(str == "Hello Arduino"); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]") -{ - arduino::String str1("Hello"); - - char *buffer2 = NULL; - arduino::String str2(buffer2); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL does not leave string unchanged", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE(str != "Hello"); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL produces invalid string", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE_FALSE(str); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]") -{ - char *buffer1 = NULL; - arduino::String str1(buffer1); - - arduino::String str2("Hello"); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1("Arduino"); - str1 = static_cast(str+ch); - REQUIRE(str1 == "Hello!"); -} diff --git a/test/src/String/test_remove.cpp b/test/src/String/test_remove.cpp deleted file mode 100644 index 6281d773..00000000 --- a/test/src/String/test_remove.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::remove(index) when string is empty", "[String-remove-01]") -{ - arduino::String str; - str.remove(0); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index) when index is > string length", "[String-remove-02]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]") -{ - arduino::String str; - str.remove(0, 10); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index,count) when index is > string length", "[String-remove-05]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100, 10); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 100); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 1); - REQUIRE(str == "HelloArduino!"); -} diff --git a/test/src/String/test_replace.cpp b/test/src/String/test_replace.cpp deleted file mode 100644 index 36b44136..00000000 --- a/test/src/String/test_replace.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::replace(char, char) when string is empty", "[String-replace-01]") -{ - arduino::String str; - str.replace('a', 'b'); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements != 'find'", "[String-replace-02]") -{ - arduino::String str("Hello Arduino!"); - str.replace('Z', '0'); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]") -{ - arduino::String str("Hello Arduino!"); - str.replace('o', '0'); - str.replace('e', '3'); - str.replace('i', '1'); - REQUIRE(str == "H3ll0 Ardu1n0!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string does not contain substr 'find'", "[String-replace-04]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("Zulu"), arduino::String("11")); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string contains substr 'find'", "[String-replace-05]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(str == "He11o Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace'", "[String-replace-06]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("llo"), arduino::String("11")); - REQUIRE(str == "He11 Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-07]") -{ - arduino::String str("Hello Arduino!"); - 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 deleted file mode 100644 index 6397b905..00000000 --- a/test/src/String/test_substring.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::substring(unsigned int, unsigned int)", "[String-substring-01]") -{ - WHEN ("left higher than len") - { - arduino::String str("Hello"); - str.substring(7,9); - } - - WHEN ("right higher than len") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(1,9)); - } - - WHEN ("left higher than right") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(9,1)); - } -} diff --git a/test/src/String/test_toDouble.cpp b/test/src/String/test_toDouble.cpp deleted file mode 100644 index 3bb1ba5a..00000000 --- a/test/src/String/test_toDouble.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toDouble when string is empty", "[String-toDouble-01]") -{ - arduino::String str; - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains no number", "[String-toDouble-02]") -{ - arduino::String str("abc"); - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains a number", "[String-toDouble-03]") -{ - arduino::String str("-1.2345"); - double const val = str.toDouble(); - REQUIRE(val == -1.2345); -} - -TEST_CASE ("Testing String::toDouble when string does not have a buffer", "[String-toDouble-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toDouble() == 0); -} diff --git a/test/src/String/test_toFloat.cpp b/test/src/String/test_toFloat.cpp deleted file mode 100644 index 28fca212..00000000 --- a/test/src/String/test_toFloat.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toFloat when string is empty", "[String-toFloat-01]") -{ - arduino::String str; - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains no number", "[String-toFloat-02]") -{ - arduino::String str("abc"); - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains a number", "[String-toFloat-03]") -{ - arduino::String str("-1.2345"); - float const val = str.toFloat(); - REQUIRE(val == -1.2345f); -} diff --git a/test/src/String/test_toInt.cpp b/test/src/String/test_toInt.cpp deleted file mode 100644 index c93fcc4a..00000000 --- a/test/src/String/test_toInt.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toInt when string is empty", "[String-toInt-01]") -{ - arduino::String str; - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains no number", "[String-toInt-02]") -{ - arduino::String str("abc"); - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains a number", "[String-toInt-03]") -{ - arduino::String str("-1"); - int const val = str.toInt(); - REQUIRE(val == -1); -} - -TEST_CASE ("Testing String::toInt when string does not have a buffer", "[String-toInt-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toInt() == 0); -} diff --git a/test/src/String/test_toLowerCase.cpp b/test/src/String/test_toLowerCase.cpp deleted file mode 100644 index ec0f9eb3..00000000 --- a/test/src/String/test_toLowerCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toLowerCase", "[String-toLowerCase-01]") -{ - arduino::String str("HELLO ARDUINO"); - str.toLowerCase(); - REQUIRE(str == "hello arduino"); -} diff --git a/test/src/String/test_toUpperCase.cpp b/test/src/String/test_toUpperCase.cpp deleted file mode 100644 index 937fa52d..00000000 --- a/test/src/String/test_toUpperCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toUpperCase", "[String-toUpperCase-01]") -{ - arduino::String str("hello arduino"); - str.toUpperCase(); - REQUIRE(str == "HELLO ARDUINO"); -} diff --git a/test/src/String/test_trim.cpp b/test/src/String/test_trim.cpp deleted file mode 100644 index eddc9fdb..00000000 --- a/test/src/String/test_trim.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::trim with space at the beginning", "[String-trim-01]") -{ - arduino::String str(" hello"); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]") -{ - arduino::String str("hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at both beginning and end", "[String-trim-03]") -{ - arduino::String str(" hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]") -{ - arduino::String str("Hello Arduino!"); - str.trim(); - REQUIRE(str == "Hello Arduino!"); -} diff --git a/test/src/WCharacter/test_isAscii.cpp b/test/src/WCharacter/test_isAscii.cpp deleted file mode 100644 index 4ec92d3b..00000000 --- a/test/src/WCharacter/test_isAscii.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isAscii(...) is called with a valid ascii character", "[isAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::isAscii(c) == true); - }); -} - -TEST_CASE ("isAscii(...) is called with a invalid ascii character", "[isAscii-02]") -{ - REQUIRE(arduino::isAscii(0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a invalid casted ascii character", "[isAscii-03]") -{ - REQUIRE(arduino::isAscii((unsigned char)0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a character latger than 1 byte", "[isAscii-04]") -{ - REQUIRE(arduino::isAscii(0x3030) == false); -} - diff --git a/test/src/WCharacter/test_isControl.cpp b/test/src/WCharacter/test_isControl.cpp deleted file mode 100644 index c4e985c4..00000000 --- a/test/src/WCharacter/test_isControl.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_CONTROL_VECT = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,'\t','\f','\v','\n','\r',0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x7F}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isControl(...) is called with control char", "[isControl-01]") -{ - std::for_each(std::begin(VALID_CONTROL_VECT), - std::end (VALID_CONTROL_VECT), - [](char const c) - { - REQUIRE(arduino::isControl(c) == true); - }); -} - -TEST_CASE ("isControl(...) is called with non control char", "[isControl-02]") -{ - REQUIRE(arduino::isControl('z') == false); -} diff --git a/test/src/WCharacter/test_isDigit.cpp b/test/src/WCharacter/test_isDigit.cpp deleted file mode 100644 index 3303cf49..00000000 --- a/test/src/WCharacter/test_isDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_DIGIT_VECT = {'0','1','2','3','4','5','6','7','8','9'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isDigit(...) is called with valid digits", "[isDigit-01]") -{ - std::for_each(std::begin(VALID_DIGIT_VECT), - std::end (VALID_DIGIT_VECT), - [](char const c) - { - REQUIRE(arduino::isDigit(c) == true); - }); -} - -TEST_CASE ("isDigit(...) is called with non digit", "[isDigit-02]") -{ - REQUIRE(arduino::isDigit('z') == false); -} diff --git a/test/src/WCharacter/test_isHexadecimalDigit.cpp b/test/src/WCharacter/test_isHexadecimalDigit.cpp deleted file mode 100644 index ad5a0f4b..00000000 --- a/test/src/WCharacter/test_isHexadecimalDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_HEXADECIMAL_NUMBER_VECT = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isHexadecimalDigit(...) is called with valid hexadecimal numbers", "[isHexadecimalDigit-01]") -{ - std::for_each(std::begin(VALID_HEXADECIMAL_NUMBER_VECT), - std::end (VALID_HEXADECIMAL_NUMBER_VECT), - [](char const c) - { - REQUIRE(arduino::isHexadecimalDigit(c) == true); - }); -} - -TEST_CASE ("isHexadecimalDigit(...) is called with non hexadecimal number", "[isHexadecimalDigit-02]") -{ - REQUIRE(arduino::isHexadecimalDigit('z') == false); -} diff --git a/test/src/WCharacter/test_isLowerCase.cpp b/test/src/WCharacter/test_isLowerCase.cpp deleted file mode 100644 index 7a752200..00000000 --- a/test/src/WCharacter/test_isLowerCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isLowerCase(...) is called with a upper case number", "[isLowerCase-01]") -{ - REQUIRE(arduino::isLowerCase('A') == false); -} - -TEST_CASE ("isLowerCase(...) is called with a lower case number", "[isLowerCase-02]") -{ - REQUIRE(arduino::isLowerCase('a') == true); -} - -TEST_CASE ("isLowerCase(...) is called with a non-alphabetic number", "[isLowerCase-03]") -{ - REQUIRE(arduino::isLowerCase('0') == false); -} diff --git a/test/src/WCharacter/test_isPunct.cpp b/test/src/WCharacter/test_isPunct.cpp deleted file mode 100644 index 6d1167d3..00000000 --- a/test/src/WCharacter/test_isPunct.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_PUNCT_VECT = {'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isPunct('.') is called with a valid punct character", "[isPunct-01]") -{ - std::for_each(std::begin(VALID_PUNCT_VECT), - std::end (VALID_PUNCT_VECT), - [](char const c) - { - REQUIRE(arduino::isPunct(c) == true); - }); -} - -TEST_CASE ("isPunct(...) is called with a invalid punct character", "[isPunct-02]") -{ - REQUIRE(arduino::isPunct('a') == false); -} diff --git a/test/src/WCharacter/test_isSpace.cpp b/test/src/WCharacter/test_isSpace.cpp deleted file mode 100644 index 5c0be948..00000000 --- a/test/src/WCharacter/test_isSpace.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_SPACE_VECT = {' ', '\t', '\n', '\v', '\f', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isSpace(...) is called with a valid white space character", "[isSpace-01]") -{ - std::for_each(std::begin(VALID_SPACE_VECT), - std::end (VALID_SPACE_VECT), - [](char const c) - { - REQUIRE(arduino::isSpace(c) == true); - }); -} - -TEST_CASE ("isSpace(...) is called with a invalid white space character", "[isSpace-02]") -{ - REQUIRE(arduino::isSpace('{') == false); -} diff --git a/test/src/WCharacter/test_isUpperCase.cpp b/test/src/WCharacter/test_isUpperCase.cpp deleted file mode 100644 index 01dbf86a..00000000 --- a/test/src/WCharacter/test_isUpperCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isUpperCase(...) is called with a upper case number", "[isUpperCase-01]") -{ - REQUIRE(arduino::isUpperCase('A') == true); -} - -TEST_CASE ("isUpperCase(...) is called with a lower case number", "[isUpperCase-02]") -{ - REQUIRE(arduino::isUpperCase('a') == false); -} - -TEST_CASE ("isUpperCase(...) is called with a non-alphabetic number", "[isUpperCase-03]") -{ - REQUIRE(arduino::isUpperCase('0') == false); -} diff --git a/test/src/WCharacter/test_isWhitespace.cpp b/test/src/WCharacter/test_isWhitespace.cpp deleted file mode 100644 index 0eaa96de..00000000 --- a/test/src/WCharacter/test_isWhitespace.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isWhitespace(...) is called with ' '", "[isWhitespace-01]") -{ - REQUIRE(arduino::isWhitespace(' ') == true); -} - -TEST_CASE ("isWhitespace(...) is called with '\t'", "[isWhitespace-02]") -{ - REQUIRE(arduino::isWhitespace('\t') == true); -} - -TEST_CASE ("isWhitespace(...) is called with a non whitespace char", "[isWhitespace-03]") -{ - REQUIRE(arduino::isWhitespace('\r') == false); -} diff --git a/test/src/WCharacter/test_toAscii.cpp b/test/src/WCharacter/test_toAscii.cpp deleted file mode 100644 index eb085cbb..00000000 --- a/test/src/WCharacter/test_toAscii.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("toAscii(...) is called with a valid ascii character", "[toAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::toAscii(c) == c); - }); -} - -TEST_CASE ("toAscii(...) is called with a invalid ascii character", "[toAscii-02]") -{ - REQUIRE(arduino::toAscii(0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toAscii-03]") -{ - REQUIRE(arduino::toAscii((unsigned char)0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]") -{ - REQUIRE(arduino::toAscii(0x3030) == 0x30); -} diff --git a/test/src/dtostrf.cpp b/test/src/dtostrf.cpp deleted file mode 100644 index 02ea2fe7..00000000 --- a/test/src/dtostrf.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/test/src/itoa.cpp b/test/src/itoa.cpp deleted file mode 100644 index 4070ca62..00000000 --- a/test/src/itoa.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -std::string radixToFmtString(int const radix) -{ - if (radix == 8) return std::string("%o"); - else if (radix == 10) return std::string("%d"); - else if (radix == 16) return std::string("%X"); - else throw std::runtime_error("Invalid 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; -}