From 19e167a35d3249e28300525f4ac7dd0fe060180c Mon Sep 17 00:00:00 2001 From: tiffany1618 Date: Fri, 4 Nov 2022 16:51:27 -0700 Subject: [PATCH] Add unit test for include header path for C++ writer --- .../test/array/HeaderPathArrayAc.ref.cpp | 211 ++++++++++++++++++ .../test/array/HeaderPathArrayAc.ref.hpp | 160 +++++++++++++ .../fpp-to-cpp/test/array/header_path.fpp | 2 + .../fpp-to-cpp/test/array/header_path.ref.txt | 0 .../tools/fpp-to-cpp/test/array/include/T.fpp | 1 + compiler/tools/fpp-to-cpp/test/array/run.sh | 6 + compiler/tools/fpp-to-cpp/test/array/tests.sh | 1 + .../tools/fpp-to-cpp/test/array/update-ref.sh | 6 + 8 files changed, 387 insertions(+) create mode 100644 compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.cpp create mode 100644 compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.hpp create mode 100644 compiler/tools/fpp-to-cpp/test/array/header_path.fpp create mode 100644 compiler/tools/fpp-to-cpp/test/array/header_path.ref.txt create mode 100644 compiler/tools/fpp-to-cpp/test/array/include/T.fpp diff --git a/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.cpp new file mode 100644 index 000000000..63b504127 --- /dev/null +++ b/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.cpp @@ -0,0 +1,211 @@ +// ====================================================================== +// \title HeaderPathArrayAc.cpp +// \author Generated by fpp-to-cpp +// \brief cpp file for HeaderPath array +// ====================================================================== + +#include +#include + +#include "Fw/Types/Assert.hpp" +#include "Fw/Types/StringUtils.hpp" +#include "HeaderPathArrayAc.hpp" + +// ---------------------------------------------------------------------- +// Constructors +// ---------------------------------------------------------------------- + +HeaderPath :: + HeaderPath() : + Serializable() +{ + // Construct using element-wise constructor + *this = HeaderPath( + T(), + T(), + T() + ); +} + +HeaderPath :: + HeaderPath(const ElementType (&a)[SIZE]) : + Serializable() +{ + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = a[index]; + } +} + +HeaderPath :: + HeaderPath(const ElementType& e) : + Serializable() +{ + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = e; + } +} + +HeaderPath :: + HeaderPath( + const ElementType& e1, + const ElementType& e2, + const ElementType& e3 + ) : + Serializable() +{ + this->elements[0] = e1; + this->elements[1] = e2; + this->elements[2] = e3; +} + +HeaderPath :: + HeaderPath(const HeaderPath& obj) : + Serializable() +{ + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = obj.elements[index]; + } +} + +// ---------------------------------------------------------------------- +// Operators +// ---------------------------------------------------------------------- + +HeaderPath::ElementType& HeaderPath :: + operator[](const U32 i) +{ + FW_ASSERT(i < SIZE); + return this->elements[i]; +} + +const HeaderPath::ElementType& HeaderPath :: + operator[](const U32 i) const +{ + FW_ASSERT(i < SIZE); + return this->elements[i]; +} + +HeaderPath& HeaderPath :: + operator=(const HeaderPath& obj) +{ + if (this == &obj) { + return *this; + } + + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = obj.elements[index]; + } + return *this; +} + +HeaderPath& HeaderPath :: + operator=(const ElementType (&a)[SIZE]) +{ + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = a[index]; + } + return *this; +} + +HeaderPath& HeaderPath :: + operator=(const ElementType& e) +{ + for (U32 index = 0; index < SIZE; index++) { + this->elements[index] = e; + } + return *this; +} + +bool HeaderPath :: + operator==(const HeaderPath& obj) const +{ + for (U32 index = 0; index < SIZE; index++) { + if (!((*this)[index] == obj[index])) { + return false; + } + } + return true; +} + +bool HeaderPath :: + operator!=(const HeaderPath& obj) const +{ + return !(*this == obj); +} + +#ifdef BUILD_UT + +std::ostream& operator<<(std::ostream& os, const HeaderPath& obj) { + Fw::String s; + obj.toString(s); + os << s; + return os; +} + +#endif + +// ---------------------------------------------------------------------- +// Member functions +// ---------------------------------------------------------------------- + +Fw::SerializeStatus HeaderPath :: + serialize(Fw::SerializeBufferBase& buffer) const +{ + Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK; + for (U32 index = 0; index < SIZE; index++) { + status = buffer.serialize((*this)[index]); + if (status != Fw::FW_SERIALIZE_OK) { + return status; + } + } + return status; +} + +Fw::SerializeStatus HeaderPath :: + deserialize(Fw::SerializeBufferBase& buffer) +{ + Fw::SerializeStatus status = Fw::FW_SERIALIZE_OK; + for (U32 index = 0; index < SIZE; index++) { + status = buffer.deserialize((*this)[index]); + if (status != Fw::FW_SERIALIZE_OK) { + return status; + } + } + return status; +} + +#if FW_ARRAY_TO_STRING || BUILD_UT + +void HeaderPath :: + toString(Fw::StringBase& sb) const +{ + static const char *formatString = "[ " + "%s " + "%s " + "%s ]"; + + // Declare strings to hold any serializable toString() arguments + Fw::String str0; + Fw::String str1; + Fw::String str2; + + // Call toString for arrays and serializable types + this->elements[0].toString(str0); + this->elements[1].toString(str1); + this->elements[2].toString(str2); + + char outputString[FW_ARRAY_TO_STRING_BUFFER_SIZE]; + (void) snprintf( + outputString, + FW_ARRAY_TO_STRING_BUFFER_SIZE, + formatString, + str0.toChar(), + str1.toChar(), + str2.toChar() + ); + + outputString[FW_ARRAY_TO_STRING_BUFFER_SIZE-1] = 0; // NULL terminate + sb = outputString; +} + +#endif diff --git a/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.hpp new file mode 100644 index 000000000..f378d9e9d --- /dev/null +++ b/compiler/tools/fpp-to-cpp/test/array/HeaderPathArrayAc.ref.hpp @@ -0,0 +1,160 @@ +// ====================================================================== +// \title HeaderPathArrayAc.hpp +// \author Generated by fpp-to-cpp +// \brief hpp file for HeaderPath array +// ====================================================================== + +#ifndef HeaderPathArrayAc_HPP +#define HeaderPathArrayAc_HPP + +#include "FpConfig.hpp" +#include "Fw/Types/Serializable.hpp" +#include "Fw/Types/String.hpp" +#include "include/T.hpp" + +//! Test the include header path of an abstract type +class HeaderPath : + public Fw::Serializable +{ + + public: + + // ---------------------------------------------------------------------- + // Types + // ---------------------------------------------------------------------- + + //! The element type + typedef T ElementType; + + public: + + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- + + enum { + //! The size of the array + SIZE = 3, + //! The size of the serial representation + SERIALIZED_SIZE = SIZE * T::SERIALIZED_SIZE, + }; + + public: + + // ---------------------------------------------------------------------- + // Constructors + // ---------------------------------------------------------------------- + + //! Constructor (default value) + HeaderPath(); + + //! Constructor (user-provided value) + HeaderPath( + const ElementType (&a)[SIZE] //!< The array + ); + + //! Constructor (single element) + HeaderPath( + const ElementType& e //!< The element + ); + + //! Constructor (multiple elements) + HeaderPath( + const ElementType& e1, //!< Element 1 + const ElementType& e2, //!< Element 2 + const ElementType& e3 //!< Element 3 + ); + + //! Copy Constructor + HeaderPath( + const HeaderPath& obj //!< The source object + ); + + public: + + // ---------------------------------------------------------------------- + // Operators + // ---------------------------------------------------------------------- + + //! Subscript operator + ElementType& operator[]( + const U32 i //!< The subscript index + ); + + //! Const subscript operator + const ElementType& operator[]( + const U32 i //!< The subscript index + ) const; + + //! Copy assignment operator (object) + HeaderPath& operator=( + const HeaderPath& obj //!< The source object + ); + + //! Copy assignment operator (raw array) + HeaderPath& operator=( + const ElementType (&a)[SIZE] //!< The source array + ); + + //! Copy assignment operator (single element) + HeaderPath& operator=( + const ElementType& e //!< The element + ); + + //! Equality operator + bool operator==( + const HeaderPath& obj //!< The other object + ) const; + + //! Inequality operator + bool operator!=( + const HeaderPath& obj //!< The other object + ) const; + +#ifdef BUILD_UT + + //! Ostream operator + friend std::ostream& operator<<( + std::ostream& os, //!< The ostream + const HeaderPath& obj //!< The object + ); + +#endif + + public: + + // ---------------------------------------------------------------------- + // Member functions + // ---------------------------------------------------------------------- + + //! Serialization + Fw::SerializeStatus serialize( + Fw::SerializeBufferBase& buffer //!< The serial buffer + ) const; + + //! Deserialization + Fw::SerializeStatus deserialize( + Fw::SerializeBufferBase& buffer //!< The serial buffer + ); + +#if FW_ARRAY_TO_STRING || BUILD_UT + + //! Convert array to string + void toString( + Fw::StringBase& sb //!< The StringBase object to hold the result + ) const; + +#endif + + private: + + // ---------------------------------------------------------------------- + // Member variables + // ---------------------------------------------------------------------- + + //! The array elements + ElementType elements[SIZE]; + +}; + +#endif diff --git a/compiler/tools/fpp-to-cpp/test/array/header_path.fpp b/compiler/tools/fpp-to-cpp/test/array/header_path.fpp new file mode 100644 index 000000000..16711010c --- /dev/null +++ b/compiler/tools/fpp-to-cpp/test/array/header_path.fpp @@ -0,0 +1,2 @@ +@ Test the include header path of an abstract type +array HeaderPath = [3] T diff --git a/compiler/tools/fpp-to-cpp/test/array/header_path.ref.txt b/compiler/tools/fpp-to-cpp/test/array/header_path.ref.txt new file mode 100644 index 000000000..e69de29bb diff --git a/compiler/tools/fpp-to-cpp/test/array/include/T.fpp b/compiler/tools/fpp-to-cpp/test/array/include/T.fpp new file mode 100644 index 000000000..268793f07 --- /dev/null +++ b/compiler/tools/fpp-to-cpp/test/array/include/T.fpp @@ -0,0 +1 @@ +type T diff --git a/compiler/tools/fpp-to-cpp/test/array/run.sh b/compiler/tools/fpp-to-cpp/test/array/run.sh index 71546f245..4fbb7fb4c 100644 --- a/compiler/tools/fpp-to-cpp/test/array/run.sh +++ b/compiler/tools/fpp-to-cpp/test/array/run.sh @@ -58,3 +58,9 @@ component() diff_cpp C_AArray && \ diff_cpp AArray } + +header_path() +{ + run_test "-p $PWD" "include/T.fpp header_path" header_path && \ + diff_cpp HeaderPathArray +} diff --git a/compiler/tools/fpp-to-cpp/test/array/tests.sh b/compiler/tools/fpp-to-cpp/test/array/tests.sh index a794e4a67..64e19df85 100644 --- a/compiler/tools/fpp-to-cpp/test/array/tests.sh +++ b/compiler/tools/fpp-to-cpp/test/array/tests.sh @@ -7,4 +7,5 @@ builtin_type abs_type struct component +header_path " diff --git a/compiler/tools/fpp-to-cpp/test/array/update-ref.sh b/compiler/tools/fpp-to-cpp/test/array/update-ref.sh index 01ad01133..dcfae70f1 100644 --- a/compiler/tools/fpp-to-cpp/test/array/update-ref.sh +++ b/compiler/tools/fpp-to-cpp/test/array/update-ref.sh @@ -58,3 +58,9 @@ component() move_cpp C_AArray move_cpp AArray } + +header_path() +{ + update "-p $PWD" "include/T.fpp header_path" header_path + move_cpp HeaderPathArray +}