Example #1
0
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);
}
Example #2
0
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);
}
Example #3
0
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);
}
Example #4
0
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);
}
Example #5
0
// 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);
}
Example #6
0
// 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);
}
Example #7
0
static
bool simple_random_messages_test()
{
	bool ret = false;
	char* str;
	unsigned len;

	// construct messages
	const fix_message_data* const messages = make_n_messages(NUM_MESSAGES, &str, &len);

	// construct parser
	fix_parser* const parser = create_FIX44_parser();

	if(!parser)
	{
		REPORT_FAILURE("NULL parser");
		goto EXIT;
	}

	// parser loop
	unsigned i = 0;

	for(const fix_parser_result* res = get_first_fix_message(parser, str, len);
		res;
		res = get_next_fix_message(parser))
	{
		// check for errors
		if(!parser_result_ok(res, __FILE__, __LINE__))
		{
			print_raw_message(parser);
			goto EXIT;
		}

		// check message index
		if(i == NUM_MESSAGES)
		{
			REPORT_FAILURE("Parser unexpectedly produced too many messages");
			goto EXIT;
		}

		// validate message
		if(!valid_fix_message(res->root, messages + i))
		{
			print_raw_message(parser);
			goto EXIT;
		}

		++i;
	}

	// check for fatal errors
	const fix_error_details* const error = get_fix_parser_error_details(parser);

	if(error->code > FE_OTHER)
	{
		report_error_details(error, __FILE__, __LINE__);
		goto EXIT;
	}

	// final check of message index
	if(i != NUM_MESSAGES)
	{
		REPORT_FAILURE("Parser produced %u messages instead of %u", i, (unsigned)NUM_MESSAGES);
		goto EXIT;
	}

	// all clear
	ret = true;

EXIT:
	// clean-up
	free(str);
	free((void*)messages);
	free_fix_parser(parser);
	TEST_END(ret);
}