File: data_stream.cpp

package info (click to toggle)
btllib 1.4.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,340 kB
  • sloc: cpp: 61,642; sh: 301; python: 222; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,254 bytes parent folder | download | duplicates (2)
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
#include "btllib/data_stream.hpp"

#include "helpers.hpp"

#include <cstdio>
#include <cstring>
#include <fstream>
#include <thread>

int
main()
{
  const char* txt = "data_stream test";
  char* line = new char[128];
  size_t line_len;

  // Test .gz
  const auto gz_filename = get_random_name(64) + ".gz";

  std::cerr << "Test .gz write" << std::endl;
  btllib::DataSink gz_sink(gz_filename, false);
  TEST_ASSERT_EQ(fwrite(txt, 1, strlen(txt), gz_sink), strlen(txt));
  gz_sink.close();

  std::cerr << "Test .gz read" << std::endl;
  btllib::DataSource gz_source(gz_filename);
  TEST_ASSERT_GT(getline(&line, &line_len, gz_source), 0);
  gz_source.close();
  TEST_ASSERT_EQ(strcmp(line, txt), 0);

  std::remove(gz_filename.c_str());

  // Test .xz
  const auto xz_filename = get_random_name(64) + ".xz";

  std::cerr << "Test .xz write" << std::endl;
  btllib::DataSink xz_sink(xz_filename, false);
  TEST_ASSERT_EQ(fwrite(txt, 1, strlen(txt), xz_sink), strlen(txt));
  xz_sink.close();

  std::cerr << "Test .xz read" << std::endl;
  btllib::DataSource xz_source(xz_filename);
  TEST_ASSERT_GT(getline(&line, &line_len, xz_source), 0);
  xz_source.close();
  TEST_ASSERT_EQ(strcmp(line, txt), 0);

  std::remove(xz_filename.c_str());

  return 0;
}