diff --git a/simgear/misc/sgstream_test.cxx b/simgear/misc/sgstream_test.cxx index 71581b4b..43561e5c 100644 --- a/simgear/misc/sgstream_test.cxx +++ b/simgear/misc/sgstream_test.cxx @@ -1,52 +1,53 @@ #include -#include +#include // for EXIT_SUCCESS -#include // for EXIT_FAILURE - -using std::ofstream; +using std::string; using std::cout; using std::endl; +#include #include #include +#include int main() { - const char* fileName = "testfile"; + const string fileName = "testfile"; + simgear::Dir tmpDir = simgear::Dir::tempDir("FlightGear"); + tmpDir.setRemoveOnDestroy(); + SGPath p(tmpDir.path() / fileName); + { - ofstream f; - f.open(fileName, std::ios::binary | std::ios::trunc | std::ios::out); + sg_ofstream f(p, std::ios::binary | std::ios::trunc | std::ios::out); f.write("first line ends with line-feed\n" "second line ends with just a cr\r" "third line ends with both\r\n" "fourth line as well\r\n" "fifth line is another CR/LF line\r\n" "end of test\r\n", 158); - f.close(); - } + } - SGPath p(fileName); sg_gzifstream sg(p); std::string stuff; sg >> skipeol; sg >> stuff; - if (stuff != "second") return EXIT_FAILURE; + SG_CHECK_EQUAL(stuff, "second"); cout << "Detection of LF works." << endl; sg >> skipeol; sg >> stuff; - if (stuff != "third") return EXIT_FAILURE; + SG_CHECK_EQUAL(stuff, "third"); cout << "Detection of CR works." << endl; sg >> skipeol; sg >> stuff; - if (stuff != "fourth") return EXIT_FAILURE; + SG_CHECK_EQUAL(stuff, "fourth"); cout << "Detection of CR/LF works." << endl; sg >> skipeol; sg >> skipeol; sg >> stuff; - if (stuff != "end") return EXIT_FAILURE; + SG_CHECK_EQUAL(stuff, "end"); cout << "Detection of 2 following CR/LF lines works." << endl; return EXIT_SUCCESS;