C++ Utilities
5.0.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Go to the documentation of this file.
3 #include "../conversion/conversionexception.h"
4 #include "../conversion/stringbuilder.h"
6 #include "../io/ansiescapecodes.h"
7 #include "../io/binaryreader.h"
8 #include "../io/binarywriter.h"
9 #include "../io/bitreader.h"
10 #include "../io/copy.h"
11 #include "../io/inifile.h"
12 #include "../io/misc.h"
13 #include "../io/nativefilestream.h"
14 #include "../io/path.h"
16 #include <cppunit/TestFixture.h>
17 #include <cppunit/extensions/HelperMacros.h>
24 #ifdef PLATFORM_WINDOWS
29 #include <sys/fcntl.h>
30 #include <sys/types.h>
36 using namespace CPPUNIT_NS;
43 CPPUNIT_TEST(testBinaryReader);
44 CPPUNIT_TEST(testBinaryWriter);
45 CPPUNIT_TEST(testBitReader);
46 CPPUNIT_TEST(testPathUtilities);
47 CPPUNIT_TEST(testIniFile);
48 CPPUNIT_TEST(testCopy);
49 CPPUNIT_TEST(testReadFile);
50 CPPUNIT_TEST(testAnsiEscapeCodes);
51 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
52 CPPUNIT_TEST(testNativeFileStream);
54 CPPUNIT_TEST_SUITE_END();
60 void testBinaryReader();
61 void testBinaryWriter();
63 void testPathUtilities();
67 void testAnsiEscapeCodes();
68 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
69 void testNativeFileStream();
90 testFile.exceptions(ios_base::failbit | ios_base::badbit);
91 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
93 CPPUNIT_ASSERT_EQUAL(reader.
readStreamsize(), static_cast<istream::pos_type>(398));
102 CPPUNIT_ASSERT(reader.
readUInt56LE() == 0x01020304050607u);
103 CPPUNIT_ASSERT(reader.
readUInt56BE() == 0x01020304050607u);
104 CPPUNIT_ASSERT(reader.
readUInt64LE() == 0x0102030405060708u);
105 CPPUNIT_ASSERT(reader.
readUInt64BE() == 0x0102030405060708u);
111 CPPUNIT_ASSERT(reader.
readInt32LE() == 0x01020304);
112 CPPUNIT_ASSERT(reader.
readInt32BE() == 0x01020304);
113 CPPUNIT_ASSERT(reader.
readInt40LE() == 0x0102030405);
114 CPPUNIT_ASSERT(reader.
readInt40BE() == 0x0102030405);
115 CPPUNIT_ASSERT(reader.
readInt56LE() == 0x01020304050607);
116 CPPUNIT_ASSERT(reader.
readInt56BE() == 0x01020304050607);
117 CPPUNIT_ASSERT(reader.
readInt64LE() == 0x0102030405060708);
118 CPPUNIT_ASSERT(reader.
readInt64BE() == 0x0102030405060708);
123 CPPUNIT_ASSERT(reader.
readBool() ==
false);
124 CPPUNIT_ASSERT(reader.
readBool() ==
true);
125 CPPUNIT_ASSERT(reader.
readString(3) ==
"abc");
128 ==
"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
129 "23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"
130 "45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
131 "678901234567890123456789");
133 testFile.seekg(-4, ios_base::cur);
136 CPPUNIT_ASSERT_MESSAGE(
"pos in stream not advanced on conversion error", reader.
readByte() == 0);
155 testFile.exceptions(ios_base::failbit | ios_base::badbit);
156 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
159 stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
160 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
162 outputStream.rdbuf()->pubsetbuf(testData,
sizeof(testData));
180 for (
char c : testData) {
181 CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
182 if (testFile.tellg() >= 58) {
187 outputStream.seekp(0);
210 writer.
writeLengthPrefixedString(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
211 "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
212 "234567890123456789012345678901234567890123456789012345678901234567890123456789");
216 for (
char c : testData) {
217 CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
235 const std::uint8_t testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20, 0xFF, 0xFA };
236 BitReader reader(reinterpret_cast<const char *>(testData),
sizeof(testData));
237 CPPUNIT_ASSERT(reader.
readBit() == 1);
239 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(3), reader.
showBits<std::uint8_t>(2));
240 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(3), reader.
readBits<std::uint8_t>(2));
241 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint32_t>(0x103C4428 << 1), reader.
readBits<std::uint32_t>(32));
243 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0x44), reader.
readBits<std::uint8_t>(8));
246 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0), reader.
readBit());
247 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0), reader.
readBit());
250 CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0xA), reader.
readBits<std::uint8_t>(4));
251 CPPUNIT_ASSERT_THROW(reader.
readBit(), std::ios_base::failure);
252 CPPUNIT_ASSERT_THROW(reader.
skipBits(1), std::ios_base::failure);
253 reader.
reset(reinterpret_cast<const char *>(testData),
sizeof(testData));
254 CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8 *
sizeof(testData)), reader.
bitsAvailable());
262 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"C:\\libs\\libc++utilities.so"));
263 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"C:\\libs/libc++utilities.so"));
264 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"/usr/lib/libc++utilities.so"));
265 CPPUNIT_ASSERT_EQUAL(
"/usr/lib/"s,
directory(
"/usr/lib/libc++utilities.so"));
266 CPPUNIT_ASSERT_EQUAL(
string(),
directory(
"libc++utilities.so"));
267 CPPUNIT_ASSERT_EQUAL(
"C:\\libs\\"s,
directory(
"C:\\libs\\libc++utilities.so"));
268 CPPUNIT_ASSERT_EQUAL(
"C:\\libs/"s,
directory(
"C:\\libs/libc++utilities.so"));
269 string invalidPath(
"lib/c++uti*lities.so?");
271 CPPUNIT_ASSERT(invalidPath ==
"libc++utilities.so");
281 inputFile.exceptions(ios_base::failbit | ios_base::badbit);
285 ini.
parse(inputFile);
286 const auto globalScope = ini.
data().at(0);
287 const auto scope1 = ini.
data().at(1);
288 const auto scope2 = ini.
data().at(2);
289 CPPUNIT_ASSERT(globalScope.first.empty());
290 CPPUNIT_ASSERT(globalScope.second.find(
"key0") != globalScope.second.cend());
291 CPPUNIT_ASSERT(globalScope.second.find(
"key0")->second ==
"value 0");
292 CPPUNIT_ASSERT(globalScope.second.find(
"key1") == globalScope.second.cend());
293 CPPUNIT_ASSERT(scope1.first ==
"scope 1");
294 CPPUNIT_ASSERT(scope1.second.find(
"key1") != scope1.second.cend());
295 CPPUNIT_ASSERT(scope1.second.find(
"key1")->second ==
"value 1");
296 CPPUNIT_ASSERT(scope1.second.find(
"key2") != scope1.second.cend());
297 CPPUNIT_ASSERT(scope1.second.find(
"key2")->second ==
"value=2");
298 CPPUNIT_ASSERT(scope2.first ==
"scope 2");
299 CPPUNIT_ASSERT(scope2.second.find(
"key5") == scope2.second.cend());
303 outputFile.exceptions(ios_base::failbit | ios_base::badbit);
304 outputFile.open(
workingCopyPath(
"output.ini", WorkingCopyMode::NoCopy), ios_base::out | ios_base::trunc);
305 ini.
make(outputFile);
309 outputFile.open(
workingCopyPath(
"output.ini", WorkingCopyMode::NoCopy), ios_base::in);
311 ini2.
parse(outputFile);
312 CPPUNIT_ASSERT(ini.
data() == ini2.
data());
322 testFile.exceptions(ios_base::failbit | ios_base::badbit);
323 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
324 stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
325 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
329 copyHelper.
copy(testFile, outputStream, 50);
333 for (
auto i = 0;
i < 50; ++
i) {
334 CPPUNIT_ASSERT(testFile.get() == outputStream.get());
345 CPPUNIT_ASSERT_EQUAL(
"# file for testing INI parser\n"
349 "key1=value 1 # comment\n"
360 CPPUNIT_ASSERT_THROW(
readFile(iniFilePath, 10), std::ios_base::failure);
363 #if !defined(PLATFORM_WINDOWS) || defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
364 CPPUNIT_ASSERT_EQUAL(
"file with non-ASCII character 'รค' in its name\n"s,
readFile(
testFilePath(
"tรคst.txt")));
372 ss1 << EscapeCodes::Phrases::Error <<
"some error" << EscapeCodes::Phrases::End;
373 ss1 << EscapeCodes::Phrases::Warning <<
"some warning" << EscapeCodes::Phrases::End;
374 ss1 << EscapeCodes::Phrases::Info <<
"some info" << EscapeCodes::Phrases::End;
375 ss1 << EscapeCodes::Phrases::ErrorMessage <<
"Arch-style error" << EscapeCodes::Phrases::End;
376 ss1 << EscapeCodes::Phrases::WarningMessage <<
"Arch-style warning" << EscapeCodes::Phrases::End;
377 ss1 << EscapeCodes::Phrases::PlainMessage <<
"Arch-style message" << EscapeCodes::Phrases::End;
378 ss1 << EscapeCodes::Phrases::SuccessMessage <<
"Arch-style success" << EscapeCodes::Phrases::End;
379 ss1 << EscapeCodes::Phrases::SubMessage <<
"Arch-style sub-message" << EscapeCodes::Phrases::End;
380 ss1 <<
EscapeCodes::color(EscapeCodes::Color::Blue, EscapeCodes::Color::Red, EscapeCodes::TextAttribute::Blink)
381 <<
"blue, blinking text on red background" << EscapeCodes::TextAttribute::Reset <<
'\n';
382 cout <<
"\noutput for formatting with ANSI escape codes:\n" << ss1.str() <<
"---------------------------------------------\n";
383 fstream(
"/tmp/test.txt", ios_base::out | ios_base::trunc) << ss1.str();
384 CPPUNIT_ASSERT_EQUAL(
"\e[1;31mError: \e[0m\e[1msome error\e[0m\n"
385 "\e[1;33mWarning: \e[0m\e[1msome warning\e[0m\n"
386 "\e[1;34mInfo: \e[0m\e[1msome info\e[0m\n"
387 "\e[1;31m==> ERROR: \e[0m\e[1mArch-style error\e[0m\n"
388 "\e[1;33m==> WARNING: \e[0m\e[1mArch-style warning\e[0m\n"
389 " \e[0m\e[1mArch-style message\e[0m\n"
390 "\e[1;32m==> \e[0m\e[1mArch-style success\e[0m\n"
391 "\e[1;32m -> \e[0m\e[1mArch-style sub-message\e[0m\n"
392 "\e[5;34;41mblue, blinking text on red background\e[0m\n"s,
397 ss2 << EscapeCodes::Phrases::Info <<
"some info" << EscapeCodes::Phrases::End;
398 CPPUNIT_ASSERT_EQUAL(
"Info: some info\n"s, ss2.str());
401 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
405 void IoTests::testNativeFileStream()
410 fileStream.exceptions(ios_base::badbit | ios_base::failbit);
411 CPPUNIT_ASSERT(!fileStream.is_open());
412 fileStream.open(txtFilePath, ios_base::in);
413 CPPUNIT_ASSERT(fileStream.is_open());
414 #if defined(PLATFORM_WINDOWS) && defined(CPP_UTILITIES_USE_BOOST_IOSTREAMS)
415 CPPUNIT_ASSERT(fileStream.fileHandle() !=
nullptr);
417 CPPUNIT_ASSERT(fileStream.fileDescriptor() != -1);
419 CPPUNIT_ASSERT_EQUAL(static_cast<char>(fileStream.get()),
'f');
420 fileStream.seekg(0, ios_base::end);
421 CPPUNIT_ASSERT_EQUAL(fileStream.tellg(), static_cast<NativeFileStream::pos_type>(47));
423 CPPUNIT_ASSERT(!fileStream.is_open());
425 fileStream.open(
"non existing file", ios_base::in | ios_base::out | ios_base::binary);
426 CPPUNIT_FAIL(
"expected exception");
427 }
catch (
const std::ios_base::failure &failure) {
428 #ifdef PLATFORM_WINDOWS
429 #ifdef CPP_UTILITIES_USE_BOOST_IOSTREAMS
430 CPPUNIT_ASSERT_EQUAL(
"CreateFileW failed: iostream error"s,
string(failure.what()));
432 CPPUNIT_ASSERT_EQUAL(
"_wopen failed: iostream error"s,
string(failure.what()));
435 CPPUNIT_ASSERT_EQUAL(
"open failed: iostream error"s,
string(failure.what()));
441 #ifndef PLATFORM_WINDOWS
442 auto readWriteFileDescriptor = open(txtFilePath.data(), O_RDWR);
443 CPPUNIT_ASSERT(readWriteFileDescriptor);
444 fileStream.open(readWriteFileDescriptor, ios_base::in | ios_base::out | ios_base::binary);
445 CPPUNIT_ASSERT(fileStream.is_open());
446 CPPUNIT_ASSERT_EQUAL(static_cast<char>(fileStream.get()),
'f');
447 fileStream.seekg(0, ios_base::end);
448 CPPUNIT_ASSERT_EQUAL(fileStream.tellg(), static_cast<NativeFileStream::pos_type>(47));
451 CPPUNIT_ASSERT(!fileStream.is_open());
454 fileStream.open(-1, ios_base::in | ios_base::out | ios_base::binary);
456 CPPUNIT_FAIL(
"expected exception");
457 }
catch (
const std::ios_base::failure &failure) {
458 #ifndef PLATFORM_WINDOWS
460 "expected error message",
"(basic_ios::clear|failed reading: Bad file descriptor): iostream error"s,
string(failure.what()));
469 fileStream2.exceptions(ios_base::failbit | ios_base::badbit);
470 fileStream2.open(txtFilePath, ios_base::in | ios_base::out | ios_base::app);
471 CPPUNIT_ASSERT(fileStream2.is_open());
472 fileStream2 <<
"foo";
475 CPPUNIT_ASSERT(!fileStream2.is_open());
476 CPPUNIT_ASSERT_EQUAL(
"file with non-ASCII character 'รค' in its name\nfoo"s,
readFile(txtFilePath, 50));
479 fileStream2.open(txtFilePath, ios_base::out | ios_base::trunc);
480 CPPUNIT_ASSERT(fileStream2.is_open());
481 fileStream2 <<
"bar";
483 CPPUNIT_ASSERT(!fileStream2.is_open());
484 CPPUNIT_ASSERT_EQUAL(
"bar"s,
readFile(txtFilePath, 4));
487 #ifdef PLATFORM_WINDOWS
488 const auto wideTxtFilePath = NativeFileStream::makeWidePath(txtFilePath);
489 const auto appendFileHandle = _wfopen(wideTxtFilePath.get(), L
"a+");
491 const auto appendFileHandle = fopen(txtFilePath.data(),
"a");
493 CPPUNIT_ASSERT(appendFileHandle);
494 fileStream2.open(fileno(appendFileHandle), ios_base::out | ios_base::app);
495 CPPUNIT_ASSERT(fileStream2.is_open());
496 fileStream2 <<
"foo";
498 CPPUNIT_ASSERT(!fileStream2.is_open());
499 CPPUNIT_ASSERT_EQUAL(
"barfoo"s,
readFile(txtFilePath, 7));
void writeInt16LE(std::int16_t value)
Writes a 16-bit little endian signed integer to the current stream and advances the current position ...
std::uint8_t readBit()
Reads the one bit from the buffer advancing the current position by one bit.
std::fstream NativeFileStream
std::uint64_t readUInt40LE()
Reads a 40-bit little endian unsigned integer from the current stream and advances the current positi...
void writeInt64LE(std::int64_t value)
Writes a 64-bit little endian signed integer to the current stream and advances the current position ...
std::int32_t readInt24LE()
Reads a 24-bit little endian signed integer from the current stream and advances the current position...
std::int64_t readInt56BE()
Reads a 56-bit big endian signed integer from the current stream and advances the current position of...
void writeBool(bool value)
Writes a boolean value to the current stream and advances the current position of the stream by one b...
The IniFile class parses and makes INI files.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::testFilePath().
The BitReader class provides bitwise reading of buffered data.
void make(std::ostream &outputStream)
Write the current data to the specified outputStream.
void writeUInt32LE(std::uint32_t value)
Writes a 32-bit little endian unsigned integer to the current stream and advances the current positio...
void writeUInt56LE(std::uint64_t value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
std::uint8_t readByte()
Reads a single byte/unsigned character from the current stream and advances the current position of t...
void writeUInt56BE(std::uint64_t value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
void writeInt16BE(std::int16_t value)
Writes a 16-bit big endian signed integer to the current stream and advances the current position of ...
void writeUInt32BE(std::uint32_t value)
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position o...
double readFloat64LE()
Reads a 64-bit little endian floating point value from the current stream and advances the current po...
std::int64_t readInt64LE()
Reads a 64-bit little endian signed integer from the current stream and advances the current position...
Writes primitive data types to a std::ostream.
std::int32_t readInt32LE()
Reads a 32-bit little endian signed integer from the current stream and advances the current position...
void writeInt40BE(std::int64_t value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
void testBinaryWriter()
Tests the most important methods of the BinaryWriter.
bool readBool()
Reads a boolean value from the current stream and advances the current position of the stream by one ...
void align()
Re-establishes alignment.
std::int16_t readInt16BE()
Reads a 16-bit big endian signed integer from the current stream and advances the current position of...
CPP_UTILITIES_EXPORT std::string readFile(const std::string &path, std::string::size_type maxSize=std::string::npos)
Reads all contents of the specified file in a single call.
void writeUInt64BE(std::uint64_t value)
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position o...
void writeFloat32BE(float value)
Writes a 32-bit big endian floating point value to the current stream and advances the current positi...
void testAnsiEscapeCodes()
void skipBits(std::size_t bitCount)
Skips the specified number of bits without reading it.
bool hasOwnership() const
Returns whether the reader takes ownership over the assigned stream.
void writeInt24LE(std::int32_t value)
Writes a 24-bit little endian signed integer to the current stream and advances the current position ...
constexpr auto color(Color foreground, Color background, TextAttribute displayAttribute=TextAttribute::Reset)
void writeInt56BE(std::int64_t value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
void writeUInt40BE(std::uint64_t value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
The IoTests class tests classes and functions provided by the files inside the io directory.
void writeFloat64LE(double value)
Writes a 64-bit little endian floating point value to the current stream and advances the current pos...
intType readSignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (signed).
std::uint32_t readUInt32BE()
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position ...
void testIniFile()
Tests IniFile.
void writeTerminatedString(const std::string &value)
Writes a terminated string to the current stream and advances the current position of the stream by t...
float readFloat32LE()
Reads a 32-bit little endian floating point value from the current stream and advances the current po...
void testBitReader()
Tests the BitReader.
void parse(std::istream &inputStream)
Parses all data from the specified inputStream.
std::istream::pos_type readStreamsize()
Returns the size of the assigned stream.
void writeUInt64LE(std::uint64_t value)
Writes a 64-bit little endian unsigned integer to the current stream and advances the current positio...
std::uint32_t readUInt24BE()
Reads a 24-bit big endian unsigned integer from the current stream and advances the current position ...
void writeInt40LE(std::int64_t value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
#define CPP_UTILITIES_UNUSED(x)
Prevents warnings about unused variables.
std::int64_t readInt40LE()
Reads a 40-bit little endian signed integer from the current stream and advances the current position...
const std::istream * stream() const
Returns a pointer to the stream the reader will read from when calling one of the read-methods.
#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString)
Asserts whether the specified string matches the specified regex.
std::int64_t readInt64BE()
Reads a 64-bit big endian signed integer from the current stream and advances the current position of...
intType showBits(std::uint8_t bitCount)
Reads the specified number of bits from the buffer without advancing the current position.
CPP_UTILITIES_EXPORT std::string directory(const std::string &path)
Returns the directory of the specified path string (including trailing slash).
void copy(std::istream &input, std::ostream &output, std::size_t count)
Copies count bytes from input to output.
std::int64_t readInt56LE()
Reads a 56-bit little endian signed integer from the current stream and advances the current position...
std::size_t bitsAvailable()
Returns the number of bits which are still available to read.
void testBinaryReader()
Tests the most important methods of the BinaryReader.
void writeFloat32LE(float value)
Writes a 32-bit little endian floating point value to the current stream and advances the current pos...
std::uint16_t readUInt16BE()
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position ...
float readFloat32BE()
Reads a 32-bit big endian floating point value from the current stream and advances the current posit...
Contains all utilities provides by the c++utilities library.
std::vector< std::pair< std::string, std::multimap< std::string, std::string > > > & data()
Returns the data of the file.
void writeString(const std::string &value)
Writes a string to the current stream and advances the current position of the stream by the length o...
std::uint32_t readUInt32LE()
Reads a 32-bit little endian unsigned integer from the current stream and advances the current positi...
std::uint32_t readUInt24LE()
Reads a 24-bit little endian unsigned integer from the current stream and advances the current positi...
void writeUInt16LE(std::uint16_t value)
Writes a 16-bit little endian unsigned integer to the current stream and advances the current positio...
std::uint64_t readUInt56LE()
Reads a 56-bit little endian unsigned integer from the current stream and advances the current positi...
std::string readTerminatedString(std::uint8_t termination=0)
Reads a terminated string from the current stream.
std::uint64_t readUInt64LE()
Reads a 64-bit little endian unsigned integer from the current stream and advances the current positi...
void writeFloat64BE(double value)
Writes a 64-bit big endian floating point value to the current stream and advances the current positi...
void testReadFile()
Tests readFile().
std::uint64_t readUInt64BE()
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position ...
void writeUInt40LE(std::uint64_t value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
The CopyHelper class helps to copy bytes from one stream to another.
std::int64_t readInt40BE()
Reads a 40-bit big endian signed integer from the current stream and advances the current position of...
std::uint64_t readUInt56BE()
Reads a 56-bit big endian unsigned integer from the current stream and advances the current position ...
void writeUInt16BE(std::uint16_t value)
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position o...
CPPUNIT_TEST_SUITE_REGISTRATION(IoTests)
std::uint64_t readUInt40BE()
Reads a 40-bit big endian unsigned integer from the current stream and advances the current position ...
The ConversionException class is thrown by the various conversion functions of this library when a co...
void setStream(std::istream *stream, bool giveOwnership=false)
Assigns the stream the reader will read from when calling one of the read-methods.
void writeUInt24LE(std::uint32_t value)
Writes a 24-bit little endian unsigned integer to the current stream and advances the current positio...
Reads primitive data types from a std::istream.
void writeInt24BE(std::int32_t value)
Writes a 24-bit big endian signed integer to the current stream and advances the current position of ...
void writeUInt24BE(std::uint32_t value)
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position o...
void writeInt56LE(std::int64_t value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
std::string readString(std::size_t length)
Reads a string from the current stream of the given length from the stream and advances the current p...
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
std::uint16_t readUInt16LE()
Reads a 16-bit little endian unsigned integer from the current stream and advances the current positi...
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
void writeLengthPrefixedString(const std::string &value)
Writes the length of a string and the string itself to the current stream.
double readFloat64BE()
Reads a 64-bit big endian floating point value from the current stream and advances the current posit...
void setStream(std::ostream *stream, bool giveOwnership=false)
Assigns the stream the writer will write to when calling one of the write-methods.
void writeInt32LE(std::int32_t value)
Writes a 32-bit little endian signed integer to the current stream and advances the current position ...
CPP_UTILITIES_EXPORT std::string workingCopyPath(const std::string &relativeTestFilePath, WorkingCopyMode mode=WorkingCopyMode::CreateCopy)
Convenience function to invoke TestApplication::workingCopyPath().
intType readUnsignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (unsigned).
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName)
Removes invalid characters from the specified fileName.
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path)
Returns the file name and extension of the specified path string.
void reset(const char *buffer, std::size_t bufferSize)
Resets the reader.
intType readBits(std::uint8_t bitCount)
Reads the specified number of bits from the buffer advancing the current position by bitCount bits.
bool hasOwnership() const
Returns whether the writer takes ownership over the assigned stream.
void writeInt64BE(std::int64_t value)
Writes a 64-bit big endian signed integer to the current stream and advances the current position of ...
std::int32_t readInt24BE()
Reads a 24-bit big endian signed integer from the current stream and advances the current position of...
void testCopy()
Tests CopyHelper.
std::int32_t readInt32BE()
Reads a 32-bit big endian signed integer from the current stream and advances the current position of...
std::int16_t readInt16LE()
Reads a 16-bit little endian signed integer from the current stream and advances the current position...
CPP_UTILITIES_EXPORT bool enabled
Controls whether the functions inside the EscapeCodes namespace actually make use of escape codes.
void testPathUtilities()
Tests fileName() and removeInvalidChars().
std::string readLengthPrefixedString()
Reads a length prefixed string from the current stream.
void writeInt32BE(std::int32_t value)
Writes a 32-bit big endian signed integer to the current stream and advances the current position of ...