#include #include "lib/jetfix/codec/FIXEncodingStream.h" #include namespace bts { namespace jetfix { static config::JetFIX::Connection get_jetfix_cfg() { config::JetFIX::Connection jfcfg; jfcfg.set_name("test"); jfcfg.set_socket_connect_host_ip("10.96.18.160"); jfcfg.set_socket_connect_port(9999); jfcfg.set_sender_compid("O2TESTER"); jfcfg.set_target_compid("BTS"); jfcfg.set_target_subid("BTS"); jfcfg.set_use_persisted_quote_ids(false); jfcfg.set_start_time("00:30:00"); jfcfg.set_end_time("23:30:00"); jfcfg.set_start_day("sunday"); jfcfg.set_end_day("friday"); jfcfg.set_log_fix_stream(true); jfcfg.set_seconds_to_pause(10); jfcfg.set_sender_subid("BTS"); jfcfg.set_raw_data("1U7"); jfcfg.set_self_match_prevention_id("bluestream"); return jfcfg; } TEST_CASE("JetFIX FIX Encoding", "[jetfix_encoding]") { SECTION("smoke") { FIXEncodingStream stream(get_jetfix_cfg()); auto &msg = stream.new_msg(MessageTypes::MassQuote); msg.add("hello", 5); auto &msg2 = stream.new_msg(MessageTypes::Advertisement); msg2.add("olleh", 5); stream.close(); auto out = stream.to_str(); REQUIRE(out.size()); } SECTION("body_lenght_is_correct") { using namespace fix; FIXEncodingStream stream(get_jetfix_cfg()); auto &msg = stream.new_msg(MessageTypes::MassQuote); msg.add("hello", 5); stream.close(); auto str = stream.to_human_str(); REQUIRE( str.compare( 0, strlen("8=FIX.4.2|9=000092|"), "8=FIX.4.2|9=000092|") == 0); } SECTION("checksum_is_correct") { char target[] = "8=FIX.4.2\0019=000092\00135=i\00134=000000000\001369=000000000\001" "52=20150427-19:05:18.923\00149=O2TESTER\00156=BTS\00157=BTS\001" "58=hello\001"; uint32_t byte_sum = 0; for (auto c : target) byte_sum += c; FIXEncodingStream stream(get_jetfix_cfg()); auto &msg = stream.new_msg(MessageTypes::MassQuote); msg.add("hello", 5); stream.close(); // std::string human_target(target); // std::replace(human_target.begin(), human_target.end(),'\001','|'); // std::cout << human_target << "\n"; // std::cout << stream.to_human_str() << "\n"; auto chk = stream.msg_map()[0].checksum; REQUIRE(chk == byte_sum); } SECTION("stamp_works") { FIXEncodingStream stream(get_jetfix_cfg()); auto &msg = stream.new_msg(MessageTypes::MassQuote); msg.add("hello", 5); stream.close(); stream.stamp(1, 1000, "20150427-19:05:18.922"); std::string lit = "8=FIX.4.2\0019=000092\00135=i\00134=000000002\001369=000001000\001" "52=20150427-19:05:18.922\00149=O2TESTER\00156=BTS\00157=BTS\001" "58=hello\001"; uint32_t lit_checksum = 0; for (auto c : lit) lit_checksum += c; std::ostringstream s; s << lit << "10=" << std::setfill('0') << std::setw(3) << (lit_checksum % 256) << "\001"; lit = s.str(); REQUIRE(lit == stream.to_str()); } } } // namespace jetfix } // namespace bts