Revise fpp-to-cpp tests

This commit is contained in:
Rob Bocchino 2025-05-13 19:21:35 -07:00
parent feef3583b1
commit 42925be2f2
7 changed files with 281 additions and 0 deletions

View File

@ -0,0 +1,103 @@
// ======================================================================
// \title AliasSerialTypeEnumAc.cpp
// \author Generated by fpp-to-cpp
// \brief cpp file for AliasSerialType enum
// ======================================================================
#include <cstring>
#include <limits>
#include "Fw/Types/Assert.hpp"
#include "AliasSerialTypeEnumAc.hpp"
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
AliasSerialType& AliasSerialType ::
operator=(const AliasSerialType& obj)
{
this->e = obj.e;
return *this;
}
AliasSerialType& AliasSerialType ::
operator=(T e1)
{
this->e = e1;
return *this;
}
#ifdef BUILD_UT
std::ostream& operator<<(std::ostream& os, const AliasSerialType& obj) {
Fw::String s;
obj.toString(s);
os << s;
return os;
}
#endif
// ----------------------------------------------------------------------
// Member functions
// ----------------------------------------------------------------------
bool AliasSerialType ::
isValid() const
{
return ((e >= A) && (e <= B));
}
Fw::SerializeStatus AliasSerialType ::
serialize(Fw::SerializeBufferBase& buffer) const
{
const Fw::SerializeStatus status = buffer.serialize(
static_cast<SerialType>(this->e)
);
return status;
}
Fw::SerializeStatus AliasSerialType ::
deserialize(Fw::SerializeBufferBase& buffer)
{
SerialType es;
Fw::SerializeStatus status = buffer.deserialize(es);
if (status == Fw::FW_SERIALIZE_OK) {
this->e = static_cast<T>(es);
if (!this->isValid()) {
status = Fw::FW_DESERIALIZE_FORMAT_ERROR;
}
}
return status;
}
#if FW_SERIALIZABLE_TO_STRING
void AliasSerialType ::
toString(Fw::StringBase& sb) const
{
Fw::String s;
switch (e) {
case A:
s = "A";
break;
case B:
s = "B";
break;
default:
s = "[invalid]";
break;
}
sb.format("%s (%" PRIu32 ")", s.toChar(), e);
}
#elif FW_ENABLE_TEXT_LOGGING
void AliasSerialType ::
toString(Fw::StringBase& sb) const
{
sb.format("%" PRIu32 "", e);
}
#endif

View File

@ -0,0 +1,161 @@
// ======================================================================
// \title AliasSerialTypeEnumAc.hpp
// \author Generated by fpp-to-cpp
// \brief hpp file for AliasSerialType enum
// ======================================================================
#ifndef AliasSerialTypeEnumAc_HPP
#define AliasSerialTypeEnumAc_HPP
#include "Fw/FPrimeBasicTypes.hpp"
#include "Fw/Types/Serializable.hpp"
#include "Fw/Types/String.hpp"
//! An enum type with an alias as its serial type
class AliasSerialType :
public Fw::Serializable
{
public:
// ----------------------------------------------------------------------
// Types
// ----------------------------------------------------------------------
//! The serial representation type
typedef U32 SerialType;
//! The raw enum type
enum T {
A = 0,
B = 1,
};
//! For backwards compatibility
typedef T t;
public:
// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------
enum {
//! The size of the serial representation
SERIALIZED_SIZE = sizeof(SerialType),
//! The number of enumerated constants
NUM_CONSTANTS = 2,
};
public:
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
//! Constructor (default value of A)
AliasSerialType()
{
this->e = A;
}
//! Constructor (user-provided value)
AliasSerialType(
const T e1 //!< The raw enum value
)
{
this->e = e1;
}
//! Copy constructor
AliasSerialType(
const AliasSerialType& obj //!< The source object
)
{
this->e = obj.e;
}
public:
// ----------------------------------------------------------------------
// Operators
// ----------------------------------------------------------------------
//! Copy assignment operator (object)
AliasSerialType& operator=(
const AliasSerialType& obj //!< The source object
);
//! Copy assignment operator (raw enum)
AliasSerialType& operator=(
T e1 //!< The enum value
);
//! Conversion operator
operator T() const
{
return this->e;
}
//! Equality operator
bool operator==(T e1) const
{
return this->e == e1;
}
//! Inequality operator
bool operator!=(T e1) const
{
return !(*this == e1);
}
#ifdef BUILD_UT
//! Ostream operator
friend std::ostream& operator<<(
std::ostream& os, //!< The ostream
const AliasSerialType& obj //!< The object
);
#endif
public:
// ----------------------------------------------------------------------
// Member functions
// ----------------------------------------------------------------------
//! Check raw enum value for validity
bool isValid() const;
//! Serialize raw enum value to SerialType
Fw::SerializeStatus serialize(
Fw::SerializeBufferBase& buffer //!< The serial buffer
) const;
//! Deserialize raw enum value from SerialType
Fw::SerializeStatus deserialize(
Fw::SerializeBufferBase& buffer //!< The serial buffer
);
#if FW_SERIALIZABLE_TO_STRING
//! Convert enum to string
void toString(
Fw::StringBase& sb //!< The StringBase object to hold the result
) const;
#endif
public:
// ----------------------------------------------------------------------
// Member variables
// ----------------------------------------------------------------------
//! The raw enum value
T e;
};
#endif

View File

@ -0,0 +1,4 @@
type T = U32
@ An enum type with an alias as its serial type
enum AliasSerialType: T { A, B }

View File

@ -1,3 +1,9 @@
alias_serial_type()
{
run_test "-p $PWD" alias_serial_type && \
diff_cpp AliasSerialTypeEnum
}
default()
{
run_test "-p $PWD" default && \

View File

@ -1,4 +1,5 @@
tests="
alias_serial_type
duplicate
default
explicit

View File

@ -1,3 +1,9 @@
alias_serial_type()
{
update "-p $PWD" alias_serial_type
move_cpp AliasSerialTypeEnum
}
default()
{
update "-p $PWD" default