From c1d920375c01028af23e11910accbdf298aa8dea Mon Sep 17 00:00:00 2001 From: Frank Benkstein Date: Sat, 29 Dec 2007 16:13:31 +0100 Subject: [PATCH] tests/test_process.c: test_create_child_process --- tests/test_process.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/test_process.c b/tests/test_process.c index c348c60..cb3712c 100644 --- a/tests/test_process.c +++ b/tests/test_process.c @@ -106,9 +106,40 @@ void test_create_child_function(void) (void) close(child.stdout_fd); } +void test_create_child_process(void) +{ + const char *s1 = "hello\n"; + const char *s2 = "olleh\n"; + ssize_t l1 = strlen(s1); + ssize_t l2 = strlen(s2); + const char *argv[] = { "sh", "-c", "rev", NULL }; + struct child_process child = { + .path = "/bin/sh", + .argv = argv, + .stdin_fd = REDIRECT_PIPE, + .stdout_fd = REDIRECT_PIPE, + .stderr_fd = REDIRECT_DEV_NULL, + .function = NULL, + }; + char buffer[LINE_MAX]; + + CU_ASSERT(create_child(&child)); + + CU_ASSERT(write(child.stdin_fd, s1, l1) == l1); + (void) close(child.stdin_fd); + + CU_ASSERT(read(child.stdout_fd, buffer, sizeof buffer) == l2); + (void) close(child.stdout_fd); + + CU_ASSERT(strncmp(buffer, s2, l2) == 0); + + CU_ASSERT(wait_for_death(child.pid, 0, 0)); +} + CU_TestInfo process_tests[] = { { "test_wait_for_death", test_wait_for_death }, { "test_ensure_death", test_ensure_death }, { "test_create_child_function", test_create_child_function }, + { "test_create_child_process", test_create_child_process }, CU_TEST_INFO_NULL, }; -- 2.11.4.GIT