run auto-formatter
fsfw/fsfw/pipeline/head This commit looks good Details

This commit is contained in:
Robin Müller 2022-07-29 15:54:17 +02:00
parent c7b4dc349a
commit f4beef8c9f
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 58 additions and 80 deletions

View File

@ -1,57 +1,38 @@
#ifndef FSFW_UTIL_OBJECTID_H
#define FSFW_UTIL_OBJECTID_H
#include "fsfw/objectmanager.h"
#include "UnsignedByteField.h"
#include <functional>
#include "UnsignedByteField.h"
#include "fsfw/objectmanager.h"
class ObjectId : public UnsignedByteField<object_id_t> {
public:
ObjectId(object_id_t id, const char* name) : UnsignedByteField<object_id_t>(id), name_(name) {}
[[nodiscard]] const char* name() const {
return name_;
}
[[nodiscard]] const char* name() const { return name_; }
[[nodiscard]] object_id_t id() const {
return getValue();
}
[[nodiscard]] object_id_t id() const { return getValue(); }
bool operator==(const ObjectId& other) const {
return id() == other.id();
}
bool operator==(const ObjectId& other) const { return id() == other.id(); }
bool operator!=(const ObjectId& other) const {
return id() != other.id();
}
bool operator!=(const ObjectId& other) const { return id() != other.id(); }
bool operator<(const ObjectId& other) const {
return id() < other.id();
}
bool operator<(const ObjectId& other) const { return id() < other.id(); }
bool operator>(const ObjectId& other) const {
return id() > other.id();
}
bool operator>(const ObjectId& other) const { return id() > other.id(); }
bool operator>=(const ObjectId& other) const {
return id() >= other.id();
}
bool operator>=(const ObjectId& other) const { return id() >= other.id(); }
bool operator<=(const ObjectId& other) const { return id() <= other.id(); }
bool operator<=(const ObjectId& other) const {
return id() <= other.id();
}
private:
const char* name_;
};
template <>
struct std::hash<ObjectId>
{
std::size_t operator()(ObjectId const& s) const noexcept
{
return std::hash<uint32_t>{}(s.id());
}
struct std::hash<ObjectId> {
std::size_t operator()(ObjectId const& s) const noexcept { return std::hash<uint32_t>{}(s.id()); }
};
#endif // FSFW_UTIL_OBJECTID_H

View File

@ -19,17 +19,12 @@ class UnsignedByteField: public SerializeIF {
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
}
[[nodiscard]] size_t getSerializedSize() const override {
return sizeof(T);
}
[[nodiscard]] size_t getSerializedSize() const override { return sizeof(T); }
[[nodiscard]] T getValue() const {
return value;
}
[[nodiscard]] T getValue() const { return value; }
void setValue(T value_) { value = value_; }
void setValue(T value_) {
value = value_;
}
private:
T value;
};

View File

@ -1,7 +1,7 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/ObjectId.h"
#include <array>
TEST_CASE("Object Id", "[object-id]") {
auto objectId = ObjectId(10, "TEST_ID");

View File

@ -1,10 +1,9 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/UnsignedByteField.h"
#include <array>
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
auto testByteField = UnsignedByteField<uint32_t>(10);
auto u32ByteField = U32ByteField(10);
@ -28,7 +27,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
}
SECTION("Serialize U32") {
CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(serLen == 4);
CHECK(buf[0] == 0);
CHECK(buf[3] == 10);
@ -60,7 +60,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
buf[2] = 0x30;
buf[3] = 0x20;
size_t deserLen = 0;
CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(testByteField.getValue() == 0x50403020);
}
@ -68,7 +69,8 @@ TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
buf[0] = 0x50;
buf[1] = 0x40;
size_t deserLen = 0;
CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(u16ByteField.getValue() == 0x5040);
}
}