Brian Silverman | af78486 | 2014-05-13 08:14:55 -0700 | [diff] [blame^] | 1 | #include "aos/common/util/run_command.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | namespace aos { |
| 6 | namespace util { |
| 7 | namespace testing { |
| 8 | |
| 9 | TEST(RunCommandTest, True) { |
| 10 | int result = RunCommand("true"); |
| 11 | ASSERT_NE(-1, result); |
| 12 | ASSERT_TRUE(WIFEXITED(result)); |
| 13 | EXPECT_EQ(0, WEXITSTATUS(result)); |
| 14 | } |
| 15 | |
| 16 | TEST(RunCommandTest, False) { |
| 17 | int result = RunCommand("false"); |
| 18 | ASSERT_NE(-1, result); |
| 19 | ASSERT_TRUE(WIFEXITED(result)); |
| 20 | EXPECT_EQ(1, WEXITSTATUS(result)); |
| 21 | } |
| 22 | |
| 23 | TEST(RunCommandTest, CommandNotFound) { |
| 24 | int result = RunCommand("ajflkjasdlfa"); |
| 25 | ASSERT_NE(-1, result); |
| 26 | ASSERT_TRUE(WIFEXITED(result)); |
| 27 | EXPECT_EQ(127, WEXITSTATUS(result)); |
| 28 | } |
| 29 | |
| 30 | TEST(RunCommandTest, KilledBySignal) { |
| 31 | int result = RunCommand("kill -QUIT $$"); |
| 32 | ASSERT_NE(-1, result); |
| 33 | ASSERT_TRUE(WIFSIGNALED(result)); |
| 34 | EXPECT_EQ(SIGQUIT, WTERMSIG(result)); |
| 35 | } |
| 36 | |
| 37 | } // namespace testing |
| 38 | } // namespace util |
| 39 | } // namespace aos |