diff options
Diffstat (limited to 'Source/kwsys/testFStream.cxx')
-rw-r--r-- | Source/kwsys/testFStream.cxx | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Source/kwsys/testFStream.cxx b/Source/kwsys/testFStream.cxx index afba953..3325e20 100644 --- a/Source/kwsys/testFStream.cxx +++ b/Source/kwsys/testFStream.cxx @@ -99,12 +99,50 @@ static int testBOM() return 0; } +static int testBOMIO() +{ + // test various encodings in binary mode + for (int i = 0; i < num_test_files; i++) { + kwsys::fstream f("bomio.txt", + kwsys::fstream::in | kwsys::fstream::out | + kwsys::fstream::binary | kwsys::fstream::trunc); + f.write(reinterpret_cast<const char*>(expected_bom_data[i] + 1), + *expected_bom_data[i]); + f.write(reinterpret_cast<const char*>(file_data[i] + 1), file_data[i][0]); + if (!f.good()) { + std::cout << "Unable to write data " << i << std::endl; + return 1; + } + f.seekp(0); + + kwsys::FStream::BOM bom = kwsys::FStream::ReadBOM(f); + if (bom != expected_bom[i]) { + std::cout << "Unexpected BOM " << i << std::endl; + return 1; + } + char data[max_test_file_size]; + f.read(data, file_data[i][0]); + if (!f.good()) { + std::cout << "Unable to read data " << i << std::endl; + return 1; + } + + if (memcmp(data, file_data[i] + 1, file_data[i][0]) != 0) { + std::cout << "Incorrect read data " << i << std::endl; + return 1; + } + } + + return 0; +} + int testFStream(int, char* []) { int ret = 0; ret |= testNoFile(); ret |= testBOM(); + ret |= testBOMIO(); return ret; } |