| 1 | #include <cstdlib> |
| 2 | #include <string> |
| 3 | #include <fstream> |
| 4 | #include <iostream> |
| 5 | |
| 6 | int numberfn() |
| 7 | { |
| 8 | return 0x5a; |
| 9 | } |
| 10 | |
| 11 | int |
| 12 | main(int argc, char const *argv[]) |
| 13 | { |
| 14 | // The program writes its output to the following file: |
| 15 | // |
| 16 | // o "output1.txt" for test_pass_host_env_vars() test case |
| 17 | // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case |
| 18 | // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case |
| 19 | std::ofstream outfile; |
| 20 | if (argc == 1) |
| 21 | outfile.open(s: "output1.txt" ); |
| 22 | else |
| 23 | outfile.open(s: "output2.txt" ); |
| 24 | |
| 25 | for (unsigned i = 0; i < argc; ++i) { |
| 26 | std::string theArg(argv[i]); |
| 27 | if (i == 1 && "A" == theArg) |
| 28 | outfile << "argv[1] matches\n" ; |
| 29 | |
| 30 | if (i == 2 && "B" == theArg) |
| 31 | outfile << "argv[2] matches\n" ; |
| 32 | |
| 33 | if (i == 3 && "C" == theArg) |
| 34 | outfile << "argv[3] matches\n" ; |
| 35 | } |
| 36 | |
| 37 | // For passing environment vars from the debugger to the launched process. |
| 38 | if (::getenv(name: "MY_ENV_VAR" )) { |
| 39 | std::string MY_ENV_VAR(getenv(name: "MY_ENV_VAR" )); |
| 40 | if ("YES" == MY_ENV_VAR) { |
| 41 | outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n" ; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | |
| 46 | // For passing host environment vars to the launched process. |
| 47 | if (::getenv(name: "MY_HOST_ENV_VAR1" )) { |
| 48 | std::string MY_HOST_ENV_VAR1(getenv(name: "MY_HOST_ENV_VAR1" )); |
| 49 | if ("VAR1" == MY_HOST_ENV_VAR1) { |
| 50 | outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n" ; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if (::getenv(name: "MY_HOST_ENV_VAR2" )) { |
| 55 | std::string MY_HOST_ENV_VAR2(getenv(name: "MY_HOST_ENV_VAR2" )); |
| 56 | if ("VAR2" == MY_HOST_ENV_VAR2) { |
| 57 | outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n" ; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | std::cerr << "This message should go to standard error.\n" ; |
| 62 | std::cout << "This message should go to standard out.\n" ; |
| 63 | |
| 64 | outfile.close(); |
| 65 | return numberfn(); |
| 66 | } |
| 67 | |