mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-29 06:16:19 +08:00
21 lines
632 B
C++
21 lines
632 B
C++
#ifndef WRITE_AND_READ_
|
|
#define WRITE_AND_READ_
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <rfl/json.hpp>
|
|
|
|
template <class... Ps>
|
|
void write_and_read(const auto& _struct) {
|
|
using T = std::remove_cvref_t<decltype(_struct)>;
|
|
const auto serialized1 = rfl::to_generic<Ps...>(_struct);
|
|
EXPECT_EQ(rfl::json::write(serialized1), rfl::json::write<Ps...>(_struct));
|
|
const auto res = rfl::from_generic<T, Ps...>(serialized1);
|
|
EXPECT_TRUE(res && true) << "Test failed on read. Error: "
|
|
<< res.error().what();
|
|
EXPECT_EQ(rfl::json::write(serialized1),
|
|
rfl::json::write<Ps...>(res.value()));
|
|
}
|
|
|
|
#endif
|