Skip to content

Commit

Permalink
Dropped boolean push. Added unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
skuzniar authored and jamesdbrock committed Feb 19, 2024
1 parent 533a8d4 commit 8db3581
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
18 changes: 0 additions & 18 deletions include/hffix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
//@{
/*!
Expand Down
40 changes: 40 additions & 0 deletions test/src/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8db3581

Please sign in to comment.