]> git.mxchange.org Git - simgear.git/blob - simgear/misc/sgstream_test.cxx
HTTP: Rename urlretrieve/urlload to save/load.
[simgear.git] / simgear / misc / sgstream_test.cxx
1 #include <iostream>
2 #include <fstream>
3
4 #include <cstdlib> // for EXIT_FAILURE
5
6 using std::ofstream;
7 using std::cout;
8 using std::endl;
9
10 #include <simgear/misc/sgstream.hxx>
11
12 int main()
13 {
14     const char* fileName = "testfile";
15     {
16        ofstream f;
17        f.open(fileName, std::ios::binary | std::ios::trunc | std::ios::out);
18        f.write("first line ends with line-feed\n"
19            "second line ends with just a cr\r"
20            "third line ends with both\r\n"
21            "fourth line as well\r\n"
22            "fifth line is another CR/LF line\r\n"
23            "end of test\r\n", 1024);
24        f.close();
25    }
26
27    sg_gzifstream sg(fileName);
28    std::string stuff;
29    sg >> skipeol;
30    sg >> stuff;
31    if (stuff != "second") return EXIT_FAILURE;
32    cout << "Detection of LF works." << endl;
33
34    sg >> skipeol;
35    sg >> stuff;
36    if (stuff != "third") return EXIT_FAILURE;
37    cout << "Detection of CR works." << endl;
38
39    sg >> skipeol;
40    sg >> stuff;
41    if (stuff != "fourth") return EXIT_FAILURE;
42    cout << "Detection of CR/LF works." << endl;
43
44    sg >> skipeol;
45    sg >> skipeol;
46    sg >> stuff;
47    if (stuff != "end") return EXIT_FAILURE;
48    cout << "Detection of 2 following CR/LF lines works." << endl;
49
50    return EXIT_SUCCESS;
51 }