C++ Utilities  4.12.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
iotests.cpp
Go to the documentation of this file.
1 #include "./testutils.h"
2 
3 #include "../conversion/conversionexception.h"
4 #include "../io/ansiescapecodes.h"
5 #include "../io/binaryreader.h"
6 #include "../io/binarywriter.h"
7 #include "../io/bitreader.h"
8 #include "../io/catchiofailure.h"
9 #include "../io/copy.h"
10 #include "../io/inifile.h"
11 #include "../io/misc.h"
12 #include "../io/path.h"
13 
14 #include <cppunit/TestFixture.h>
15 #include <cppunit/extensions/HelperMacros.h>
16 
17 #include <algorithm>
18 #include <fstream>
19 #include <sstream>
20 
21 using namespace std;
22 using namespace IoUtilities;
23 using namespace TestUtilities;
24 using namespace TestUtilities::Literals;
25 using namespace ConversionUtilities;
26 
27 using namespace CPPUNIT_NS;
28 
32 class IoTests : public TestFixture {
33  CPPUNIT_TEST_SUITE(IoTests);
34  CPPUNIT_TEST(testFailure);
35  CPPUNIT_TEST(testBinaryReader);
36  CPPUNIT_TEST(testBinaryWriter);
37  CPPUNIT_TEST(testBitReader);
38  CPPUNIT_TEST(testPathUtilities);
39  CPPUNIT_TEST(testIniFile);
40  CPPUNIT_TEST(testCopy);
41  CPPUNIT_TEST(testMisc);
42  CPPUNIT_TEST(testAnsiEscapeCodes);
43  CPPUNIT_TEST_SUITE_END();
44 
45 public:
46  void setUp();
47  void tearDown();
48 
49  void testFailure();
50  void testBinaryReader();
51  void testBinaryWriter();
52  void testBitReader();
53  void testPathUtilities();
54  void testIniFile();
55  void testCopy();
56  void testMisc();
57  void testAnsiEscapeCodes();
58 };
59 
61 
63 {
64 }
65 
67 {
68 }
69 
76 {
77  //fstream stream;
78  //stream.exceptions(ios_base::failbit | ios_base::badbit);
79  //CPPUNIT_ASSERT_THROW(stream.open("path/to/file/which/does/not/exist", ios_base::in), ios_base::failure);
80  // check other exceptions used by my applications, too
81  vector<int> testVec;
82  map<string, string> testMap;
83  CPPUNIT_ASSERT_THROW(testVec.at(1), out_of_range);
84  CPPUNIT_ASSERT_THROW(testMap.at("test"), out_of_range);
85 
86  // check workaround
87  try {
88  fstream stream;
89  stream.exceptions(ios_base::failbit | ios_base::badbit);
90  stream.open("path/to/file/which/does/not/exist", ios_base::in);
91  } catch (...) {
93  }
94 }
95 
100 {
101  // read test file
102  fstream testFile;
103  testFile.exceptions(ios_base::failbit | ios_base::badbit);
104  testFile.open(TestUtilities::testFilePath("some_data"), ios_base::in | ios_base::binary);
105  BinaryReader reader(&testFile);
106  CPPUNIT_ASSERT_EQUAL(reader.readStreamsize(), static_cast<istream::pos_type>(398));
107  CPPUNIT_ASSERT(reader.readUInt16LE() == 0x0102u);
108  CPPUNIT_ASSERT(reader.readUInt16BE() == 0x0102u);
109  CPPUNIT_ASSERT(reader.readUInt24LE() == 0x010203u);
110  CPPUNIT_ASSERT(reader.readUInt24BE() == 0x010203u);
111  CPPUNIT_ASSERT(reader.readUInt32LE() == 0x01020304u);
112  CPPUNIT_ASSERT(reader.readUInt32BE() == 0x01020304u);
113  CPPUNIT_ASSERT(reader.readUInt40LE() == 0x0102030405u);
114  CPPUNIT_ASSERT(reader.readUInt40BE() == 0x0102030405u);
115  CPPUNIT_ASSERT(reader.readUInt56LE() == 0x01020304050607u);
116  CPPUNIT_ASSERT(reader.readUInt56BE() == 0x01020304050607u);
117  CPPUNIT_ASSERT(reader.readUInt64LE() == 0x0102030405060708u);
118  CPPUNIT_ASSERT(reader.readUInt64BE() == 0x0102030405060708u);
119  testFile.seekg(0);
120  CPPUNIT_ASSERT(reader.readInt16LE() == 0x0102);
121  CPPUNIT_ASSERT(reader.readInt16BE() == 0x0102);
122  CPPUNIT_ASSERT(reader.readInt24LE() == 0x010203);
123  CPPUNIT_ASSERT(reader.readInt24BE() == 0x010203);
124  CPPUNIT_ASSERT(reader.readInt32LE() == 0x01020304);
125  CPPUNIT_ASSERT(reader.readInt32BE() == 0x01020304);
126  CPPUNIT_ASSERT(reader.readInt40LE() == 0x0102030405);
127  CPPUNIT_ASSERT(reader.readInt40BE() == 0x0102030405);
128  CPPUNIT_ASSERT(reader.readInt56LE() == 0x01020304050607);
129  CPPUNIT_ASSERT(reader.readInt56BE() == 0x01020304050607);
130  CPPUNIT_ASSERT(reader.readInt64LE() == 0x0102030405060708);
131  CPPUNIT_ASSERT(reader.readInt64BE() == 0x0102030405060708);
132  CPPUNIT_ASSERT(reader.readFloat32LE() == 1.125);
133  CPPUNIT_ASSERT(reader.readFloat64LE() == 1.625);
134  CPPUNIT_ASSERT(reader.readFloat32BE() == 1.125);
135  CPPUNIT_ASSERT(reader.readFloat64BE() == 1.625);
136  CPPUNIT_ASSERT(reader.readBool() == false);
137  CPPUNIT_ASSERT(reader.readBool() == true);
138  CPPUNIT_ASSERT(reader.readString(3) == "abc");
139  CPPUNIT_ASSERT(reader.readLengthPrefixedString() == "ABC");
140  CPPUNIT_ASSERT(reader.readLengthPrefixedString()
141  == "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
142  "23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123"
143  "45678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
144  "678901234567890123456789");
145  CPPUNIT_ASSERT_EQUAL("def"s, reader.readTerminatedString());
146  testFile.seekg(-4, ios_base::cur);
147  CPPUNIT_ASSERT_EQUAL("def"s, reader.readTerminatedString(5, 0));
148  testFile.seekg(-4, ios_base::cur);
149  CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(5, 0x6600));
150  testFile.seekg(-4, ios_base::cur);
151  CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(5, 0x0066));
152  testFile.seekg(-4, ios_base::cur);
153  CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(static_cast<uint16>(0x6600)));
154  testFile.seekg(-4, ios_base::cur);
155  CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(static_cast<uint16>(0x0066)));
156  CPPUNIT_ASSERT_THROW(reader.readLengthPrefixedString(), ConversionException);
157  CPPUNIT_ASSERT_MESSAGE("pos in stream not advanced on conversion error", reader.readByte() == 0);
158 
159  // test ownership
160  reader.setStream(nullptr, true);
161  reader.setStream(new fstream(), true);
162  BinaryReader reader2(reader);
163  CPPUNIT_ASSERT(reader2.stream() == reader.stream());
164  CPPUNIT_ASSERT(!reader2.hasOwnership());
165  reader.setStream(&testFile, false);
166  reader.setStream(new fstream(), true);
167 }
168 
173 {
174  // prepare reading expected data
175  fstream testFile;
176  testFile.exceptions(ios_base::failbit | ios_base::badbit);
177  testFile.open(TestUtilities::testFilePath("some_data"), ios_base::in | ios_base::binary);
178 
179  // prepare output stream
180  stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
181  outputStream.exceptions(ios_base::failbit | ios_base::badbit);
182  char testData[397];
183  outputStream.rdbuf()->pubsetbuf(testData, sizeof(testData));
184 
185  // write test data
186  BinaryWriter writer(&outputStream);
187  writer.writeUInt16LE(0x0102u);
188  writer.writeUInt16BE(0x0102u);
189  writer.writeUInt24LE(0x010203u);
190  writer.writeUInt24BE(0x010203u);
191  writer.writeUInt32LE(0x01020304u);
192  writer.writeUInt32BE(0x01020304u);
193  writer.writeUInt40LE(0x0102030405u);
194  writer.writeUInt40BE(0x0102030405u);
195  writer.writeUInt56LE(0x01020304050607u);
196  writer.writeUInt56BE(0x01020304050607u);
197  writer.writeUInt64LE(0x0102030405060708u);
198  writer.writeUInt64BE(0x0102030405060708u);
199 
200  // test written values
201  for (char c : testData) {
202  CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
203  if (testFile.tellg() >= 58) {
204  break;
205  }
206  }
207  testFile.seekg(0);
208  outputStream.seekp(0);
209 
210  // write more test data
211  writer.writeInt16LE(0x0102);
212  writer.writeInt16BE(0x0102);
213  writer.writeInt24LE(0x010203);
214  writer.writeInt24BE(0x010203);
215  writer.writeInt32LE(0x01020304);
216  writer.writeInt32BE(0x01020304);
217  writer.writeInt40LE(0x0102030405);
218  writer.writeInt40BE(0x0102030405);
219  writer.writeInt56LE(0x01020304050607);
220  writer.writeInt56BE(0x01020304050607);
221  writer.writeInt64LE(0x0102030405060708);
222  writer.writeInt64BE(0x0102030405060708);
223  writer.writeFloat32LE(1.125);
224  writer.writeFloat64LE(1.625);
225  writer.writeFloat32BE(1.125);
226  writer.writeFloat64BE(1.625);
227  writer.writeBool(false);
228  writer.writeBool(true);
229  writer.writeString("abc");
230  writer.writeLengthPrefixedString("ABC");
231  writer.writeLengthPrefixedString("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
232  "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901"
233  "234567890123456789012345678901234567890123456789012345678901234567890123456789");
234  writer.writeTerminatedString("def");
235 
236  // test written values
237  for (char c : testData) {
238  CPPUNIT_ASSERT(c == static_cast<char>(testFile.get()));
239  }
240 
241  // test ownership
242  writer.setStream(nullptr, true);
243  writer.setStream(new fstream(), true);
244  BinaryWriter writer2(writer);
245  CPPUNIT_ASSERT(writer2.stream() == writer.stream());
246  CPPUNIT_ASSERT(!writer2.hasOwnership());
247  writer.setStream(&testFile, false);
248  writer.setStream(new fstream(), true);
249 }
250 
255 {
256  const byte testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20, 0xFF, 0xFA };
257  BitReader reader(reinterpret_cast<const char *>(testData), sizeof(testData));
258  CPPUNIT_ASSERT(reader.readBit() == 1);
259  reader.skipBits(6);
260  CPPUNIT_ASSERT(reader.showBits<byte>(2) == 3);
261  CPPUNIT_ASSERT(reader.readBits<byte>(2) == 3);
262  CPPUNIT_ASSERT(reader.readBits<uint32>(32) == (0x103C4428 << 1));
263  reader.align();
264  CPPUNIT_ASSERT(reader.readBits<byte>(8) == 0x44);
265  CPPUNIT_ASSERT(reader.readUnsignedExpGolombCodedBits<byte>() == 7);
266  CPPUNIT_ASSERT(reader.readSignedExpGolombCodedBits<sbyte>() == 4);
267  CPPUNIT_ASSERT(reader.readBit() == 0);
268  CPPUNIT_ASSERT(reader.readBit() == 0);
269  reader.skipBits(8 + 4);
270  CPPUNIT_ASSERT_EQUAL(4_st, reader.bitsAvailable());
271  CPPUNIT_ASSERT_EQUAL(static_cast<byte>(0xA), reader.readBits<byte>(4));
272  try {
273  reader.readBit();
274  CPPUNIT_FAIL("no exception");
275  } catch (...) {
276  catchIoFailure();
277  }
278  try {
279  reader.skipBits(1);
280  CPPUNIT_FAIL("no exception");
281  } catch (...) {
282  catchIoFailure();
283  }
284  reader.reset(reinterpret_cast<const char *>(testData), sizeof(testData));
285  CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(8 * sizeof(testData)), reader.bitsAvailable());
286 }
287 
292 {
293  CPPUNIT_ASSERT_EQUAL("libc++utilities.so"s, fileName("C:\\libs\\libc++utilities.so"));
294  CPPUNIT_ASSERT_EQUAL("libc++utilities.so"s, fileName("C:\\libs/libc++utilities.so"));
295  CPPUNIT_ASSERT_EQUAL("libc++utilities.so"s, fileName("/usr/lib/libc++utilities.so"));
296  CPPUNIT_ASSERT_EQUAL("/usr/lib/"s, directory("/usr/lib/libc++utilities.so"));
297  CPPUNIT_ASSERT_EQUAL(string(), directory("libc++utilities.so"));
298  CPPUNIT_ASSERT_EQUAL("C:\\libs\\"s, directory("C:\\libs\\libc++utilities.so"));
299  CPPUNIT_ASSERT_EQUAL("C:\\libs/"s, directory("C:\\libs/libc++utilities.so"));
300  string invalidPath("lib/c++uti*lities.so?");
301  removeInvalidChars(invalidPath);
302  CPPUNIT_ASSERT(invalidPath == "libc++utilities.so");
303 #ifdef PLATFORM_UNIX
304  const string iniFilePath = TestUtilities::testFilePath("test.ini");
305  const string testFilesDir = iniFilePath.substr(0, iniFilePath.size() - 9);
306  auto testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::All);
307  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") != testFilesDirEntries.cend());
308  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") != testFilesDirEntries.cend());
309  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") != testFilesDirEntries.cend());
310  testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::Directory);
311  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") == testFilesDirEntries.cend());
312  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") != testFilesDirEntries.cend());
313  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") != testFilesDirEntries.cend());
314  testFilesDirEntries = directoryEntries(testFilesDir.c_str(), DirectoryEntryType::File);
315  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "test.ini") != testFilesDirEntries.cend());
316  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), ".") == testFilesDirEntries.cend());
317  CPPUNIT_ASSERT(find(testFilesDirEntries.cbegin(), testFilesDirEntries.cend(), "..") == testFilesDirEntries.cend());
318 #endif
319 }
320 
325 {
326  // prepare reading test file
327  fstream inputFile;
328  inputFile.exceptions(ios_base::failbit | ios_base::badbit);
329  inputFile.open(TestUtilities::testFilePath("test.ini"), ios_base::in);
330 
331  IniFile ini;
332  ini.parse(inputFile);
333  const auto globalScope = ini.data().at(0);
334  const auto scope1 = ini.data().at(1);
335  const auto scope2 = ini.data().at(2);
336  CPPUNIT_ASSERT(globalScope.first.empty());
337  CPPUNIT_ASSERT(globalScope.second.find("key0") != globalScope.second.cend());
338  CPPUNIT_ASSERT(globalScope.second.find("key0")->second == "value 0");
339  CPPUNIT_ASSERT(globalScope.second.find("key1") == globalScope.second.cend());
340  CPPUNIT_ASSERT(scope1.first == "scope 1");
341  CPPUNIT_ASSERT(scope1.second.find("key1") != scope1.second.cend());
342  CPPUNIT_ASSERT(scope1.second.find("key1")->second == "value 1");
343  CPPUNIT_ASSERT(scope1.second.find("key2") != scope1.second.cend());
344  CPPUNIT_ASSERT(scope1.second.find("key2")->second == "value=2");
345  CPPUNIT_ASSERT(scope2.first == "scope 2");
346  CPPUNIT_ASSERT(scope2.second.find("key5") == scope2.second.cend());
347 
348  // write values to another file
349  fstream outputFile;
350  outputFile.exceptions(ios_base::failbit | ios_base::badbit);
351  outputFile.open(workingCopyPathMode("output.ini", WorkingCopyMode::NoCopy), ios_base::out | ios_base::trunc);
352  ini.make(outputFile);
353 
354  // parse written values (again)
355  outputFile.close();
356  outputFile.open(workingCopyPathMode("output.ini", WorkingCopyMode::NoCopy), ios_base::in);
357  IniFile ini2;
358  ini2.parse(outputFile);
359  CPPUNIT_ASSERT(ini.data() == ini2.data());
360 }
361 
366 {
367  // prepare streams
368  fstream testFile;
369  testFile.exceptions(ios_base::failbit | ios_base::badbit);
370  testFile.open(TestUtilities::testFilePath("some_data"), ios_base::in | ios_base::binary);
371  stringstream outputStream(ios_base::in | ios_base::out | ios_base::binary);
372  outputStream.exceptions(ios_base::failbit | ios_base::badbit);
373 
374  // copy
375  CopyHelper<13> copyHelper;
376  copyHelper.copy(testFile, outputStream, 50);
377 
378  // test
379  testFile.seekg(0);
380  for (byte i = 0; i < 50; ++i) {
381  CPPUNIT_ASSERT(testFile.get() == outputStream.get());
382  }
383 }
384 
389 {
390  const string iniFilePath(testFilePath("test.ini"));
391  CPPUNIT_ASSERT_EQUAL("# file for testing INI parser\n"
392  "key0=value 0\n"
393  "\n"
394  "[scope 1]\n"
395  "key1=value 1 # comment\n"
396  "key2=value=2\n"
397  "key3=value 3\n"
398  "\n"
399  "[scope 2]\n"
400  "key4=value 4\n"
401  "#key5=value 5\n"
402  "key6=value 6\n"s,
403  readFile(iniFilePath));
404  try {
405  readFile(iniFilePath, 10);
406  CPPUNIT_FAIL("no exception");
407  } catch (...) {
408  catchIoFailure();
409  }
410 }
411 
413 {
414  stringstream ss1;
415  EscapeCodes::enabled = true;
416  ss1 << EscapeCodes::Phrases::Error << "some error" << EscapeCodes::Phrases::End;
417  ss1 << EscapeCodes::Phrases::Warning << "some warning" << EscapeCodes::Phrases::End;
418  ss1 << EscapeCodes::Phrases::Info << "some info" << EscapeCodes::Phrases::End;
419  ss1 << EscapeCodes::Phrases::ErrorMessage << "Arch-style error" << EscapeCodes::Phrases::End;
420  ss1 << EscapeCodes::Phrases::WarningMessage << "Arch-style warning" << EscapeCodes::Phrases::End;
421  ss1 << EscapeCodes::Phrases::PlainMessage << "Arch-style message" << EscapeCodes::Phrases::End;
422  ss1 << EscapeCodes::Phrases::SuccessMessage << "Arch-style success" << EscapeCodes::Phrases::End;
423  ss1 << EscapeCodes::Phrases::SubMessage << "Arch-style sub-message" << EscapeCodes::Phrases::End;
425  << "blue, blinking text on red background" << EscapeCodes::TextAttribute::Reset << '\n';
426  cout << "\noutput for formatting with ANSI escape codes:\n" << ss1.str() << "---------------------------------------------\n";
427  fstream("/tmp/test.txt", ios_base::out | ios_base::trunc) << ss1.str();
428  CPPUNIT_ASSERT_EQUAL("\e[1;31mError: \e[0m\e[1msome error\e[0m\n"
429  "\e[1;33mWarning: \e[0m\e[1msome warning\e[0m\n"
430  "\e[1;34mInfo: \e[0m\e[1msome info\e[0m\n"
431  "\e[1;31m==> ERROR: \e[0m\e[1mArch-style error\e[0m\n"
432  "\e[1;33m==> WARNING: \e[0m\e[1mArch-style warning\e[0m\n"
433  " \e[0m\e[1mArch-style message\e[0m\n"
434  "\e[1;32m==> \e[0m\e[1mArch-style success\e[0m\n"
435  "\e[1;32m -> \e[0m\e[1mArch-style sub-message\e[0m\n"
436  "\e[5;34;41mblue, blinking text on red background\e[0m\n"s,
437  ss1.str());
438 
439  stringstream ss2;
440  EscapeCodes::enabled = false;
441  ss2 << EscapeCodes::Phrases::Info << "some info" << EscapeCodes::Phrases::End;
442  CPPUNIT_ASSERT_EQUAL("Info: some info\n"s, ss2.str());
443 }
int64 readInt64LE()
Reads a 64-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:449
auto color(Color foreground, Color background, TextAttribute displayAttribute=TextAttribute::Reset)
bool readBool()
Reads a boolean value from the current stream and advances the current position of the stream by one ...
Definition: binaryreader.h:504
void writeInt24LE(int32 value)
Writes a 24-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:349
float32 readFloat32BE()
Reads a 32-bit big endian floating point value from the current stream and advances the current posit...
Definition: binaryreader.h:323
int64 readInt40BE()
Reads a 40-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:257
int16 readInt16LE()
Reads a 16-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:341
void writeFloat64LE(float64 value)
Writes a 64-bit little endian floating point value to the current stream and advances the current pos...
Definition: binarywriter.h:455
void writeInt56LE(int64 value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:409
Reads primitive data types from a std::istream.
Definition: binaryreader.h:11
float64 readFloat64LE()
Reads a 64-bit little endian floating point value from the current stream and advances the current po...
Definition: binaryreader.h:476
bool hasOwnership() const
Returns whether the writer takes ownership over the assigned stream.
Definition: binarywriter.h:104
int32 readInt32LE()
Reads a 32-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:383
Writes primitive data types to a std::ostream.
Definition: binarywriter.h:13
float32 readFloat32LE()
Reads a 32-bit little endian floating point value from the current stream and advances the current po...
Definition: binaryreader.h:467
intType readSignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (signed).
Definition: bitreader.h:119
uint32 readUInt24BE()
Reads a 24-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:229
int16 readInt16BE()
Reads a 16-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:197
intType readUnsignedExpGolombCodedBits()
Reads "Exp-Golomb coded" bits (unsigned).
Definition: bitreader.h:102
CPP_UTILITIES_EXPORT std::list< std::string > directoryEntries(const char *path, DirectoryEntryType types=DirectoryEntryType::All)
Returns the names of the directory entries in the specified path with the specified types...
Definition: path.cpp:181
The ConversionException class is thrown by the various conversion functions of this library when a co...
void testBinaryReader()
Tests the most important methods of the BinaryReader.
Definition: iotests.cpp:99
void writeInt40LE(int64 value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:389
The IoTests class tests classes and methods of the IoUtilities namespace.
Definition: iotests.cpp:32
void writeUInt24BE(uint32 value)
Writes a 24-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:226
STL namespace.
void make(std::ostream &outputStream)
Write the current data to the specified outputStream.
Definition: inifile.cpp:153
void testCopy()
Tests CopyHelper.
Definition: iotests.cpp:365
void writeUInt16BE(uint16 value)
Writes a 16-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:206
The CopyHelper class helps to copy bytes from one stream to another.
Definition: copy.h:16
void writeUInt56BE(uint64 value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:285
int64 readInt64BE()
Reads a 64-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:305
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
Definition: testutils.h:219
void writeUInt40BE(uint64 value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:265
void writeUInt16LE(uint16 value)
Writes a 16-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:339
void writeBool(bool value)
Writes a boolean value to the current stream and advances the current position of the stream by one b...
Definition: binarywriter.h:189
void testMisc()
Tests misc IO utilities.
Definition: iotests.cpp:388
void writeUInt24LE(uint32 value)
Writes a 24-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:360
The BitReader class provides bitwise reading of buffered data.
Definition: bitreader.h:14
float64 readFloat64BE()
Reads a 64-bit big endian floating point value from the current stream and advances the current posit...
Definition: binaryreader.h:332
std::vector< std::pair< std::string, std::multimap< std::string, std::string > > > & data()
Returns the data of the file.
Definition: inifile.h:38
int64 readInt56BE()
Reads a 56-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:281
std::size_t bitsAvailable()
Returns the number of bits which are still available to read.
Definition: bitreader.h:137
uint64 readUInt56LE()
Reads a 56-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:439
void writeInt16LE(int16 value)
Writes a 16-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:330
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.
Definition: misc.cpp:16
bool hasOwnership() const
Returns whether the reader takes ownership over the assigned stream.
Definition: binaryreader.h:114
void writeLengthPrefixedString(const std::string &value)
Writes the length of a string and the string itself to the current stream.
uint32 readUInt32LE()
Reads a 32-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:392
CPPUNIT_TEST_SUITE_REGISTRATION(IoTests)
void writeFloat64BE(float64 value)
Writes a 64-bit big endian floating point value to the current stream and advances the current positi...
Definition: binarywriter.h:321
void writeFloat32BE(float32 value)
Writes a 32-bit big endian floating point value to the current stream and advances the current positi...
Definition: binarywriter.h:312
uint32 readUInt32BE()
Reads a 32-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:248
Contains utility classes helping to read and write streams.
Definition: binaryreader.h:10
Contains classes and functions utilizing creating of test applications.
Definition: testutils.h:12
void writeUInt40LE(uint64 value)
Writes a 40-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:399
std::int8_t sbyte
signed byte
Definition: types.h:9
void setUp()
Definition: iotests.cpp:62
CPP_UTILITIES_EXPORT bool enabled
Controls whether the functions inside the EscapeCodes namespace actually make use of escape codes...
void testBinaryWriter()
Tests the most important methods of the BinaryWriter.
Definition: iotests.cpp:172
void setStream(std::ostream *stream, bool giveOwnership=false)
Assigns the stream the writer will write to when calling one of the write-methods.
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...
Definition: binarywriter.h:464
uint64 readUInt40BE()
Reads a 40-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:271
void writeInt56BE(int64 value)
Writes a 56-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:275
Contains several functions providing conversions between different data types.
void copy(std::istream &input, std::ostream &output, std::size_t count)
Copies count bytes from input to output.
Definition: copy.h:40
std::istream::pos_type readStreamsize()
Returns the size of the assigned stream.
uint64 readUInt64BE()
Reads a 64-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:314
std::uint32_t uint32
unsigned 32-bit integer
Definition: types.h:44
void writeUInt56LE(uint64 value)
Writes a 56-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:419
uint16 readUInt16LE()
Reads a 16-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:350
uint16 readUInt16BE()
Reads a 16-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:206
void writeUInt32LE(uint32 value)
Writes a 32-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:379
int32 readInt24LE()
Reads a 24-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:359
void writeInt32LE(int32 value)
Writes a 32-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:370
void writeInt16BE(int16 value)
Writes a 16-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:197
void testPathUtilities()
Tests fileName() and removeInvalidChars().
Definition: iotests.cpp:291
void testIniFile()
Tests IniFile.
Definition: iotests.cpp:324
void writeInt64LE(int64 value)
Writes a 64-bit little endian signed integer to the current stream and advances the current position ...
Definition: binarywriter.h:428
void setStream(std::istream *stream, bool giveOwnership=false)
Assigns the stream the reader will read from when calling one of the read-methods.
CPP_UTILITIES_EXPORT std::string directory(const std::string &path)
Returns the directory of the specified path string (including trailing slash).
Definition: path.cpp:52
std::string readTerminatedString(byte termination=0)
Reads a terminated string from the current stream.
const std::ostream * stream() const
Returns a pointer to the stream the writer will write to when calling one of the write-methods.
Definition: binarywriter.h:92
void writeUInt32BE(uint32 value)
Writes a 32-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:245
void writeInt24BE(int32 value)
Writes a 24-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:216
const std::istream * stream() const
Returns a pointer to the stream the reader will read from when calling one of the read-methods...
Definition: binaryreader.h:102
void skipBits(std::size_t bitCount)
Skips the specified number of bits without reading it.
Definition: bitreader.cpp:19
intType readBits(byte bitCount)
Reads the specified number of bits from the buffer advancing the current position by bitCount bits...
Definition: bitreader.h:68
void writeFloat32LE(float32 value)
Writes a 32-bit little endian floating point value to the current stream and advances the current pos...
Definition: binarywriter.h:446
void parse(std::istream &inputStream)
Parses all data from the specified inputStream.
Definition: inifile.cpp:18
int32 readInt32BE()
Reads a 32-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:239
int32 readInt24BE()
Reads a 24-bit big endian signed integer from the current stream and advances the current position of...
Definition: binaryreader.h:215
std::uint8_t byte
unsigned byte
Definition: types.h:14
void reset(const char *buffer, std::size_t bufferSize)
Resets the reader.
Definition: bitreader.h:148
void writeInt64BE(int64 value)
Writes a 64-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:294
The IniFile class parses and makes INI files.
Definition: inifile.h:12
void testFailure()
Tests for GCC Bug 66145.
Definition: iotests.cpp:75
std::string readMultibyteTerminatedStringLE(uint16 termination=0)
Reads a multibyte-terminated string from the current stream.
uint32 readUInt24LE()
Reads a 24-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:373
int64 readInt56LE()
Reads a 56-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:425
byte readByte()
Reads a single byte/unsigned character from the current stream and advances the current position of t...
Definition: binaryreader.h:494
void writeUInt64LE(uint64 value)
Writes a 64-bit little endian unsigned integer to the current stream and advances the current positio...
Definition: binarywriter.h:437
void writeInt32BE(int32 value)
Writes a 32-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:236
CPP_UTILITIES_EXPORT const char * catchIoFailure()
Provides a workaround for GCC Bug 66145.
CPP_UTILITIES_EXPORT std::string fileName(const std::string &path)
Returns the file name and extension of the specified path string.
Definition: path.cpp:32
uint64 readUInt64LE()
Reads a 64-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:458
void testBitReader()
Tests the BitReader.
Definition: iotests.cpp:254
CPP_UTILITIES_EXPORT void removeInvalidChars(std::string &fileName)
Removes invalid characters from the specified fileName.
Definition: path.cpp:74
void align()
Re-establishes alignment.
Definition: bitreader.h:171
void tearDown()
Definition: iotests.cpp:66
std::string readLengthPrefixedString()
Reads a length prefixed string from the current stream.
byte readBit()
Reads the one bit from the buffer advancing the current position by one bit.
Definition: bitreader.h:89
void writeUInt64BE(uint64 value)
Writes a 64-bit big endian unsigned integer to the current stream and advances the current position o...
Definition: binarywriter.h:303
std::string readMultibyteTerminatedStringBE(uint16 termination=0)
Reads a multibyte-terminated string from the current stream.
void writeTerminatedString(const std::string &value)
Writes a terminated string to the current stream and advances the current position of the stream by t...
Definition: binarywriter.h:472
uint64 readUInt56BE()
Reads a 56-bit big endian unsigned integer from the current stream and advances the current position ...
Definition: binaryreader.h:295
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...
int64 readInt40LE()
Reads a 40-bit little endian signed integer from the current stream and advances the current position...
Definition: binaryreader.h:401
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &name)
Convenience function which returns the full path of the test file with the specified name...
Definition: testutils.h:105
intType showBits(byte bitCount)
Reads the specified number of bits from the buffer without advancing the current position.
Definition: bitreader.h:128
void testAnsiEscapeCodes()
Definition: iotests.cpp:412
uint64 readUInt40LE()
Reads a 40-bit little endian unsigned integer from the current stream and advances the current positi...
Definition: binaryreader.h:415
void writeInt40BE(int64 value)
Writes a 40-bit big endian signed integer to the current stream and advances the current position of ...
Definition: binarywriter.h:255