static void splitter_test() { std::string s(copy_simple_message(4)); fix_parser* parser = create_fix_parser(get_dummy_classifier); ensure(parser != nullptr); const size_t n = 100; size_t counter = 0; const char* p = s.c_str(); const char* const end = p + s.size(); for(; p < end; p += n) { for(const fix_message* pm = get_first_fix_message(parser, p, std::min(n, (size_t)(end - p))); pm; pm = get_next_fix_message(parser)) { ensure(!get_fix_parser_error(parser)); validate_message(pm); ++counter; } } free_fix_parser(parser); ensure(counter == 4); }
static void invalid_message_test() { const char m[] = "8=FIX.4.4\x01" "9=122\x01" "35=D\x02"; fix_parser* parser = create_fix_parser(get_dummy_classifier); const fix_message* pm = get_first_fix_message(parser, m, sizeof(m) - 1); ensure(!pm); ensure(strcmp(get_fix_parser_error(parser), "Unexpected byte 0x2 in FIX message type") == 0); ensure(!get_next_fix_message(parser)); free_fix_parser(parser); }
static void basic_test() { fix_parser* parser = create_fix_parser(get_dummy_classifier); const fix_message* pm = get_first_fix_message(parser, simple_message, simple_message_size); ensure(pm != nullptr); ensure(!get_fix_parser_error(parser)); validate_message(pm); ensure(!get_next_fix_message(parser)); free_fix_parser(parser); }
static void test_binary_tag() { std::string msg(m, sizeof(m) - 1); msg += "354=3\x01" "355=XYZ\x01"; msg = make_fix_message(msg.c_str()); fix_parser* const parser = create_fix_parser(mb_message_classifier); const fix_message* const pm = get_first_fix_message(parser, msg.c_str(), msg.size()); ensure(pm); validate_mb_message(pm); ensure(!get_next_fix_message(parser)); free_fix_parser(parser); }
// test driver static void test_for_error(void (*modifier)(std::string&), void (*validator)(const fix_message*)) { std::string msg(m, sizeof(m) - 1); if(modifier) modifier(msg); msg = make_fix_message(msg.c_str()); fix_parser* const parser = create_fix_parser(m_message_classifier); const fix_message* const pm = get_first_fix_message(parser, msg.c_str(), msg.size()); ensure(pm); validator(pm); ensure(!get_next_fix_message(parser)); free_fix_parser(parser); }
// message tester void test_for_speed(const char* test_type, const fix_tag_classifier* (*classifier)(fix_message_version, const char*), std::string (*creator)(size_t), void (*validator)(const fix_message*)) { const int M = 10; const std::string s(creator(M)); const size_t step = 101, #ifdef _DEBUG N = 1000; #else N = 100000; #endif const char* const end = s.c_str() + s.size(); fix_parser* const parser = create_fix_parser(classifier); int count = 0; clock_t t_start = clock(); for(size_t i = 0; i < N; ++i) { for(const char* p = s.c_str(); p < end; p += step) { for(const fix_message* pm = get_first_fix_message(parser, p, std::min(step, (size_t)(end - p))); pm; pm = get_next_fix_message(parser)) { ensure(!pm->error); validator(pm); ++count; } ensure(!get_fix_parser_error(parser)); } } const clock_t t_end = clock(); free_fix_parser(parser); ensure(count == N * M); print_running_time(test_type, N * M, t_start, t_end); }