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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include "test.h"
#include <fstream>
#include "contrib/ozstream.hpp"
#include "file_line_provider.h"
#include "mock_log_lines.h"
TEST_CASE("readfile") {
list<string> data = {
"hello", "there", "good", "people", "and",
"welcome", "to", "the", "test"};
filesystem::path filename = filesystem::weakly_canonical("/tmp/.logserver_filelinetest.dat");
ofstream fout(filename);
CHECK(fout.good());
for (const auto &x : data) fout << x << endl;
fout.flush();
MockLogLines ll;
ll.expect(data);
FileLineProvider flp(&ll, filename);
flp.start();
while (!ll.eof()) {
usleep(1000);
}
CHECK(ll.no_expectations());
ll.expect("more data");
ll.expect("and yet more");
fout << "more data" << endl;
fout.flush();
usleep(10000);
fout << "and yet more" << endl;
fout.flush();
fout.close();
ifstream fin(filename);
assert(fin.good());
fin.close();
while (!ll.no_expectations()) {
usleep(1000);
}
// live updated file should no longer signal eof
CHECK(ll.eof() == false);
}
TEST_CASE("read zip file") {
list<string> data = {
"hello", "there", "good", "people", "and",
"welcome", "to", "the", "test"};
filesystem::path filename = filesystem::weakly_canonical("/tmp/.logserver_filelinetest.dat");
ofstream fout(filename);
zstream::ogzstream zout(fout);
for (const auto &x : data) zout << x << endl;
zout.close();
MockLogLines ll;
ll.expect(data);
FileLineProvider flp(&ll, filename);
flp.start();
while (!ll.eof()) {
usleep(1000);
}
CHECK(ll.no_expectations());
}
|