Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_compressed_file.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <list>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <sysio/trace_api/compressed_file.hpp>
#include <sysio/trace_api/test_common.hpp>
Include dependency graph for test_compressed_file.cpp:

Go to the source code of this file.

Classes

struct  temp_file_fixture
 

Namespaces

namespace  std
 

Macros

#define BOOST_TEST_MODULE   trace_compressed_file
 

Typedefs

typedef std::tuple< uint64_t, std::array< char, 6733 > > test_types
 

Functions

template<typename T , size_t S>
std::ostream & std::operator<< (std::ostream &os, const std::array< T, S > &array)
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE (random_access_test, T, test_types, temp_file_fixture)
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE (sequential_access, T, test_types, temp_file_fixture)
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE (blob_access, T, test_types, temp_file_fixture)
 
 BOOST_FIXTURE_TEST_CASE_TEMPLATE (blob_access_no_seek_points, T, test_types, temp_file_fixture)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   trace_compressed_file

Definition at line 1 of file test_compressed_file.cpp.

Typedef Documentation

◆ test_types

typedef std::tuple<uint64_t, std::array<char, 6733> > test_types

Definition at line 46 of file test_compressed_file.cpp.

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE_TEMPLATE() [1/4]

BOOST_FIXTURE_TEST_CASE_TEMPLATE ( blob_access ,
T ,
test_types ,
temp_file_fixture  )

Definition at line 156 of file test_compressed_file.cpp.

156 {
157 // generate a large dataset where ever 8 bytes is the offset to that 8 bytes of data
158 auto data = std::vector<T>(128);
159 std::generate(data.begin(), data.end(), []() {
160 return make_random<T>();
161 });
162
163 auto uncompressed_filename = create_temp_file(data.data(), data.size() * sizeof(T));
164 auto compressed_filename = create_temp_file(nullptr, 0);
165
166 BOOST_TEST(compressed_file::process(uncompressed_filename, compressed_filename, 512));
167
168 // test that you can read all of the offsets from the compressed form through the end of the file
169 for (size_t i = 0; i < data.size(); i++) {
170 auto actual_data = std::vector<T>(128);
171 auto compf = compressed_file(compressed_filename);
172 compf.open();
173 compf.seek(i * sizeof(T));
174 compf.read(reinterpret_cast<char*>(actual_data.data()), (actual_data.size() - i) * sizeof(T));
175 compf.close();
176 BOOST_REQUIRE_EQUAL_COLLECTIONS(data.begin() + i, data.end(), actual_data.begin(), actual_data.end() - i);
177 }
178}
static bool process(const fc::path &input_path, const fc::path &output_path, size_t seek_point_stride)
#define T(meth, val, expected)
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE_TEMPLATE() [2/4]

BOOST_FIXTURE_TEST_CASE_TEMPLATE ( blob_access_no_seek_points ,
T ,
test_types ,
temp_file_fixture  )

Definition at line 180 of file test_compressed_file.cpp.

180 {
181 // generate a large dataset where ever 8 bytes is the offset to that 8 bytes of data
182 auto data = std::vector<T>(32);
183 std::generate(data.begin(), data.end(), []() {
184 return make_random<T>();
185 });
186
187 auto uncompressed_size = data.size() * sizeof(T);
188 auto uncompressed_filename = create_temp_file(data.data(), uncompressed_size);
189 auto compressed_filename = create_temp_file(nullptr, 0);
190
191 // set a stride of the whole file which should result in no seek points
192 BOOST_TEST(compressed_file::process(uncompressed_filename, compressed_filename, uncompressed_size));
193
194 // verify that no seek points were created
195 fc::cfile compressed;
196 compressed.set_file_path(compressed_filename);
197 compressed.open("r");
198 compressed.seek(fc::file_size(compressed_filename) - 2);
199 const uint16_t expected_seek_point_count = 0;
200 uint16_t actual_seek_point_count = std::numeric_limits<uint16_t>::max();
201 compressed.read(reinterpret_cast<char*>(&actual_seek_point_count), 2);
202 BOOST_REQUIRE_EQUAL(expected_seek_point_count, actual_seek_point_count);
203
204 // test that you can read all of the offsets from the compressed form through the end of the file
205 for (size_t i = 0; i < data.size(); i++) {
206 auto actual_data = std::vector<T>(32);
207 auto compf = compressed_file(compressed_filename);
208 compf.open();
209 compf.seek(i * sizeof(T));
210 compf.read(reinterpret_cast<char*>(actual_data.data()), (actual_data.size() - i) * sizeof(T));
211 compf.close();
212 BOOST_REQUIRE_EQUAL_COLLECTIONS(data.begin() + i, data.end(), actual_data.begin(), actual_data.end() - i);
213 }
214}
void read(char *d, size_t n)
Definition cfile.hpp:114
void seek(long loc)
Definition cfile.hpp:87
void open(const char *mode)
Definition cfile.hpp:65
void set_file_path(fc::path file_path)
Definition cfile.hpp:37
uint64_t file_size(const path &p)
unsigned short uint16_t
Definition stdint.h:125
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE_TEMPLATE() [3/4]

BOOST_FIXTURE_TEST_CASE_TEMPLATE ( random_access_test ,
T ,
test_types ,
temp_file_fixture  )

Definition at line 104 of file test_compressed_file.cpp.

104 {
105 // generate a large dataset where ever 8 bytes is the offset to that 8 bytes of data
106 auto data = std::vector<T>(128);
107 std::generate(data.begin(), data.end(), [offset=0ULL]() mutable {
108 auto result = offset;
109 offset+=sizeof(T);
110 return convert_to<T>(result);
111 });
112
113 auto uncompressed_filename = create_temp_file(data.data(), data.size() * sizeof(T));
114 auto compressed_filename = create_temp_file(nullptr, 0);
115
116 BOOST_TEST(compressed_file::process(uncompressed_filename, compressed_filename, 512));
117
118 // test that you can read all of the offsets from the compressed form by opening and seeking to them
119 for (size_t i = 0; i < data.size(); i++) {
120 const auto& entry = data.at(i);
121 auto compf = compressed_file(compressed_filename);
122 compf.open();
123 T value;
124 compf.seek((long)i * sizeof(T));
125 compf.read(reinterpret_cast<char*>(&value), sizeof(T));
126 BOOST_TEST(value == entry);
127 compf.close();
128 }
129}
#define value
Definition pkcs11.h:157
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE_TEMPLATE() [4/4]

BOOST_FIXTURE_TEST_CASE_TEMPLATE ( sequential_access ,
T ,
test_types ,
temp_file_fixture  )

Definition at line 131 of file test_compressed_file.cpp.

131 {
132 // generate a large dataset where ever 8 bytes is the offset to that 8 bytes of data
133 auto data = std::vector<T>(128);
134 std::generate(data.begin(), data.end(), [offset=0ULL]() mutable {
135 auto result = offset;
136 offset+=sizeof(T);
137 return convert_to<T>(result);
138 });
139
140 auto uncompressed_filename = create_temp_file(data.data(), data.size() * sizeof(T));
141 auto compressed_filename = create_temp_file(nullptr, 0);
142
143 BOOST_TEST(compressed_file::process(uncompressed_filename, compressed_filename, 512));
144
145 // test that you can read all of the offsets from the compressed form sequentially
146 auto compf = compressed_file(compressed_filename);
147 compf.open();
148 for( const auto& entry : data ) {
149 T value;
150 compf.read(reinterpret_cast<char*>(&value), sizeof(value));
151 BOOST_TEST(value == entry);
152 }
153 compf.close();
154}
Here is the call graph for this function: