1 |
|
|
|
2 |
|
|
/*************************************** |
3 |
|
|
Auteur : Pierre Aubert |
4 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
5 |
|
|
Licence : CeCILL-C |
6 |
|
|
****************************************/ |
7 |
|
|
|
8 |
|
|
#include <iostream> |
9 |
|
|
#include "PStream.h" |
10 |
|
|
|
11 |
|
|
///Test the PStream |
12 |
|
|
/** @return true on success, false otherwise |
13 |
|
|
*/ |
14 |
|
1 |
bool testPStream(){ |
15 |
|
1 |
bool b(true); |
16 |
|
|
|
17 |
✓ |
2 |
PStream strOut; |
18 |
✓✓✓ |
1 |
b &= strOut.open("testInt.bin", "w"); |
19 |
✓ |
1 |
strOut << 42; |
20 |
✓ |
1 |
strOut.close(); |
21 |
|
|
|
22 |
✓ |
1 |
PStream strIn; |
23 |
✓✓✓ |
1 |
b &= strIn.open("testInt.bin", "r"); |
24 |
|
1 |
int val(0); |
25 |
✓ |
1 |
strIn >> val; |
26 |
|
|
|
27 |
✓✓✓ |
1 |
std::cout << "testPStream : val = " << val << std::endl; |
28 |
|
1 |
b &= val == 42; |
29 |
|
|
|
30 |
|
2 |
return b; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
///Test the PStream |
34 |
|
|
/** @return true on success, false otherwise |
35 |
|
|
*/ |
36 |
|
1 |
bool testPStreamTable(){ |
37 |
|
1 |
bool b(true); |
38 |
|
|
|
39 |
|
1 |
int tabInt [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
40 |
|
1 |
int tabIntRead [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
41 |
|
|
|
42 |
✓ |
2 |
PStream strOut; |
43 |
✓✓✓ |
1 |
b &= strOut.open("testTabInt.bin", "w"); |
44 |
✓ |
1 |
strOut.write(tabInt, 10lu); |
45 |
✓ |
1 |
strOut.close(); |
46 |
|
|
|
47 |
✓ |
1 |
PStream strIn; |
48 |
✓✓✓ |
1 |
b &= strIn.open("testTabInt.bin", "r"); |
49 |
✓ |
1 |
strIn.read(tabIntRead, 10lu); |
50 |
|
|
|
51 |
✓✓✓ |
1 |
std::cout << "testPStreamTable : tabIntRead[9] = " << tabIntRead[9] << std::endl; |
52 |
✓✓✓✗
|
11 |
for(size_t i(0); i < 10lu && b; ++i){ |
53 |
|
10 |
b &= tabInt[i] == tabIntRead[i]; |
54 |
|
|
} |
55 |
✓✓✓ |
1 |
std::cout << "testPStreamTable : b = " << b << std::endl; |
56 |
|
2 |
return b; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
|
///Test the PStream |
60 |
|
|
/** @return true on success, false otherwise |
61 |
|
|
*/ |
62 |
|
1 |
bool testPStreamMatrix(){ |
63 |
|
1 |
bool b(true); |
64 |
|
|
|
65 |
|
1 |
int tabInt [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
66 |
|
1 |
int tabIntRead [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
67 |
|
|
|
68 |
✓ |
2 |
PStream strOut; |
69 |
✓✓✓ |
1 |
b &= strOut.open("testMatInt.bin", "w"); |
70 |
✓ |
1 |
strOut.write(tabInt, 2lu, 5lu, 0lu); |
71 |
✓ |
1 |
strOut.close(); |
72 |
|
|
|
73 |
✓ |
1 |
PStream strIn; |
74 |
✓✓✓ |
1 |
b &= strIn.open("testMatInt.bin", "r"); |
75 |
✓ |
1 |
strIn.read(tabIntRead, 2lu, 5lu, 0lu); |
76 |
|
|
|
77 |
✓✓✓ |
1 |
std::cout << "testPStreamMatrix : tabIntRead[9] = " << tabIntRead[9] << std::endl; |
78 |
✓✓✓✗
|
11 |
for(size_t i(0); i < 10lu && b; ++i){ |
79 |
|
10 |
b &= tabInt[i] == tabIntRead[i]; |
80 |
|
|
} |
81 |
✓✓✓ |
1 |
std::cout << "testPStreamMatrix : b = " << b << std::endl; |
82 |
|
2 |
return b; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
1 |
int main(int argc, char** argv){ |
86 |
|
1 |
bool b(true); |
87 |
|
1 |
b &= testPStream(); |
88 |
|
1 |
b &= testPStreamTable(); |
89 |
|
1 |
b &= testPStreamMatrix(); |
90 |
|
1 |
return b - 1; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|