Imported Upstream version 1.5.7
[platform/upstream/libpipeline.git] / tests / pump.c
index d52b65b..3f22f99 100644 (file)
@@ -23,8 +23,8 @@
 #  include "config.h"
 #endif
 
-#include <unistd.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include "full-write.h"
 #include "xalloc.h"
 /* Include private definitions so that we can inspect redirections. */
 #include "pipeline-private.h"
 
-static void fail_unless_files_equal (const char *left, const char *right)
+const char *program_name = "pump";
+
+static void assert_files_equal (const char *left, const char *right)
 {
-       pipeline *diff = pipeline_new_command_args
-               ("diff", "-u", left, right, NULL);
-       int ret = pipeline_run (diff);
-       fail_unless (ret == 0);
+       pipeline *diff = pipeline_new_command_args ("diff", "-u", left, right,
+                                                   (void *) 0);
+       ck_assert_int_eq (pipeline_run (diff), 0);
 }
 
 START_TEST (test_pump_connect_attaches_correctly)
@@ -49,18 +50,18 @@ START_TEST (test_pump_connect_attaches_correctly)
        pipeline *two = pipeline_new ();
        pipeline *three = pipeline_new ();
 
-       pipeline_connect (one, two, three, NULL);
-       fail_unless (one->redirect_out == REDIRECT_FD);
-       fail_unless (one->want_out < 0);
-       fail_unless (one->want_outfile == NULL);
-       fail_unless (two->source == one);
-       fail_unless (two->redirect_in == REDIRECT_FD);
-       fail_unless (two->want_in < 0);
-       fail_unless (two->want_infile == NULL);
-       fail_unless (three->source == one);
-       fail_unless (three->redirect_in == REDIRECT_FD);
-       fail_unless (three->want_in < 0);
-       fail_unless (three->want_infile == NULL);
+       pipeline_connect (one, two, three, (void *) 0);
+       ck_assert_int_eq (one->redirect_out, REDIRECT_FD);
+       ck_assert_int_le (one->want_out, 0);
+       ck_assert_ptr_eq (one->want_outfile, NULL);
+       ck_assert_ptr_eq (two->source, one);
+       ck_assert_int_eq (two->redirect_in, REDIRECT_FD);
+       ck_assert_int_le (two->want_in, 0);
+       ck_assert_ptr_eq (two->want_infile, NULL);
+       ck_assert_ptr_eq (three->source, one);
+       ck_assert_int_eq (three->redirect_in, REDIRECT_FD);
+       ck_assert_int_le (three->want_in, 0);
+       ck_assert_ptr_eq (three->want_infile, NULL);
 
        pipeline_free (three);
        pipeline_free (two);
@@ -68,7 +69,7 @@ START_TEST (test_pump_connect_attaches_correctly)
 }
 END_TEST
 
-static void tee_source (void *data PIPELINE_ATTR_UNUSED)
+static void tee_source (void *data _GL_UNUSED)
 {
        unsigned char buf[256];
        int i;
@@ -86,19 +87,21 @@ START_TEST (test_pump_tee)
        char *process_outfile, *function_outfile;
 
        source = pipeline_new ();
-       pipeline_command (source,
-                         pipecmd_new_function ("source", tee_source, 
-                                               NULL, NULL));
-       sink_process = pipeline_new_command_args ("cat", NULL);
+       pipeline_command (source, pipecmd_new_function ("source", tee_source,
+                                                       NULL, NULL));
+       sink_process = pipeline_new_command_args ("cat", (void *) 0);
        process_outfile = xasprintf ("%s/process", temp_dir);
        pipeline_want_outfile (sink_process, process_outfile);
        sink_function = pipeline_new ();
        pipeline_command (sink_function, pipecmd_new_passthrough ());
        function_outfile = xasprintf ("%s/function", temp_dir);
        pipeline_want_outfile (sink_function, function_outfile);
-       pipeline_connect (source, sink_process, sink_function, NULL);
-       pipeline_pump (source, sink_process, sink_function, NULL);
-       fail_unless_files_equal (process_outfile, function_outfile);
+       pipeline_connect (source, sink_process, sink_function, (void *) 0);
+       pipeline_pump (source, sink_process, sink_function, (void *) 0);
+       ck_assert_int_eq (pipeline_wait (source), 0);
+       ck_assert_int_eq (pipeline_wait (sink_process), 0);
+       ck_assert_int_eq (pipeline_wait (sink_function), 0);
+       assert_files_equal (process_outfile, function_outfile);
 
        free (function_outfile);
        free (process_outfile);
@@ -108,13 +111,13 @@ START_TEST (test_pump_tee)
 }
 END_TEST
 
-Suite *pump_suite (void)
+static Suite *pump_suite (void)
 {
        Suite *s = suite_create ("Pump");
 
        TEST_CASE (s, pump, connect_attaches_correctly);
-       TEST_CASE_WITH_FIXTURE (s, pump, tee,
-                               temp_dir_setup, temp_dir_teardown);
+       TEST_CASE_WITH_FIXTURE (s, pump, tee, temp_dir_setup,
+                               temp_dir_teardown);
 
        return s;
 }