1 /* GLib testing framework examples and tests
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
24 /* ---------------------------------------------------------------------------------------------------- */
27 on_notify_locked (GObject
*object
,
31 gint
*count
= user_data
;
42 m
= g_dbus_message_new ();
45 G_CALLBACK (on_notify_locked
),
47 g_assert (!g_dbus_message_get_locked (m
));
48 g_dbus_message_lock (m
);
49 g_assert (g_dbus_message_get_locked (m
));
50 g_assert_cmpint (count
, ==, 1);
51 g_dbus_message_lock (m
);
52 g_assert (g_dbus_message_get_locked (m
));
53 g_assert_cmpint (count
, ==, 1);
55 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
56 "*Attempted to modify a locked message*");
57 g_dbus_message_set_serial (m
, 42);
58 g_test_assert_expected_messages ();
60 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
61 "*Attempted to modify a locked message*");
62 g_dbus_message_set_byte_order (m
, G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN
);
63 g_test_assert_expected_messages ();
65 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
66 "*Attempted to modify a locked message*");
67 g_dbus_message_set_message_type (m
, G_DBUS_MESSAGE_TYPE_METHOD_CALL
);
68 g_test_assert_expected_messages ();
70 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
71 "*Attempted to modify a locked message*");
72 g_dbus_message_set_flags (m
, G_DBUS_MESSAGE_FLAGS_NONE
);
73 g_test_assert_expected_messages ();
75 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
76 "*Attempted to modify a locked message*");
77 g_dbus_message_set_body (m
, NULL
);
78 g_test_assert_expected_messages ();
80 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_WARNING
,
81 "*Attempted to modify a locked message*");
82 g_dbus_message_set_header (m
, 0, NULL
);
83 g_test_assert_expected_messages ();
88 /* ---------------------------------------------------------------------------------------------------- */
100 m
= g_dbus_message_new_method_call ("org.example.Name",
101 "/org/example/Object",
102 "org.example.Interface",
104 g_dbus_message_set_serial (m
, 42);
105 g_dbus_message_set_byte_order (m
, G_DBUS_MESSAGE_BYTE_ORDER_BIG_ENDIAN
);
108 copy
= g_dbus_message_copy (m
, &error
);
109 g_assert_no_error (error
);
110 g_assert (G_IS_DBUS_MESSAGE (copy
));
111 g_assert (m
!= copy
);
112 g_assert_cmpint (G_OBJECT (m
)->ref_count
, ==, 1);
113 g_assert_cmpint (G_OBJECT (copy
)->ref_count
, ==, 1);
115 g_assert_cmpint (g_dbus_message_get_serial (copy
), ==, g_dbus_message_get_serial (m
));
116 g_assert_cmpint (g_dbus_message_get_byte_order (copy
), ==, g_dbus_message_get_byte_order (m
));
117 g_assert_cmpint (g_dbus_message_get_flags (copy
), ==, g_dbus_message_get_flags (m
));
118 g_assert_cmpint (g_dbus_message_get_message_type (copy
), ==, g_dbus_message_get_message_type (m
));
119 m_headers
= g_dbus_message_get_header_fields (m
);
120 copy_headers
= g_dbus_message_get_header_fields (copy
);
121 g_assert (m_headers
!= NULL
);
122 g_assert (copy_headers
!= NULL
);
123 for (n
= 0; m_headers
[n
] != 0; n
++)
127 m_val
= g_dbus_message_get_header (m
, m_headers
[n
]);
128 copy_val
= g_dbus_message_get_header (m
, m_headers
[n
]);
129 g_assert (m_val
!= NULL
);
130 g_assert (copy_val
!= NULL
);
131 g_assert (g_variant_equal (m_val
, copy_val
));
133 g_assert_cmpint (n
, >, 0); /* make sure we actually compared headers etc. */
134 g_assert_cmpint (copy_headers
[n
], ==, 0);
136 g_free (copy_headers
);
138 g_object_unref (copy
);
142 /* ---------------------------------------------------------------------------------------------------- */
148 setlocale (LC_ALL
, "C");
150 g_test_init (&argc
, &argv
, NULL
);
152 g_test_add_func ("/gdbus/message/lock", message_lock
);
153 g_test_add_func ("/gdbus/message/copy", message_copy
);