From 9e79e50fdc60a3a5ad48308f3acf760a6b34c2e6 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 19 Mar 2020 13:13:16 -0700 Subject: [PATCH] test Value::copyIn/copyOut --- src/pvxs/data.h | 24 ++++++++++++++++++++++++ test/testdata.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/pvxs/data.h b/src/pvxs/data.h index e67ff17..d10ea89 100644 --- a/src/pvxs/data.h +++ b/src/pvxs/data.h @@ -182,6 +182,30 @@ inline std::ostream& operator<<(std::ostream& strm, TypeCode c) { return strm; } +namespace impl { +template +struct ScalarMap; + +#define CASE(TYPE, STORE, CODE) \ +template<> struct ScalarMap { typedef STORE store_t; static constexpr TypeCode::code_t code{TypeCode::CODE}; } + +CASE(bool , uint64_t, Bool); +CASE(uint8_t , uint64_t, UInt8); +CASE(uint16_t, uint64_t, UInt16); +CASE(uint32_t, uint64_t, UInt32); +CASE(uint64_t, uint64_t, UInt64); +CASE(int8_t , int64_t , Int8); +CASE(int16_t , int64_t , Int16); +CASE(int32_t , int64_t , Int32); +CASE(int64_t , int64_t , Int64); +CASE(float , double , Float32); +CASE(double , double , Float64); +CASE(std::string, std::string, String); + +#undef CASE + +} // namespace + //! Definition of a member of a Struct/Union for use with TypeDef struct Member { private: diff --git a/test/testdata.cpp b/test/testdata.cpp index 4fc6b57..e6963ce 100644 --- a/test/testdata.cpp +++ b/test/testdata.cpp @@ -172,16 +172,57 @@ void testPvRequest() } } +template +void testConvertScalar(const Store& store, const Inout& inout) +{ + testShow()<<__func__<<"("< store_t; + + auto cont = TypeDef(store_t::code).create(); + + try { + cont.from(inout); + }catch(std::exception& e){ + testCase(false)<<"Error storing as "<())<())<"<(1.0, true); + testConvertScalar(0.0, false); + testConvertScalar(5.0, 5); + testConvertScalar(5.0, 5); + testConvertScalar(-5.0, -5); + testConvertScalar(-5.0, -5.0); + testConvertScalar(-5.0, "-5"); + testConvertScalar(1, true); + testConvertScalar(0, false); + testConvertScalar(5, 5); + testConvertScalar(5, 5); + testConvertScalar(-5, -5); + testConvertScalar(-5, -5.0); + testConvertScalar(-5, "-5"); + testConvertScalar("true", true); + testConvertScalar("false", false); + testConvertScalar("5", 5); + testConvertScalar("5", 5); + testConvertScalar("-5", -5); + testConvertScalar("-5", -5.0); + testConvertScalar("-5", "-5"); cleanup_for_valgrind(); return testDone(); }