C++ Utilities
5.3.0
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(testWriteFile);
51 CPPUNIT_TEST(testAnsiEscapeCodes);
52 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
53 CPPUNIT_TEST(testNativeFileStream);
55 CPPUNIT_TEST_SUITE_END();
58 void setUp()
override;
59 void tearDown()
override;
61 void testBinaryReader();
62 void testBinaryWriter();
64 void testPathUtilities();
69 void testAnsiEscapeCodes();
70 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
71 void testNativeFileStream();
92 testFile.exceptions(ios_base::failbit | ios_base::badbit);
93 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
95 CPPUNIT_ASSERT_EQUAL(
static_cast<istream::pos_type
>(398), reader.
readStreamsize());
96 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint16_t
>(0x0102u), reader.
readUInt16LE());
97 CPPUNIT_ASSERT_EQUAL(
static_cast<istream::pos_type
>(396), reader.
readRemainingBytes());
98 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint16_t
>(0x0102u), reader.
readUInt16BE());
101 CPPUNIT_ASSERT_EQUAL(0x01020304u, reader.
readUInt32LE());
102 CPPUNIT_ASSERT_EQUAL(0x01020304u, reader.
readUInt32BE());
103 CPPUNIT_ASSERT_EQUAL(0x0102030405u, reader.
readUInt40LE());
104 CPPUNIT_ASSERT_EQUAL(0x0102030405u, reader.
readUInt40BE());
105 CPPUNIT_ASSERT_EQUAL(0x01020304050607u, reader.
readUInt56LE());
106 CPPUNIT_ASSERT_EQUAL(0x01020304050607u, reader.
readUInt56BE());
107 CPPUNIT_ASSERT_EQUAL(0x0102030405060708u, reader.
readUInt64LE());
108 CPPUNIT_ASSERT_EQUAL(0x0102030405060708u, reader.
readUInt64BE());
110 CPPUNIT_ASSERT_EQUAL(reader.
readInt16LE(),
static_cast<std::int16_t
>(0x0102));
111 CPPUNIT_ASSERT_EQUAL(reader.
readInt16BE(),
static_cast<std::int16_t
>(0x0102));
112 CPPUNIT_ASSERT_EQUAL(0x010203, reader.
readInt24LE());
113 CPPUNIT_ASSERT_EQUAL(0x010203, reader.
readInt24BE());
114 CPPUNIT_ASSERT_EQUAL(0x01020304, reader.
readInt32LE());
115 CPPUNIT_ASSERT_EQUAL(0x01020304, reader.
readInt32BE());
116 CPPUNIT_ASSERT_EQUAL(0x0102030405, reader.
readInt40LE());
117 CPPUNIT_ASSERT_EQUAL(0x0102030405, reader.
readInt40BE());
118 CPPUNIT_ASSERT_EQUAL(0x01020304050607, reader.
readInt56LE());
119 CPPUNIT_ASSERT_EQUAL(0x01020304050607, reader.
readInt56BE());
120 CPPUNIT_ASSERT_EQUAL(0x0102030405060708, reader.
readInt64LE());
121 CPPUNIT_ASSERT_EQUAL(0x0102030405060708, reader.
readInt64BE());
126 CPPUNIT_ASSERT_EQUAL(
false, reader.
readBool());
127 CPPUNIT_ASSERT_EQUAL(
true, reader.
readBool());
128 CPPUNIT_ASSERT_EQUAL(
"abc"s, reader.
readString(3));
130 CPPUNIT_ASSERT_EQUAL(
"01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
131 "23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"
132 "45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
133 "678901234567890123456789"s,
136 testFile.seekg(-4, ios_base::cur);
139 CPPUNIT_ASSERT_MESSAGE(
"pos in stream not advanced on conversion error", reader.
readByte() == 0);
158 testFile.exceptions(ios_base::failbit | ios_base::badbit);
159 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
162 stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
163 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
165 outputStream.rdbuf()->pubsetbuf(testData,
sizeof(testData));
183 for (
char c : testData) {
184 CPPUNIT_ASSERT(c ==
static_cast<char>(testFile.get()));
185 if (testFile.tellg() >= 58) {
190 outputStream.seekp(0);
213 writer.
writeLengthPrefixedString(
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
214 "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
215 "234567890123456789012345678901234567890123456789012345678901234567890123456789");
219 for (
char c : testData) {
220 CPPUNIT_ASSERT(c ==
static_cast<char>(testFile.get()));
238 const std::uint8_t testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20, 0xFF, 0xFA };
239 BitReader reader(
reinterpret_cast<const char *
>(testData),
sizeof(testData));
240 CPPUNIT_ASSERT(reader.
readBit() == 1);
242 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(3), reader.
showBits<std::uint8_t>(2));
243 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(3), reader.
readBits<std::uint8_t>(2));
244 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint32_t
>(0x103C4428 << 1), reader.
readBits<std::uint32_t>(32));
246 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(0x44), reader.
readBits<std::uint8_t>(8));
249 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(0), reader.
readBit());
250 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(0), reader.
readBit());
253 CPPUNIT_ASSERT_EQUAL(
static_cast<std::uint8_t
>(0xA), reader.
readBits<std::uint8_t>(4));
254 CPPUNIT_ASSERT_THROW(reader.
readBit(), std::ios_base::failure);
255 CPPUNIT_ASSERT_THROW(reader.
skipBits(1), std::ios_base::failure);
256 reader.
reset(
reinterpret_cast<const char *
>(testData),
sizeof(testData));
257 CPPUNIT_ASSERT_EQUAL(
static_cast<std::size_t
>(8 *
sizeof(testData)), reader.
bitsAvailable());
265 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"C:\\libs\\libc++utilities.so"));
266 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"C:\\libs/libc++utilities.so"));
267 CPPUNIT_ASSERT_EQUAL(
"libc++utilities.so"s,
fileName(
"/usr/lib/libc++utilities.so"));
268 CPPUNIT_ASSERT_EQUAL(
"/usr/lib/"s,
directory(
"/usr/lib/libc++utilities.so"));
269 CPPUNIT_ASSERT_EQUAL(
string(),
directory(
"libc++utilities.so"));
270 CPPUNIT_ASSERT_EQUAL(
"C:\\libs\\"s,
directory(
"C:\\libs\\libc++utilities.so"));
271 CPPUNIT_ASSERT_EQUAL(
"C:\\libs/"s,
directory(
"C:\\libs/libc++utilities.so"));
272 string invalidPath(
"lib/c++uti*lities.so?");
274 CPPUNIT_ASSERT(invalidPath ==
"libc++utilities.so");
284 inputFile.exceptions(ios_base::failbit | ios_base::badbit);
288 ini.
parse(inputFile);
289 const auto globalScope = ini.
data().at(0);
290 const auto scope1 = ini.
data().at(1);
291 const auto scope2 = ini.
data().at(2);
292 CPPUNIT_ASSERT(globalScope.first.empty());
293 CPPUNIT_ASSERT(globalScope.second.find(
"key0") != globalScope.second.cend());
294 CPPUNIT_ASSERT(globalScope.second.find(
"key0")->second ==
"value 0");
295 CPPUNIT_ASSERT(globalScope.second.find(
"key1") == globalScope.second.cend());
296 CPPUNIT_ASSERT(scope1.first ==
"scope 1");
297 CPPUNIT_ASSERT(scope1.second.find(
"key1") != scope1.second.cend());
298 CPPUNIT_ASSERT(scope1.second.find(
"key1")->second ==
"value 1");
299 CPPUNIT_ASSERT(scope1.second.find(
"key2") != scope1.second.cend());
300 CPPUNIT_ASSERT(scope1.second.find(
"key2")->second ==
"value=2");
301 CPPUNIT_ASSERT(scope2.first ==
"scope 2");
302 CPPUNIT_ASSERT(scope2.second.find(
"key5") == scope2.second.cend());
306 outputFile.exceptions(ios_base::failbit | ios_base::badbit);
307 outputFile.open(
workingCopyPath(
"output.ini", WorkingCopyMode::NoCopy), ios_base::out | ios_base::trunc);
308 ini.
make(outputFile);
312 outputFile.open(
workingCopyPath(
"output.ini", WorkingCopyMode::NoCopy), ios_base::in);
314 ini2.
parse(outputFile);
315 CPPUNIT_ASSERT(ini.
data() == ini2.
data());
325 testFile.exceptions(ios_base::failbit | ios_base::badbit);
326 testFile.open(
testFilePath(
"some_data"), ios_base::in | ios_base::binary);
327 stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
328 outputStream.exceptions(ios_base::failbit | ios_base::badbit);
332 copyHelper.
copy(testFile, outputStream, 50);
336 for (
auto i = 0;
i < 50; ++
i) {
337 CPPUNIT_ASSERT(testFile.get() == outputStream.get());
348 CPPUNIT_ASSERT_EQUAL(
"# file for testing INI parser\n"
352 "key1=value 1 # comment\n"
363 CPPUNIT_ASSERT_THROW(
readFile(iniFilePath, 10), std::ios_base::failure);
366 #if !defined(PLATFORM_WINDOWS) || defined(CPP_UTILITIES_USE_NATIVE_FILE_BUFFER)
367 CPPUNIT_ASSERT_EQUAL(
"file with non-ASCII character 'รค' in its name\n"s,
readFile(
testFilePath(
"tรคst.txt")));
376 const string path(
workingCopyPath(
"test.ini", WorkingCopyMode::NoCopy));
378 CPPUNIT_ASSERT_EQUAL(
"some contents"s,
readFile(path));
388 ss1 << EscapeCodes::Phrases::Error <<
"some error" << EscapeCodes::Phrases::End;
389 ss1 << EscapeCodes::Phrases::Warning <<
"some warning" << EscapeCodes::Phrases::End;
390 ss1 << EscapeCodes::Phrases::Info <<
"some info" << EscapeCodes::Phrases::End;
391 ss1 << EscapeCodes::Phrases::ErrorMessage <<
"Arch-style error" << EscapeCodes::Phrases::End;
392 ss1 << EscapeCodes::Phrases::WarningMessage <<
"Arch-style warning" << EscapeCodes::Phrases::End;
393 ss1 << EscapeCodes::Phrases::PlainMessage <<
"Arch-style message" << EscapeCodes::Phrases::End;
394 ss1 << EscapeCodes::Phrases::SuccessMessage <<
"Arch-style success" << EscapeCodes::Phrases::End;
395 ss1 << EscapeCodes::Phrases::SubMessage <<
"Arch-style sub-message" << EscapeCodes::Phrases::End;
396 ss1 <<
EscapeCodes::color(EscapeCodes::Color::Blue, EscapeCodes::Color::Red, EscapeCodes::TextAttribute::Blink)
397 <<
"blue, blinking text on red background" << EscapeCodes::TextAttribute::Reset <<
'\n';
398 cout <<
"\noutput for formatting with ANSI escape codes:\n" << ss1.str() <<
"---------------------------------------------\n";
399 fstream(
"/tmp/test.txt", ios_base::out | ios_base::trunc) << ss1.str();
400 CPPUNIT_ASSERT_EQUAL(
"\e[1;31mError: \e[0m\e[1msome error\e[0m\n"
401 "\e[1;33mWarning: \e[0m\e[1msome warning\e[0m\n"
402 "\e[1;34mInfo: \e[0m\e[1msome info\e[0m\n"
403 "\e[1;31m==> ERROR: \e[0m\e[1mArch-style error\e[0m\n"
404 "\e[1;33m==> WARNING: \e[0m\e[1mArch-style warning\e[0m\n"
405 " \e[0m\e[1mArch-style message\e[0m\n"
406 "\e[1;32m==> \e[0m\e[1mArch-style success\e[0m\n"
407 "\e[1;32m -> \e[0m\e[1mArch-style sub-message\e[0m\n"
408 "\e[5;34;41mblue, blinking text on red background\e[0m\n"s,
413 ss2 << EscapeCodes::Phrases::Info <<
"some info" << EscapeCodes::Phrases::End;
414 CPPUNIT_ASSERT_EQUAL(
"Info: some info\n"s, ss2.str());
417 #ifdef CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
421 void IoTests::testNativeFileStream()
426 fileStream.exceptions(ios_base::badbit | ios_base::failbit);
427 CPPUNIT_ASSERT(!fileStream.is_open());
428 fileStream.open(txtFilePath, ios_base::in);
429 CPPUNIT_ASSERT(fileStream.is_open());
430 #if defined(PLATFORM_WINDOWS) && defined(CPP_UTILITIES_USE_BOOST_IOSTREAMS)
431 CPPUNIT_ASSERT(fileStream.fileHandle() !=
nullptr);
433 CPPUNIT_ASSERT(fileStream.fileDescriptor() != -1);
435 CPPUNIT_ASSERT_EQUAL(
static_cast<char>(fileStream.get()),
'f');
436 fileStream.seekg(0, ios_base::end);
437 CPPUNIT_ASSERT_EQUAL(fileStream.tellg(),
static_cast<NativeFileStream::pos_type
>(47));
439 CPPUNIT_ASSERT(!fileStream.is_open());
441 fileStream.open(
"non existing file", ios_base::in | ios_base::out | ios_base::binary);
442 CPPUNIT_FAIL(
"expected exception");
443 }
catch (
const std::ios_base::failure &failure) {
444 #ifdef PLATFORM_WINDOWS
445 #ifdef CPP_UTILITIES_USE_BOOST_IOSTREAMS
457 #ifndef PLATFORM_WINDOWS
458 auto readWriteFileDescriptor = open(txtFilePath.data(), O_RDWR);
459 CPPUNIT_ASSERT(readWriteFileDescriptor);
460 fileStream.open(readWriteFileDescriptor, ios_base::in | ios_base::out | ios_base::binary);
461 CPPUNIT_ASSERT(fileStream.is_open());
462 CPPUNIT_ASSERT_EQUAL(
static_cast<char>(fileStream.get()),
'f');
463 fileStream.seekg(0, ios_base::end);
464 CPPUNIT_ASSERT_EQUAL(fileStream.tellg(),
static_cast<NativeFileStream::pos_type
>(47));
467 CPPUNIT_ASSERT(!fileStream.is_open());
470 fileStream.open(-1, ios_base::in | ios_base::out | ios_base::binary);
472 CPPUNIT_FAIL(
"expected exception");
473 }
catch (
const std::ios_base::failure &failure) {
474 #ifndef PLATFORM_WINDOWS
476 "expected error message",
"(basic_ios::clear|failed reading: Bad file descriptor): iostream error"s,
string(failure.what()));
485 fileStream2.exceptions(ios_base::failbit | ios_base::badbit);
486 fileStream2.open(txtFilePath, ios_base::in | ios_base::out | ios_base::app);
487 CPPUNIT_ASSERT(fileStream2.is_open());
488 fileStream2 <<
"foo";
491 CPPUNIT_ASSERT(!fileStream2.is_open());
492 CPPUNIT_ASSERT_EQUAL(
"file with non-ASCII character 'รค' in its name\nfoo"s,
readFile(txtFilePath, 50));
495 fileStream2.open(txtFilePath, ios_base::out | ios_base::trunc);
496 CPPUNIT_ASSERT(fileStream2.is_open());
497 fileStream2 <<
"bar";
499 CPPUNIT_ASSERT(!fileStream2.is_open());
500 CPPUNIT_ASSERT_EQUAL(
"bar"s,
readFile(txtFilePath, 4));
503 #ifdef PLATFORM_WINDOWS
504 const auto wideTxtFilePath = NativeFileStream::makeWidePath(txtFilePath);
505 const auto appendFileHandle = _wfopen(wideTxtFilePath.get(), L
"a+");
507 const auto appendFileHandle = fopen(txtFilePath.data(),
"a");
509 CPPUNIT_ASSERT(appendFileHandle);
510 fileStream2.open(fileno(appendFileHandle), ios_base::out | ios_base::app);
511 CPPUNIT_ASSERT(fileStream2.is_open());
512 fileStream2 <<
"foo";
514 CPPUNIT_ASSERT(!fileStream2.is_open());
515 CPPUNIT_ASSERT_EQUAL(
"barfoo"s,
readFile(txtFilePath, 7));
void testWriteFile()
Tests writeFile().
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...
CPP_UTILITIES_EXPORT void writeFile(std::string_view path, std::string_view contents)
Writes all contents to the specified file in a single call.
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()
Tests formatting functions of CppUtilities::EscapeCodes namespace.
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.
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...
ScopeList & data()
Returns the data of the file.
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().
std::istream::pos_type readRemainingBytes()
Returns the number of remaining bytes in the stream from the current offset.
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 ...