~cjdahlin/libnih/async

« back to all changes in this revision

Viewing changes to nih/tests/test_com.netsplit.Nih.Test_proxy.c

  • Committer: Casey Dahlin
  • Date: 2009-01-28 03:28:11 UTC
  • Revision ID: cdahlin@redhat.com-20090128032811-9igj4mtnmiklxbhj
* nih/dbus.h: Add NihAsyncNotifyData struct for passing data to the
DBusPendingCall callback.
* nih/nih_dbus_tool.py (asyncDispatchPrototype): Remove useless in_args/out_args
calculations and change arguments to use an NihAsyncNotifyData rather than just
a function pointer.
(asyncNotifyPrototype): Add userdata to callback prototype
(asyncNotifyFunction): Remove useless in_args calculations and change arguments
to use an NihAsyncNotifyData rather than just a function pointer. Also fix a
double deref, and make reply arguments allocated as children of the proxy.
(asyncDispatchFunction): Use NihAsyncNotifyData not a function pointer.
(staticPrototypes): Move async notify function here
(exportPrototypes): Remove async notify function from here
* nih/tests/test_com.netsplit.Nih.Test_proxy.c: Add a testcase for async calls

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
        char           **str_array;
57
57
        size_t           array_len;
58
58
        int              ret;
 
59
        int              called;
59
60
 
60
61
        TEST_GROUP ("method dispatching");
61
62
 
83
84
        my_teardown (conn);
84
85
 
85
86
 
 
87
        /* Check that we can make an asynchronous D-Bus method call, passing in
 
88
         * the expected arguments and receiving the expected arguments in the
 
89
         * callback.
 
90
         */
 
91
        TEST_FEATURE ("with valid argument (async)");
 
92
        conn = my_setup ();
 
93
        proxy = nih_dbus_proxy_new (NULL, conn, NULL, "/com/netsplit/Nih");
 
94
 
 
95
        auto void async_with_valid_argument (void *userdata, char *output);
 
96
 
 
97
        called = 0;
 
98
 
 
99
        ret = proxy_test_method_async (proxy, async_with_valid_argument,
 
100
                                       "userdata", "test data", 0);
 
101
 
 
102
        TEST_EQ (ret, 0);
 
103
 
 
104
        void async_with_valid_argument (void *userdata, char *async_output)
 
105
        {
 
106
                TEST_NE_P (async_output, NULL);
 
107
                TEST_ALLOC_PARENT (async_output, proxy);
 
108
                TEST_EQ_STR (async_output, "test data");
 
109
                TEST_EQ_STR (userdata, "userdata");
 
110
                called = 1;
 
111
        }
 
112
 
 
113
        while (! called)
 
114
                dbus_connection_read_write_dispatch (conn, -1);
 
115
 
 
116
        nih_free (proxy);
 
117
 
 
118
        my_teardown (conn);
 
119
 
 
120
 
86
121
        /* Check that if the method call returns a D-Bus error, the proxy
87
122
         * call returns a negative number and raises the same D-Bus error.
88
123
         */