From 8db3581b7549b4cdacba545586932495d4f5e7b0 Mon Sep 17 00:00:00 2001 From: Slawomir Kuzniar Date: Sun, 18 Feb 2024 17:53:39 -0500 Subject: [PATCH] Dropped boolean push. Added unit tests. --- include/hffix.hpp | 18 ------------------ test/src/unit_tests.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/include/hffix.hpp b/include/hffix.hpp index acaddae..3915ef4 100644 --- a/include/hffix.hpp +++ b/include/hffix.hpp @@ -912,24 +912,6 @@ class message_writer { } //@} - /*! - \brief Append a boolean field to the message. - - \param tag FIX tag. - \param bool. - - \throw std::out_of_range When the remaining buffer size is too small. - */ - void push_back_bool(int tag, bool v) { - next_ = details::itoa(tag, next_, buffer_end_); - if (next_ >= buffer_end_) details::throw_range_error(); - *next_++ = '='; - *next_++ = v ? 'Y' : 'N'; - if (next_ >= buffer_end_) details::throw_range_error(); - *next_++ = '\x01'; - } -//@} - /*! \name Integer Fields */ //@{ /*! diff --git a/test/src/unit_tests.cpp b/test/src/unit_tests.cpp index 74939b6..e4e06bf 100644 --- a/test/src/unit_tests.cpp +++ b/test/src/unit_tests.cpp @@ -382,5 +382,45 @@ BOOST_AUTO_TEST_CASE(chrono_nano) // std::string tstr = oss.str(); // BOOST_CHECK_EQUAL(tstr, i->value().as_string()); } + #endif +#if __cplusplus >= 201703L +// test that setting header unsing char pointer and string view are equivalent +BOOST_AUTO_TEST_CASE(header) +{ + const char* begstr_cp = "FIX.4.2"; + std::string_view begstr_sv = begstr_cp; + + char buffer_cp[100] = {}; + char buffer_sv[100] = {}; + + message_writer writer_cp(buffer_cp); + message_writer writer_sv(buffer_sv); + + writer_cp.push_back_header(begstr_cp); + writer_sv.push_back_header(begstr_sv); + + BOOST_REQUIRE(writer_cp.message_size() == writer_sv.message_size()); + BOOST_REQUIRE(std::memcmp(writer_cp.message_begin(), writer_sv.message_begin(), writer_cp.message_size()) == 0); +} + +BOOST_AUTO_TEST_CASE(read_string) +{ + char buffer[100] = {}; + + message_writer writer(buffer); + + writer.push_back_header("FIX.4.2"); + writer.push_back_string(hffix::tag::MsgType, "A"); + writer.push_back_trailer(); + + message_reader reader(buffer); + + auto i = reader.begin(); + BOOST_CHECK(reader.find_with_hint(tag::MsgType, i)); + BOOST_CHECK(i->value() == "A"); + + BOOST_REQUIRE(i->value().as_string() == i->value().as_string_view()); +} +#endif