diff --git a/.codespellrc b/.codespellrc deleted file mode 100644 index 4da64a41..00000000 --- a/.codespellrc +++ /dev/null @@ -1,7 +0,0 @@ -# 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,shiftin -check-filenames = -check-hidden = -skip = ./.git,./test/external diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 93c700e8..00000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.vscode/ -.idea/ diff --git a/api/ArduinoAPI.h b/ArduinoAPI.h similarity index 100% rename from api/ArduinoAPI.h rename to ArduinoAPI.h diff --git a/api/Binary.h b/Binary.h similarity index 100% rename from api/Binary.h rename to Binary.h diff --git a/api/CanMsg.cpp b/CanMsg.cpp similarity index 100% rename from api/CanMsg.cpp rename to CanMsg.cpp diff --git a/api/CanMsg.h b/CanMsg.h similarity index 100% rename from api/CanMsg.h rename to CanMsg.h diff --git a/api/CanMsgRingbuffer.cpp b/CanMsgRingbuffer.cpp similarity index 100% rename from api/CanMsgRingbuffer.cpp rename to CanMsgRingbuffer.cpp diff --git a/api/CanMsgRingbuffer.h b/CanMsgRingbuffer.h similarity index 100% rename from api/CanMsgRingbuffer.h rename to CanMsgRingbuffer.h diff --git a/api/Client.h b/Client.h similarity index 100% rename from api/Client.h rename to Client.h diff --git a/api/Common.cpp b/Common.cpp similarity index 100% rename from api/Common.cpp rename to Common.cpp diff --git a/api/Common.h b/Common.h similarity index 92% rename from api/Common.h rename to Common.h index 9b28f40a..6fea707c 100644 --- a/api/Common.h +++ b/Common.h @@ -36,11 +36,14 @@ typedef enum { } PinStatus; typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, - OUTPUT_OPENDRAIN = 0x4, + INPUT = 0x0, + OUTPUT = 0x1, + INPUT_PULLUP = 0x2, + INPUT_FLOATING = INPUT, + INPUT_PULLDOWN = 0x3, + INPUT_ANALOG = 0x4, + OUTPUT_OPEN_DRAIN = 0x5, + OUTPUT_OPENDRAIN = OUTPUT_OPEN_DRAIN, } PinMode; typedef enum { @@ -93,12 +96,12 @@ typedef void (*voidFuncPtrParam)(void*); #endif /* TODO: request for removal */ -typedef bool boolean; +typedef bool boolean __attribute__((deprecated)); typedef uint8_t byte; typedef uint16_t word; void init(void); -void initVariant(void); +extern void initVariant() __attribute__((weak)); #ifndef HOST int atexit(void (*func)()) __attribute__((weak)); @@ -141,13 +144,13 @@ void loop(void); #endif #ifdef __cplusplus - template + template auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) { return (b < a) ? b : a; } - template + template auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) { return (a < b) ? b : a; diff --git a/api/Compat.h b/Compat.h similarity index 100% rename from api/Compat.h rename to Compat.h diff --git a/api/DMAPool.h b/DMAPool.h similarity index 100% rename from api/DMAPool.h rename to DMAPool.h diff --git a/api/HardwareCAN.h b/HardwareCAN.h similarity index 100% rename from api/HardwareCAN.h rename to HardwareCAN.h diff --git a/api/HardwareI2C.h b/HardwareI2C.h similarity index 100% rename from api/HardwareI2C.h rename to HardwareI2C.h diff --git a/api/HardwareSPI.h b/HardwareSPI.h similarity index 100% rename from api/HardwareSPI.h rename to HardwareSPI.h diff --git a/api/HardwareSerial.h b/HardwareSerial.h similarity index 100% rename from api/HardwareSerial.h rename to HardwareSerial.h diff --git a/api/IPAddress.cpp b/IPAddress.cpp similarity index 100% rename from api/IPAddress.cpp rename to IPAddress.cpp diff --git a/api/IPAddress.h b/IPAddress.h similarity index 100% rename from api/IPAddress.h rename to IPAddress.h diff --git a/api/Interrupts.h b/Interrupts.h similarity index 100% rename from api/Interrupts.h rename to Interrupts.h diff --git a/LICENSE b/LICENSE deleted file mode 100644 index c6487f4f..00000000 --- a/LICENSE +++ /dev/null @@ -1,176 +0,0 @@ -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/api/PluggableUSB.cpp b/PluggableUSB.cpp similarity index 100% rename from api/PluggableUSB.cpp rename to PluggableUSB.cpp diff --git a/api/PluggableUSB.h b/PluggableUSB.h similarity index 100% rename from api/PluggableUSB.h rename to PluggableUSB.h diff --git a/api/Print.cpp b/Print.cpp similarity index 84% rename from api/Print.cpp rename to Print.cpp index 4a6e942a..521ffe81 100644 --- a/api/Print.cpp +++ b/Print.cpp @@ -21,11 +21,17 @@ #include #include #include +#include +#include "uart.h" #include "Print.h" using namespace arduino; +#if defined (VIRTIO_LOG) + #include "virtio_log.h" +#endif + // Public Methods ////////////////////////////////////////////////////////////// /* default implementation: may be overridden */ @@ -130,6 +136,11 @@ size_t Print::print(unsigned long long n, int base) else return printULLNumber(n, base); } +size_t Print::print(float n, int digits) +{ + return printFloat(n, digits); +} + size_t Print::print(double n, int digits) { return printFloat(n, digits); @@ -222,6 +233,13 @@ size_t Print::println(unsigned long long num, int base) return n; } +size_t Print::println(float num, int digits) +{ + size_t n = print(num, digits); + n += println(); + return n; +} + size_t Print::println(double num, int digits) { size_t n = print(num, digits); @@ -236,6 +254,58 @@ size_t Print::println(const Printable& x) return n; } +extern "C" { + __attribute__((weak)) + int _write(int file, char *ptr, int len) + { + switch (file) { + case STDOUT_FILENO: + case STDERR_FILENO: + /* Used for core_debug() */ +#if defined (VIRTIO_LOG) + virtio_log((uint8_t *)ptr, (uint32_t)len); +#elif defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) + uart_debug_write((uint8_t *)ptr, (uint32_t)len); +#endif + break; + case STDIN_FILENO: + break; + default: + ((class Print *)file)->write((uint8_t *)ptr, len); + break; + } + return len; + } +} + +int Print::printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int retval = vdprintf((int)this, format, ap); + va_end(ap); + return retval; +} + +int Print::printf(const __FlashStringHelper *format, ...) +{ + va_list ap; + va_start(ap, format); + int retval = vdprintf((int)this, (const char *)format, ap); + va_end(ap); + return retval; +} + +int Print::vprintf(const char *format, va_list ap) +{ + return vdprintf((int)this, format, ap); +} + +int Print::vprintf(const __FlashStringHelper *format, va_list ap) +{ + return vdprintf((int)this, (const char *)format, ap); +} + // Private Methods ///////////////////////////////////////////////////////////// size_t Print::printNumber(unsigned long n, uint8_t base) diff --git a/api/Print.h b/Print.h similarity index 90% rename from api/Print.h rename to Print.h index 2016d7d5..b0621597 100644 --- a/api/Print.h +++ b/Print.h @@ -21,6 +21,7 @@ #include #include // for size_t +#include // for printf #include "String.h" #include "Printable.h" @@ -72,6 +73,7 @@ class Print size_t print(unsigned long, int = DEC); size_t print(long long, int = DEC); size_t print(unsigned long long, int = DEC); + size_t print(float, int = 2); size_t print(double, int = 2); size_t print(const Printable&); @@ -86,12 +88,18 @@ class Print size_t println(unsigned long, int = DEC); size_t println(long long, int = DEC); size_t println(unsigned long long, int = DEC); + size_t println(float, int = 2); size_t println(double, int = 2); size_t println(const Printable&); size_t println(void); + int printf(const char *format, ...); + int printf(const __FlashStringHelper *format, ...); + int vprintf(const __FlashStringHelper *format, va_list ap); + int vprintf(const char *format, va_list ap); + virtual void flush() { /* Empty implementation for backward compatibility */ } }; } -using arduino::Print; \ No newline at end of file +using arduino::Print; diff --git a/api/Printable.h b/Printable.h similarity index 100% rename from api/Printable.h rename to Printable.h diff --git a/README.md b/README.md deleted file mode 100644 index e533b69e..00000000 --- a/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# ArduinoCore-API - -[![Unit Tests](https://github.com/arduino/ArduinoCore-API/workflows/Unit%20Tests/badge.svg)](https://github.com/arduino/ArduinoCore-API/actions?workflow=Unit+Tests) -[![codecov](https://codecov.io/gh/arduino/ArduinoCore-API/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino/ArduinoCore-API) -[![Spell Check status](https://github.com/arduino/ArduinoCore-API/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino/ArduinoCore-API/actions/workflows/spell-check.yml) - -This repository hosts the hardware independent layer of Arduino core. In other words it contains the abstract definition of the Arduino core API, consisting of hardware-independent header files that are then included and implemented by the various platform-specific cores. - -Having a single place where the Arduino API is defined means that there is no longer a String implementation within every Arduino core (a String module within ArduinoCore-avr, a String module within ArduinoCore-samd, a String module within ArduinoCore-megaavr …) but rather one String implementation within ArduinoCore-API which all other cores utilise. This has the pleasant side effects that bugs fixed or features added within the ArduinoCore-API String implementation are automatically propagated to all cores utilizing ArduinoCore-API. - -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. - -## Documentation - -The Arduino API is documented in the official [language reference](https://www.arduino.cc/reference/en/), whose sources are located in [this repository](https://github.com/arduino/reference-en) and are open to contributions from the community. - -## Support - -This repository is not directly usable by final users. If you need assistance with Arduino, see the [Help Center](https://support.arduino.cc/) and browse the [forum](https://forum.arduino.cc). - -## Development - -### Bugs & Issues - -If you want to report an issue with this core, you can submit it to the [issue tracker](https://github.com/arduino/ArduinoCore-API/issues) of this repository. Some rules apply: - -* If your issue is about a specific hardware platform, report it to its repository. This one is only about discussing the generic API. -* Before posting, please check if the same problem has been already reported by someone else to avoid duplicates. -* Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. Make sure you're using an original Arduino board. - -### Contributions - -Contributions are always welcome! You can submit them directly to this repository as Pull Requests. Please provide a detailed description of the problem you're trying to solve. We also appreciate any help in testing issues and patches contributed by other users. - -### Unit testing - -This repository includes a test suite that covers most of the API and that is designed to run on generic hardware, thus not requiring a development board. We call this _host-based unit-testing_. In order to test the features that are only defined but not implemented in this repository, mock implementations are included. - -Please help us improve the coverage of the test suite! - -#### To build and run unit tests - -The unit tests are automatically built by GitHub as part of pull request checks (in `.github/workflows/unit-tests.yml`). - -To build and run locally: - -**Dependencies** - -* [CMake](https://cmake.org/) -* [GCC](https://gcc.gnu.org/) - -On (Ubuntu) Linux run: - -```bash -sudo apt-get install build-essential cmake -``` - -From the project root: - -```bash -cd test && mkdir build && cd build -cmake .. -make && bin/test-ArduinoCore-API -``` - -### Implementing ArduinoCore-API - -In order to compile a core which is implementing ArduinoCore-API you'll need to copy/symlink the `api` directory to the target's `cores/arduino` directory as part of your development and release workflow. The most elegant and effective solution is to develop your core with `api` symlinked and produce the distributable archive by telling `tar` to follow symlinks. Example: - -```bash -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) -* [ArduinoCore-samd](https://github.com/arduino/ArduinoCore-samd/#developing) - -## Support the project - -This open source code is maintained by Arduino with the help of the community. We invest a considerable amount of time in testing code, optimizing it and introducing new features. Please consider [buying original Arduino boards](https://store.arduino.cc) to support our work on the project. - -## License and credits - -This code is licensed under the terms of the GNU LGPL 2.1. If you have questions about licensing please contact us at [license@arduino.cc](mailto:license@arduino.cc). - diff --git a/api/RingBuffer.h b/RingBuffer.h similarity index 98% rename from api/RingBuffer.h rename to RingBuffer.h index b69c20d4..0e7e39ad 100644 --- a/api/RingBuffer.h +++ b/RingBuffer.h @@ -31,7 +31,7 @@ namespace arduino { // using a ring buffer (I think), in which head is the index of the location // to which to write the next incoming character and tail is the index of the // location from which to read. -#define SERIAL_BUFFER_SIZE 64 +#define SERIAL_BUFFER_SIZE 128 //64 template class RingBufferN diff --git a/api/Server.h b/Server.h similarity index 100% rename from api/Server.h rename to Server.h diff --git a/api/Stream.cpp b/Stream.cpp similarity index 100% rename from api/Stream.cpp rename to Stream.cpp diff --git a/api/Stream.h b/Stream.h similarity index 100% rename from api/Stream.h rename to Stream.h diff --git a/api/String.cpp b/String.cpp similarity index 100% rename from api/String.cpp rename to String.cpp diff --git a/api/String.h b/String.h similarity index 100% rename from api/String.h rename to String.h diff --git a/api/USBAPI.h b/USBAPI.h similarity index 100% rename from api/USBAPI.h rename to USBAPI.h diff --git a/api/Udp.h b/Udp.h similarity index 100% rename from api/Udp.h rename to Udp.h diff --git a/api/WCharacter.h b/WCharacter.h similarity index 100% rename from api/WCharacter.h rename to WCharacter.h diff --git a/api/deprecated-avr-comp/avr/dtostrf.c.impl b/deprecated-avr-comp/avr/dtostrf.c.impl similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.c.impl rename to deprecated-avr-comp/avr/dtostrf.c.impl diff --git a/api/deprecated-avr-comp/avr/dtostrf.h b/deprecated-avr-comp/avr/dtostrf.h similarity index 100% rename from api/deprecated-avr-comp/avr/dtostrf.h rename to deprecated-avr-comp/avr/dtostrf.h diff --git a/api/deprecated-avr-comp/avr/interrupt.h b/deprecated-avr-comp/avr/interrupt.h similarity index 100% rename from api/deprecated-avr-comp/avr/interrupt.h rename to deprecated-avr-comp/avr/interrupt.h diff --git a/api/deprecated-avr-comp/avr/pgmspace.h b/deprecated-avr-comp/avr/pgmspace.h similarity index 100% rename from api/deprecated-avr-comp/avr/pgmspace.h rename to deprecated-avr-comp/avr/pgmspace.h diff --git a/api/deprecated/Client.h b/deprecated/Client.h similarity index 100% rename from api/deprecated/Client.h rename to deprecated/Client.h diff --git a/api/deprecated/HardwareSerial.h b/deprecated/HardwareSerial.h similarity index 100% rename from api/deprecated/HardwareSerial.h rename to deprecated/HardwareSerial.h diff --git a/api/deprecated/IPAddress.h b/deprecated/IPAddress.h similarity index 100% rename from api/deprecated/IPAddress.h rename to deprecated/IPAddress.h diff --git a/api/deprecated/Print.h b/deprecated/Print.h similarity index 100% rename from api/deprecated/Print.h rename to deprecated/Print.h diff --git a/api/deprecated/Printable.h b/deprecated/Printable.h similarity index 100% rename from api/deprecated/Printable.h rename to deprecated/Printable.h diff --git a/api/deprecated/Server.h b/deprecated/Server.h similarity index 100% rename from api/deprecated/Server.h rename to deprecated/Server.h diff --git a/api/deprecated/Stream.h b/deprecated/Stream.h similarity index 100% rename from api/deprecated/Stream.h rename to deprecated/Stream.h diff --git a/api/deprecated/Udp.h b/deprecated/Udp.h similarity index 100% rename from api/deprecated/Udp.h rename to deprecated/Udp.h diff --git a/api/deprecated/WString.h b/deprecated/WString.h similarity index 100% rename from api/deprecated/WString.h rename to deprecated/WString.h diff --git a/api/itoa.h b/itoa.h similarity index 100% rename from api/itoa.h rename to itoa.h diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index faa6a97b..00000000 --- a/test/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -build -### CMake ### -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -### CMake Patch ### -CMakeUserPresets.json - -# External projects -*-prefix/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index d8050249..00000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,158 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later - -########################################################################## - -cmake_minimum_required(VERSION 2.8) - -########################################################################## - -project(test-ArduinoCore-API) - -Include(FetchContent) - -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 -) - -FetchContent_MakeAvailable(Catch2) - -########################################################################## - -include_directories(..) -include_directories(include) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -set(TEST_TARGET ${CMAKE_PROJECT_NAME}) - -########################################################################## - -set(TEST_SRCS - src/CanMsg/test_CanMsg.cpp - src/CanMsg/test_CanMsg_CopyCtor.cpp - src/CanMsg/test_CanExtendedId.cpp - src/CanMsg/test_CanStandardId.cpp - src/CanMsg/test_isExtendedId.cpp - src/CanMsg/test_isStandardId.cpp - src/CanMsg/test_operator_assignment.cpp - src/CanMsg/test_printTo.cpp - src/CanMsgRingbuffer/test_available.cpp - src/Common/test_makeWord.cpp - src/Common/test_map.cpp - src/Common/test_max.cpp - src/Common/test_min.cpp - src/IPAddress/test_toString.cpp - src/IPAddress/test_fromString.cpp - src/IPAddress/test_fromString6.cpp - src/IPAddress/test_IPAddress.cpp - src/IPAddress/test_IPAddress6.cpp - src/IPAddress/test_operator_assignment.cpp - src/IPAddress/test_operator_comparison.cpp - src/IPAddress/test_operator_comparison6.cpp - src/IPAddress/test_operator_parentheses.cpp - src/IPAddress/test_operator_parentheses6.cpp - src/IPAddress/test_printTo.cpp - src/IPAddress/test_printTo6.cpp - src/Print/test_clearWriteError.cpp - src/Print/test_getWriteError.cpp - src/Print/test_print.cpp - src/Print/test_println.cpp - src/Print/test_availableForWrite.cpp - src/Ringbuffer/test_available.cpp - src/Ringbuffer/test_availableForStore.cpp - src/Ringbuffer/test_clear.cpp - src/Ringbuffer/test_isFull.cpp - src/Ringbuffer/test_peek.cpp - src/Ringbuffer/test_read_char.cpp - src/Ringbuffer/test_store_char.cpp - src/Stream/test_find.cpp - src/Stream/test_findUntil.cpp - src/Stream/test_getTimeout.cpp - src/Stream/test_parseFloat.cpp - src/Stream/test_parseInt.cpp - src/Stream/test_readBytes.cpp - src/Stream/test_readBytesUntil.cpp - src/Stream/test_readString.cpp - src/Stream/test_readStringUntil.cpp - src/Stream/test_setTimeout.cpp - src/String/test_concat.cpp - src/String/test_operators.cpp - src/String/test_compareTo.cpp - src/String/test_comparisonFunc.cpp - src/String/test_characterAccessFunc.cpp - src/String/test_substring.cpp - src/String/test_indexOf.cpp - src/String/test_lastIndexOf.cpp - src/String/test_length.cpp - src/String/test_move.cpp - src/String/test_remove.cpp - src/String/test_replace.cpp - src/String/test_String.cpp - src/String/test_toDouble.cpp - src/String/test_toFloat.cpp - src/String/test_toInt.cpp - src/String/test_toLowerCase.cpp - src/String/test_toUpperCase.cpp - src/String/test_trim.cpp - src/WCharacter/test_isAscii.cpp - src/WCharacter/test_isControl.cpp - src/WCharacter/test_isDigit.cpp - src/WCharacter/test_isHexadecimalDigit.cpp - src/WCharacter/test_isLowerCase.cpp - src/WCharacter/test_isPunct.cpp - src/WCharacter/test_isSpace.cpp - src/WCharacter/test_isUpperCase.cpp - src/WCharacter/test_isWhitespace.cpp - src/WCharacter/test_toAscii.cpp -) - -set(TEST_DUT_SRCS - ../api/CanMsg.cpp - ../api/CanMsgRingbuffer.cpp - ../api/Common.cpp - ../api/IPAddress.cpp - ../api/String.cpp - ../api/Stream.cpp - ../api/Print.cpp -) - -########################################################################## - -set(TEST_TARGET_SRCS - src/dtostrf.cpp - src/itoa.cpp - src/MillisFake.cpp - src/PrintMock.cpp - src/StreamMock.cpp - ${TEST_SRCS} - ${TEST_DUT_SRCS} -) - -########################################################################## - -add_compile_definitions(HOST) -add_compile_options(-Wall -Wextra -Wpedantic -Werror) -add_compile_options(-Wno-cast-function-type) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -Wno-deprecated-copy") - -########################################################################## - -add_executable( - ${TEST_TARGET} - ${TEST_TARGET_SRCS} -) - -target_link_libraries( ${TEST_TARGET} Catch2WithMain ) - -########################################################################## - diff --git a/test/include/MillisFake.h b/test/include/MillisFake.h deleted file mode 100644 index bdb3f14c..00000000 --- a/test/include/MillisFake.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef MILLIS_FAKE_H_ -#define MILLIS_FAKE_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * FUNCTION DECLARATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -void millis_autoOn(); -void millis_autoOff(); -void set_millis(unsigned long const val); - -#ifdef __cplusplus -} -#endif - -#endif /* MILLIS_FAKE_H_ */ \ No newline at end of file diff --git a/test/include/PrintMock.h b/test/include/PrintMock.h deleted file mode 100644 index 9a103848..00000000 --- a/test/include/PrintMock.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINT_MOCK_H_ -#define PRINT_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintMock : public Print -{ -public: - std::string _str; - virtual size_t write(uint8_t b) override; - void mock_setWriteError() { setWriteError(); } - void mock_setWriteError(int err) { setWriteError(err); } -}; - -#endif /* PRINT_MOCK_H_ */ diff --git a/test/include/PrintableMock.h b/test/include/PrintableMock.h deleted file mode 100644 index f55540d1..00000000 --- a/test/include/PrintableMock.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINTABLE_MOCK_H_ -#define PRINTABLE_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintableMock : public arduino::Printable -{ -public: - int _i; - virtual size_t printTo(arduino::Print& p) const override - { - size_t written = 0; - written += p.print("PrintableMock i = "); - written += p.print(_i); - return written; - } -}; - -#endif /* PRINTABLE_MOCK_H_ */ diff --git a/test/include/StreamMock.h b/test/include/StreamMock.h deleted file mode 100644 index afa4b487..00000000 --- a/test/include/StreamMock.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef STREAM_MOCK_H_ -#define STREAM_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class StreamMock : public arduino::Stream -{ -public: - - void operator << (char const * str); - - virtual size_t write(uint8_t ch) override; - virtual int available() override; - virtual int read() override; - virtual int peek() override; - -private: - std::deque _stream; - -}; - -#endif /* STREAM_MOCK_H_ */ diff --git a/test/src/CanMsg/test_CanExtendedId.cpp b/test/src/CanMsg/test_CanExtendedId.cpp deleted file mode 100644 index caf7bccc..00000000 --- a/test/src/CanMsg/test_CanExtendedId.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for lowest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-01]") -{ - REQUIRE(CanExtendedId(0) == (CanMsg::CAN_EFF_FLAG | 0U)); -} - -TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for highest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-02]") -{ - REQUIRE(CanExtendedId(0x1FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); -} - -TEST_CASE ("Verify capping of CAN IDs exceeding 29-Bit CAN ID range", "[CanMsg-CanExtendedId-03]") -{ - REQUIRE(CanExtendedId(0x2FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); - REQUIRE(CanExtendedId(0x3FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); - REQUIRE(CanExtendedId(0x4FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); - REQUIRE(CanExtendedId(0x5FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); - /* ... */ - REQUIRE(CanExtendedId(0xFFFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); -} diff --git a/test/src/CanMsg/test_CanMsg.cpp b/test/src/CanMsg/test_CanMsg.cpp deleted file mode 100644 index 1394eee4..00000000 --- a/test/src/CanMsg/test_CanMsg.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]") -{ - CanMsg const msg(CanStandardId(0x20), 0, nullptr); - - REQUIRE(msg.data_length == 0); - for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++) - REQUIRE(msg.data[i] == 0); -} - -TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); - - REQUIRE(msg.data_length == 4); - for (size_t i = 0; i < msg.data_length; i++) - REQUIRE(msg.data[i] == msg_data[i]); -} - -TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]") -{ - uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - - CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); - - REQUIRE(msg.data_length == 8); - for (size_t i = 0; i < msg.data_length; i++) - REQUIRE(msg.data[i] == msg_data[i]); -} - -TEST_CASE ("Test constructor constructing a CAN frame with standard ID", "[CanMsg-CanMsg-04]") -{ - CanMsg const msg(CanStandardId(0x20), 0, nullptr); - - REQUIRE(msg.id == 0x20); -} - -TEST_CASE ("Test constructor constructing a CAN frame with extended ID", "[CanMsg-CanMsg-05]") -{ - CanMsg const msg(CanExtendedId(0x20), 0, nullptr); - - REQUIRE(msg.id == (CanMsg::CAN_EFF_FLAG | 0x20)); -} diff --git a/test/src/CanMsg/test_CanMsg_CopyCtor.cpp b/test/src/CanMsg/test_CanMsg_CopyCtor.cpp deleted file mode 100644 index c7878152..00000000 --- a/test/src/CanMsg/test_CanMsg_CopyCtor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Test copy constructor", "[CanMsg-CopyCtor-01]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); - CanMsg const msg_2(msg_1); - - REQUIRE(msg_1.data_length == msg_2.data_length); - - for (size_t i = 0; i < msg_1.data_length; i++) - { - REQUIRE(msg_1.data[i] == msg_data[i]); - REQUIRE(msg_2.data[i] == msg_data[i]); - } -} diff --git a/test/src/CanMsg/test_CanStandardId.cpp b/test/src/CanMsg/test_CanStandardId.cpp deleted file mode 100644 index 23b862fe..00000000 --- a/test/src/CanMsg/test_CanStandardId.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for lowest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-01]") -{ - REQUIRE(CanStandardId(0) == 0U); -} - -TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for highest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-02]") -{ - REQUIRE(CanStandardId(0x7FF) == 0x7FF); -} - -TEST_CASE ("Verify capping of CAN IDs exceeding 11-Bit CAN ID range", "[CanMsg-CanStandardId-03]") -{ - REQUIRE(CanStandardId(0x800U) == 0x000U); - REQUIRE(CanStandardId(0x801U) == 0x001U); - REQUIRE(CanStandardId(0x8FFU) == 0x0FFU); - REQUIRE(CanStandardId(0x1FFFFFFFU) == 0x7FFU); - REQUIRE(CanStandardId(0xFFFFFFFFU) == 0x7FFU); -} diff --git a/test/src/CanMsg/test_isExtendedId.cpp b/test/src/CanMsg/test_isExtendedId.cpp deleted file mode 100644 index 7c3dd478..00000000 --- a/test/src/CanMsg/test_isExtendedId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("\"isExtendedId\" should return true for extended CAN ID", "[CanMsg-isExtendedId-01]") -{ - CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); - REQUIRE(msg_ext_id.isExtendedId() == true); -} - -TEST_CASE ("\"isExtendedId\" should return false for standard CAN ID", "[CanMsg-isExtendedId-02]") -{ - CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); - REQUIRE(msg_std_id.isExtendedId() == false); -} diff --git a/test/src/CanMsg/test_isStandardId.cpp b/test/src/CanMsg/test_isStandardId.cpp deleted file mode 100644 index 00fee646..00000000 --- a/test/src/CanMsg/test_isStandardId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("\"isStandardId\" should return true for standard CAN ID", "[CanMsg-isStandardId-01]") -{ - CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); - REQUIRE(msg_std_id.isStandardId() == true); -} - -TEST_CASE ("\"isStandardId\" should return false for extended CAN ID", "[CanMsg-isStandardId-02]") -{ - CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); - REQUIRE(msg_ext_id.isStandardId() == false); -} diff --git a/test/src/CanMsg/test_operator_assignment.cpp b/test/src/CanMsg/test_operator_assignment.cpp deleted file mode 100644 index 7bdde6c0..00000000 --- a/test/src/CanMsg/test_operator_assignment.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing CanMsg::operator = (CanMsg const &)", "[CanMsg-Operator-=-1]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); - CanMsg msg_2(CanStandardId(0x21), 0, nullptr); - - msg_2 = msg_1; - - REQUIRE(msg_1.data_length == msg_2.data_length); - - for (size_t i = 0; i < msg_1.data_length; i++) - { - REQUIRE(msg_1.data[i] == msg_data[i]); - REQUIRE(msg_2.data[i] == msg_data[i]); - } -} diff --git a/test/src/CanMsg/test_printTo.cpp b/test/src/CanMsg/test_printTo.cpp deleted file mode 100644 index a434bdf4..00000000 --- a/test/src/CanMsg/test_printTo.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print CAN frame with standard ID", "[CanMsg-printTo-1]") -{ - uint8_t const std_msg_data[] = {0xBE, 0xEF}; - CanMsg const std_msg(CanStandardId(0x20), sizeof(std_msg_data), std_msg_data); - - PrintMock mock; - mock.print(std_msg); - - REQUIRE(mock._str == "[020] (2) : BEEF"); -} - -TEST_CASE ("Print CAN frame with extended ID", "[CanMsg-printTo-2]") -{ - uint8_t const ext_msg_data[] = {0xDE, 0xAD, 0xC0, 0xDE}; - CanMsg const ext_msg(CanExtendedId(0x20), sizeof(ext_msg_data), ext_msg_data); - - PrintMock mock; - mock.print(ext_msg); - - REQUIRE(mock._str == "[00000020] (4) : DEADC0DE"); -} diff --git a/test/src/CanMsgRingbuffer/test_available.cpp b/test/src/CanMsgRingbuffer/test_available.cpp deleted file mode 100644 index f843a673..00000000 --- a/test/src/CanMsgRingbuffer/test_available.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'available' should return 0 for empty CanMsg ring buffer", "[CanMsgRingbuffer-available-01]") -{ - arduino::CanMsgRingbuffer ringbuffer; - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("'available' should return number of elements in CanMsg ringbuffer", "[CanMsgRingbuffer-available-02]") -{ - arduino::CanMsgRingbuffer ringbuffer; - arduino::CanMsg msg; - ringbuffer.enqueue(msg); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.enqueue(msg); - REQUIRE(ringbuffer.available() == 2); - ringbuffer.dequeue(); - REQUIRE(ringbuffer.available() == 1); -} diff --git a/test/src/Common/test_makeWord.cpp b/test/src/Common/test_makeWord.cpp deleted file mode 100644 index 2f1e706a..00000000 --- a/test/src/Common/test_makeWord.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'makeWord(w)'", "[makeWord-01]") -{ - REQUIRE(makeWord(0xDEAD) == 0xDEAD); - REQUIRE(makeWord(0xDE) == 0x00DE); -} - -TEST_CASE ("Calling 'makeWord(h,l)'", "[makeWord-02]") -{ - REQUIRE(makeWord(0xDE, 0xAD) == 0xDEAD); -} - -TEST_CASE ("Calling 'word(...)'", "[makeWord-03]") -{ - REQUIRE(word(0xDEAD) == 0xDEAD); - REQUIRE(word(0xDE, 0xAD) == 0xDEAD); -} diff --git a/test/src/Common/test_map.cpp b/test/src/Common/test_map.cpp deleted file mode 100644 index bd2b5845..00000000 --- a/test/src/Common/test_map.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with reduction of output", "[map-01]") -{ - REQUIRE(map(50, 0, 100, 0, 10) == 5); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with increase of output", "[map-02]") -{ - REQUIRE(map(5, 0, 10, 0, 100) == 50); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' where output is reduced to a value < 0", "[map-03]") -{ - REQUIRE(map(1, 0, 100, 0, 10) == 0); /* Would be 0.1 if we'd be using floating point. */ -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' default usage with negative values", "[map-04]") -{ - WHEN ("Negative 'from' values") - { - REQUIRE(map(0, 0, -256, 0, 1024) == 0); - REQUIRE(map(-256, 0, -256, 0, 1024) == 1024); - REQUIRE(map(-128, 0, -256, 0, 1024) == 512); - } - WHEN ("Negative 'to' values") - { - REQUIRE(map(0, 0, 256, 0, -1024) == 0); - REQUIRE(map(256, 0, 256, 0, -1024) == -1024); - REQUIRE(map(128, 0, 256, 0, -1024) == -512); - } -} diff --git a/test/src/Common/test_max.cpp b/test/src/Common/test_max.cpp deleted file mode 100644 index 815f0ec1..00000000 --- a/test/src/Common/test_max.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'max(a,b)' with a < b", "[max-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(1,5) == 5); - WHEN("a < 0 and b > 0") REQUIRE(max(-1,5) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-5,-1) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a > b", "[max-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(5,1) == 5); - WHEN("a > 0 and b < 0") REQUIRE(max(5,-1) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-1,-5) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a == b", "[max-03]") -{ - WHEN("a = b > 0") REQUIRE(max(5,5) == 5); - WHEN("a = b < 0") REQUIRE(max(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(max(0,0) == 0); -} - -TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int64_t)); - } -} diff --git a/test/src/Common/test_min.cpp b/test/src/Common/test_min.cpp deleted file mode 100644 index b37158ff..00000000 --- a/test/src/Common/test_min.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'min(a,b)' with a < b", "[min-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(1,5) == 1); - WHEN("a < 0 and b > 0") REQUIRE(min(-1,5) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-5,-1) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a > b", "[min-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(5,1) == 1); - WHEN("a > 0 and b < 0") REQUIRE(min(5,-1) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-1,-5) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a == b", "[min-03]") -{ - WHEN("a = b > 0") REQUIRE(min(5,5) == 5); - WHEN("a = b < 0") REQUIRE(min(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(min(0,0) == 0); -} - -TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int64_t)); - } -} diff --git a/test/src/IPAddress/test_IPAddress.cpp b/test/src/IPAddress/test_IPAddress.cpp deleted file mode 100644 index 848a2c75..00000000 --- a/test/src/IPAddress/test_IPAddress.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress() default constructor()", "[IPAddress-Ctor-01]") -{ - arduino::IPAddress ip; - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o) constructor", "[IPAddress-Ctor-02]") -{ - arduino::IPAddress ip(129,168,1,2); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a) constructor", "[IPAddress-Ctor-03]") -{ - arduino::IPAddress ip(129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a *) constructor", "[IPAddress-Ctor-04]") -{ - uint8_t const ip_addr_array[] = {129,168,1,2}; - - arduino::IPAddress ip(ip_addr_array); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} diff --git a/test/src/IPAddress/test_IPAddress6.cpp b/test/src/IPAddress/test_IPAddress6.cpp deleted file mode 100644 index fc48f4c0..00000000 --- a/test/src/IPAddress/test_IPAddress6.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress(type) constructor()", "[IPAddress6-Ctor-01]") -{ - arduino::IPAddress ip (arduino::IPType::IPv6); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o) constructor", "[IPAddress-Ctor6-02]") -{ - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Testing IPAddress(type, a *) constructor", "[IPAddress6-Ctor-03]") -{ - uint8_t const ip_addr_array[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - arduino::IPAddress ip(arduino::IPType::IPv6, ip_addr_array); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} diff --git a/test/src/IPAddress/test_fromString.cpp b/test/src/IPAddress/test_fromString.cpp deleted file mode 100644 index 1e7795a3..00000000 --- a/test/src/IPAddress/test_fromString.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IP address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("129.168.1.2") == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract valid IP address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("129.168.1.2"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract invalid IP address 'fromString(const char *)'", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("") == false); - REQUIRE(ip.fromString("1") == false); - REQUIRE(ip.fromString("1.") == false); - REQUIRE(ip.fromString("1.1") == false); - REQUIRE(ip.fromString("1.1.") == false); - REQUIRE(ip.fromString("1.1.1") == false); - REQUIRE(ip.fromString("1.1.1.") == false); - REQUIRE(ip.fromString("...") == false); - REQUIRE(ip.fromString("256.1.1.1") == false); - REQUIRE(ip.fromString("a.1.1.1") == false); - REQUIRE(ip.fromString("-.1.1.1") == false); - REQUIRE(ip.fromString("-1.1.1.1") == false); -} diff --git a/test/src/IPAddress/test_fromString6.cpp b/test/src/IPAddress/test_fromString6.cpp deleted file mode 100644 index bb9f01b0..00000000 --- a/test/src/IPAddress/test_fromString6.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IPv6 address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("2001:db8:102:304:506:708:90a:b0c"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 any address", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 localhost address", "[IPAddress-fromString-04]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::1") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 1); -} - -TEST_CASE ("Extract valid IPv6 different length segments", "[IPAddress-fromString-05]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("abcd:ef1:23:0:4::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0xab); - REQUIRE(ip[1] == 0xcd); - REQUIRE(ip[2] == 0xe); - REQUIRE(ip[3] == 0xf1); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0x23); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 4); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 zero start", "[IPAddress-fromString-06]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - - -TEST_CASE ("Extract valid IPv6 zero end", "[IPAddress-fromString-07]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1:2:3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero start", "[IPAddress-fromString-08]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero end", "[IPAddress-fromString-9]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -// Non-canonical - -TEST_CASE ("Extract valid IPv6 any full long form", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 upper case", "[IPAddress-fromString-11]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:DB8:102:304:506:708:90A:B0C") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 explicit start zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 explicit end zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 compression of one group of zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1::3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - -// Invalid cases - -TEST_CASE ("Extract invalid IPv6 address", "[IPAddress-fromString-12]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString(":::") == false); // three colons by self - REQUIRE(ip.fromString("::3:4:5:6::") == false); // two compressions - REQUIRE(ip.fromString("2001:db8:102:10304:506:708:90a:b0c") == false); // 5 character field - REQUIRE(ip.fromString("200x:db8:102:304:506:708:90a:b0c") == false); // invalid character - REQUIRE(ip.fromString("2001:db8:102:304::506:708:90a:b0c") == false); // double colon with 8 other fields (so not a compression) - REQUIRE(ip.fromString("2001:db8:102:304:::708:90a:b0c") == false); // three colons in middle - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c:d0e") == false); // 9 fields - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a") == false); // only seven groups - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:0") == false); // nine zeros - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:") == false); // extra colon - REQUIRE(ip.fromString("0:0:0:0:0:0:0:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("0:0:0:0:0:0:0") == false); // only seven groups -} diff --git a/test/src/IPAddress/test_operator_assignment.cpp b/test/src/IPAddress/test_operator_assignment.cpp deleted file mode 100644 index 0d4e0041..00000000 --- a/test/src/IPAddress/test_operator_assignment.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator = (const uint8_t * a)", "[IPAddress-Operator-=-01]") -{ - arduino::IPAddress ip1; - uint8_t const ip2[] = {192,168,1,2}; - - ip1 = ip2; - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} - -TEST_CASE ("Testing IPAddress::operator = (uint32_t a)", "[IPAddress-Operator-=-02]") -{ - arduino::IPAddress ip1; - uint32_t const ip2 = 192 | (168 << 8) | (1 << 16) | (2 << 24); - - ip1 = ip2; - // NOTE: Only correct on little-endian systems - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} diff --git a/test/src/IPAddress/test_operator_comparison.cpp b/test/src/IPAddress/test_operator_comparison.cpp deleted file mode 100644 index 75139bf3..00000000 --- a/test/src/IPAddress/test_operator_comparison.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 == ip2", "[IPAddress-Operator-==-01]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 != ip2", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {129,168,1,2}; - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {10,0,0,1}; - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 != ip2) == false); -} diff --git a/test/src/IPAddress/test_operator_comparison6.cpp b/test/src/IPAddress/test_operator_comparison6.cpp deleted file mode 100644 index 1a50f251..00000000 --- a/test/src/IPAddress/test_operator_comparison6.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing two basic constructs the same", "[IPAddress6-Operator-==-01]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing two addresses different", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing not equals different address is true", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing not equals same address is false", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 != ip2) == false); -} - -// IPv4 and IPv6 differ based on type (irrespective of bytes) - -TEST_CASE ("Testing IPv4 vs IPv6", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 equivalent IPv4-compatible address (deprecated)", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(127, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 equivalent compatible address vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(0, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv6 never matches as raw byte sequence assumed to be length 4", "[IPAddress6-Operator-==-06]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - uint8_t const ip2[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - REQUIRE((ip1 == ip2) == false); -} diff --git a/test/src/IPAddress/test_operator_parentheses.cpp b/test/src/IPAddress/test_operator_parentheses.cpp deleted file mode 100644 index b9ad65c7..00000000 --- a/test/src/IPAddress/test_operator_parentheses.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator uint32_t() const", "[IPAddress-Operator-()-01]") -{ - arduino::IPAddress ip(129,168,1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - // NOTE: Only correct on little-endian systems - REQUIRE(val_expected == val_actual); -} diff --git a/test/src/IPAddress/test_operator_parentheses6.cpp b/test/src/IPAddress/test_operator_parentheses6.cpp deleted file mode 100644 index d360f129..00000000 --- a/test/src/IPAddress/test_operator_parentheses6.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -// These comparisons should always return false, as you can't compare an IPv6 to an int32_t - -TEST_CASE ("Testing implicit cast of IPv6 compatible (little endian) to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems, considering only last four octets (ignoring the rest) - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 full little endian to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems (full value) - arduino::IPAddress ip(129,168, 1,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // Actual value of the 128-bit IPv6 address, which is network byte order - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = ((129 << 24) | (168 << 16) | (1 << 8) | 2); - REQUIRE((val_expected == val_actual) == false); -} diff --git a/test/src/IPAddress/test_printTo.cpp b/test/src/IPAddress/test_printTo.cpp deleted file mode 100644 index 68e2ea9f..00000000 --- a/test/src/IPAddress/test_printTo.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPAddress via print method", "[IPAddress-printTo-01]") -{ - PrintMock mock; - arduino::IPAddress const ip(192,168,1,2); - - mock.print(ip); - - REQUIRE(mock._str == "192.168.1.2"); -} diff --git a/test/src/IPAddress/test_printTo6.cpp b/test/src/IPAddress/test_printTo6.cpp deleted file mode 100644 index 71dea49f..00000000 --- a/test/src/IPAddress/test_printTo6.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPv6", "[IPAddress-printTo6-01]") -{ - PrintMock mock; - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - mock.print(ip); - - REQUIRE(mock._str == "2001:db8:102:304:506:708:90a:b0c"); -} - -TEST_CASE ("Print IPv6 any", "[IPAddress-printTo6-02]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::"); -} - -TEST_CASE ("Print IPv6 localhost", "[IPAddress-printTo6-03]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); - - mock.print(ip); - - REQUIRE(mock._str == "::1"); -} - -TEST_CASE ("Print IPv6 different length segments", "[IPAddress-printTo6-04]") -{ - PrintMock mock; - arduino::IPAddress const ip(0xab,0xcd, 0x0e,0xf1, 0x00,0x23, 0,0, 0x00,0x04, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "abcd:ef1:23:0:4::"); -} - -TEST_CASE ("Print IPv6 zero longest run end", "[IPAddress-printTo6-05]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,2, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1:0:0:2::"); -} - -TEST_CASE ("Print IPv6 zero longest run mid", "[IPAddress-printTo6-06]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,0, 0,2, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1::2:0:0"); -} - -TEST_CASE ("Print IPv6 start zero", "[IPAddress-printTo6-07]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6:7:8"); -} - -TEST_CASE ("Print IPv6 ending zero", "[IPAddress-printTo6-08]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "1:2:3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 start two zero", "[IPAddress-printTo6-09]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,0, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 ending two zero", "[IPAddress-printTo6-10]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6::"); -} - -TEST_CASE ("Print IPv6 first out of same length", "[IPAddress-printTo6-11]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,0, 0,4, 0,5, 0,0, 0,0, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1::4:5:0:0:8"); -} - - -TEST_CASE ("Print IPv6 single zeros not compressed", "[IPAddress-printTo6-12]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,3, 0,0, 0,5, 0,0, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1:0:3:0:5:0:7:8"); -} diff --git a/test/src/IPAddress/test_toString.cpp b/test/src/IPAddress/test_toString.cpp deleted file mode 100644 index 1bd8d749..00000000 --- a/test/src/IPAddress/test_toString.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid string from IPv4address", "[IPAddress-toString-01]") -{ - arduino::IPAddress ip(129,168,1,2); - - REQUIRE(ip.toString().equals("129.168.1.2") == true); -} - -TEST_CASE ("Extract valid ipv6 string from IPv6address", "[IPAddress-toString-02]") -{ - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - REQUIRE(ip.toString().equals("2001:0db8:0102:0304:0506:0708:090a:0b0c") == true); -} - -TEST_CASE ("Extract 0.0.0.0 string from uninitialized IP address", "[IPAddress-toString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.toString().equals("0.0.0.0") == true); -} diff --git a/test/src/MillisFake.cpp b/test/src/MillisFake.cpp deleted file mode 100644 index 293af87f..00000000 --- a/test/src/MillisFake.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TYPEDEF - **************************************************************************************/ - -enum class MillisFakeMode -{ - Auto, Manual -}; - -/************************************************************************************** - * GLOBAL VARIABLES - **************************************************************************************/ - -static unsigned long millis_val = 0; -static MillisFakeMode millis_fake_mode = MillisFakeMode::Auto; -static std::chrono::steady_clock::time_point const millis_begin = std::chrono::steady_clock::now(); - -/************************************************************************************** - * FUNCTION DEFINITION - **************************************************************************************/ - -void millis_autoOn() -{ - millis_fake_mode = MillisFakeMode::Auto; -} - -void millis_autoOff() -{ - millis_fake_mode = MillisFakeMode::Manual; -} - -void set_millis(unsigned long const val) -{ - millis_autoOff(); - millis_val = val; -} - -unsigned long millis() -{ - if (millis_fake_mode == MillisFakeMode::Manual) - return millis_val; - - if (millis_fake_mode == MillisFakeMode::Auto) - { - std::chrono::steady_clock::time_point millis_now = std::chrono::steady_clock::now(); - auto millis = std::chrono::duration_cast(millis_now - millis_begin).count(); - return static_cast(millis); - } - - return 0; -} diff --git a/test/src/Print/test_availableForWrite.cpp b/test/src/Print/test_availableForWrite.cpp deleted file mode 100644 index ab6647cb..00000000 --- a/test/src/Print/test_availableForWrite.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::availableForWrite() should return 0 if not overwritten by derived class", "[Print-availableForWrite-01]") -{ - PrintMock mock; - REQUIRE(mock.availableForWrite() == 0); -} diff --git a/test/src/Print/test_clearWriteError.cpp b/test/src/Print/test_clearWriteError.cpp deleted file mode 100644 index 5f674cb2..00000000 --- a/test/src/Print/test_clearWriteError.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Clear write error should set the error code back to 0", "[Print-clearWriteError-01]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - mock.clearWriteError(); - REQUIRE(mock.getWriteError() == 0); -} diff --git a/test/src/Print/test_getWriteError.cpp b/test/src/Print/test_getWriteError.cpp deleted file mode 100644 index ff9eb0df..00000000 --- a/test/src/Print/test_getWriteError.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("No write error has been set", "[Print-getWriteError-01]") -{ - PrintMock mock; - REQUIRE(mock.getWriteError() == 0); -} - -TEST_CASE ("A write error has been set", "[Print-getWriteError-02]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - REQUIRE(mock.getWriteError() == 5); -} diff --git a/test/src/Print/test_print.cpp b/test/src/Print/test_print.cpp deleted file mode 100644 index 1a41c462..00000000 --- a/test/src/Print/test_print.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::print(char)", "[Print-print-01]") -{ - PrintMock mock; - - mock.print('A'); - - REQUIRE(mock._str == "A"); -} - -TEST_CASE ("Print::print(const String &)", "[Print-print-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(const char str[])", "[Print-print-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(int, int = DEC|HEX|OCT|BIN)", "[Print-print-04]") -{ - PrintMock mock; - - int const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned int, int = DEC|HEX|OCT|BIN)", "[Print-print-05]") -{ - PrintMock mock; - - unsigned int const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } -} - -TEST_CASE ("Print::print(long, int = DEC|HEX|OCT|BIN)", "[Print-print-06]") -{ - PrintMock mock; - - long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long, int = DEC|HEX|OCT|BIN)", "[Print-print-07]") -{ - PrintMock mock; - - unsigned long const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } -} - -TEST_CASE ("Print::print(long long, int = DEC|HEX|OCT|BIN)", "[Print-print-08]") -{ - PrintMock mock; - - long long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-print-09]") -{ - PrintMock mock; - - GIVEN("a value of zero ...") - { - unsigned long long const val = 0; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); } - } - GIVEN("a non-zero value ...") - { - unsigned long long const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } - } -} - -TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]") -{ - PrintMock mock; - - WHEN ("val is a positive floating point value") - { - double const val = 3.1459; - WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); } - WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); } - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); } - WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); } - WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); } - WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); } - } - - WHEN ("digits are negative") - { - double const val = 3.1459; - WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); } - } - - WHEN ("val is a negative floating point value") - { - double const val = -3.1459; - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); } - } - - WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); } - WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); } -} - -TEST_CASE ("Print::print(Printable)", "[Print-print-11]") -{ - PrintMock mock; - - PrintableMock printable; - printable._i = 1; - - mock.print(printable); - - REQUIRE(mock._str == "PrintableMock i = 1"); -} - -TEST_CASE ("Print::print(unsigned char, int)", "[Print-print-12]") -{ - PrintMock mock; - - WHEN("DEC") { mock.print('A', DEC); REQUIRE(mock._str == "65"); } - WHEN("HEX") { mock.print('A', HEX); REQUIRE(mock._str == "41"); } - WHEN("OCT") { mock.print('A', OCT); REQUIRE(mock._str == "101"); } - WHEN("BIN") { mock.print('A', BIN); REQUIRE(mock._str == "1000001"); } -} - -TEST_CASE ("Testing Print::print(const __FlashStringHelper *)", "[Print-print-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.print(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string"); -} diff --git a/test/src/Print/test_println.cpp b/test/src/Print/test_println.cpp deleted file mode 100644 index e35814e0..00000000 --- a/test/src/Print/test_println.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::println(char)", "[Print-println-01]") -{ - PrintMock mock; - - mock.println('A'); - - REQUIRE(mock._str == "A\r\n"); -} - -TEST_CASE ("Print::println(const String &)", "[Print-println-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(const char str[])", "[Print-println-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(int, int = DEC (default))", "[Print-println-04]") -{ - PrintMock mock; - int const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned int, int = DEC (default))", "[Print-println-05]") -{ - PrintMock mock; - unsigned int const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long, int = DEC (default))", "[Print-println-06]") -{ - PrintMock mock; - long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long, int = DEC (default))", "[Print-println-07]") -{ - PrintMock mock; - unsigned long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long long, int = DEC (default))", "[Print-println-08]") -{ - PrintMock mock; - long long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-println-09]") -{ - PrintMock mock; - unsigned long long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(double, int = 2)", "[Print-println-10]") -{ - PrintMock mock; - double const val = 3.1459; - - mock.println(val); - - REQUIRE(mock._str == "3.15\r\n"); -} - -TEST_CASE ("Print::println(Printable)", "[Print-println-11]") -{ - PrintMock mock; - PrintableMock printable; - printable._i = 1; - - mock.println(printable); - - REQUIRE(mock._str == "PrintableMock i = 1\r\n"); -} - -TEST_CASE ("Print::println(unsigned char, int base = DEC (default))", "[Print-println-12]") -{ - PrintMock mock; - - mock.println('A', DEC); - - REQUIRE(mock._str == "65\r\n"); -} - -TEST_CASE ("Testing Print::println(const __FlashStringHelper *)", "[Print-println-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.println(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string\r\n"); -} diff --git a/test/src/PrintMock.cpp b/test/src/PrintMock.cpp deleted file mode 100644 index ffa7c58f..00000000 --- a/test/src/PrintMock.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -size_t PrintMock::write(uint8_t b) -{ - _str.append(1, static_cast(b)); - return 1; -} diff --git a/test/src/Ringbuffer/test_available.cpp b/test/src/Ringbuffer/test_available.cpp deleted file mode 100644 index 171dcbf6..00000000 --- a/test/src/Ringbuffer/test_available.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'available' should return 0 for empty ring buffer", "[Ringbuffer-available-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("'available' should return number of elements in ringbuffer", "[Ringbuffer-available-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.available() == 2); -} diff --git a/test/src/Ringbuffer/test_availableForStore.cpp b/test/src/Ringbuffer/test_availableForStore.cpp deleted file mode 100644 index 4a06e839..00000000 --- a/test/src/Ringbuffer/test_availableForStore.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'availableForStore' should return ring buffer size for empty ring buffer", "[Ringbuffer-availableForStore-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.availableForStore() == 2); -} - -TEST_CASE ("'availableForStore' should return number of free elements in ringbuffer", "[Ringbuffer-availableForStore-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.availableForStore() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.availableForStore() == 0); -} diff --git a/test/src/Ringbuffer/test_clear.cpp b/test/src/Ringbuffer/test_clear.cpp deleted file mode 100644 index e2868c16..00000000 --- a/test/src/Ringbuffer/test_clear.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'clear' on a empty ring buffer should have no effect", "[Ringbuffer-clear-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("Calling 'clear' on a partially filled ring buffer should \"remove\" all elements", "[Ringbuffer-clear-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} diff --git a/test/src/Ringbuffer/test_isFull.cpp b/test/src/Ringbuffer/test_isFull.cpp deleted file mode 100644 index a7208f85..00000000 --- a/test/src/Ringbuffer/test_isFull.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'isFull' should return false for empty ring buffer", "[Ringbuffer-isFull-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return false for a partial full ring buffer", "[Ringbuffer-isFull-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return true for full ring buffer", "[Ringbuffer-isFull-03]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.isFull() == true); -} diff --git a/test/src/Ringbuffer/test_peek.cpp b/test/src/Ringbuffer/test_peek.cpp deleted file mode 100644 index 145a7f37..00000000 --- a/test/src/Ringbuffer/test_peek.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is accessed but not removed from the ring buffer via 'peek'", "[Ringbuffer-peek-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'peek' should return -1") - REQUIRE(ringbuffer.peek() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'peek' should return first inserted element first (FIFO) and not remove it") - { - REQUIRE(ringbuffer.peek() == 'A'); - REQUIRE(ringbuffer.peek() == 'A'); - } - } -} diff --git a/test/src/Ringbuffer/test_read_char.cpp b/test/src/Ringbuffer/test_read_char.cpp deleted file mode 100644 index c6941adb..00000000 --- a/test/src/Ringbuffer/test_read_char.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is removed from the ring buffer via 'read_char'", "[Ringbuffer-read_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'read_char' should return -1") - REQUIRE(ringbuffer.read_char() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'read_char' should return first inserted element first (FIFO)") - { - REQUIRE(ringbuffer.read_char() == 'A'); - REQUIRE(ringbuffer.read_char() == 'B'); - } - } -} diff --git a/test/src/Ringbuffer/test_store_char.cpp b/test/src/Ringbuffer/test_store_char.cpp deleted file mode 100644 index 705d979a..00000000 --- a/test/src/Ringbuffer/test_store_char.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is put into the ring buffer via 'store_char'", "[Ringbuffer-store_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer._aucBuffer[0] == 'A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer._aucBuffer[1] == 'B'); -} diff --git a/test/src/Stream/test_find.cpp b/test/src/Stream/test_find.cpp deleted file mode 100644 index c3c69d04..00000000 --- a/test/src/Stream/test_find.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing find(const char *target)", "[Stream-find-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find("test") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(const char *target, size_t length)", "[Stream-find-02]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - /* 'length' should actually be '4' or strlen("test"). I'd rather - * think this API should not be exposed at all. - */ - REQUIRE(mock.find("test", 3) == true); - REQUIRE(mock.readString() == arduino::String("t string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test", 3) == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(char target)", "[Stream-find-03]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find('t') == true); - REQUIRE(mock.readString() == arduino::String("est string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find('!') == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_findUntil.cpp b/test/src/Stream/test_findUntil.cpp deleted file mode 100644 index acd5ea1e..00000000 --- a/test/src/Stream/test_findUntil.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing findUntil(const char *target, const char *terminator)", "[Stream-findUntil-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - WHEN ("'terminator' appears before 'target'") - { - mock << "This is a : test string"; - REQUIRE(mock.findUntil("test", ": ") == false); - REQUIRE(mock.readString() == arduino::String("test string")); - } - WHEN ("'terminator' appears after 'target'") - { - mock << "This is a test : string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" : string")); - } - WHEN ("'terminator' is not included in the string at all") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - } - - WHEN ("'target' is not contained in stream") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("abc", "def") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_getTimeout.cpp b/test/src/Stream/test_getTimeout.cpp deleted file mode 100644 index 9a9e6e1b..00000000 --- a/test/src/Stream/test_getTimeout.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if default timeout is returned correctly", "[Stream-getTimeout-01]") -{ - StreamMock mock; - REQUIRE(mock.getTimeout() == 1000); -} diff --git a/test/src/Stream/test_parseFloat.cpp b/test/src/Stream/test_parseFloat.cpp deleted file mode 100644 index 2c273370..00000000 --- a/test/src/Stream/test_parseFloat.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -using namespace Catch; - -#include - -#include - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-01]") -{ - StreamMock mock; - - WHEN ("Only a integer (no comma) is contained in stream") - { - mock << "12"; - REQUIRE(mock.parseFloat() == 12.0f); - } - WHEN ("A positive float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A negative float is contained in stream") - { - mock << "-12.34"; - REQUIRE(mock.parseFloat() == -12.34f); - } - WHEN ("A float is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A float is provided with too many digits after the decimal point") - { - mock << "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870064"; - REQUIRE(mock.parseFloat() == Approx(3.141592654f)); - } - WHEN ("A float is larger than LONG_MAX") - { - mock << "602200000000000000000000.00"; - REQUIRE(mock.parseFloat() == Approx(6.022e23f)); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-02]") -{ - StreamMock mock; - - WHEN ("Only a integer is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef12.34")); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 12.34")); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-03]") -{ - StreamMock mock; - - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_WHITESPACE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } -} - - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseFloat-04]") -{ - StreamMock mock; - - WHEN ("A float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The float contains only ignore char values") - { - mock << "12a.3a4a"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 1.0f); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/test/src/Stream/test_parseInt.cpp b/test/src/Stream/test_parseInt.cpp deleted file mode 100644 index 69cf5805..00000000 --- a/test/src/Stream/test_parseInt.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -using namespace arduino; - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-01]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A negative integer is contained in stream") - { - mock << "-1234"; - REQUIRE(mock.parseInt() == -1234); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt() == 1234); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-02]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef1234")); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 1234")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-03]") -{ - StreamMock mock; - - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_WHITESPACE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseInt-04]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains only ignore char values") - { - mock << "12a3a4a"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/test/src/Stream/test_readBytes.cpp b/test/src/Stream/test_readBytes.cpp deleted file mode 100644 index 814a602f..00000000 --- a/test/src/Stream/test_readBytes.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytes(char *buffer, size_t length)", "[Stream-readBytes-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains less data than we want to read") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - mock << str; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == strlen(str)); - REQUIRE(strncmp(buf, str, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } - - WHEN ("the stream contains more data than we want to read") - { - char buf[5] = {0}; - mock << "some stream content"; - char const EXPECTED_STR[] = "some "; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 5); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } -} diff --git a/test/src/Stream/test_readBytesUntil.cpp b/test/src/Stream/test_readBytesUntil.cpp deleted file mode 100644 index fa0cff10..00000000 --- a/test/src/Stream/test_readBytesUntil.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytesUntil(char terminator, char *buffer, size_t length)", "[Stream-readBytesUntil-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains the termination character") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - char const EXPECTED_STR[] = "some"; - mock << str; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == strlen("some")); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } - - WHEN ("the stream does not contain the termination character") - { - char buf[32] = {0}; - char const STR[] = "some stream content"; - mock << STR; - - REQUIRE(mock.readBytesUntil('!', buf, sizeof(buf)) == strlen(STR)); - REQUIRE(strncmp(buf, STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/test/src/Stream/test_readString.cpp b/test/src/Stream/test_readString.cpp deleted file mode 100644 index 996be6e7..00000000 --- a/test/src/Stream/test_readString.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readString' with data available within the stream", "[Stream-readString-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test stream content"; - - REQUIRE(mock.readString() == arduino::String("This is test stream content")); -} diff --git a/test/src/Stream/test_readStringUntil.cpp b/test/src/Stream/test_readStringUntil.cpp deleted file mode 100644 index c4f52b54..00000000 --- a/test/src/Stream/test_readStringUntil.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include -#include -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readStringUntil' with separator available within the stream", "[Stream-readStringUntil-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test! lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test")); -} - -TEST_CASE ("Testing 'readStringUntil' with separator not available within the stream", "[Stream-readStringUntil-02]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test ... lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test ... lorem ipsum lalala")); -} diff --git a/test/src/Stream/test_setTimeout.cpp b/test/src/Stream/test_setTimeout.cpp deleted file mode 100644 index 08840c97..00000000 --- a/test/src/Stream/test_setTimeout.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if calling 'setTimeout' is indeed modifying the timeout", "[Stream-setTimeout-01]") -{ - StreamMock mock; - - mock.setTimeout(100); - - REQUIRE(mock.getTimeout() == 100); -} diff --git a/test/src/StreamMock.cpp b/test/src/StreamMock.cpp deleted file mode 100644 index c1768859..00000000 --- a/test/src/StreamMock.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -void StreamMock::operator << (char const * str) -{ - for (size_t c = 0; c < strlen(str); c++) - _stream.push_back(str[c]); -} - -size_t StreamMock::write(uint8_t ch) -{ - _stream.push_back(static_cast(ch)); - return 1; -} - -int StreamMock::available() -{ - return _stream.size(); -} - -int StreamMock::read() -{ - if (available() == 0) - return -1; - - /* Extract first/oldest element. */ - char const c = _stream.at(0); - /* Erase first/oldest element. */ - _stream.pop_front(); - - return c; -} - -int StreamMock::peek() -{ - if (available() == 0) - return -1; - - return _stream.at(0); -} diff --git a/test/src/String/StringPrinter.h b/test/src/String/StringPrinter.h deleted file mode 100644 index 1785f983..00000000 --- a/test/src/String/StringPrinter.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#pragma once - -#include -#include - -namespace Catch { - /** - * Template specialization that makes sure Catch can properly print - * Arduino Strings when used in comparisons directly. - * - * Note that without this, String objects are printed as 0 and 1, - * because they are implicitly convertible to StringIfHelperType, - * which is a dummy pointer. - */ - template<> - struct StringMaker { - static std::string convert(const arduino::String& str) { - if (str) - return ::Catch::Detail::stringify(std::string(str.c_str(), str.length())); - else - return "{invalid String}"; - } - }; -} // namespace Catch diff --git a/test/src/String/test_String.cpp b/test/src/String/test_String.cpp deleted file mode 100644 index d6ef7254..00000000 --- a/test/src/String/test_String.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]") -{ - char const CSTR[] = "Hello Arduino String Class"; - arduino::String str(CSTR); - REQUIRE(str == CSTR); -} - -TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]") -{ - arduino::String str1("Hello Arduino String class"), - str2(str1); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-Ctor-03]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1(F("Hello")); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-04]") -{ - char const ch = 'A'; - arduino::String str(ch); - REQUIRE(str == "A"); -} - -TEST_CASE ("Testing String(unsigned char, unsigned char base = 10) constructor()", "[String-Ctor-05]") -{ - unsigned char const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-06]") -{ - int const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-07]") -{ - unsigned int const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-08]") -{ - long const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-09]") -{ - unsigned long const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]") -{ - WHEN ("String::String (some float value)") - { - arduino::String str(1.234f); - REQUIRE(str == "1.23"); - } - WHEN ("String::String (FLT_MAX)") - { - arduino::String str(FLT_MAX); - REQUIRE(str == "340282346638528859811704183484516925440.00"); - } - WHEN ("String::String (-FLT_MAX)") - { - arduino::String str(-FLT_MAX); - REQUIRE(str == "-340282346638528859811704183484516925440.00"); - } -} - -TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-11]") -{ - WHEN ("String::String (some double value)") - { - arduino::String str(5.678); - REQUIRE(str == "5.68"); - } - WHEN ("String::String (DBL_MAX)") - { - arduino::String str(DBL_MAX); - REQUIRE(str == "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } - WHEN ("String::String (-DBL_MAX)") - { - arduino::String str(-DBL_MAX); - REQUIRE(str == "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid buffer", "[String-Ctor-12]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - char *buffer = NULL; - - arduino::String str1(F(buffer)); - REQUIRE_FALSE(str1); -} - -TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1(static_cast(str+ch)); - REQUIRE(str1 == "Hello!"); -} - -TEST_CASE ("Testing String(String &&) constructor()", "[String-Ctor-14]") -{ - arduino::String str("Hello"); - arduino::String str1(static_cast(str)); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to larger buffer", "[String-Ctor-15]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smaller buffer", "[String-Ctor-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str = static_cast(str1); - REQUIRE(str == "Arduino"); -} diff --git a/test/src/String/test_characterAccessFunc.cpp b/test/src/String/test_characterAccessFunc.cpp deleted file mode 100644 index e191f1d0..00000000 --- a/test/src/String/test_characterAccessFunc.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::charAt(unsigned int)", "[String-charAt-01]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.charAt(2) == 'l'); -} - -TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-02]") -{ - arduino::String str1("Hello"); - str1.setCharAt(1, 'a'); - REQUIRE(str1 == "Hallo"); -} - -TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]") -{ - WHEN("No bufsize") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 0, 0); - } - - WHEN("Index >= len") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 5, 6); - } - - WHEN("Valid operation") { - arduino::String str("Hello"); - unsigned char buf[3]; - str.getBytes(buf, 5, 3); - REQUIRE(buf[0] == 'l'); - REQUIRE(buf[1] == 'o'); - REQUIRE(buf[2] == '\0'); - } -} - -TEST_CASE ("Testing & String::operator[]", "[String-&operator subscript-03]") -{ - arduino::String str("Hello"); - str[0] = 'M'; - REQUIRE(str == "Mello"); -} - -TEST_CASE ("Testing & String::operator[] with invalid buffer", "[String-&operator subscript-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - str[0] = 'M'; - REQUIRE(str[0] == 0); -} diff --git a/test/src/String/test_compareTo.cpp b/test/src/String/test_compareTo.cpp deleted file mode 100644 index b5673201..00000000 --- a/test/src/String/test_compareTo.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]") -{ - WHEN ("Strings are equal") - { - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.compareTo(str2) == 0); - } - - WHEN ("str2 is empty") - { - arduino::String str1("Hello"), str2; - REQUIRE(str1.compareTo(str2) > 0); - } - - WHEN ("str1 is empty") - { - arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo(str2) < 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") -{ - WHEN ("Strings are equal") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("Hello") == 0); - } - - WHEN ("Passed string is empty") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("") > 0); - } - - WHEN ("Passed string is compared with empty string") - { - arduino::String str; - REQUIRE(str.compareTo("") == 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String-compareTo-03]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str("Hello"); - REQUIRE(str.compareTo(buffer) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str(buffer1); - REQUIRE(str.compareTo(buffer2) == 0); - } -} - - -TEST_CASE ("Testing String::compareTo(const String &) with empty buffer", "[String-compareTo-04]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str1("Hello"); - arduino::String str2(buffer); - REQUIRE(str1.compareTo(str2) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str1(buffer1); - arduino::String str2(buffer2); - REQUIRE(str1.compareTo(str2) == 0); - } -} diff --git a/test/src/String/test_comparisonFunc.cpp b/test/src/String/test_comparisonFunc.cpp deleted file mode 100644 index 558012d1..00000000 --- a/test/src/String/test_comparisonFunc.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::equals(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equals(str2) == 1); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String::operator!=(const String &) with exit status FAIL", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE_FALSE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equals(str2) == 0); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE_FALSE(str1 == str2); -} - -TEST_CASE ("Testing String::operator !=(const String &) with exit status PASS", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("Hello") == 1); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status FAIL", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 != "Hello"); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("World") == 0); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 == "World"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status PASS", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 != "World"); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string", "[String-equalsIgnoreCase-05]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equalsIgnoreCase(str2) == 1); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with NON-empty string", "[String-equalsIgnoreCase-06]") -{ - arduino::String str1("Hello"), str2("Hel"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with different strings", "[String-equalsIgnoreCase-07]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with same string", "[String-equalsIgnoreCase-08]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equalsIgnoreCase(str1) == 1); -} - -TEST_CASE ("Testing String::startsWith(const String &)", "[String-startsWith-09]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.startsWith(str2) == 0); - } - WHEN ("str1 starts with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Hello"); - REQUIRE(str1.startsWith(str2) == 1); - } - WHEN ("str1 does NOT start with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.startsWith(str2) == 0); - } -} - -TEST_CASE ("Testing String::endsWith(const String &)", "[String-endsWith-10]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.endsWith(str2) == 0); - } - WHEN ("str1 ends with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("World"); - REQUIRE(str1.endsWith(str2) == 1); - } - WHEN ("str1 does NOT end with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.endsWith(str2) == 0); - } -} diff --git a/test/src/String/test_concat.cpp b/test/src/String/test_concat.cpp deleted file mode 100644 index 81136591..00000000 --- a/test/src/String/test_concat.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::concat(const String &)", "[String-concat-01]") -{ - arduino::String str1("Hello "), str2("Arduino!"); - REQUIRE(str1.concat(str2) == 1); - REQUIRE(str1 == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]") -{ - arduino::String str("Hello "); - REQUIRE(str.concat("Arduino!") == 1); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") -{ - arduino::String str("Hello "); - char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello A"); -} - -TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") -{ - arduino::String str("Hello "); - unsigned char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello 65"); /* ASCII['A'] = 65 */ -} - -TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") -{ - arduino::String str("Hello "); - int const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") -{ - arduino::String str("Hello "); - unsigned int const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") -{ - arduino::String str("Hello "); - long const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") -{ - arduino::String str("Hello "); - unsigned long const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") -{ - arduino::String str("Hello "); - float const num = 1.234f; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1.23"); -} - -TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") -{ - arduino::String str("Hello "); - double const num = 5.678; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 5.68"); -} - -TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-concat-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello"); - REQUIRE(str1.concat(F(" Arduino")) == 1); - REQUIRE(str1 == "Hello Arduino"); -} diff --git a/test/src/String/test_indexOf.cpp b/test/src/String/test_indexOf.cpp deleted file mode 100644 index 12de054c..00000000 --- a/test/src/String/test_indexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::indexOf(char ch)", "[String-indexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l') == 2); - } -} - -TEST_CASE ("Testing String::indexOf(char ch, unsigned int fromIndex)", "[String-indexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf('a', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::indexOf(const String &)", "[String-indexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str) == 6); - } -} - -TEST_CASE ("Testing String::indexOf(const String &, unsigned int fromIndex)", "[String-indexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 3) == 6); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 8) == -1); - } -} diff --git a/test/src/String/test_isEmpty.cpp b/test/src/String/test_isEmpty.cpp deleted file mode 100644 index a6e30f94..00000000 --- a/test/src/String/test_isEmpty.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::isEmpty when string is empty", "[String-isEmpty-01]") -{ - arduino::String str; - REQUIRE(str.isEmpty()); -} - -TEST_CASE ("Testing String::isEmpty when string contains characters", "[String-isEmpty-02]") -{ - arduino::String str("Testing String::isEmpty"); - REQUIRE(!str.isEmpty()); -} diff --git a/test/src/String/test_lastIndexOf.cpp b/test/src/String/test_lastIndexOf.cpp deleted file mode 100644 index 13e850cb..00000000 --- a/test/src/String/test_lastIndexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::lastIndexOf(char ch)", "[String-lastIndexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l') == 7); - } -} - -TEST_CASE ("Testing String::lastIndexOf(char ch, unsigned int fromIndex)", "[String-lastIndexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf('o', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &)", "[String-lastIndexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str) == 15); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &, unsigned int fromIndex)", "[String-lastIndexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 17) == 15); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } -} diff --git a/test/src/String/test_length.cpp b/test/src/String/test_length.cpp deleted file mode 100644 index 062ba819..00000000 --- a/test/src/String/test_length.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::length when string is empty", "[String-length-01]") -{ - arduino::String str; - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::length when string contains characters", "[String-length-02]") -{ - arduino::String str("Testing String::length"); - REQUIRE(str.length() == strlen("Testing String::length")); -} diff --git a/test/src/String/test_move.cpp b/test/src/String/test_move.cpp deleted file mode 100644 index fda0a0d2..00000000 --- a/test/src/String/test_move.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include - -#include - -#include "StringPrinter.h" - -#include - -TEST_CASE("Testing String move constructor", "[String-move-01]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b(std::move(a)); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b.c_str() == a_str); - REQUIRE(b.length() == 3); -} - -TEST_CASE("Testing String move assignment", "[String-move-02]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b; - b = std::move(a); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b == arduino::String("src")); - REQUIRE(b.c_str() == a_str); -} - -TEST_CASE("Testing String move self assignment", "[String-move-03]") -{ -#if (defined(GCC_VERSION) && GCC_VERSION >= 13) || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wself-move" -#endif - arduino::String a("src"); - a = std::move(a); - REQUIRE(a == "src"); -#if defined(GCC_VERSION) && GCC_VERSION >= 13 || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#pragma GCC diagnostic pop -#endif -} diff --git a/test/src/String/test_operators.cpp b/test/src/String/test_operators.cpp deleted file mode 100644 index 14f826b0..00000000 --- a/test/src/String/test_operators.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", "[String-operator+-01]") -{ - arduino::String str1("Hello "); - arduino::String str2("Arduino"); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+str2); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const char *)", "[String-operator+-02]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+"Arduino"); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]") -{ - arduino::String str1("Hello"); - char ch='!'; - arduino::String str("Hello!"); - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]") -{ - arduino::String str1("Hello "); - unsigned char ch='A'; - arduino::String str("Hello 65"); /* ASCII['A'] = 65 */ - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, int)", "[String-operator+-05]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello 1"); - REQUIRE(str == str1+1); -} - -TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]") -{ - arduino::String str1("Hello "); - unsigned int const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]") -{ - arduino::String str1("Hello "); - long const num = -1; - arduino::String str("Hello -1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]") -{ - arduino::String str1("Hello "); - unsigned long const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]") -{ - arduino::String str1("Hello "); - float const num = 1.234f; - arduino::String str("Hello 1.23"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]") -{ - arduino::String str1("Hello "); - double const num = 5.678; - arduino::String str("Hello 5.68"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+F("Arduino")); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&rval)", "[String-operator+-12]") -{ - arduino::String str1("Hello "); - arduino::String str = (str1+"Arduino"); - REQUIRE(str == "Hello Arduino"); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]") -{ - arduino::String str1("Hello"); - - char *buffer2 = NULL; - arduino::String str2(buffer2); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL does not leave string unchanged", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE(str != "Hello"); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL produces invalid string", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE_FALSE(str); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]") -{ - char *buffer1 = NULL; - arduino::String str1(buffer1); - - arduino::String str2("Hello"); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1("Arduino"); - str1 = static_cast(str+ch); - REQUIRE(str1 == "Hello!"); -} diff --git a/test/src/String/test_remove.cpp b/test/src/String/test_remove.cpp deleted file mode 100644 index 6281d773..00000000 --- a/test/src/String/test_remove.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::remove(index) when string is empty", "[String-remove-01]") -{ - arduino::String str; - str.remove(0); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index) when index is > string length", "[String-remove-02]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]") -{ - arduino::String str; - str.remove(0, 10); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index,count) when index is > string length", "[String-remove-05]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100, 10); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 100); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 1); - REQUIRE(str == "HelloArduino!"); -} diff --git a/test/src/String/test_replace.cpp b/test/src/String/test_replace.cpp deleted file mode 100644 index 36b44136..00000000 --- a/test/src/String/test_replace.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::replace(char, char) when string is empty", "[String-replace-01]") -{ - arduino::String str; - str.replace('a', 'b'); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements != 'find'", "[String-replace-02]") -{ - arduino::String str("Hello Arduino!"); - str.replace('Z', '0'); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]") -{ - arduino::String str("Hello Arduino!"); - str.replace('o', '0'); - str.replace('e', '3'); - str.replace('i', '1'); - REQUIRE(str == "H3ll0 Ardu1n0!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string does not contain substr 'find'", "[String-replace-04]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("Zulu"), arduino::String("11")); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string contains substr 'find'", "[String-replace-05]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(str == "He11o Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace'", "[String-replace-06]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("llo"), arduino::String("11")); - REQUIRE(str == "He11 Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-07]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("ll"), arduino::String("111")); - REQUIRE(str == "He111o Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]") -{ - arduino::String str("Hello Arduino! Hello, Hello, Hello"); - str.replace(arduino::String("ll"), arduino::String("lll")); - REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]") -{ - arduino::String str("Hello Arduino! Hello, Hello, Hello"); - str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(str == "He11o Arduino! He11o, He11o, He11o"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]") -{ - arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo"); - str.replace(arduino::String("lll"), arduino::String("ll")); - REQUIRE(str == "Hello Arduino! Hello, Hello, Hello"); -} diff --git a/test/src/String/test_substring.cpp b/test/src/String/test_substring.cpp deleted file mode 100644 index 6397b905..00000000 --- a/test/src/String/test_substring.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::substring(unsigned int, unsigned int)", "[String-substring-01]") -{ - WHEN ("left higher than len") - { - arduino::String str("Hello"); - str.substring(7,9); - } - - WHEN ("right higher than len") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(1,9)); - } - - WHEN ("left higher than right") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(9,1)); - } -} diff --git a/test/src/String/test_toDouble.cpp b/test/src/String/test_toDouble.cpp deleted file mode 100644 index 3bb1ba5a..00000000 --- a/test/src/String/test_toDouble.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toDouble when string is empty", "[String-toDouble-01]") -{ - arduino::String str; - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains no number", "[String-toDouble-02]") -{ - arduino::String str("abc"); - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains a number", "[String-toDouble-03]") -{ - arduino::String str("-1.2345"); - double const val = str.toDouble(); - REQUIRE(val == -1.2345); -} - -TEST_CASE ("Testing String::toDouble when string does not have a buffer", "[String-toDouble-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toDouble() == 0); -} diff --git a/test/src/String/test_toFloat.cpp b/test/src/String/test_toFloat.cpp deleted file mode 100644 index 28fca212..00000000 --- a/test/src/String/test_toFloat.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toFloat when string is empty", "[String-toFloat-01]") -{ - arduino::String str; - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains no number", "[String-toFloat-02]") -{ - arduino::String str("abc"); - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains a number", "[String-toFloat-03]") -{ - arduino::String str("-1.2345"); - float const val = str.toFloat(); - REQUIRE(val == -1.2345f); -} diff --git a/test/src/String/test_toInt.cpp b/test/src/String/test_toInt.cpp deleted file mode 100644 index c93fcc4a..00000000 --- a/test/src/String/test_toInt.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toInt when string is empty", "[String-toInt-01]") -{ - arduino::String str; - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains no number", "[String-toInt-02]") -{ - arduino::String str("abc"); - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains a number", "[String-toInt-03]") -{ - arduino::String str("-1"); - int const val = str.toInt(); - REQUIRE(val == -1); -} - -TEST_CASE ("Testing String::toInt when string does not have a buffer", "[String-toInt-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toInt() == 0); -} diff --git a/test/src/String/test_toLowerCase.cpp b/test/src/String/test_toLowerCase.cpp deleted file mode 100644 index ec0f9eb3..00000000 --- a/test/src/String/test_toLowerCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toLowerCase", "[String-toLowerCase-01]") -{ - arduino::String str("HELLO ARDUINO"); - str.toLowerCase(); - REQUIRE(str == "hello arduino"); -} diff --git a/test/src/String/test_toUpperCase.cpp b/test/src/String/test_toUpperCase.cpp deleted file mode 100644 index 937fa52d..00000000 --- a/test/src/String/test_toUpperCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toUpperCase", "[String-toUpperCase-01]") -{ - arduino::String str("hello arduino"); - str.toUpperCase(); - REQUIRE(str == "HELLO ARDUINO"); -} diff --git a/test/src/String/test_trim.cpp b/test/src/String/test_trim.cpp deleted file mode 100644 index eddc9fdb..00000000 --- a/test/src/String/test_trim.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::trim with space at the beginning", "[String-trim-01]") -{ - arduino::String str(" hello"); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]") -{ - arduino::String str("hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at both beginning and end", "[String-trim-03]") -{ - arduino::String str(" hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]") -{ - arduino::String str("Hello Arduino!"); - str.trim(); - REQUIRE(str == "Hello Arduino!"); -} diff --git a/test/src/WCharacter/test_isAscii.cpp b/test/src/WCharacter/test_isAscii.cpp deleted file mode 100644 index 4ec92d3b..00000000 --- a/test/src/WCharacter/test_isAscii.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isAscii(...) is called with a valid ascii character", "[isAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::isAscii(c) == true); - }); -} - -TEST_CASE ("isAscii(...) is called with a invalid ascii character", "[isAscii-02]") -{ - REQUIRE(arduino::isAscii(0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a invalid casted ascii character", "[isAscii-03]") -{ - REQUIRE(arduino::isAscii((unsigned char)0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a character latger than 1 byte", "[isAscii-04]") -{ - REQUIRE(arduino::isAscii(0x3030) == false); -} - diff --git a/test/src/WCharacter/test_isControl.cpp b/test/src/WCharacter/test_isControl.cpp deleted file mode 100644 index c4e985c4..00000000 --- a/test/src/WCharacter/test_isControl.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_CONTROL_VECT = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,'\t','\f','\v','\n','\r',0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x7F}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isControl(...) is called with control char", "[isControl-01]") -{ - std::for_each(std::begin(VALID_CONTROL_VECT), - std::end (VALID_CONTROL_VECT), - [](char const c) - { - REQUIRE(arduino::isControl(c) == true); - }); -} - -TEST_CASE ("isControl(...) is called with non control char", "[isControl-02]") -{ - REQUIRE(arduino::isControl('z') == false); -} diff --git a/test/src/WCharacter/test_isDigit.cpp b/test/src/WCharacter/test_isDigit.cpp deleted file mode 100644 index 3303cf49..00000000 --- a/test/src/WCharacter/test_isDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_DIGIT_VECT = {'0','1','2','3','4','5','6','7','8','9'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isDigit(...) is called with valid digits", "[isDigit-01]") -{ - std::for_each(std::begin(VALID_DIGIT_VECT), - std::end (VALID_DIGIT_VECT), - [](char const c) - { - REQUIRE(arduino::isDigit(c) == true); - }); -} - -TEST_CASE ("isDigit(...) is called with non digit", "[isDigit-02]") -{ - REQUIRE(arduino::isDigit('z') == false); -} diff --git a/test/src/WCharacter/test_isHexadecimalDigit.cpp b/test/src/WCharacter/test_isHexadecimalDigit.cpp deleted file mode 100644 index ad5a0f4b..00000000 --- a/test/src/WCharacter/test_isHexadecimalDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_HEXADECIMAL_NUMBER_VECT = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isHexadecimalDigit(...) is called with valid hexadecimal numbers", "[isHexadecimalDigit-01]") -{ - std::for_each(std::begin(VALID_HEXADECIMAL_NUMBER_VECT), - std::end (VALID_HEXADECIMAL_NUMBER_VECT), - [](char const c) - { - REQUIRE(arduino::isHexadecimalDigit(c) == true); - }); -} - -TEST_CASE ("isHexadecimalDigit(...) is called with non hexadecimal number", "[isHexadecimalDigit-02]") -{ - REQUIRE(arduino::isHexadecimalDigit('z') == false); -} diff --git a/test/src/WCharacter/test_isLowerCase.cpp b/test/src/WCharacter/test_isLowerCase.cpp deleted file mode 100644 index 7a752200..00000000 --- a/test/src/WCharacter/test_isLowerCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isLowerCase(...) is called with a upper case number", "[isLowerCase-01]") -{ - REQUIRE(arduino::isLowerCase('A') == false); -} - -TEST_CASE ("isLowerCase(...) is called with a lower case number", "[isLowerCase-02]") -{ - REQUIRE(arduino::isLowerCase('a') == true); -} - -TEST_CASE ("isLowerCase(...) is called with a non-alphabetic number", "[isLowerCase-03]") -{ - REQUIRE(arduino::isLowerCase('0') == false); -} diff --git a/test/src/WCharacter/test_isPunct.cpp b/test/src/WCharacter/test_isPunct.cpp deleted file mode 100644 index 6d1167d3..00000000 --- a/test/src/WCharacter/test_isPunct.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_PUNCT_VECT = {'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isPunct('.') is called with a valid punct character", "[isPunct-01]") -{ - std::for_each(std::begin(VALID_PUNCT_VECT), - std::end (VALID_PUNCT_VECT), - [](char const c) - { - REQUIRE(arduino::isPunct(c) == true); - }); -} - -TEST_CASE ("isPunct(...) is called with a invalid punct character", "[isPunct-02]") -{ - REQUIRE(arduino::isPunct('a') == false); -} diff --git a/test/src/WCharacter/test_isSpace.cpp b/test/src/WCharacter/test_isSpace.cpp deleted file mode 100644 index 5c0be948..00000000 --- a/test/src/WCharacter/test_isSpace.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_SPACE_VECT = {' ', '\t', '\n', '\v', '\f', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isSpace(...) is called with a valid white space character", "[isSpace-01]") -{ - std::for_each(std::begin(VALID_SPACE_VECT), - std::end (VALID_SPACE_VECT), - [](char const c) - { - REQUIRE(arduino::isSpace(c) == true); - }); -} - -TEST_CASE ("isSpace(...) is called with a invalid white space character", "[isSpace-02]") -{ - REQUIRE(arduino::isSpace('{') == false); -} diff --git a/test/src/WCharacter/test_isUpperCase.cpp b/test/src/WCharacter/test_isUpperCase.cpp deleted file mode 100644 index 01dbf86a..00000000 --- a/test/src/WCharacter/test_isUpperCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isUpperCase(...) is called with a upper case number", "[isUpperCase-01]") -{ - REQUIRE(arduino::isUpperCase('A') == true); -} - -TEST_CASE ("isUpperCase(...) is called with a lower case number", "[isUpperCase-02]") -{ - REQUIRE(arduino::isUpperCase('a') == false); -} - -TEST_CASE ("isUpperCase(...) is called with a non-alphabetic number", "[isUpperCase-03]") -{ - REQUIRE(arduino::isUpperCase('0') == false); -} diff --git a/test/src/WCharacter/test_isWhitespace.cpp b/test/src/WCharacter/test_isWhitespace.cpp deleted file mode 100644 index 0eaa96de..00000000 --- a/test/src/WCharacter/test_isWhitespace.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isWhitespace(...) is called with ' '", "[isWhitespace-01]") -{ - REQUIRE(arduino::isWhitespace(' ') == true); -} - -TEST_CASE ("isWhitespace(...) is called with '\t'", "[isWhitespace-02]") -{ - REQUIRE(arduino::isWhitespace('\t') == true); -} - -TEST_CASE ("isWhitespace(...) is called with a non whitespace char", "[isWhitespace-03]") -{ - REQUIRE(arduino::isWhitespace('\r') == false); -} diff --git a/test/src/WCharacter/test_toAscii.cpp b/test/src/WCharacter/test_toAscii.cpp deleted file mode 100644 index eb085cbb..00000000 --- a/test/src/WCharacter/test_toAscii.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("toAscii(...) is called with a valid ascii character", "[toAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::toAscii(c) == c); - }); -} - -TEST_CASE ("toAscii(...) is called with a invalid ascii character", "[toAscii-02]") -{ - REQUIRE(arduino::toAscii(0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toAscii-03]") -{ - REQUIRE(arduino::toAscii((unsigned char)0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]") -{ - REQUIRE(arduino::toAscii(0x3030) == 0x30); -} diff --git a/test/src/dtostrf.cpp b/test/src/dtostrf.cpp deleted file mode 100644 index 02ea2fe7..00000000 --- a/test/src/dtostrf.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/test/src/itoa.cpp b/test/src/itoa.cpp deleted file mode 100644 index 4070ca62..00000000 --- a/test/src/itoa.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -std::string radixToFmtString(int const radix) -{ - if (radix == 8) return std::string("%o"); - else if (radix == 10) return std::string("%d"); - else if (radix == 16) return std::string("%X"); - else throw std::runtime_error("Invalid radix."); -} - -char * itoa(int value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * ltoa(long value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * utoa(unsigned value, char *str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * ultoa(unsigned long value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -}