| 1016 | } |
| 1017 | |
| 1018 | static bool CheckGetLineFromStreamLongLine() |
| 1019 | { |
| 1020 | std::string const fileWithLongLine("longlines.txt"); |
| 1021 | std::string firstLine, secondLine; |
| 1022 | // First line: large buffer, containing a carriage return for some reason. |
| 1023 | firstLine.assign(2050, ' '); |
| 1024 | firstLine += "\rfirst"; |
| 1025 | secondLine.assign(2050, 'y'); |
| 1026 | secondLine += "second"; |
| 1027 | |
| 1028 | // Create file with long lines. |
| 1029 | { |
| 1030 | kwsys::ofstream out(fileWithLongLine.c_str(), std::ios::binary); |
| 1031 | if (!out) { |
| 1032 | std::cerr << "Problem opening for write: " << fileWithLongLine |
| 1033 | << std::endl; |
| 1034 | return false; |
| 1035 | } |
| 1036 | out << firstLine << "\r\n\n" << secondLine << "\n"; |
| 1037 | } |
| 1038 | |
| 1039 | kwsys::ifstream file(fileWithLongLine.c_str(), std::ios::binary); |
| 1040 | if (!file) { |
| 1041 | std::cerr << "Problem opening: " << fileWithLongLine << std::endl; |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | std::string line; |
| 1046 | bool has_newline = false; |
| 1047 | bool result; |
| 1048 | |
| 1049 | // Read first line. |
| 1050 | result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, |
| 1051 | std::string::npos); |
| 1052 | if (!result || line != firstLine) { |
| 1053 | std::cerr << "First line does not match, expected " << firstLine.size() |
| 1054 | << " characters, got " << line.size() << std::endl; |
| 1055 | return false; |
| 1056 | } |
| 1057 | if (!has_newline) { |
| 1058 | std::cerr << "Expected new line to be read from first line" << std::endl; |
| 1059 | return false; |
| 1060 | } |
| 1061 | |
| 1062 | // Read empty line. |
| 1063 | has_newline = false; |
| 1064 | result = kwsys::SystemTools::GetLineFromStream(file, line, &has_newline, |
| 1065 | std::string::npos); |
| 1066 | if (!result || !line.empty()) { |
| 1067 | std::cerr << "Expected successful read with an empty line, got " |
| 1068 | << line.size() << " characters" << std::endl; |
| 1069 | return false; |
| 1070 | } |
| 1071 | if (!has_newline) { |
| 1072 | std::cerr << "Expected new line to be read for an empty line" << std::endl; |
| 1073 | return false; |
| 1074 | } |
| 1075 |
no test coverage detected
searching dependent graphs…