File: test_fd_line_provider.cc

package info (click to toggle)
logserver 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 720 kB
  • sloc: cpp: 10,815; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 887 bytes parent folder | download
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
#include "test.h"

#include <fstream>

#include "fd_line_provider.h"
#include "mock_log_lines.h"

TEST_CASE("read fd") {
	int fd[2];
	CHECK(!pipe(fd));

	list<string> data = {
		"hello", "there", "good", "people", "and",
		"welcome", "to", "the", "test"};

	MockLogLines ll;
	ll.expect(data);
	FDLineProvider fdlp(&ll, fd[0]);
	fdlp.start();

	for (const auto& x : data) {
		CHECK(x.size() == static_cast<size_t>(
			write(fd[1], x.data(), x.size())));
		CHECK(1 == write(fd[1], "\n", 1));
	}

	while (!ll.no_expectations()) {
		usleep(1000);
	}
	CHECK(ll.no_expectations());
	ll.expect("more data");
	ll.expect("and yet more");
	CHECK(10 == write(fd[1], "more data\n", 10));
	usleep(10000);
	CHECK(13 == write(fd[1], "and yet more\n", 13));
	while (!ll.no_expectations()) {
		usleep(1000);
	}
	// pipe is open
	CHECK(ll.eof() == false);
	close(fd[1]);
	while (!ll.eof()) usleep(100);
}