aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2020-01-13 15:16:43 +0100
committerJay Berkenbilt <ejb@ql.org>2020-01-13 17:26:18 +0100
commit211a7f57be1913a32239b9868c85f18cd6b28683 (patch)
tree496fc07c16e80e373fe3bde3b68f147155f41fe9 /libtests/qutil.cc
parent9a398504ca869e00de15c713108264e0beead504 (diff)
downloadqpdf-211a7f57be1913a32239b9868c85f18cd6b28683.tar.zst
QUtil::read_lines_from_file: optional EOL preservation
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 0331d715..935cdfc2 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -418,6 +418,31 @@ void read_from_file_test()
fclose(fp);
}
+ // Test with EOL preservation
+ std::list<std::string> lines2 =
+ QUtil::read_lines_from_file("other-file", true);
+ auto line = lines2.begin();
+ assert(37 == (*line).length());
+ assert('.' == (*line).at(35));
+ assert('\n' == (*line).at(36));
+ ++line;
+ assert(24 == (*line).length());
+ assert('.' == (*line).at(21));
+ assert('\r' == (*line).at(22));
+ assert('\n' == (*line).at(23));
+ ++line;
+ assert(24591 == (*line).length());
+ assert('.' == (*line).at(24589));
+ assert('\n' == (*line).at(24590));
+ // Test the other versions and make sure we get the same results
+ {
+ std::ifstream infs("other-file", std::ios_base::binary);
+ assert(QUtil::read_lines_from_file(infs, true) == lines2);
+ FILE* fp = QUtil::safe_fopen("other-file", "rb");
+ assert(QUtil::read_lines_from_file(fp, true) == lines2);
+ fclose(fp);
+ }
+
PointerHolder<char> buf;
size_t size = 0;
QUtil::read_file_into_memory("other-file", buf, size);