~xnox/ubuntu/raring/libnih/fix-xfs

« back to all changes in this revision

Viewing changes to nih-dbus-tool/tests/test_demarshal.c

  • Committer: Scott James Remnant
  • Date: 2010-12-23 22:08:49 UTC
  • mfrom: (0.1.4 upstream)
  • Revision ID: scott@netsplit.com-20101223220849-jf1o5p8bg51p28g9
* NEWS: Release 1.0.3
* nih-dbus-tool/type.c (type_const, type_of): Add support for the
DBUS_TYPE_UNIX_FD type, with a C type of "int".
* nih-dbus-tool/tests/test_type.c (test_const, test_of): Check the types
are correct.
* nih-dbus-tool/tests/marshal_factory.c: Generate function for
unix_fd testing
* nih-dbus-tool/tests/marshal_code.h: Add header for generated function
* nih-dbus-tool/tests/test_marshal.c (test_marshal): Test the generator
and the generated function
* nih-dbus-tool/tests/demarshal_factory.c: Generate function for
unix_fd testing
* nih-dbus-tool/tests/demarshal_code.h: Add header for generated function
* nih-dbus-tool/tests/test_demarshal.c (test_demarshal): Test the
generator and the generated code
* nih-dbus-tool/tests/com.netsplit.Nih.Test.xml: Add methods, signal and
properties for testing.
* nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.h: Add property
definition
* nih-dbus-tool/tests/com.netsplit.Nih.Test_impl.c (my_test_unix_fd_to_str)
(my_test_str_to_unix_fd, my_test_get_unix_fd)
(my_test_set_unix_fd): Test implementation.
* nih-dbus-tool/tests/test_com.netsplit.Nih.Test_object.c (test_unix_fd_to_str)
(test_str_to_unix_fd, test_new_unix_fd, test_get_unix_fd)
(test_set_unix_fd): Add methods to test the object implementation.
* nih-dbus-tool/tests/test_com.netsplit.Nih.Test_proxy.c (test_unix_fd_to_str)
(test_unix_fd_to_str_sync, test_str_to_unix_fd)
(test_str_to_unix_fd_sync, test_new_unix_fd, test_get_unix_fd)
(test_get_unix_fd_sync, test_set_unix_fd, test_set_unix_fd_sync): Add tests
for unix fds.
(test_get_all, test_get_all_sync): Add unix fd to tests.
* NEWS: Update
* configure.ac: Bump version to 1.0.3
* NEWS: Begin new release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * test_demarshal.c - test suite for nih-dbus-tool/demarshal.c
4
4
 *
5
 
 * Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
6
 
 * Copyright © 2009 Canonical Ltd.
 
5
 * Copyright © 2010 Scott James Remnant <scott@netsplit.com>.
 
6
 * Copyright © 2010 Canonical Ltd.
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License version 2, as
67
67
        MyStructValue *   struct_value;
68
68
        MyStructArrayValueElement **struct_array;
69
69
        MyDictEntryArrayValueElement **dict_entry_array;
 
70
        int               unix_fd_value;
70
71
 
71
72
        TEST_FUNCTION ("demarshal");
72
73
 
4778
4779
 
4779
4780
                dbus_shutdown ();
4780
4781
        }
 
4782
 
 
4783
 
 
4784
        /* Check that the code to demarshal a D-Bus file descriptor into an
 
4785
         * int is correctly generated and returned as an allocated string.
 
4786
         */
 
4787
        TEST_FEATURE ("with file descriptor");
 
