tests: First batch of tests with mocked functions

This implements a simple way to mock library functions, and adds a few
test cases to make use of them. Currently only socket() and send() are
mocked, both in a very simple, always-fail way.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
tests: More mocked functions

Mock out recv() and sendto() as well, and add a few tests to trigger the
error-paths.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
tests: Reduce code duplication

Collapse all the _mock_*() functions into a single one, implemented by
mocks.c.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
tests: Simplify mocking

The mocking code was reworked a little to be less verbose, and require
less code duplication.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
tests: Introduce mock_enosys_ssize_t_always_fail()

Make the mock function holding variables correctly typed, and introduce
mock_enosys_ssize_t_always_fail() for the ssize_t case.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
tests: Add more mocking tests

This adds a few tests to check what happens when serialisation /
deserialisation fails.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
message: Fix the errno on serialisation failure

When message serialisation fails, we never set an errno, it was
inherited from whatever set it last. To be more in line with other
functions, and to be testable, set errno to EPROTO in
riemann_message_from_buffer(), before calling msg__unpack().

If we return non-NULL, errno should be ignored anyway. But if it returns
NULL, then it will be set to the correct value now.

Also added a test case to trigger this behaviour.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Merge branch 'f/tests/stubbing'