diff --git a/.codespellrc b/.codespellrc index 8d12eef4..4da64a41 100644 --- a/.codespellrc +++ b/.codespellrc @@ -1,7 +1,7 @@ # See: https://github.com/codespell-project/codespell#using-a-config-file [codespell] # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: -ignore-words-list = hel +ignore-words-list = hel,shiftin check-filenames = check-hidden = skip = ./.git,./test/external diff --git a/.github/ISSUE_TEMPLATE/api-deprecation.md b/.github/ISSUE_TEMPLATE/api-deprecation.md new file mode 100644 index 00000000..74e4c785 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/api-deprecation.md @@ -0,0 +1,25 @@ +--- +name: API deprecation +about: Suggest the deprecation of an API component defined by ArduinoCore-API. +title: "" +labels: enhancement +assignees: "" +--- + +### API component + + + +### Description + + + + +### Replacement API component + + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/api-improvement.md b/.github/ISSUE_TEMPLATE/api-improvement.md new file mode 100644 index 00000000..1cfa43bb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/api-improvement.md @@ -0,0 +1,24 @@ +--- +name: API improvement +about: Suggest an improvement to an existing API component. +title: "" +labels: enhancement +assignees: "" +--- + +### API component + + + +### Description + + + +### Is this a breaking change? + + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..cc410ae0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Report problems with the code in this repository. +title: "" +labels: bug +assignees: "" +--- + +### Description + + + +### Environment + +- Boards platform name: +- Boards platform version (as shown in Boards Manager): +- ArduinoCore-API version (if you manually installed it): + +### Current behavior + + + +### Expected behavior + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..af023790 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,10 @@ +contact_links: + - name: Learn about the Arduino language + url: https://www.arduino.cc/reference/en + about: User documentation is available at the Arduino language reference. + - name: Support request + url: https://forum.arduino.cc/ + about: We can help you out on the Arduino Forum! + - name: Discuss ArduinoCore-API development + url: https://groups.google.com/a/arduino.cc/g/developers + about: Arduino Developers Mailing List diff --git a/.github/ISSUE_TEMPLATE/new-api-component.md b/.github/ISSUE_TEMPLATE/new-api-component.md new file mode 100644 index 00000000..15991f46 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/new-api-component.md @@ -0,0 +1,15 @@ +--- +name: New API component +about: Suggest the addition of a new API component to ArduinoCore-API. +title: "" +labels: enhancement +assignees: "" +--- + +### Description + + + +### Additional information + + diff --git a/.github/ISSUE_TEMPLATE/other-enhancement.md b/.github/ISSUE_TEMPLATE/other-enhancement.md new file mode 100644 index 00000000..c72cea49 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other-enhancement.md @@ -0,0 +1,22 @@ +--- +name: Other enhancement +about: + Suggest an improvement for this project that doesn't fit in the specific categories + above. +title: "" +labels: enhancement +assignees: "" +--- + +### Description + + + +### Is this a breaking change? + + + + +### Additional information + + diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f72d58b1..55d5b650 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -38,8 +38,9 @@ jobs: coverage-data-path: ${{ env.COVERAGE_DATA_PATH }} # See: https://github.com/codecov/codecov-action/blob/master/README.md - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v1 + - name: Code coverage + uses: codecov/codecov-action@v3 with: - file: ${{ env.COVERAGE_DATA_PATH }} + token: ${{ secrets.CODECOV_TOKEN }} + files: ${{ env.COVERAGE_DATA_PATH }} fail_ci_if_error: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..93c700e8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +.idea/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..c6487f4f --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ +GNU LESSER GENERAL PUBLIC LICENSE + +Version 2.1, February 1999 + +Copyright (C) 1991, 1999 Free Software Foundation, Inc. +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] + +Preamble + +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. + +This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. + +When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. + +To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. + +For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. + +We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. + +To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. + +Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. + +Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. + +When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. + +We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. + +For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. + +In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. + +Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. + +The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. + +GNU LESSER GENERAL PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". + +A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. + +The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) + +"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. + +1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. + +(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. + +Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. + +This option is useful when you wish to copy part of the code of the Library into a program that is not a library. + +4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. + +If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. + +5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. + +However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. + +When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. + +If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) + +Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. + +6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. + +You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: + + a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. + + e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. + +For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. + +It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. + +7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. + + b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. + +10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. + +11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. + +14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Libraries + +If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). + +To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + one line to give the library's name and an idea of what it does. + Copyright (C) year name of author + + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: + +Yoyodyne, Inc., hereby disclaims all copyright interest in +the library `Frob' (a library for tweaking knobs) written +by James Random Hacker. + +signature of Ty Coon, 1 April 1990 +Ty Coon, President of Vice +That's all there is to it! diff --git a/README.md b/README.md index 16367ce5..506569a8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ As of now, the following official cores are utilising ArduinoCore-API: * [megaavr](https://github.com/arduino/ArduinoCore-megaAVR) * [mbed](https://github.com/arduino/ArduinoCore-mbed) * [samd](https://github.com/arduino/ArduinoCore-samd) +* [renesas](https://github.com/arduino/ArduinoCore-renesas) There's an ongoing effort to port the others, while maintainers of third-party cores are strongly invited to follow the same route in order to stay up-to-date with the new language features. For backwards compatibility, every revision of this repo will increase the `ARDUINO_API_VERSION` define. @@ -77,6 +78,8 @@ In order to compile a core which is implementing ArduinoCore-API you'll need to tar --exclude='*.git*' -cjhvf $yourcore-$version.tar.bz2 $yourcore/ ``` +The API is coded to the C++11 standard and the core's compiler must be able to support that version of the language. + Documentation for how to integrate with a Arduino core (which is necessary if you do not download the Arduino core via the Boards Manager) can be found here: * [ArduinoCore-megaavr](https://github.com/arduino/ArduinoCore-megaavr#developing) * [ArduinoCore-mbed](https://github.com/arduino/ArduinoCore-mbed#clone-the-repository-in-sketchbookhardwarearduino-git) diff --git a/api/ArduinoAPI.h b/api/ArduinoAPI.h index edc04918..3d53085b 100644 --- a/api/ArduinoAPI.h +++ b/api/ArduinoAPI.h @@ -9,7 +9,7 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public @@ -20,8 +20,8 @@ #ifndef ARDUINO_API_H #define ARDUINO_API_H -// version 1.4.0 -#define ARDUINO_API_VERSION 10400 +// version 1.5.1 +#define ARDUINO_API_VERSION 10501 #include "Binary.h" diff --git a/api/CanMsg.cpp b/api/CanMsg.cpp new file mode 100644 index 00000000..f4f93ce8 --- /dev/null +++ b/api/CanMsg.cpp @@ -0,0 +1,46 @@ +/* + CanMsg.cpp - Library for CAN message handling + Copyright (c) 2023 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsg.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * STATIC CONST DEFINITION + **************************************************************************************/ + +uint8_t const CanMsg::MAX_DATA_LENGTH; +uint32_t const CanMsg::CAN_EFF_FLAG; +uint32_t const CanMsg::CAN_SFF_MASK; +uint32_t const CanMsg::CAN_EFF_MASK; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ diff --git a/api/CanMsg.h b/api/CanMsg.h new file mode 100644 index 00000000..a8e32e5b --- /dev/null +++ b/api/CanMsg.h @@ -0,0 +1,156 @@ +/* + CanMsg.h - Library for CAN message handling + Copyright (c) 2023 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef ARDUINOCORE_API_CAN_MSG_H_ +#define ARDUINOCORE_API_CAN_MSG_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include +#include + +#include "Print.h" +#include "Printable.h" +#include "Common.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class CanMsg : public Printable +{ +public: + static uint8_t constexpr MAX_DATA_LENGTH = 8; + + static uint32_t constexpr CAN_EFF_FLAG = 0x80000000U; + static uint32_t constexpr CAN_SFF_MASK = 0x000007FFU; /* standard frame format (SFF) */ + static uint32_t constexpr CAN_EFF_MASK = 0x1FFFFFFFU; /* extended frame format (EFF) */ + + + CanMsg(uint32_t const can_id, uint8_t const can_data_len, uint8_t const * can_data_ptr) + : id{can_id} + , data_length{min(can_data_len, MAX_DATA_LENGTH)} + , data{0} + { + if (data_length && can_data_ptr) + memcpy(data, can_data_ptr, data_length); + } + + CanMsg() : CanMsg(0, 0, nullptr) { } + + CanMsg(CanMsg const & other) + { + id = other.id; + data_length = other.data_length; + if (data_length > 0) + memcpy(data, other.data, data_length); + } + + virtual ~CanMsg() { } + + CanMsg & operator = (CanMsg const & other) + { + if (this != &other) + { + id = other.id; + data_length = other.data_length; + if (data_length > 0) + memcpy(data, other.data, data_length); + } + return (*this); + } + + virtual size_t printTo(Print & p) const override + { + char buf[20] = {0}; + size_t len = 0; + + /* Print the header. */ + if (isStandardId()) + len = snprintf(buf, sizeof(buf), "[%03" PRIX32 "] (%d) : ", getStandardId(), data_length); + else + len = snprintf(buf, sizeof(buf), "[%08" PRIX32 "] (%d) : ", getExtendedId(), data_length); + size_t n = p.write(buf, len); + + /* Print the data. */ + for (size_t d = 0; d < data_length; d++) + { + len = snprintf(buf, sizeof(buf), "%02X", data[d]); + n += p.write(buf, len); + } + + /* Wrap up. */ + return n; + } + + + uint32_t getStandardId() const { + return (id & CAN_SFF_MASK); + } + uint32_t getExtendedId() const { + return (id & CAN_EFF_MASK); + } + bool isStandardId() const { + return ((id & CAN_EFF_FLAG) == 0); + } + bool isExtendedId() const { + return ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG); + } + + + /* + * CAN ID semantics (mirroring definition by linux/can.h): + * |- Bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) + * |- Bit 30 : reserved (future remote transmission request flag) + * |- Bit 29 : reserved (future error frame flag) + * |- Bit 0-28 : CAN identifier (11/29 bit) + */ + uint32_t id; + uint8_t data_length; + uint8_t data[MAX_DATA_LENGTH]; +}; + +/************************************************************************************** + * FREE FUNCTIONS + **************************************************************************************/ + +inline uint32_t CanStandardId(uint32_t const id) { + return (id & CanMsg::CAN_SFF_MASK); +} + +inline uint32_t CanExtendedId(uint32_t const id) { + return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK)); +} + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_CAN_MSG_H_ */ diff --git a/api/CanMsgRingbuffer.cpp b/api/CanMsgRingbuffer.cpp new file mode 100644 index 00000000..56abbac4 --- /dev/null +++ b/api/CanMsgRingbuffer.cpp @@ -0,0 +1,74 @@ +/* + CanMsgRingbuffer.cpp - Library for CAN message handling + Copyright (c) 2023 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsgRingbuffer.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CTOR/DTOR + **************************************************************************************/ + +CanMsgRingbuffer::CanMsgRingbuffer() +: _head{0} +, _tail{0} +, _num_elems{0} +{ +} + +/************************************************************************************** + * PUBLIC MEMBER FUNCTIONS + **************************************************************************************/ + +void CanMsgRingbuffer::enqueue(CanMsg const & msg) +{ + if (isFull()) + return; + + _buf[_head] = msg; + _head = next(_head); + _num_elems = _num_elems + 1; +} + +CanMsg CanMsgRingbuffer::dequeue() +{ + if (isEmpty()) + return CanMsg(); + + CanMsg const msg = _buf[_tail]; + _tail = next(_tail); + _num_elems = _num_elems - 1; + + return msg; +} + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ diff --git a/api/CanMsgRingbuffer.h b/api/CanMsgRingbuffer.h new file mode 100644 index 00000000..9eb6bafc --- /dev/null +++ b/api/CanMsgRingbuffer.h @@ -0,0 +1,72 @@ +/* + CanMsgRingbuffer.h - Library for CAN message handling + Copyright (c) 2023 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ +#define ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include "CanMsg.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class CanMsgRingbuffer +{ +public: + static size_t constexpr RING_BUFFER_SIZE = 32U; + + CanMsgRingbuffer(); + + inline bool isFull() const { return (_num_elems == RING_BUFFER_SIZE); } + void enqueue(CanMsg const & msg); + + inline bool isEmpty() const { return (_num_elems == 0); } + CanMsg dequeue(); + + inline size_t available() const { return _num_elems; } + +private: + CanMsg _buf[RING_BUFFER_SIZE]; + volatile size_t _head; + volatile size_t _tail; + volatile size_t _num_elems; + + inline size_t next(size_t const idx) const { return ((idx + 1) % RING_BUFFER_SIZE); } +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ */ diff --git a/api/Common.cpp b/api/Common.cpp index d1f822c9..8299247a 100644 --- a/api/Common.cpp +++ b/api/Common.cpp @@ -1,3 +1,22 @@ +/* + Common.cpp - Common function implementations + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include "Common.h" /* C++ prototypes */ diff --git a/api/Common.h b/api/Common.h index 44fe95e8..9b28f40a 100644 --- a/api/Common.h +++ b/api/Common.h @@ -1,3 +1,22 @@ +/* + Common.h - Common definitions for Arduino core + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #pragma once #include #include diff --git a/api/Compat.h b/api/Compat.h index 725ccd66..564170c6 100644 --- a/api/Compat.h +++ b/api/Compat.h @@ -1,3 +1,22 @@ +/* + Compat.h - Compatibility layer for Arduino API + Copyright (c) 2018 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #ifndef __COMPAT_H__ #define __COMPAT_H__ diff --git a/api/DMAPool.h b/api/DMAPool.h new file mode 100644 index 00000000..815f5d3e --- /dev/null +++ b/api/DMAPool.h @@ -0,0 +1,316 @@ +/* + This file is part of the Arduino_AdvancedAnalog library. + Copyright (c) 2023-2024 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __DMA_POOL_H__ +#define __DMA_POOL_H__ + +#include +#include + +namespace arduino { + +#if defined(__DCACHE_PRESENT) +#define __CACHE_LINE_SIZE__ __SCB_DCACHE_LINE_SIZE +#elif defined(__cpp_lib_hardware_interference_size) +#define __CACHE_LINE_SIZE__ std::hardware_constructive_interference_size +#else // No cache. +#define __CACHE_LINE_SIZE__ alignof(int) +#endif + +// Single-producer, single-consumer, lock-free bounded Queue. +template class SPSCQueue { + private: + size_t capacity; + std::atomic head; + std::atomic tail; + std::unique_ptr buff; + + public: + SPSCQueue(size_t size=0): + capacity(0), tail(0), head(0), buff(nullptr) { + if (size) { + T *mem = new T[size + 1]; + if (mem) { + buff.reset(mem); + capacity = size + 1; + } + } + } + + void reset() { + tail = head = 0; + } + + size_t empty() { + return tail == head; + } + + operator bool() const { + return buff.get() != nullptr; + } + + bool push(T data) { + size_t curr = head.load(std::memory_order_relaxed); + size_t next = (curr + 1) % capacity; + if (!buff || (next == tail.load(std::memory_order_acquire))) { + return false; + } + buff[curr] = data; + head.store(next, std::memory_order_release); + return true; + } + + T pop(bool peek=false) { + size_t curr = tail.load(std::memory_order_relaxed); + if (!buff || (curr == head.load(std::memory_order_acquire))) { + return nullptr; + } + T data = buff[curr]; + if (!peek) { + size_t next = (curr + 1) % capacity; + tail.store(next, std::memory_order_release); + } + return data; + } +}; + +enum { + DMA_BUFFER_READ = (1 << 0), + DMA_BUFFER_WRITE = (1 << 1), + DMA_BUFFER_DISCONT = (1 << 2), + DMA_BUFFER_INTRLVD = (1 << 3), +} DMABufferFlags; + +// Forward declaration of DMAPool class. +template class DMAPool; + +template class DMABuffer { + private: + DMAPool *pool; + size_t n_samples; + size_t n_channels; + T *ptr; + uint32_t ts; + uint32_t flags; + + public: + DMABuffer(DMAPool *pool=nullptr, size_t samples=0, size_t channels=0, T *mem=nullptr): + pool(pool), n_samples(samples), n_channels(channels), ptr(mem), ts(0), flags(0) { + } + + T *data() { + return ptr; + } + + size_t size() { + return n_samples * n_channels; + } + + size_t bytes() { + return n_samples * n_channels * sizeof(T); + } + + void flush() { + #if __DCACHE_PRESENT + if (ptr) { + SCB_CleanDCache_by_Addr(data(), bytes()); + } + #endif + } + + void invalidate() { + #if __DCACHE_PRESENT + if (ptr) { + SCB_InvalidateDCache_by_Addr(data(), bytes()); + } + #endif + } + + uint32_t timestamp() { + return ts; + } + + void timestamp(uint32_t ts) { + this->ts = ts; + } + + uint32_t channels() { + return n_channels; + } + + void release() { + if (pool && ptr) { + pool->free(this, flags); + } + } + + void set_flags(uint32_t f) { + flags |= f; + } + + bool get_flags(uint32_t f=0xFFFFFFFFU) { + return flags & f; + } + + void clr_flags(uint32_t f=0xFFFFFFFFU) { + flags &= (~f); + } + + T& operator[](size_t i) { + assert(ptr && i < size()); + return ptr[i]; + } + + const T& operator[](size_t i) const { + assert(ptr && i < size()); + return ptr[i]; + } + + operator bool() const { + return (ptr != nullptr); + } +}; + +template class DMAPool { + private: + uint8_t *mem; + bool managed; + SPSCQueue*> wqueue; + SPSCQueue*> rqueue; + + // Allocates dynamic aligned memory. + // Note this memory must be free'd with aligned_free. + static void *aligned_malloc(size_t size) { + void **ptr, *stashed; + size_t offset = A - 1 + sizeof(void *); + if ((A % 2) || !((stashed = ::malloc(size + offset)))) { + return nullptr; + } + ptr = (void **) (((uintptr_t) stashed + offset) & ~(A - 1)); + ptr[-1] = stashed; + return ptr; + } + + // Frees dynamic aligned memory allocated with aligned_malloc. + static void aligned_free(void *ptr) { + if (ptr != nullptr) { + ::free(((void **) ptr)[-1]); + } + } + + public: + DMAPool(size_t n_samples, size_t n_channels, size_t n_buffers, void *mem_in=nullptr): + mem((uint8_t *) mem_in), managed(mem_in==nullptr), wqueue(n_buffers), rqueue(n_buffers) { + // Round up to the next multiple of the alignment. + size_t bufsize = (((n_samples * n_channels * sizeof(T)) + (A-1)) & ~(A-1)); + if (bufsize && rqueue && wqueue) { + if (mem == nullptr) { + // Allocate an aligned memory block for the DMA buffers' memory. + mem = (uint8_t *) aligned_malloc(n_buffers * bufsize); + if (!mem) { + // Failed to allocate memory. + return; + } + } + // Allocate the DMA buffers, initialize them using aligned + // pointers from the pool, and add them to the write queue. + for (size_t i=0; i *buf = new DMABuffer( + this, n_samples, n_channels, (T *) &mem[i * bufsize] + ); + if (buf == nullptr) { + break; + } + wqueue.push(buf); + } + } + } + + ~DMAPool() { + while (readable()) { + delete alloc(DMA_BUFFER_READ); + } + + while (writable()) { + delete alloc(DMA_BUFFER_WRITE); + } + + if (mem && managed) { + aligned_free(mem); + } + } + + bool writable() { + return !(wqueue.empty()); + } + + bool readable() { + return !(rqueue.empty()); + } + + void flush() { + while (readable()) { + DMABuffer *buf = alloc(DMA_BUFFER_READ); + if (buf) { + buf->release(); + } + } + } + + DMABuffer *alloc(uint32_t flags) { + DMABuffer *buf = nullptr; + if (flags & DMA_BUFFER_READ) { + // Get a DMA buffer from the read/ready queue. + buf = rqueue.pop(); + } else { + // Get a DMA buffer from the write/free queue. + buf = wqueue.pop(); + } + if (buf) { + buf->clr_flags(DMA_BUFFER_READ | DMA_BUFFER_WRITE); + buf->set_flags(flags); + } + return buf; + } + + void free(DMABuffer *buf, uint32_t flags=0) { + if (buf == nullptr) { + return; + } + if (flags == 0) { + flags = buf->get_flags(); + } + if (flags & DMA_BUFFER_READ) { + // Return the DMA buffer to the write/free queue. + buf->clr_flags(); + wqueue.push(buf); + } else { + // Return the DMA buffer to the read/ready queue. + rqueue.push(buf); + } + } + +}; + +} // namespace arduino + +using arduino::DMAPool; +using arduino::DMABuffer; +using arduino::SPSCQueue; +#endif //__DMA_POOL_H__ diff --git a/api/HardwareCAN.h b/api/HardwareCAN.h new file mode 100644 index 00000000..57d9d582 --- /dev/null +++ b/api/HardwareCAN.h @@ -0,0 +1,118 @@ +/* + HardwareCAN.h - CAN bus interface for Arduino core + Copyright (c) 2023 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef ARDUINOCORE_API_HARDWARECAN_H +#define ARDUINOCORE_API_HARDWARECAN_H + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include "CanMsg.h" +#include "CanMsgRingbuffer.h" + +/************************************************************************************** + * TYPEDEF + **************************************************************************************/ + +enum class CanBitRate : int +{ + BR_125k = 125000, + BR_250k = 250000, + BR_500k = 500000, + BR_1000k = 1000000, +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace arduino +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class HardwareCAN +{ +public: + virtual ~HardwareCAN() {} + + + /** + * Initialize the CAN controller. + * + * @param can_bitrate the bus bit rate + * @return true if initialization succeeded and the controller is operational + */ + virtual bool begin(CanBitRate const can_bitrate) = 0; + + /** + * Disable the CAN controller. + * + * Whether any messages that are buffered will be sent is _implementation defined_. + */ + virtual void end() = 0; + + /** + * Enqueue a message for transmission to the CAN bus. + * + * This call returns when the message has been enqueued for transmission. + * Due to bus arbitration and error recovery there may be a substantial delay + * before the message is actually sent. + * + * An implementation must ensure that all messages with the same CAN priority + * are sent in the order in which they are enqueued. + * + * It is _implementation defined_ whether multiple messages can be enqueued + * for transmission, and if messages with higher CAN priority can preempt the + * transmission of previously enqueued messages. The default configuration for + * and implementation should not allow multiple messages to be enqueued. + * + * @param msg the message to send + * @return 1 if the message was enqueued, an _implementation defined_ error code < 0 if there was an error + * @todo define specific error codes, especially "message already pending" + */ + virtual int write(CanMsg const &msg) = 0; + + /** + * Determine if any messages have been received and buffered. + * + * @return the number of unread messages that have been received + */ + virtual size_t available() = 0; + + /** + * Returns the first message received, or an empty message if none are available. + * + * Messages must be returned in the order received. + * + * @return the first message in the receive buffer + */ + virtual CanMsg read() = 0; +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +} /* arduino */ + +#endif /* ARDUINOCORE_API_HARDWARECAN_H */ diff --git a/api/HardwareI2C.h b/api/HardwareI2C.h index 4a8e5f98..98c6bfd7 100644 --- a/api/HardwareI2C.h +++ b/api/HardwareI2C.h @@ -1,4 +1,5 @@ /* + HardwareI2C.h - Hardware I2C interface for Arduino Copyright (c) 2016 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/api/HardwareSPI.h b/api/HardwareSPI.h index 8b8affd0..7f6aea2b 100644 --- a/api/HardwareSPI.h +++ b/api/HardwareSPI.h @@ -1,4 +1,5 @@ /* + HardwareSPI.h - Hardware SPI interface for Arduino Copyright (c) 2018 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/api/HardwareSerial.h b/api/HardwareSerial.h index e8f0657a..b687cdf1 100644 --- a/api/HardwareSerial.h +++ b/api/HardwareSerial.h @@ -1,4 +1,5 @@ /* + HardwareSerial.h - Hardware serial interface for Arduino Copyright (c) 2016 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/api/IPAddress.cpp b/api/IPAddress.cpp index 4b729319..05b41bc1 100644 --- a/api/IPAddress.cpp +++ b/api/IPAddress.cpp @@ -94,6 +94,33 @@ IPAddress::IPAddress(const char *address) fromString(address); } +String IPAddress::toString4() const +{ + char szRet[16]; + snprintf(szRet, sizeof(szRet), "%u.%u.%u.%u", _address.bytes[IPADDRESS_V4_BYTES_INDEX], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3]); + return String(szRet); +} + +String IPAddress::toString6() const +{ + char szRet[40]; + snprintf(szRet, sizeof(szRet), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", + _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3], + _address.bytes[4], _address.bytes[5], _address.bytes[6], _address.bytes[7], + _address.bytes[8], _address.bytes[9], _address.bytes[10], _address.bytes[11], + _address.bytes[12], _address.bytes[13], _address.bytes[14], _address.bytes[15]); + return String(szRet); +} + +String IPAddress::toString() const +{ + if (_type == IPv4) { + return toString4(); + } else { + return toString6(); + } +} + bool IPAddress::fromString(const char *address) { if (!fromString4(address)) { return fromString6(address); diff --git a/api/IPAddress.h b/api/IPAddress.h index 964faa67..31a2d06d 100644 --- a/api/IPAddress.h +++ b/api/IPAddress.h @@ -96,8 +96,9 @@ class IPAddress : public Printable { IPAddress& operator=(const char *address); virtual size_t printTo(Print& p) const; + String toString() const; - IPType type() { return _type; } + IPType type() const { return _type; } friend class UDP; friend class Client; @@ -110,6 +111,8 @@ class IPAddress : public Printable { protected: bool fromString4(const char *address); bool fromString6(const char *address); + String toString4() const; + String toString6() const; }; extern const IPAddress IN6ADDR_ANY; diff --git a/api/Interrupts.h b/api/Interrupts.h index e306fc79..c3e37ade 100644 --- a/api/Interrupts.h +++ b/api/Interrupts.h @@ -1,3 +1,22 @@ +/* + Interrupts.h - Arduino interrupt management functions + Copyright (c) 2018 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #ifndef W_INTERRUPTS_CPP #define W_INTERRUPTS_CPP #ifdef __cplusplus diff --git a/api/Print.cpp b/api/Print.cpp index 8c3e1930..4a6e942a 100644 --- a/api/Print.cpp +++ b/api/Print.cpp @@ -1,4 +1,5 @@ /* + Print.cpp - Base class that provides print() and println() Copyright (c) 2014 Arduino. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software @@ -287,6 +288,12 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base) uint8_t i = 0; uint8_t innerLoops = 0; + // Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178 + if (n64 == 0) { + write('0'); + return 1; + } + // prevent crash if called with base == 1 if (base < 2) base = 10; diff --git a/api/Print.h b/api/Print.h index 5a19fe78..2016d7d5 100644 --- a/api/Print.h +++ b/api/Print.h @@ -1,4 +1,5 @@ /* + Print.h - Base class that provides print() and println() Copyright (c) 2016 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/api/Printable.h b/api/Printable.h index 972866e8..850c8d21 100644 --- a/api/Printable.h +++ b/api/Printable.h @@ -1,4 +1,5 @@ /* + Printable.h - Interface for classes that can be printed via Print Copyright (c) 2016 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/api/RingBuffer.h b/api/RingBuffer.h index 833350d1..b69c20d4 100644 --- a/api/RingBuffer.h +++ b/api/RingBuffer.h @@ -1,4 +1,5 @@ /* + RingBuffer.h - Ring buffer implementation Copyright (c) 2014 Arduino. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software @@ -77,7 +78,7 @@ void RingBufferN::store_char( uint8_t c ) { _aucBuffer[_iHead] = c ; _iHead = nextIndex(_iHead); - _numElems++; + _numElems = _numElems + 1; } } @@ -97,7 +98,7 @@ int RingBufferN::read_char() uint8_t value = _aucBuffer[_iTail]; _iTail = nextIndex(_iTail); - _numElems--; + _numElems = _numElems - 1; return value; } @@ -138,4 +139,4 @@ bool RingBufferN::isFull() } #endif /* _RING_BUFFER_ */ -#endif /* __cplusplus */ \ No newline at end of file +#endif /* __cplusplus */ diff --git a/api/String.cpp b/api/String.cpp index 0a5c11fe..4f176374 100644 --- a/api/String.cpp +++ b/api/String.cpp @@ -63,7 +63,6 @@ String::String(const __FlashStringHelper *pstr) *this = pstr; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String::String(String &&rval) : buffer(rval.buffer) , capacity(rval.capacity) @@ -73,7 +72,6 @@ String::String(String &&rval) rval.capacity = 0; rval.len = 0; } -#endif String::String(char c) { @@ -213,7 +211,6 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length) return *this; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void String::move(String &rhs) { if (this != &rhs) @@ -229,31 +226,28 @@ void String::move(String &rhs) rhs.capacity = 0; } } -#endif String & String::operator = (const String &rhs) { if (this == &rhs) return *this; - + if (rhs.buffer) copy(rhs.buffer, rhs.len); else invalidate(); - + return *this; } -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & String::operator = (String &&rval) { move(rval); return *this; } -#endif String & String::operator = (const char *cstr) { if (cstr) copy(cstr, strlen(cstr)); else invalidate(); - + return *this; } @@ -484,7 +478,7 @@ bool String::equalsIgnoreCase( const String &s2 ) const const char *p2 = s2.buffer; while (*p1) { if (tolower(*p1++) != tolower(*p2++)) return false; - } + } return true; } @@ -515,7 +509,7 @@ char String::charAt(unsigned int loc) const return operator[](loc); } -void String::setCharAt(unsigned int loc, char c) +void String::setCharAt(unsigned int loc, char c) { if (loc < len) buffer[loc] = c; } @@ -652,9 +646,9 @@ void String::replace(const String& find, const String& replace) } } else if (diff < 0) { unsigned int size = len; // compute size needed for result + diff = 0 - diff; while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { readFrom = foundAt + find.len; - diff = 0 - diff; size -= diff; } if (size == len) return; diff --git a/api/String.h b/api/String.h index 03ecf442..0bafd35a 100644 --- a/api/String.h +++ b/api/String.h @@ -72,9 +72,7 @@ class String String(const uint8_t *cstr, unsigned int length) : String((const char*)cstr, length) {} String(const String &str); String(const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String(String &&rval); - #endif explicit String(char c); explicit String(unsigned char, unsigned char base=10); explicit String(int, unsigned char base=10); @@ -91,6 +89,7 @@ class String // invalid string (i.e., "if (s)" will be true afterwards) bool reserve(unsigned int size); inline unsigned int length(void) const {return len;} + inline bool isEmpty(void) const { return length() == 0; } // creates a copy of the assigned value. if the value is null or // invalid, or if the memory allocation fails, the string will be @@ -98,9 +97,7 @@ class String String & operator = (const String &rhs); String & operator = (const char *cstr); String & operator = (const __FlashStringHelper *str); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) String & operator = (String &&rval); - #endif // concatenate (works w/ built-in types) @@ -231,9 +228,7 @@ class String // copy and move String & copy(const char *cstr, unsigned int length); String & copy(const __FlashStringHelper *pstr, unsigned int length); - #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) void move(String &rhs); - #endif }; class StringSumHelper : public String diff --git a/api/WCharacter.h b/api/WCharacter.h index e3642ccb..d0508424 100644 --- a/api/WCharacter.h +++ b/api/WCharacter.h @@ -70,7 +70,7 @@ inline bool isAscii(int c) // Checks for a blank character, that is, a space or a tab. inline bool isWhitespace(int c) { - return ( isblank (c) == 0 ? false : true); + return ( c == '\t' || c == ' '); } @@ -98,7 +98,7 @@ inline bool isGraph(int c) // Checks for a lower-case character. inline bool isLowerCase(int c) { - return (islower (c) == 0 ? false : true); + return ( c >= 'a' && c <= 'z' ); } @@ -113,7 +113,7 @@ inline bool isPrintable(int c) // or an alphanumeric character. inline bool isPunct(int c) { - return ( ispunct (c) == 0 ? false : true); + return ( isPrintable(c) && !isSpace(c) && !isAlphaNumeric(c) ); } diff --git a/api/deprecated-avr-comp/avr/dtostrf.c.impl b/api/deprecated-avr-comp/avr/dtostrf.c.impl index 96987a8f..f410886c 100644 --- a/api/deprecated-avr-comp/avr/dtostrf.c.impl +++ b/api/deprecated-avr-comp/avr/dtostrf.c.impl @@ -29,9 +29,12 @@ char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { asm(".global _printf_float"); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" char fmt[20]; sprintf(fmt, "%%%d.%df", width, prec); sprintf(sout, fmt, val); return sout; +#pragma GCC diagnostic pop } diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/api/deprecated-avr-comp/avr/pgmspace.h index 95897d75..a80e4a51 100644 --- a/api/deprecated-avr-comp/avr/pgmspace.h +++ b/api/deprecated-avr-comp/avr/pgmspace.h @@ -30,7 +30,9 @@ #include #define PROGMEM +#define __ATTR_PROGMEM__ #define PGM_P const char * +#define PGM_VOID_P const void * #define PSTR(str) (str) #define _SFR_BYTE(n) (n) diff --git a/api/itoa.h b/api/itoa.h index 55b28493..c2077833 100644 --- a/api/itoa.h +++ b/api/itoa.h @@ -1,4 +1,5 @@ /* + itoa.h - Integer to ASCII conversion Copyright (c) 2016 Arduino LLC. All right reserved. This library is free software; you can redistribute it and/or @@ -8,8 +9,8 @@ This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0f6200b2..31b75483 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + ########################################################################## cmake_minimum_required(VERSION 2.8) @@ -8,7 +10,7 @@ project(test-ArduinoCore-API) ########################################################################## -include_directories(../api) +include_directories(..) include_directories(include) include_directories(external/catch/v2.13.9/include) @@ -25,10 +27,20 @@ set(TEST_TARGET ${CMAKE_PROJECT_NAME}) ########################################################################## set(TEST_SRCS + src/CanMsg/test_CanMsg.cpp + src/CanMsg/test_CanMsg_CopyCtor.cpp + src/CanMsg/test_CanExtendedId.cpp + src/CanMsg/test_CanStandardId.cpp + src/CanMsg/test_isExtendedId.cpp + src/CanMsg/test_isStandardId.cpp + src/CanMsg/test_operator_assignment.cpp + src/CanMsg/test_printTo.cpp + src/CanMsgRingbuffer/test_available.cpp src/Common/test_makeWord.cpp src/Common/test_map.cpp src/Common/test_max.cpp src/Common/test_min.cpp + src/IPAddress/test_toString.cpp src/IPAddress/test_fromString.cpp src/IPAddress/test_fromString6.cpp src/IPAddress/test_IPAddress.cpp @@ -94,6 +106,8 @@ set(TEST_SRCS ) set(TEST_DUT_SRCS + ../api/CanMsg.cpp + ../api/CanMsgRingbuffer.cpp ../api/Common.cpp ../api/IPAddress.cpp ../api/String.cpp @@ -120,8 +134,8 @@ add_compile_definitions(HOST) add_compile_options(-Wall -Wextra -Wpedantic -Werror) add_compile_options(-Wno-cast-function-type) -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "--coverage") -set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "--coverage -Wno-deprecated-copy") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -Wno-deprecated-copy") ########################################################################## diff --git a/test/include/MillisFake.h b/test/include/MillisFake.h index da21049b..bdb3f14c 100644 --- a/test/include/MillisFake.h +++ b/test/include/MillisFake.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef MILLIS_FAKE_H_ @@ -9,7 +11,7 @@ * INCLUDE **************************************************************************************/ -#include +#include /************************************************************************************** * FUNCTION DECLARATION diff --git a/test/include/PrintMock.h b/test/include/PrintMock.h index 87c83313..9a103848 100644 --- a/test/include/PrintMock.h +++ b/test/include/PrintMock.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef PRINT_MOCK_H_ @@ -11,7 +13,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/include/PrintableMock.h b/test/include/PrintableMock.h index cfc00555..f55540d1 100644 --- a/test/include/PrintableMock.h +++ b/test/include/PrintableMock.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef PRINTABLE_MOCK_H_ @@ -11,7 +13,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/include/StreamMock.h b/test/include/StreamMock.h index 91eb3c26..afa4b487 100644 --- a/test/include/StreamMock.h +++ b/test/include/StreamMock.h @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ #ifndef STREAM_MOCK_H_ @@ -11,7 +13,7 @@ #include -#include +#include /************************************************************************************** * CLASS DECLARATION diff --git a/test/src/CanMsg/test_CanExtendedId.cpp b/test/src/CanMsg/test_CanExtendedId.cpp new file mode 100644 index 00000000..0377a40a --- /dev/null +++ b/test/src/CanMsg/test_CanExtendedId.cpp @@ -0,0 +1,43 @@ +/* + * 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 new file mode 100644 index 00000000..f132e84a --- /dev/null +++ b/test/src/CanMsg/test_CanMsg.cpp @@ -0,0 +1,68 @@ +/* + * 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 new file mode 100644 index 00000000..9c4ee4e1 --- /dev/null +++ b/test/src/CanMsg/test_CanMsg_CopyCtor.cpp @@ -0,0 +1,39 @@ +/* + * 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 new file mode 100644 index 00000000..28fc3373 --- /dev/null +++ b/test/src/CanMsg/test_CanStandardId.cpp @@ -0,0 +1,42 @@ +/* + * 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 new file mode 100644 index 00000000..ff309d9c --- /dev/null +++ b/test/src/CanMsg/test_isExtendedId.cpp @@ -0,0 +1,35 @@ +/* + * 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 new file mode 100644 index 00000000..36789d07 --- /dev/null +++ b/test/src/CanMsg/test_isStandardId.cpp @@ -0,0 +1,35 @@ +/* + * 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 new file mode 100644 index 00000000..a2f56457 --- /dev/null +++ b/test/src/CanMsg/test_operator_assignment.cpp @@ -0,0 +1,41 @@ +/* + * 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 new file mode 100644 index 00000000..53e9e059 --- /dev/null +++ b/test/src/CanMsg/test_printTo.cpp @@ -0,0 +1,46 @@ +/* + * 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 new file mode 100644 index 00000000..9a3b55cd --- /dev/null +++ b/test/src/CanMsgRingbuffer/test_available.cpp @@ -0,0 +1,35 @@ +/* + * 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 index 2e0a29dc..55ca55ec 100644 --- a/test/src/Common/test_makeWord.cpp +++ b/test/src/Common/test_makeWord.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Common/test_map.cpp b/test/src/Common/test_map.cpp index aef3e72a..c1ccde28 100644 --- a/test/src/Common/test_map.cpp +++ b/test/src/Common/test_map.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Common/test_max.cpp b/test/src/Common/test_max.cpp index 6612cc95..bff6830c 100644 --- a/test/src/Common/test_max.cpp +++ b/test/src/Common/test_max.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE @@ -53,7 +55,7 @@ TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") { uint32_t const a = 32; uint64_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(unsigned long)); + REQUIRE(typeid(max(a,b)) == typeid(uint64_t)); } WHEN("type(A) = int8_t, type(b) = int16_t") { @@ -71,6 +73,6 @@ TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") { int32_t const a = -32; int64_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(long)); + REQUIRE(typeid(max(a,b)) == typeid(int64_t)); } } diff --git a/test/src/Common/test_min.cpp b/test/src/Common/test_min.cpp index 2298dc6c..dcb24b81 100644 --- a/test/src/Common/test_min.cpp +++ b/test/src/Common/test_min.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE @@ -53,7 +55,7 @@ TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") { uint32_t const a = 32; uint64_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(unsigned long)); + REQUIRE(typeid(min(a,b)) == typeid(uint64_t)); } WHEN("type(A) = int8_t, type(b) = int16_t") { @@ -71,6 +73,6 @@ TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") { int32_t const a = -32; int64_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(long)); + REQUIRE(typeid(min(a,b)) == typeid(int64_t)); } } diff --git a/test/src/IPAddress/test_IPAddress.cpp b/test/src/IPAddress/test_IPAddress.cpp index d12db0f3..67aea868 100644 --- a/test/src/IPAddress/test_IPAddress.cpp +++ b/test/src/IPAddress/test_IPAddress.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_IPAddress6.cpp b/test/src/IPAddress/test_IPAddress6.cpp index a6941b71..c6351300 100644 --- a/test/src/IPAddress/test_IPAddress6.cpp +++ b/test/src/IPAddress/test_IPAddress6.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_fromString.cpp b/test/src/IPAddress/test_fromString.cpp index 2c918052..be44c8c2 100644 --- a/test/src/IPAddress/test_fromString.cpp +++ b/test/src/IPAddress/test_fromString.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,8 +10,8 @@ #include -#include -#include +#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_fromString6.cpp b/test/src/IPAddress/test_fromString6.cpp index a0f09c73..61fa1402 100644 --- a/test/src/IPAddress/test_fromString6.cpp +++ b/test/src/IPAddress/test_fromString6.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,8 +10,8 @@ #include -#include -#include +#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_assignment.cpp b/test/src/IPAddress/test_operator_assignment.cpp index e9fc8691..1d7431f6 100644 --- a/test/src/IPAddress/test_operator_assignment.cpp +++ b/test/src/IPAddress/test_operator_assignment.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_comparison.cpp b/test/src/IPAddress/test_operator_comparison.cpp index c3283b71..c36a0112 100644 --- a/test/src/IPAddress/test_operator_comparison.cpp +++ b/test/src/IPAddress/test_operator_comparison.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_comparison6.cpp b/test/src/IPAddress/test_operator_comparison6.cpp index a5e1b87c..c584a232 100644 --- a/test/src/IPAddress/test_operator_comparison6.cpp +++ b/test/src/IPAddress/test_operator_comparison6.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_parentheses.cpp b/test/src/IPAddress/test_operator_parentheses.cpp index 27fce3a5..c58212f3 100644 --- a/test/src/IPAddress/test_operator_parentheses.cpp +++ b/test/src/IPAddress/test_operator_parentheses.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_operator_parentheses6.cpp b/test/src/IPAddress/test_operator_parentheses6.cpp index 5b4740c8..375d1492 100644 --- a/test/src/IPAddress/test_operator_parentheses6.cpp +++ b/test/src/IPAddress/test_operator_parentheses6.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/IPAddress/test_printTo.cpp b/test/src/IPAddress/test_printTo.cpp index 05e43fa5..2a6d129a 100644 --- a/test/src/IPAddress/test_printTo.cpp +++ b/test/src/IPAddress/test_printTo.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/test/src/IPAddress/test_printTo6.cpp b/test/src/IPAddress/test_printTo6.cpp index 621008af..8bee2efe 100644 --- a/test/src/IPAddress/test_printTo6.cpp +++ b/test/src/IPAddress/test_printTo6.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/test/src/IPAddress/test_toString.cpp b/test/src/IPAddress/test_toString.cpp new file mode 100644 index 00000000..f33f065e --- /dev/null +++ b/test/src/IPAddress/test_toString.cpp @@ -0,0 +1,39 @@ +/* + * 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 index b7ac98e2..293af87f 100644 --- a/test/src/MillisFake.cpp +++ b/test/src/MillisFake.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Print/test_availableForWrite.cpp b/test/src/Print/test_availableForWrite.cpp index 47f599cf..dc989d2c 100644 --- a/test/src/Print/test_availableForWrite.cpp +++ b/test/src/Print/test_availableForWrite.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_clearWriteError.cpp b/test/src/Print/test_clearWriteError.cpp index 295f4984..7fdf992e 100644 --- a/test/src/Print/test_clearWriteError.cpp +++ b/test/src/Print/test_clearWriteError.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_getWriteError.cpp b/test/src/Print/test_getWriteError.cpp index ef2b1435..7d567042 100644 --- a/test/src/Print/test_getWriteError.cpp +++ b/test/src/Print/test_getWriteError.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include diff --git a/test/src/Print/test_print.cpp b/test/src/Print/test_print.cpp index 92e9c083..2cf4e911 100644 --- a/test/src/Print/test_print.cpp +++ b/test/src/Print/test_print.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include #include @@ -110,12 +112,24 @@ TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-pr { PrintMock mock; - unsigned long long const val = 17; + GIVEN("a value of zero ...") + { + unsigned long long const val = 0; - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } + WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); } + WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); } + WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); } + WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); } + } + GIVEN("a non-zero value ...") + { + unsigned long long const val = 17; + + WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } + WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } + WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } + WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } + } } TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]") diff --git a/test/src/Print/test_println.cpp b/test/src/Print/test_println.cpp index 977ed532..d6c03753 100644 --- a/test/src/Print/test_println.cpp +++ b/test/src/Print/test_println.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include #include diff --git a/test/src/PrintMock.cpp b/test/src/PrintMock.cpp index a64031e1..ffa7c58f 100644 --- a/test/src/PrintMock.cpp +++ b/test/src/PrintMock.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Ringbuffer/test_available.cpp b/test/src/Ringbuffer/test_available.cpp index 3a79e5bc..59787360 100644 --- a/test/src/Ringbuffer/test_available.cpp +++ b/test/src/Ringbuffer/test_available.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_availableForStore.cpp b/test/src/Ringbuffer/test_availableForStore.cpp index 7d73d8da..31127621 100644 --- a/test/src/Ringbuffer/test_availableForStore.cpp +++ b/test/src/Ringbuffer/test_availableForStore.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_clear.cpp b/test/src/Ringbuffer/test_clear.cpp index 165a5bbb..2e9d8dd7 100644 --- a/test/src/Ringbuffer/test_clear.cpp +++ b/test/src/Ringbuffer/test_clear.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_isFull.cpp b/test/src/Ringbuffer/test_isFull.cpp index 8d9c4aaa..a5c52129 100644 --- a/test/src/Ringbuffer/test_isFull.cpp +++ b/test/src/Ringbuffer/test_isFull.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_peek.cpp b/test/src/Ringbuffer/test_peek.cpp index 3811dd39..7664f735 100644 --- a/test/src/Ringbuffer/test_peek.cpp +++ b/test/src/Ringbuffer/test_peek.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_read_char.cpp b/test/src/Ringbuffer/test_read_char.cpp index de754275..e873d076 100644 --- a/test/src/Ringbuffer/test_read_char.cpp +++ b/test/src/Ringbuffer/test_read_char.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Ringbuffer/test_store_char.cpp b/test/src/Ringbuffer/test_store_char.cpp index 6e127b28..82e1d7b1 100644 --- a/test/src/Ringbuffer/test_store_char.cpp +++ b/test/src/Ringbuffer/test_store_char.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/Stream/test_find.cpp b/test/src/Stream/test_find.cpp index c715d522..2dbbc34c 100644 --- a/test/src/Stream/test_find.cpp +++ b/test/src/Stream/test_find.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_findUntil.cpp b/test/src/Stream/test_findUntil.cpp index 2455ed82..72ca26a0 100644 --- a/test/src/Stream/test_findUntil.cpp +++ b/test/src/Stream/test_findUntil.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_getTimeout.cpp b/test/src/Stream/test_getTimeout.cpp index c4db2541..a7230635 100644 --- a/test/src/Stream/test_getTimeout.cpp +++ b/test/src/Stream/test_getTimeout.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_parseFloat.cpp b/test/src/Stream/test_parseFloat.cpp index a9fba616..aa78c978 100644 --- a/test/src/Stream/test_parseFloat.cpp +++ b/test/src/Stream/test_parseFloat.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_parseInt.cpp b/test/src/Stream/test_parseInt.cpp index c79ed447..8d79a2af 100644 --- a/test/src/Stream/test_parseInt.cpp +++ b/test/src/Stream/test_parseInt.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_readBytes.cpp b/test/src/Stream/test_readBytes.cpp index 65466cc8..4b636ccc 100644 --- a/test/src/Stream/test_readBytes.cpp +++ b/test/src/Stream/test_readBytes.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_readBytesUntil.cpp b/test/src/Stream/test_readBytesUntil.cpp index f8c6620e..2efc39c8 100644 --- a/test/src/Stream/test_readBytesUntil.cpp +++ b/test/src/Stream/test_readBytesUntil.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_readString.cpp b/test/src/Stream/test_readString.cpp index f58cb412..9004aee2 100644 --- a/test/src/Stream/test_readString.cpp +++ b/test/src/Stream/test_readString.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_readStringUntil.cpp b/test/src/Stream/test_readStringUntil.cpp index d8ab3473..a27b48cf 100644 --- a/test/src/Stream/test_readStringUntil.cpp +++ b/test/src/Stream/test_readStringUntil.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/Stream/test_setTimeout.cpp b/test/src/Stream/test_setTimeout.cpp index 500f49f0..d068f22b 100644 --- a/test/src/Stream/test_setTimeout.cpp +++ b/test/src/Stream/test_setTimeout.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/StreamMock.cpp b/test/src/StreamMock.cpp index 8ee18302..c1768859 100644 --- a/test/src/StreamMock.cpp +++ b/test/src/StreamMock.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** diff --git a/test/src/String/StringPrinter.h b/test/src/String/StringPrinter.h index f338a902..88c480bf 100644 --- a/test/src/String/StringPrinter.h +++ b/test/src/String/StringPrinter.h @@ -1,7 +1,13 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + #pragma once #include -#include +#include namespace Catch { /** diff --git a/test/src/String/test_String.cpp b/test/src/String/test_String.cpp index 461f2d08..a773bb0e 100644 --- a/test/src/String/test_String.cpp +++ b/test/src/String/test_String.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_characterAccessFunc.cpp b/test/src/String/test_characterAccessFunc.cpp index 329cca43..e05b7487 100644 --- a/test/src/String/test_characterAccessFunc.cpp +++ b/test/src/String/test_characterAccessFunc.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -45,10 +47,11 @@ TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)" WHEN("Valid operation") { arduino::String str("Hello"); - unsigned char buf[2]; + unsigned char buf[3]; str.getBytes(buf, 5, 3); REQUIRE(buf[0] == 'l'); REQUIRE(buf[1] == 'o'); + REQUIRE(buf[2] == '\0'); } } diff --git a/test/src/String/test_compareTo.cpp b/test/src/String/test_compareTo.cpp index 9aef1ee7..afa7c9e6 100644 --- a/test/src/String/test_compareTo.cpp +++ b/test/src/String/test_compareTo.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -27,13 +29,13 @@ TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]") WHEN ("str2 is empty") { arduino::String str1("Hello"), str2; - REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); + REQUIRE(str1.compareTo(str2) > 0); } WHEN ("str1 is empty") { arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); + REQUIRE(str1.compareTo(str2) < 0); } } @@ -47,14 +49,14 @@ TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") WHEN ("Passed string is empty") { - arduino::String str1("Hello"), str2(""); - REQUIRE(str1.compareTo("") == strcmp(str1.c_str(), str2.c_str())); + arduino::String str("Hello"); + REQUIRE(str.compareTo("") > 0); } WHEN ("Passed string is compared with empty string") { - arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str())); + arduino::String str; + REQUIRE(str.compareTo("") == 0); } } @@ -64,8 +66,8 @@ TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String { char *buffer = NULL; - arduino::String str1("Hello"); - REQUIRE(str1.compareTo(buffer) != 0); + arduino::String str("Hello"); + REQUIRE(str.compareTo(buffer) != 0); } WHEN ("First string does NOT have a valid buffer") @@ -73,8 +75,8 @@ TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String char *buffer1 = NULL; char *buffer2 = NULL; - arduino::String str1(buffer1); - REQUIRE(str1.compareTo(buffer2) == 0); + arduino::String str(buffer1); + REQUIRE(str.compareTo(buffer2) == 0); } } diff --git a/test/src/String/test_comparisonFunc.cpp b/test/src/String/test_comparisonFunc.cpp index 89a7f3be..09def716 100644 --- a/test/src/String/test_comparisonFunc.cpp +++ b/test/src/String/test_comparisonFunc.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_concat.cpp b/test/src/String/test_concat.cpp index b7390b64..e3776955 100644 --- a/test/src/String/test_concat.cpp +++ b/test/src/String/test_concat.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_indexOf.cpp b/test/src/String/test_indexOf.cpp index bcaf65ef..e3cd6461 100644 --- a/test/src/String/test_indexOf.cpp +++ b/test/src/String/test_indexOf.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp new file mode 100644 index 00000000..cc8bbdd3 --- /dev/null +++ b/test/src/String/test_isEmpty.cpp @@ -0,0 +1,31 @@ +/* + * 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 index 2ae95f54..aff48cf9 100644 --- a/test/src/String/test_lastIndexOf.cpp +++ b/test/src/String/test_lastIndexOf.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_length.cpp b/test/src/String/test_length.cpp index 3b47faed..02d67843 100644 --- a/test/src/String/test_length.cpp +++ b/test/src/String/test_length.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_move.cpp b/test/src/String/test_move.cpp index d37630c4..ba2a0aba 100644 --- a/test/src/String/test_move.cpp +++ b/test/src/String/test_move.cpp @@ -1,6 +1,12 @@ +/* + * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + #include -#include +#include #include "StringPrinter.h" @@ -31,7 +37,14 @@ TEST_CASE("Testing String move assignment", "[String-move-02]") TEST_CASE("Testing String move self assignment", "[String-move-03]") { +#if (defined(GCC_VERSION) && GCC_VERSION >= 13) || (defined(__clang_major__) && __clang_major__ >= 14) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wself-move" +#endif arduino::String a("src"); a = std::move(a); REQUIRE(a == "src"); +#if defined(GCC_VERSION) && GCC_VERSION >= 13 +#pragma GCC diagnostic pop +#endif } diff --git a/test/src/String/test_operators.cpp b/test/src/String/test_operators.cpp index 67cb39be..26da455a 100644 --- a/test/src/String/test_operators.cpp +++ b/test/src/String/test_operators.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_remove.cpp b/test/src/String/test_remove.cpp index e8c19536..9209a055 100644 --- a/test/src/String/test_remove.cpp +++ b/test/src/String/test_remove.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_replace.cpp b/test/src/String/test_replace.cpp index 5d46fafb..04fa45ca 100644 --- a/test/src/String/test_replace.cpp +++ b/test/src/String/test_replace.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" @@ -66,3 +68,24 @@ TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than ' str.replace(arduino::String("ll"), arduino::String("111")); REQUIRE(str == "He111o Arduino!"); } + +TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]") +{ + arduino::String str("Hello Arduino! Hello, Hello, Hello"); + str.replace(arduino::String("ll"), arduino::String("lll")); + REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo"); +} + +TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]") +{ + arduino::String str("Hello Arduino! Hello, Hello, Hello"); + str.replace(arduino::String("ll"), arduino::String("11")); + REQUIRE(str == "He11o Arduino! He11o, He11o, He11o"); +} + +TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]") +{ + arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo"); + str.replace(arduino::String("lll"), arduino::String("ll")); + REQUIRE(str == "Hello Arduino! Hello, Hello, Hello"); +} diff --git a/test/src/String/test_substring.cpp b/test/src/String/test_substring.cpp index 8fa43086..db9828fb 100644 --- a/test/src/String/test_substring.cpp +++ b/test/src/String/test_substring.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toDouble.cpp b/test/src/String/test_toDouble.cpp index 246f25d4..4a7e5cf7 100644 --- a/test/src/String/test_toDouble.cpp +++ b/test/src/String/test_toDouble.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toFloat.cpp b/test/src/String/test_toFloat.cpp index afef02c5..2cc637a1 100644 --- a/test/src/String/test_toFloat.cpp +++ b/test/src/String/test_toFloat.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toInt.cpp b/test/src/String/test_toInt.cpp index 43397b76..705f30b1 100644 --- a/test/src/String/test_toInt.cpp +++ b/test/src/String/test_toInt.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toLowerCase.cpp b/test/src/String/test_toLowerCase.cpp index 1ff81e91..f7101182 100644 --- a/test/src/String/test_toLowerCase.cpp +++ b/test/src/String/test_toLowerCase.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_toUpperCase.cpp b/test/src/String/test_toUpperCase.cpp index b8ae6aaf..eb80c64c 100644 --- a/test/src/String/test_toUpperCase.cpp +++ b/test/src/String/test_toUpperCase.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/String/test_trim.cpp b/test/src/String/test_trim.cpp index 539d6568..6fab9d06 100644 --- a/test/src/String/test_trim.cpp +++ b/test/src/String/test_trim.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/test/src/WCharacter/test_isAscii.cpp b/test/src/WCharacter/test_isAscii.cpp index 8c2763c4..37cb24ea 100644 --- a/test/src/WCharacter/test_isAscii.cpp +++ b/test/src/WCharacter/test_isAscii.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isControl.cpp b/test/src/WCharacter/test_isControl.cpp index 157c8bc8..5f4763b8 100644 --- a/test/src/WCharacter/test_isControl.cpp +++ b/test/src/WCharacter/test_isControl.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isDigit.cpp b/test/src/WCharacter/test_isDigit.cpp index 58b1808a..e5cdbd40 100644 --- a/test/src/WCharacter/test_isDigit.cpp +++ b/test/src/WCharacter/test_isDigit.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isHexadecimalDigit.cpp b/test/src/WCharacter/test_isHexadecimalDigit.cpp index 0eba5846..f714b9d9 100644 --- a/test/src/WCharacter/test_isHexadecimalDigit.cpp +++ b/test/src/WCharacter/test_isHexadecimalDigit.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isLowerCase.cpp b/test/src/WCharacter/test_isLowerCase.cpp index 79e1dbc4..6efd0210 100644 --- a/test/src/WCharacter/test_isLowerCase.cpp +++ b/test/src/WCharacter/test_isLowerCase.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_isPunct.cpp b/test/src/WCharacter/test_isPunct.cpp index 5f6875d1..40a9b59f 100644 --- a/test/src/WCharacter/test_isPunct.cpp +++ b/test/src/WCharacter/test_isPunct.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isSpace.cpp b/test/src/WCharacter/test_isSpace.cpp index c96557d6..d041c3a2 100644 --- a/test/src/WCharacter/test_isSpace.cpp +++ b/test/src/WCharacter/test_isSpace.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -10,7 +12,7 @@ #include -#include +#include /************************************************************************************** * CONSTANTS diff --git a/test/src/WCharacter/test_isUpperCase.cpp b/test/src/WCharacter/test_isUpperCase.cpp index e21e33db..f7be0ad8 100644 --- a/test/src/WCharacter/test_isUpperCase.cpp +++ b/test/src/WCharacter/test_isUpperCase.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_isWhitespace.cpp b/test/src/WCharacter/test_isWhitespace.cpp index 6eb3f7a6..c6ba850e 100644 --- a/test/src/WCharacter/test_isWhitespace.cpp +++ b/test/src/WCharacter/test_isWhitespace.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** @@ -8,7 +10,7 @@ #include -#include +#include /************************************************************************************** * TEST CODE diff --git a/test/src/WCharacter/test_toAscii.cpp b/test/src/WCharacter/test_toAscii.cpp index b071702f..8abb32d6 100644 --- a/test/src/WCharacter/test_toAscii.cpp +++ b/test/src/WCharacter/test_toAscii.cpp @@ -1,18 +1,18 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** * INCLUDE **************************************************************************************/ -#undef _GNU_SOURCE - #include #include -#include +#include /************************************************************************************** * CONSTANTS @@ -47,4 +47,4 @@ TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toA TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]") { REQUIRE(arduino::toAscii(0x3030) == 0x30); -} \ No newline at end of file +} diff --git a/test/src/dtostrf.cpp b/test/src/dtostrf.cpp index 0635b492..02ea2fe7 100644 --- a/test/src/dtostrf.cpp +++ b/test/src/dtostrf.cpp @@ -1,12 +1,14 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** * INCLUDE **************************************************************************************/ -#include +#include #include @@ -18,7 +20,7 @@ extern "C" { #endif -#include +#include #ifdef __cplusplus } // extern "C" diff --git a/test/src/itoa.cpp b/test/src/itoa.cpp index 84d640c3..4070ca62 100644 --- a/test/src/itoa.cpp +++ b/test/src/itoa.cpp @@ -1,12 +1,14 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /************************************************************************************** * INCLUDE **************************************************************************************/ -#include +#include #include #include @@ -27,24 +29,36 @@ std::string radixToFmtString(int const radix) char * itoa(int value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * ltoa(long value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * utoa(unsigned value, char *str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } char * ultoa(unsigned long value, char * str, int radix) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" sprintf(str, radixToFmtString(radix).c_str(), value); +#pragma GCC diagnostic pop return str; } diff --git a/test/src/main.cpp b/test/src/main.cpp index 84b7d4ed..5d425d0f 100644 --- a/test/src/main.cpp +++ b/test/src/main.cpp @@ -1,5 +1,7 @@ /* * Copyright (c) 2020 Arduino. All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later */ /**************************************************************************************