Directory: | ./ |
---|---|
File: | tmp_project/PhoenixFileParser/TESTS/TEST_OPEN_FILE_STREAM/main.cpp |
Date: | 2025-03-14 12:04:36 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 38 | 38 | 100.0% |
Branches: | 83 | 83 | 100.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | |||
2 | /*************************************** | ||
3 | Auteur : Pierre Aubert | ||
4 | Mail : pierre.aubert@lapp.in2p3.fr | ||
5 | Licence : CeCILL-C | ||
6 | ****************************************/ | ||
7 | |||
8 | #include <iostream> | ||
9 | #include "phoenix_assert.h" | ||
10 | #include "phoenix_check.h" | ||
11 | #include "openFileStream.h" | ||
12 | |||
13 | ///Check the openFileStream | ||
14 | 1 | void checkOpenFileStream(){ | |
15 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::ofstream fs; |
16 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(openFileStream(fs, PPath("fileNameOut.txt"))); |
17 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
|
1 | fs << "some content" << std::endl; |
18 |
1/1✓ Branch 1 taken 1 times.
|
1 | fs.close(); |
19 | |||
20 |
1/1✓ Branch 1 taken 1 times.
|
1 | std::ifstream ifs; |
21 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(openFileStream(ifs, PPath("fileNameOut.txt"))); |
22 |
1/1✓ Branch 1 taken 1 times.
|
1 | PString fileContent(""); |
23 |
1/1✓ Branch 1 taken 1 times.
|
1 | ifs >> fileContent; |
24 |
1/1✓ Branch 1 taken 1 times.
|
1 | ifs.close(); |
25 | |||
26 |
4/4✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 14 taken 1 times.
|
1 | phoenix_assert(fileContent == "some"); //The input stream cut on blank characters |
27 | // std::cout << "checkOpenFileStream : fileContent = '" << fileContent << "'" << std::endl; | ||
28 | |||
29 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(!openFileStream(fs, PPath("outputDirWhichNotExist/test.txt"))); |
30 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(!openFileStream(ifs, PPath("unexistingFileNameOut.txt"))); |
31 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(!openFileStream(fs, PPath(""))); |
32 |
7/7✓ Branch 2 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 22 taken 1 times.
|
1 | phoenix_assert(!openFileStream(ifs, PPath(""))); |
33 | 1 | } | |
34 | |||
35 | ///Check the openFileStream | ||
36 | /** @param fileName : name of the file to be used as a model | ||
37 | * @param nbFile : number of files to be opened | ||
38 | * @return true on success, false otherwise | ||
39 | */ | ||
40 | 20 | bool checkOpenVecFileStream(const PPath & fileName, size_t nbFile){ | |
41 | 20 | bool b(true); | |
42 | 20 | PVecOFStream vecOut; | |
43 |
1/1✓ Branch 1 taken 20 times.
|
20 | b &= openFileStream(vecOut, fileName, nbFile); |
44 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 20 times.
|
110 | for(size_t i(0lu); i < nbFile; ++i){ |
45 |
2/2✓ Branch 2 taken 90 times.
✓ Branch 5 taken 90 times.
|
90 | vecOut[i] << i << std::endl; |
46 | } | ||
47 |
1/1✓ Branch 1 taken 20 times.
|
20 | closeFileStream(vecOut); |
48 | 20 | PVecIFStream vecIn; | |
49 |
1/1✓ Branch 1 taken 20 times.
|
20 | b &= openFileStream(vecIn, fileName, nbFile); |
50 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 20 times.
|
110 | for(size_t i(0lu); i < nbFile; ++i){ |
51 | 90 | size_t val(0lu); | |
52 |
1/1✓ Branch 2 taken 90 times.
|
90 | vecIn[i] >> val; |
53 |
2/2✓ Branch 2 taken 90 times.
✓ Branch 5 taken 90 times.
|
90 | b &= phoenix_check("checkOpenVecFileStream : read element", val, i); |
54 | } | ||
55 |
1/1✓ Branch 1 taken 20 times.
|
20 | closeFileStream(vecIn); |
56 | 20 | return b; | |
57 | 20 | } | |
58 | |||
59 | |||
60 | 1 | int main(int argc, char** argv){ | |
61 | 1 | checkOpenFileStream(); | |
62 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
|
11 | for(size_t i(0lu); i < 10lu; ++i){ |
63 |
7/7✓ Branch 2 taken 10 times.
✓ Branch 6 taken 10 times.
✓ Branch 10 taken 10 times.
✓ Branch 13 taken 10 times.
✓ Branch 16 taken 10 times.
✓ Branch 19 taken 10 times.
✓ Branch 22 taken 10 times.
|
10 | phoenix_assert(checkOpenVecFileStream(PPath("some_file_name.txt"), i)); |
64 |
7/7✓ Branch 2 taken 10 times.
✓ Branch 6 taken 10 times.
✓ Branch 10 taken 10 times.
✓ Branch 13 taken 10 times.
✓ Branch 16 taken 10 times.
✓ Branch 19 taken 10 times.
✓ Branch 22 taken 10 times.
|
10 | phoenix_assert(checkOpenVecFileStream(PPath("some_file_without_extention"), i)); |
65 | } | ||
66 | 1 | return 0; | |
67 | } | ||
68 | |||
69 | |||
70 |