summaryrefslogtreecommitdiffstats
path: root/test/base-fifo.cpp
blob: 5ecf1ac7d4633afde4caedee7d4ccb209272505b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */

#include "base/fifo.hpp"
#include "base/objectlock.hpp"
#include <BoostTestTargetConfig.h>

using namespace icinga;

BOOST_AUTO_TEST_SUITE(base_fifo)

BOOST_AUTO_TEST_CASE(construct)
{
	FIFO::Ptr fifo = new FIFO();
	BOOST_CHECK(fifo);
	BOOST_CHECK(fifo->GetAvailableBytes() == 0);

	fifo->Close();
}

BOOST_AUTO_TEST_CASE(io)
{
	FIFO::Ptr fifo = new FIFO();

	fifo->Write("hello", 5);
	BOOST_CHECK(fifo->GetAvailableBytes() == 5);

	char buffer1[2];
	fifo->Read(buffer1, 2, true);
	BOOST_CHECK(memcmp(buffer1, "he", 2) == 0);
	BOOST_CHECK(fifo->GetAvailableBytes() == 3);

	char buffer2[5];
	size_t rc = fifo->Read(buffer2, 5, true);
	BOOST_CHECK(rc == 3);
	BOOST_CHECK(memcmp(buffer2, "llo", 3) == 0);
	BOOST_CHECK(fifo->GetAvailableBytes() == 0);

	BOOST_CHECK(!fifo->IsEof());

	fifo->Close();
}

BOOST_AUTO_TEST_SUITE_END()