6 #include <libmesh/libmesh.h> 7 #include <libmesh/xdr_cxx.h> 8 #include <libmesh/int_range.h> 17 class XdrTest :
public CppUnit::TestCase {
19 LIBMESH_CPPUNIT_TEST_SUITE(
XdrTest );
21 CPPUNIT_TEST( testDataVec );
22 CPPUNIT_TEST( testDataStream );
24 CPPUNIT_TEST_SUITE_END();
27 template <
typename ReadLambda,
typename WriteLambda>
54 std::stringstream stream;
58 std::ostream ostream(stream.rdbuf());
68 std::istream istream(stream.rdbuf());
88 auto act_write = [&vec](
Xdr & xdr) { xdr.data(vec,
"# This is a comment"); };
89 auto act_read = [&vec](
Xdr & xdr) {
90 std::vector<Real> vec_in;
94 CPPUNIT_ASSERT_EQUAL(vec_in.size(), vec.size());
98 LIBMESH_ASSERT_FP_EQUAL(vec[i], vec_in[i],
TOLERANCE); };
100 test_read_write(act_read, act_write);
107 std::vector<Real> vec(100);
109 vec[i] =
static_cast<Real>(i+1) / vec.size();
113 auto act_write = [&vec](
Xdr & xdr) {
114 xdr.data_stream(vec.data(), vec.size(), 16); };
117 auto act_read = [&vec](
Xdr & xdr) {
118 std::vector<Real> vec_in(100);
119 xdr.data_stream(vec_in.data(), vec_in.size());
123 LIBMESH_ASSERT_FP_EQUAL(vec[i], vec_in[i],
TOLERANCE); };
125 test_read_write(act_read, act_write);
void test_read_write(ReadLambda &act_read, WriteLambda &act_write)
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
processor_id_type rank() const
CPPUNIT_TEST_SUITE_REGISTRATION(XdrTest)
The libMesh namespace provides an interface to certain functionality in the library.
This class implements a C++ interface to the XDR (eXternal Data Representation) format.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
processor_id_type global_processor_id()
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...