add fmt tests
This commit is contained in:
parent
9d70db97f8
commit
6984404979
@ -1,5 +1,6 @@
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(example)
|
||||
add_subdirectory(test)
|
||||
|
||||
target_include_directories(${TARGET_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include "FsfwTestTask.h"
|
||||
#include "../test/testFmt.h"
|
||||
|
||||
FsfwTestTask::FsfwTestTask(object_id_t objectId, bool periodicEvent)
|
||||
: TestTask(objectId), periodicEvent(periodicEvent) {}
|
||||
: TestTask(objectId), periodicEvent(periodicEvent) {
|
||||
fmtTests();
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestTask::performPeriodicAction() {
|
||||
if (periodicEvent) {
|
||||
|
5
test/CMakeLists.txt
Normal file
5
test/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
if(FSFW_ADD_FMT_TESTS)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
testFmt.cpp
|
||||
)
|
||||
endif()
|
12
test/testFmt.cpp
Normal file
12
test/testFmt.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "testFmt.h"
|
||||
|
||||
void fmtTests() {
|
||||
sif::fdebug_t("Hallo\n");
|
||||
sif::fdebug("Hallo\n");
|
||||
sif::finfo_t("Hallo\n");
|
||||
sif::finfo("Hallo\n");
|
||||
sif::fwarning("Hello\n");
|
||||
sif::fwarning_t("Hello\n");
|
||||
sif::ferror("Hello\n");
|
||||
sif::ferror_t("Hello\n");
|
||||
}
|
82
test/testFmt.h
Normal file
82
test/testFmt.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
||||
#define FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "fsfw/ipc/MutexFactory.h"
|
||||
#include "fsfw/ipc/MutexGuard.h"
|
||||
#include "fsfw/ipc/MutexIF.h"
|
||||
#include "fsfw/timemanager/Clock.h"
|
||||
|
||||
void fmtTests();
|
||||
|
||||
namespace sif {
|
||||
|
||||
static std::array<char, 256> PRINT_BUF = {};
|
||||
static MutexIF* PRINT_MUTEX = MutexFactory::instance()->createMutex();
|
||||
|
||||
template <typename... T>
|
||||
void flog(const char* prefix, fmt::color color, fmt::format_string<T...> fmt, T&&... args) {
|
||||
MutexGuard mg(PRINT_MUTEX);
|
||||
const auto result = fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, "{} | {}",
|
||||
format(fg(color), prefix), fmt::format(fmt, args...));
|
||||
*result.out = '\0';
|
||||
fmt::print("{}", PRINT_BUF.data());
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void flog_t(const char* prefix, fmt::color color, fmt::format_string<T...> fmt, T&&... args) {
|
||||
Clock::TimeOfDay_t logTime;
|
||||
Clock::getDateAndTime(&logTime);
|
||||
flog(prefix, color, "{:02}:{:02}:{:02}.{:03} | {}", logTime.hour, logTime.minute,
|
||||
logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...));
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fdebug_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("DEBUG", fmt::color::deep_sky_blue, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fdebug(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("DEBUG", fmt::color::deep_sky_blue, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void finfo_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("INFO", fmt::color::forest_green, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void finfo(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("INFO", fmt::color::forest_green, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fwarning(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("WARNING", fmt::color::orange_red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fwarning_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("WARNING", fmt::color::orange_red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void ferror(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("ERROR", fmt::color::red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void ferror_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("ERROR", fmt::color::red, fmt, args...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
Loading…
Reference in New Issue
Block a user