mirror of https://gitlab.com/cppit/jucipp
7 changed files with 96 additions and 36 deletions
@ -0,0 +1,50 @@
|
||||
#include <glib.h> |
||||
#include "process.hpp" |
||||
|
||||
int main() { |
||||
auto output=std::make_shared<std::string>(); |
||||
auto error=std::make_shared<std::string>(); |
||||
{ |
||||
Process process("echo Test", "", [output](const char *bytes, size_t n) { |
||||
*output+=std::string(bytes, n); |
||||
}); |
||||
g_assert(process.get_exit_status()==0); |
||||
g_assert(output->substr(0, 4)=="Test"); |
||||
output->clear(); |
||||
} |
||||
|
||||
{ |
||||
Process process("echo Test && ls an_incorrect_path", "", [output](const char *bytes, size_t n) { |
||||
*output+=std::string(bytes, n); |
||||
}, [error](const char *bytes, size_t n) { |
||||
*error+=std::string(bytes, n); |
||||
}); |
||||
g_assert(process.get_exit_status()>0); |
||||
g_assert(output->substr(0, 4)=="Test"); |
||||
g_assert(!error->empty()); |
||||
output->clear(); |
||||
error->clear(); |
||||
} |
||||
|
||||
{ |
||||
Process process("bash", "", [output](const char *bytes, size_t n) { |
||||
*output+=std::string(bytes, n); |
||||
}, nullptr, true); |
||||
process.write("echo Test\n"); |
||||
process.write("exit\n"); |
||||
g_assert(process.get_exit_status()==0); |
||||
g_assert(output->substr(0, 4)=="Test"); |
||||
output->clear(); |
||||
} |
||||
|
||||
{ |
||||
Process process("cat", "", [output](const char *bytes, size_t n) { |
||||
*output+=std::string(bytes, n); |
||||
}, nullptr, true); |
||||
process.write("Test\n"); |
||||
process.close_stdin(); |
||||
g_assert(process.get_exit_status()==0); |
||||
g_assert(output->substr(0, 4)=="Test"); |
||||
output->clear(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue