1 |
|
|
|
2 |
|
|
/*************************************** |
3 |
|
|
Auteur : Pierre Aubert |
4 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
5 |
|
|
Licence : CeCILL-C |
6 |
|
|
****************************************/ |
7 |
|
|
|
8 |
|
|
#include <iostream> |
9 |
|
|
#include <vector> |
10 |
|
|
#include "string_system.h" |
11 |
|
|
|
12 |
|
|
///Test the phoenix popen function |
13 |
|
|
/** @return true on success, false otherwise |
14 |
|
|
*/ |
15 |
|
1 |
bool testPoenixPOpen(){ |
16 |
|
1 |
bool b(true); |
17 |
|
|
|
18 |
✓✓ |
3 |
std::string resCmd1(phoenix_popen("echo \"test command\"")); |
19 |
✓✓✓✓
|
1 |
std::cout << "testPoenixPOpen : resCmd1 = '" << resCmd1 << "'" << std::endl; |
20 |
|
1 |
b &= resCmd1 == "test command\n"; |
21 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
22 |
|
|
|
23 |
✓✓ |
1 |
b &= phoenix_popen("") == ""; |
24 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
25 |
|
|
|
26 |
✓✓ |
3 |
std::string resCmd3(phoenix_popen("someUnexistingCommad")); |
27 |
✓✓✓✓
|
1 |
std::cout << "testPoenixPOpen : resCmd3 = '" << resCmd3 << "'" << std::endl; |
28 |
|
1 |
b &= resCmd3 == "\0"; |
29 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
30 |
|
|
|
31 |
|
|
|
32 |
✓✓ |
1 |
int exitStatus1 = phoenix_popen(resCmd1, "echo \"test command\""); |
33 |
|
1 |
b &= resCmd1 == "test command\n"; |
34 |
|
1 |
b &= exitStatus1 == 0; |
35 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
36 |
|
|
|
37 |
✓ |
2 |
std::string resEmptyCmd(""); |
38 |
✓✓ |
1 |
int exitStatus2 = phoenix_popen(resEmptyCmd, ""); |
39 |
|
1 |
b &= resEmptyCmd == ""; |
40 |
|
1 |
b &= exitStatus2 == -1; |
41 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
42 |
|
|
|
43 |
✓ |
1 |
std::string resUnexistingCmd(""); |
44 |
✓✓ |
1 |
int exitStatus3 = phoenix_popen(resUnexistingCmd, "someUnexistingCommad"); |
45 |
|
1 |
b &= resUnexistingCmd == ""; |
46 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << std::endl; |
47 |
|
1 |
b &= exitStatus3 == 32512; |
48 |
✓✓✓✓ ✓ |
1 |
std::cout << "testPoenixPOpen : b = " << b << ", exitStatus3 = " << exitStatus3 << std::endl; |
49 |
|
|
|
50 |
✓✓✓ |
1 |
b &= phoenix_popen("command.log", "echo \"test command\"", true); |
51 |
✓✓✓ |
1 |
b &= phoenix_popen("command.log", "echo \"test command\"", false); |
52 |
✓✓✓ |
1 |
b &= !phoenix_popen("command_unexistingCommand.log", "someUnexistingCommand", true); |
53 |
✓✓✓ |
1 |
b &= !phoenix_popen("command_unexistingCommand.log", "someUnexistingCommand", false); |
54 |
✓✓✓ |
1 |
std::cout << "testPoenixPOpen : b =" << b << std::endl; |
55 |
|
2 |
return b; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
1 |
int main(int argc, char** argv){ |
59 |
|
1 |
bool b(true); |
60 |
|
1 |
b &= testPoenixPOpen(); |
61 |
|
1 |
std::cout << "Final : b =" << b << std::endl; |
62 |
|
1 |
return b - 1; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|