14 #include <gtest/gtest.h>
20 #include "CommandExecuter.hpp"
28 HCE::Process::Args
args = {
"-r"};
30 std::stringstream
inMsg(
"def\nabc\n123\n");
31 HCE::Process::Env
env = {{
"key1",
"value1"}};
40 std::stringstream outMsg, errMsg;
45 ASSERT_EQ(outMsg.str(),
inMsg.str());
46 ASSERT_TRUE(errMsg.str().empty());
49 HCE::Process::Args argsEmpty;
55 ASSERT_TRUE(errMsg.str().empty());
57 catch(std::exception& e)
59 std::cerr <<
"Exception: " << e.what() <<
std::endl;
62 ASSERT_EQ(noErrors,
true);
70 std::stringstream outMsg, errMsg;
75 ASSERT_EQ(outMsg.str(),
inMsg.str());
76 ASSERT_TRUE(errMsg.str().empty());
79 HCE::Process::Args argsEmpty;
85 ASSERT_TRUE(errMsg.str().empty());
87 catch(std::exception& e)
89 std::cerr <<
"Exception: " << e.what() <<
std::endl;
92 ASSERT_EQ(noErrors,
true);
100 std::stringstream outMsg, errMsg;
103 ASSERT_TRUE(ph.
id());
105 ASSERT_EQ(outMsg.str(),
inMsg.str());
106 ASSERT_TRUE(errMsg.str().empty());
109 HCE::Process::Args argsEmpty;
112 ASSERT_TRUE(ph.
id());
115 ASSERT_TRUE(errMsg.str().empty());
117 catch(std::exception& e)
119 std::cerr <<
"Exception: " << e.what() <<
std::endl;
122 ASSERT_EQ(noErrors,
true);
127 bool noErrors =
true;
130 std::stringstream outMsg, errMsg;
133 ASSERT_TRUE(ph.
id());
135 ASSERT_EQ(outMsg.str(),
inMsg.str());
136 ASSERT_TRUE(errMsg.str().empty());
139 HCE::Process::Args argsEmpty;
142 ASSERT_TRUE(ph.
id());
145 ASSERT_TRUE(errMsg.str().empty());
147 catch(std::exception& e)
149 std::cerr <<
"Exception: " << e.what() <<
std::endl;
152 ASSERT_EQ(noErrors,
true);
157 bool noErrors =
true;
162 ASSERT_TRUE(ph.
id());
165 HCE::Process::Args argsEmpty;
168 ASSERT_TRUE(ph.
id());
171 catch(std::exception& e)
173 std::cerr <<
"Exception: " << e.what() <<
std::endl;
176 ASSERT_EQ(noErrors,
true);
181 bool noErrors =
true;
186 ASSERT_TRUE(ph.
id());
189 HCE::Process::Args argsEmpty;
192 ASSERT_TRUE(ph.
id());
195 catch(std::exception& e)
197 std::cerr <<
"Exception: " << e.what() <<
std::endl;
200 ASSERT_EQ(noErrors,
true);
205 bool noErrors =
true;
210 ASSERT_TRUE(ph.
id());
217 catch(std::exception& e)
219 std::cerr <<
"Exception: " << e.what() <<
std::endl;
222 ASSERT_EQ(noErrors,
true);
228 HCE::Process::Args
args = {
"-r"};
229 std::stringstream
inMsg(
"def\nabc\n123\n");
231 std::stringstream outMsg, errMsg;
233 bool ret = procExec.
exec(inMsg, outMsg, errMsg);
234 ASSERT_EQ(ret,
true);
235 ASSERT_EQ(procExec.
isError(),
false);
236 ASSERT_EQ(outMsg.str(), inMsg.str());
237 ASSERT_TRUE(errMsg.str().empty());
240 TEST(CommandExecutorTest, execute)
242 std::string
command =
"sort -r";
243 std::string shell =
"bash -c";
244 std::stringstream
inMsg(
"def\nabc\n123\n");
249 HCE::CommandExecuter commandExecuter;
252 ASSERT_EQ(commandResultData.
getIsError(),
false);
254 ASSERT_EQ(commandResultData.
getOutStream().str(), inMsg.str());
255 ASSERT_TRUE(commandResultData.
getErrStream().str().empty());
262 int main (
int argc,
char** argv)
264 testing::InitGoogleTest(&argc, argv);
265 return RUN_ALL_TESTS();