4788
        TEST_ALLOC_FAIL {
 
4789
                nih_list_init (&outputs);
 
4790
                nih_list_init (&locals);
 
4791
                nih_list_init (&structs);
 
4792
 
 
4793
                dbus_signature_iter_init (&signature,
 
4794
                                          DBUS_TYPE_UNIX_FD_AS_STRING);
 
4795
 
 
4796
                str = demarshal (NULL, &signature,
 
4797
                                 "parent", "iter", "value",
 
4798
                                 "return -1;\n",
 
4799
                                 "return 1;\n",
 
4800
                                 &outputs, &locals,
 
4801
                                 "my", NULL, "unix_fd", "value",
 
4802
                                 &structs);
 
4803
 
 
4804
                if (test_alloc_failed) {
 
4805
                        TEST_EQ_P (str, NULL);
 
4806
                        TEST_LIST_EMPTY (&outputs);
 
4807
                        TEST_LIST_EMPTY (&locals);
 
4808
                        TEST_LIST_EMPTY (&structs);
 
4809
                        continue;
 
4810
                }
 
4811
 
 
4812
                TEST_EQ_STR (str, ("/* Demarshal a int from the message */\n"
 
4813
                                   "if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UNIX_FD) {\n"
 
4814
                                   "\treturn 1;\n"
 
4815
                                   "}\n"
 
4816
                                   "\n"
 
4817
                                   "dbus_message_iter_get_basic (&iter, &value);\n"
 
4818
                                   "\n"
 
4819
                                   "dbus_message_iter_next (&iter);\n"));
 
4820
 
 
4821
                TEST_LIST_NOT_EMPTY (&outputs);
 
4822
 
 
4823
                var = (TypeVar *)outputs.next;
 
4824
                TEST_ALLOC_SIZE (var, sizeof (TypeVar));
 
4825
                TEST_ALLOC_PARENT (var, str);
 
4826
                TEST_EQ_STR (var->type, "int");
 
4827
                TEST_ALLOC_PARENT (var->type, var);
 
4828
                TEST_EQ_STR (var->name, "value");
 
4829
                TEST_ALLOC_PARENT (var->name, var);
 
4830
                nih_free (var);
 
4831
 
 
4832
                TEST_LIST_EMPTY (&outputs);
 
4833
 
 
4834
                TEST_LIST_EMPTY (&locals);
 
4835
 
 
4836
                TEST_LIST_EMPTY (&structs);
 
4837
 
 
4838
                nih_free (str);
 
4839
        }
 
4840
 
 
4841
 
 
4842
        /* Check that the generated code takes the value from the D-Bus
 
4843
         * file descriptor in the message we pass and stores it in the int
 
4844
         * pointer, which should have the right value.
 
4845
         */
 
4846
        TEST_FEATURE ("with file descriptor (generated code)");
 
4847
        TEST_ALLOC_FAIL {
 
4848
                TEST_ALLOC_SAFE {
 
4849
                        message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
 
4850
 
 
4851
                        dbus_message_iter_init_append (message, &iter);
 
4852
 
 
4853
                        unix_fd_value = 1;
 
4854
                        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UNIX_FD,
 
4855
                                                        &unix_fd_value);
 
4856
                }
 
4857
 
 
4858
                unix_fd_value = -1;
 
4859
 
 
4860
                ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value);
 
4861
 
 
4862
                if (test_alloc_failed) {
 
4863
                        TEST_LT (ret, 0);
 
4864
 
 
4865
                        dbus_message_unref (message);
 
4866
                        dbus_shutdown ();
 
4867
                        continue;
 
4868
                }
 
4869
 
 
4870
                TEST_EQ (ret, 0);
 
4871
                TEST_GT (unix_fd_value, 2); // duplicated by dbus
 
4872
 
 
4873
                dbus_message_unref (message);
 
4874
                close (unix_fd_value);
 
4875
 
 
4876
                dbus_shutdown ();
 
4877
        }
 
4878
 
 
4879
 
 
4880
        /* Check that when a file descriptor is expected, but a different
 
4881
         * type is found, the type error code is run and the function returns
 
4882
         * without modifying the pointer.
 
4883
         */
 
4884
        TEST_FEATURE ("with wrong type for file descriptor (generated code)");
 
4885
        TEST_ALLOC_FAIL {
 
4886
                TEST_ALLOC_SAFE {
 
4887
                        message = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_CALL);
 
4888
 
 
4889
                        dbus_message_iter_init_append (message, &iter);
 
4890
 
 
4891
                        double_value = 3.14;
 
4892
                        dbus_message_iter_append_basic (&iter, DBUS_TYPE_DOUBLE,
 
4893
                                                        &double_value);
 
4894
                }
 
4895
 
 
4896
                unix_fd_value = -1;
 
4897
 
 
4898
                ret = my_unix_fd_demarshal (NULL, message, &unix_fd_value);
 
4899
 
 
4900
                if (test_alloc_failed) {
 
4901
                        TEST_LT (ret, 0);
 
4902
 
 
4903
                        dbus_message_unref (message);
 
4904
                        dbus_shutdown ();
 
4905
                        continue;
 
4906
                }
 
4907
 
 
4908
                TEST_GT (ret, 0);
 
4909
                TEST_EQ (unix_fd_value, -1);
 
4910
 
 
4911
                dbus_message_unref (message);
 
4912
 
 
4913
                dbus_shutdown ();
 
4914
        }
4781
4915
}
4782
4916
 
4783
4917