Project
Loading...
Searching...
No Matches
testCompStream.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
19#define BOOST_TEST_MODULE CompStream unit test
20#define BOOST_TEST_MAIN
21#define BOOST_TEST_DYN_LINK
22#include <boost/test/unit_test.hpp>
23#include <filesystem>
24#include <iostream>
25#include <iomanip>
26#include <sstream>
27
28BOOST_AUTO_TEST_CASE(test_compstream_filesink)
29{
30 const int range = 100;
31 std::stringstream filename;
32 filename << o2::utils::Str::create_unique_path(std::filesystem::temp_directory_path().native()) << "_testCompStream.gz";
33 {
35 for (int i = 0; i < range; i++) {
36 stream << i;
37 if (i % 2) {
38 stream << " ";
39 } else {
40 stream << std::endl;
41 }
42 }
43 stream << std::endl;
44 stream.flush();
45 }
46
47 {
49 int val;
50 int expected = 0;
51 while (stream >> val) {
53 if (val != expected) {
54 break;
55 }
56 ++expected;
57 }
59 }
60
61 std::filesystem::remove(filename.str());
62}
63
64BOOST_AUTO_TEST_CASE(test_compstream_methods)
65{
66 auto checker = [](o2::io::CompressionMethod method) {
67 std::stringstream pipe;
68 {
69 o2::io::ocomp_stream stream(pipe, method);
70 for (int i = 0; i < 4; i++) {
71 stream << i;
72 stream << " ";
73 }
74 stream << std::endl;
75 }
76
77 {
78 o2::io::icomp_stream stream(pipe, method);
79 int val;
80 int expected = 0;
81 while (stream >> val) {
83 if (val != expected) {
84 return false;
85 }
86 ++expected;
87 }
88 }
89 return true;
90 };
91
92 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Gzip));
93 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Zlib));
94 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Bzip2));
95 //BOOST_REQUIRE(checker(o2::io::CompressionMethod::Lzma));
96}
97
98BOOST_AUTO_TEST_CASE(test_compstream_methods_mapper)
99{
100 auto checker = [](o2::io::CompressionMethod outputmethod, std::string inputmethod) {
101 std::stringstream pipe;
102 {
103 o2::io::ocomp_stream stream(pipe, outputmethod);
104 for (int i = 0; i < 4; i++) {
105 stream << i;
106 stream << " ";
107 }
108 stream << std::endl;
109 }
110
111 {
112 o2::io::icomp_stream stream(pipe, inputmethod);
113 int val;
114 int expected = 0;
115 while (stream >> val) {
117 if (val != expected) {
118 return false;
119 }
120 ++expected;
121 }
122 }
123 return true;
124 };
125
126 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Gzip, "gzip"));
127 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Zlib, "zlib"));
128 BOOST_REQUIRE(checker(o2::io::CompressionMethod::Bzip2, "bzip2"));
129 //BOOST_REQUIRE(checker(o2::io::CompressionMethod::Lzma, "lzma"));
130}
Implementation of iostreams with compression filter.
int32_t i
GLenum GLint * range
Definition glcorearb.h:1899
GLuint GLfloat * val
Definition glcorearb.h:1582
GLuint GLuint stream
Definition glcorearb.h:1806
CompressionMethod
Definition CompStream.h:35
std::string filename()
static std::string create_unique_path(const std::string_view prefix="", int length=16)
BOOST_AUTO_TEST_CASE(test_compstream_filesink)
std::map< std::string, ID > expected
BOOST_CHECK(tree)