diff options
| author | Michael Albinus | 2020-09-06 20:45:29 +0200 |
|---|---|---|
| committer | Michael Albinus | 2020-09-06 20:45:29 +0200 |
| commit | 9ba575aeb3a28a856f40675510c5ccfcd10ef665 (patch) | |
| tree | 1d60e9d0ca21091be5ad61108860ad18700c1991 | |
| parent | 3444f397c7d20ca59f7b18f6fe95aa79b33727e5 (diff) | |
| download | emacs-9ba575aeb3a28a856f40675510c5ccfcd10ef665.tar.gz emacs-9ba575aeb3a28a856f40675510c5ccfcd10ef665.zip | |
More work on D-Bus error messages
* lisp/net/dbus.el (dbus-get-property): Adapt docstring.
(dbus-set-property): Handle case of `:write' access type.
(dbus-get-other-registered-properties): Rename from
`dbus-get-other-registered-property'.
(dbus-property-handler): Fix thinkos.
* src/dbusbind.c (xd_read_message_1): Add error_name to event args
in case of DBUS_MESSAGE_TYPE_ERROR.
* test/lisp/net/dbus-tests.el (dbus--test-enabled-session-bus)
(dbus--test-enabled-system-bus): Make them defconst.
(dbus--test-service, dbus--test-path, dbus--test-interface):
New defconst. Replace all occurences of `dbus-service-emacs' by
`dbus--test-service'.
(dbus--test-method-handler): New defun.
(dbus-test04-register-method, dbus-test05-register-property): New tests.
| -rw-r--r-- | lisp/net/dbus.el | 45 | ||||
| -rw-r--r-- | src/dbusbind.c | 12 | ||||
| -rw-r--r-- | test/lisp/net/dbus-tests.el | 222 |
3 files changed, 237 insertions, 42 deletions
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index ad5ff8d450e..ba6a66d79c7 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el | |||
| @@ -565,8 +565,9 @@ placed in the queue. | |||
| 565 | `:already-owner': Service is already the primary owner." | 565 | `:already-owner': Service is already the primary owner." |
| 566 | 566 | ||
| 567 | ;; Add Peer handler. | 567 | ;; Add Peer handler. |
| 568 | (dbus-register-method bus service nil dbus-interface-peer "Ping" | 568 | (dbus-register-method |
| 569 | #'dbus-peer-handler 'dont-register) | 569 | bus service nil dbus-interface-peer "Ping" |
| 570 | #'dbus-peer-handler 'dont-register) | ||
| 570 | 571 | ||
| 571 | ;; Add ObjectManager handler. | 572 | ;; Add ObjectManager handler. |
| 572 | (dbus-register-method | 573 | (dbus-register-method |
| @@ -1423,7 +1424,7 @@ be \"out\"." | |||
| 1423 | (defun dbus-get-property (bus service path interface property) | 1424 | (defun dbus-get-property (bus service path interface property) |
| 1424 | "Return the value of PROPERTY of INTERFACE. | 1425 | "Return the value of PROPERTY of INTERFACE. |
| 1425 | It will be checked at BUS, SERVICE, PATH. The result can be any | 1426 | It will be checked at BUS, SERVICE, PATH. The result can be any |
| 1426 | valid D-Bus value, or nil if there is no PROPERTY." | 1427 | valid D-Bus value, or nil if there is no PROPERTY, or PROPERTY cannot be read." |
| 1427 | (dbus-ignore-errors | 1428 | (dbus-ignore-errors |
| 1428 | ;; "Get" returns a variant, so we must use the `car'. | 1429 | ;; "Get" returns a variant, so we must use the `car'. |
| 1429 | (car | 1430 | (car |
| @@ -1440,8 +1441,11 @@ successfully set return VALUE. Otherwise, return nil." | |||
| 1440 | (dbus-call-method | 1441 | (dbus-call-method |
| 1441 | bus service path dbus-interface-properties | 1442 | bus service path dbus-interface-properties |
| 1442 | "Set" :timeout 500 interface property (list :variant value)) | 1443 | "Set" :timeout 500 interface property (list :variant value)) |
| 1443 | ;; Return VALUE. | 1444 | ;; Return VALUE. The property could have the `:write' access type, |
| 1444 | (dbus-get-property bus service path interface property))) | 1445 | ;; so we ignore errors in `dbus-get-property'. |
| 1446 | (or | ||
| 1447 | (dbus-ignore-errors (dbus-get-property bus service path interface property)) | ||
| 1448 | value))) | ||
| 1445 | 1449 | ||
| 1446 | (defun dbus-get-all-properties (bus service path interface) | 1450 | (defun dbus-get-all-properties (bus service path interface) |
| 1447 | "Return all properties of INTERFACE at BUS, SERVICE, PATH. | 1451 | "Return all properties of INTERFACE at BUS, SERVICE, PATH. |
| @@ -1465,7 +1469,8 @@ Filter out not matching PATH." | |||
| 1465 | (gethash (list :property bus interface property) | 1469 | (gethash (list :property bus interface property) |
| 1466 | dbus-registered-objects-table))) | 1470 | dbus-registered-objects-table))) |
| 1467 | 1471 | ||
| 1468 | (defun dbus-get-other-registered-property (bus _service path interface property) | 1472 | (defun dbus-get-other-registered-properties |
| 1473 | (bus _service path interface property) | ||
| 1469 | "Return PROPERTY entry of `dbus-registered-objects-table'. | 1474 | "Return PROPERTY entry of `dbus-registered-objects-table'. |
| 1470 | Filter out matching PATH." | 1475 | Filter out matching PATH." |
| 1471 | ;; Remove matching entries. | 1476 | ;; Remove matching entries. |
| @@ -1551,7 +1556,7 @@ clients from discovering the still incomplete interface." | |||
| 1551 | (cons | 1556 | (cons |
| 1552 | (if emits-signal (list access :emits-signal) (list access)) | 1557 | (if emits-signal (list access :emits-signal) (list access)) |
| 1553 | value)) | 1558 | value)) |
| 1554 | (dbus-get-other-registered-property | 1559 | (dbus-get-other-registered-properties |
| 1555 | bus service path interface property)))) | 1560 | bus service path interface property)))) |
| 1556 | (puthash key val dbus-registered-objects-table) | 1561 | (puthash key val dbus-registered-objects-table) |
| 1557 | 1562 | ||
| @@ -1578,7 +1583,7 @@ It will be registered for all objects created by `dbus-register-property'." | |||
| 1578 | `(:error ,dbus-error-invalid-args | 1583 | `(:error ,dbus-error-invalid-args |
| 1579 | ,(format-message | 1584 | ,(format-message |
| 1580 | "No such property \"%s\" at path \"%s\"" property path))) | 1585 | "No such property \"%s\" at path \"%s\"" property path))) |
| 1581 | ((eq (car object) :write) | 1586 | ((memq :write (car object)) |
| 1582 | `(:error ,dbus-error-access-denied | 1587 | `(:error ,dbus-error-access-denied |
| 1583 | ,(format-message | 1588 | ,(format-message |
| 1584 | "Property \"%s\" at path \"%s\" is not readable" property path))) | 1589 | "Property \"%s\" at path \"%s\" is not readable" property path))) |
| @@ -1596,14 +1601,14 @@ It will be registered for all objects created by `dbus-register-property'." | |||
| 1596 | `(:error ,dbus-error-invalid-args | 1601 | `(:error ,dbus-error-invalid-args |
| 1597 | ,(format-message | 1602 | ,(format-message |
| 1598 | "No such property \"%s\" at path \"%s\"" property path))) | 1603 | "No such property \"%s\" at path \"%s\"" property path))) |
| 1599 | ((eq (car object) :read) | 1604 | ((memq :read (car object)) |
| 1600 | `(:error ,dbus-error-property-read-only | 1605 | `(:error ,dbus-error-property-read-only |
| 1601 | ,(format-message | 1606 | ,(format-message |
| 1602 | "Property \"%s\" at path \"%s\" is not writable" property path))) | 1607 | "Property \"%s\" at path \"%s\" is not writable" property path))) |
| 1603 | (t (puthash (list :property bus interface property) | 1608 | (t (puthash (list :property bus interface property) |
| 1604 | (cons (append (butlast (car entry)) | 1609 | (cons (append (butlast (car entry)) |
| 1605 | (list (cons (car object) value))) | 1610 | (list (cons (car object) value))) |
| 1606 | (dbus-get-other-registered-property | 1611 | (dbus-get-other-registered-properties |
| 1607 | bus service path interface property)) | 1612 | bus service path interface property)) |
| 1608 | dbus-registered-objects-table) | 1613 | dbus-registered-objects-table) |
| 1609 | ;; Send the "PropertiesChanged" signal. | 1614 | ;; Send the "PropertiesChanged" signal. |
| @@ -1625,15 +1630,17 @@ It will be registered for all objects created by `dbus-register-property'." | |||
| 1625 | (let (result) | 1630 | (let (result) |
| 1626 | (maphash | 1631 | (maphash |
| 1627 | (lambda (key val) | 1632 | (lambda (key val) |
| 1628 | (dolist (item val) | 1633 | (when (consp val) |
| 1629 | (when (and (equal (butlast key) (list :property bus interface)) | 1634 | (dolist (item val) |
| 1630 | (string-equal path (nth 2 item)) | 1635 | (when (and (equal (butlast key) (list :property bus interface)) |
| 1631 | (not (functionp (car (last item))))) | 1636 | (string-equal path (nth 2 item)) |
| 1632 | (push | 1637 | (consp (car (last item))) |
| 1633 | (list :dict-entry | 1638 | (not (memq :write (caar (last item))))) |
| 1634 | (car (last key)) | 1639 | (push |
| 1635 | (list :variant (cdar (last item)))) | 1640 | (list :dict-entry |
| 1636 | result)))) | 1641 | (car (last key)) |
| 1642 | (list :variant (cdar (last item)))) | ||
| 1643 | result))))) | ||
| 1637 | dbus-registered-objects-table) | 1644 | dbus-registered-objects-table) |
| 1638 | ;; Return the result, or an empty array. | 1645 | ;; Return the result, or an empty array. |
| 1639 | (list :array (or result '(:signature "{sv}")))))))) | 1646 | (list :array (or result '(:signature "{sv}")))))))) |
diff --git a/src/dbusbind.c b/src/dbusbind.c index 4fce92521a4..b637c0e58aa 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -1508,7 +1508,7 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1508 | int mtype; | 1508 | int mtype; |
| 1509 | dbus_uint32_t serial; | 1509 | dbus_uint32_t serial; |
| 1510 | unsigned int ui_serial; | 1510 | unsigned int ui_serial; |
| 1511 | const char *uname, *path, *interface, *member; | 1511 | const char *uname, *path, *interface, *member, *error_name; |
| 1512 | 1512 | ||
| 1513 | dmessage = dbus_connection_pop_message (connection); | 1513 | dmessage = dbus_connection_pop_message (connection); |
| 1514 | 1514 | ||
| @@ -1544,10 +1544,11 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1544 | path = dbus_message_get_path (dmessage); | 1544 | path = dbus_message_get_path (dmessage); |
| 1545 | interface = dbus_message_get_interface (dmessage); | 1545 | interface = dbus_message_get_interface (dmessage); |
| 1546 | member = dbus_message_get_member (dmessage); | 1546 | member = dbus_message_get_member (dmessage); |
| 1547 | error_name =dbus_message_get_error_name (dmessage); | ||
| 1547 | 1548 | ||
| 1548 | XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s", | 1549 | XD_DEBUG_MESSAGE ("Event received: %s %u %s %s %s %s %s %s", |
| 1549 | XD_MESSAGE_TYPE_TO_STRING (mtype), | 1550 | XD_MESSAGE_TYPE_TO_STRING (mtype), |
| 1550 | ui_serial, uname, path, interface, member, | 1551 | ui_serial, uname, path, interface, member, error_name, |
| 1551 | XD_OBJECT_TO_STRING (args)); | 1552 | XD_OBJECT_TO_STRING (args)); |
| 1552 | 1553 | ||
| 1553 | if (mtype == DBUS_MESSAGE_TYPE_INVALID) | 1554 | if (mtype == DBUS_MESSAGE_TYPE_INVALID) |
| @@ -1571,7 +1572,10 @@ xd_read_message_1 (DBusConnection *connection, Lisp_Object bus) | |||
| 1571 | EVENT_INIT (event); | 1572 | EVENT_INIT (event); |
| 1572 | event.kind = DBUS_EVENT; | 1573 | event.kind = DBUS_EVENT; |
| 1573 | event.frame_or_window = Qnil; | 1574 | event.frame_or_window = Qnil; |
| 1574 | event.arg = Fcons (value, args); | 1575 | event.arg = |
| 1576 | Fcons (value, | ||
| 1577 | (mtype == DBUS_MESSAGE_TYPE_ERROR) | ||
| 1578 | ? (Fcons (build_string (error_name), args)) : args); | ||
| 1575 | } | 1579 | } |
| 1576 | 1580 | ||
| 1577 | else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */ | 1581 | else /* DBUS_MESSAGE_TYPE_METHOD_CALL, DBUS_MESSAGE_TYPE_SIGNAL. */ |
diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el index 45c98513653..5e721459971 100644 --- a/test/lisp/net/dbus-tests.el +++ b/test/lisp/net/dbus-tests.el | |||
| @@ -25,16 +25,25 @@ | |||
| 25 | (defvar dbus-debug nil) | 25 | (defvar dbus-debug nil) |
| 26 | (declare-function dbus-get-unique-name "dbusbind.c" (bus)) | 26 | (declare-function dbus-get-unique-name "dbusbind.c" (bus)) |
| 27 | 27 | ||
| 28 | (defvar dbus--test-enabled-session-bus | 28 | (defconst dbus--test-enabled-session-bus |
| 29 | (and (featurep 'dbusbind) | 29 | (and (featurep 'dbusbind) |
| 30 | (dbus-ignore-errors (dbus-get-unique-name :session))) | 30 | (dbus-ignore-errors (dbus-get-unique-name :session))) |
| 31 | "Check, whether we are registered at the session bus.") | 31 | "Check, whether we are registered at the session bus.") |
| 32 | 32 | ||
| 33 | (defvar dbus--test-enabled-system-bus | 33 | (defconst dbus--test-enabled-system-bus |
| 34 | (and (featurep 'dbusbind) | 34 | (and (featurep 'dbusbind) |
| 35 | (dbus-ignore-errors (dbus-get-unique-name :system))) | 35 | (dbus-ignore-errors (dbus-get-unique-name :system))) |
| 36 | "Check, whether we are registered at the system bus.") | 36 | "Check, whether we are registered at the system bus.") |
| 37 | 37 | ||
| 38 | (defconst dbus--test-service "org.gnu.Emacs.TestDBus" | ||
| 39 | "Test service.") | ||
| 40 | |||
| 41 | (defconst dbus--test-path "/org/gnu/Emacs/TestDBus" | ||
| 42 | "Test object path.") | ||
| 43 | |||
| 44 | (defconst dbus--test-interface "org.gnu.Emacs.TestDBus" | ||
| 45 | "Test interface.") | ||
| 46 | |||
| 38 | (defun dbus--test-availability (bus) | 47 | (defun dbus--test-availability (bus) |
| 39 | "Test availability of D-Bus BUS." | 48 | "Test availability of D-Bus BUS." |
| 40 | (should (dbus-list-names bus)) | 49 | (should (dbus-list-names bus)) |
| @@ -85,19 +94,19 @@ | |||
| 85 | (defun dbus--test-register-service (bus) | 94 | (defun dbus--test-register-service (bus) |
| 86 | "Check service registration at BUS." | 95 | "Check service registration at BUS." |
| 87 | ;; Cleanup. | 96 | ;; Cleanup. |
| 88 | (dbus-ignore-errors (dbus-unregister-service bus dbus-service-emacs)) | 97 | (dbus-ignore-errors (dbus-unregister-service bus dbus--test-service)) |
| 89 | 98 | ||
| 90 | ;; Register an own service. | 99 | ;; Register an own service. |
| 91 | (should (eq (dbus-register-service bus dbus-service-emacs) :primary-owner)) | 100 | (should (eq (dbus-register-service bus dbus--test-service) :primary-owner)) |
| 92 | (should (member dbus-service-emacs (dbus-list-known-names bus))) | 101 | (should (member dbus--test-service (dbus-list-known-names bus))) |
| 93 | (should (eq (dbus-register-service bus dbus-service-emacs) :already-owner)) | 102 | (should (eq (dbus-register-service bus dbus--test-service) :already-owner)) |
| 94 | (should (member dbus-service-emacs (dbus-list-known-names bus))) | 103 | (should (member dbus--test-service (dbus-list-known-names bus))) |
| 95 | 104 | ||
| 96 | ;; Unregister the service. | 105 | ;; Unregister the service. |
| 97 | (should (eq (dbus-unregister-service bus dbus-service-emacs) :released)) | 106 | (should (eq (dbus-unregister-service bus dbus--test-service) :released)) |
| 98 | (should-not (member dbus-service-emacs (dbus-list-known-names bus))) | 107 | (should-not (member dbus--test-service (dbus-list-known-names bus))) |
| 99 | (should (eq (dbus-unregister-service bus dbus-service-emacs) :non-existent)) | 108 | (should (eq (dbus-unregister-service bus dbus--test-service) :non-existent)) |
| 100 | (should-not (member dbus-service-emacs (dbus-list-known-names bus))) | 109 | (should-not (member dbus--test-service (dbus-list-known-names bus))) |
| 101 | 110 | ||
| 102 | ;; `dbus-service-dbus' is reserved for the BUS itself. | 111 | ;; `dbus-service-dbus' is reserved for the BUS itself. |
| 103 | (should-error (dbus-register-service bus dbus-service-dbus)) | 112 | (should-error (dbus-register-service bus dbus-service-dbus)) |
| @@ -106,7 +115,7 @@ | |||
| 106 | (ert-deftest dbus-test02-register-service-session () | 115 | (ert-deftest dbus-test02-register-service-session () |
| 107 | "Check service registration at `:session' bus." | 116 | "Check service registration at `:session' bus." |
| 108 | (skip-unless (and dbus--test-enabled-session-bus | 117 | (skip-unless (and dbus--test-enabled-session-bus |
| 109 | (dbus-register-service :session dbus-service-emacs))) | 118 | (dbus-register-service :session dbus--test-service))) |
| 110 | (dbus--test-register-service :session) | 119 | (dbus--test-register-service :session) |
| 111 | 120 | ||
| 112 | (let ((service "org.freedesktop.Notifications")) | 121 | (let ((service "org.freedesktop.Notifications")) |
| @@ -124,7 +133,7 @@ | |||
| 124 | (ert-deftest dbus-test02-register-service-system () | 133 | (ert-deftest dbus-test02-register-service-system () |
| 125 | "Check service registration at `:system' bus." | 134 | "Check service registration at `:system' bus." |
| 126 | (skip-unless (and dbus--test-enabled-system-bus | 135 | (skip-unless (and dbus--test-enabled-system-bus |
| 127 | (dbus-register-service :system dbus-service-emacs))) | 136 | (dbus-register-service :system dbus--test-service))) |
| 128 | (dbus--test-register-service :system)) | 137 | (dbus--test-register-service :system)) |
| 129 | 138 | ||
| 130 | (ert-deftest dbus-test02-register-service-own-bus () | 139 | (ert-deftest dbus-test02-register-service-own-bus () |
| @@ -148,7 +157,7 @@ This includes initialization and closing the bus." | |||
| 148 | (featurep 'dbusbind) | 157 | (featurep 'dbusbind) |
| 149 | (dbus-init-bus bus) | 158 | (dbus-init-bus bus) |
| 150 | (dbus-get-unique-name bus) | 159 | (dbus-get-unique-name bus) |
| 151 | (dbus-register-service bus dbus-service-emacs)))) | 160 | (dbus-register-service bus dbus--test-service)))) |
| 152 | ;; Run the test. | 161 | ;; Run the test. |
| 153 | (dbus--test-register-service bus)) | 162 | (dbus--test-register-service bus)) |
| 154 | 163 | ||
| @@ -159,19 +168,194 @@ This includes initialization and closing the bus." | |||
| 159 | "Check `dbus-interface-peer' methods." | 168 | "Check `dbus-interface-peer' methods." |
| 160 | (skip-unless | 169 | (skip-unless |
| 161 | (and dbus--test-enabled-session-bus | 170 | (and dbus--test-enabled-session-bus |
| 162 | (dbus-register-service :session dbus-service-emacs) | 171 | (dbus-register-service :session dbus--test-service) |
| 163 | ;; "GetMachineId" is not implemented (yet). When it returns a | 172 | ;; "GetMachineId" is not implemented (yet). When it returns a |
| 164 | ;; value, another D-Bus client like dbus-monitor is reacting | 173 | ;; value, another D-Bus client like dbus-monitor is reacting |
| 165 | ;; on `dbus-interface-peer'. We cannot test then. | 174 | ;; on `dbus-interface-peer'. We cannot test then. |
| 166 | (not | 175 | (not |
| 167 | (dbus-ignore-errors | 176 | (dbus-ignore-errors |
| 168 | (dbus-call-method | 177 | (dbus-call-method |
| 169 | :session dbus-service-emacs dbus-path-dbus | 178 | :session dbus--test-service dbus-path-dbus |
| 170 | dbus-interface-peer "GetMachineId" :timeout 100))))) | 179 | dbus-interface-peer "GetMachineId" :timeout 100))))) |
| 171 | 180 | ||
| 172 | (should (dbus-ping :session dbus-service-emacs 100)) | 181 | (should (dbus-ping :session dbus--test-service 100)) |
| 173 | (dbus-unregister-service :session dbus-service-emacs) | 182 | (dbus-unregister-service :session dbus--test-service) |
| 174 | (should-not (dbus-ping :session dbus-service-emacs 100))) | 183 | (should-not (dbus-ping :session dbus--test-service 100))) |
| 184 | |||
| 185 | (defun dbus--test-method-handler (&rest args) | ||
| 186 | "Method handler for `dbus-test04-register-method'." | ||
| 187 | (cond | ||
| 188 | ;; No argument. | ||
| 189 | ((null args) | ||
| 190 | :ignore) | ||
| 191 | ;; One argument. | ||
| 192 | ((= 1 (length args)) | ||
| 193 | (car args)) | ||
| 194 | ;; Two arguments. | ||
| 195 | ((= 2 (length args)) | ||
| 196 | `(:error ,dbus-error-invalid-args | ||
| 197 | ,(format-message "Wrong arguments %s" args))) | ||
| 198 | ;; More than two arguments. | ||
| 199 | (t (signal 'dbus-error (cons "D-Bus signal" args))))) | ||
| 200 | |||
| 201 | (ert-deftest dbus-test04-register-method () | ||
| 202 | "Check method registration for an own service." | ||
| 203 | (skip-unless dbus--test-enabled-session-bus) | ||
| 204 | (dbus-ignore-errors (dbus-unregister-service :session dbus--test-service)) | ||
| 205 | |||
| 206 | (unwind-protect | ||
| 207 | (let ((method "Method") | ||
| 208 | (handler #'dbus--test-method-handler)) | ||
| 209 | |||
| 210 | (should | ||
| 211 | (equal | ||
| 212 | (dbus-register-method | ||
| 213 | :session dbus--test-service dbus--test-path | ||
| 214 | dbus--test-interface method handler) | ||
| 215 | `((:method :session ,dbus--test-interface ,method) | ||
| 216 | (,dbus--test-service ,dbus--test-path ,handler)))) | ||
| 217 | |||
| 218 | ;; No argument, returns nil. | ||
| 219 | (should-not | ||
| 220 | (dbus-call-method | ||
| 221 | :session dbus--test-service dbus--test-path | ||
| 222 | dbus--test-interface method)) | ||
| 223 | ;; One argument, returns the argument. | ||
| 224 | (should | ||
| 225 | (string-equal | ||
| 226 | (dbus-call-method | ||
| 227 | :session dbus--test-service dbus--test-path | ||
| 228 | dbus--test-interface method "foo") | ||
| 229 | "foo")) | ||
| 230 | ;; Two arguments, D-Bus error activated as `(:error ...)' list. | ||
| 231 | (should | ||
| 232 | (equal | ||
| 233 | (should-error | ||
| 234 | (dbus-call-method | ||
| 235 | :session dbus--test-service dbus--test-path | ||
| 236 | dbus--test-interface method "foo" "bar")) | ||
| 237 | `(dbus-error ,dbus-error-invalid-args "Wrong arguments (foo bar)"))) | ||
| 238 | ;; Three arguments, D-Bus error activated by `dbus-error' signal. | ||
| 239 | (should | ||
| 240 | (equal | ||
| 241 | (should-error | ||
| 242 | (dbus-call-method | ||
| 243 | :session dbus--test-service dbus--test-path | ||
| 244 | dbus--test-interface method "foo" "bar" "baz")) | ||
| 245 | `(dbus-error | ||
| 246 | ,dbus-error-failed | ||
| 247 | "D-Bus error: \"D-Bus signal\", \"foo\", \"bar\", \"baz\"")))) | ||
| 248 | |||
| 249 | ;; Cleanup. | ||
| 250 | (dbus-unregister-service :session dbus--test-service))) | ||
| 251 | |||
| 252 | (ert-deftest dbus-test05-register-property () | ||
| 253 | "Check property registration for an own service." | ||
| 254 | (skip-unless dbus--test-enabled-session-bus) | ||
| 255 | (dbus-ignore-errors (dbus-unregister-service :session dbus--test-service)) | ||
| 256 | |||
| 257 | (unwind-protect | ||
| 258 | (let ((property1 "Property1") | ||
| 259 | (property2 "Property2") | ||
| 260 | (property3 "Property3")) | ||
| 261 | |||
| 262 | ;; `:read' property. | ||
| 263 | (should | ||
| 264 | (equal | ||
| 265 | (dbus-register-property | ||
| 266 | :session dbus--test-service dbus--test-path | ||
| 267 | dbus--test-interface property1 :read "foo") | ||
| 268 | `((:property :session "org.gnu.Emacs.TestDBus" ,property1) | ||
| 269 | (,dbus--test-service ,dbus--test-path)))) | ||
| 270 | (should | ||
| 271 | (string-equal | ||
| 272 | (dbus-get-property | ||
| 273 | :session dbus--test-service dbus--test-path | ||
| 274 | dbus--test-interface property1) | ||
| 275 | "foo")) | ||
| 276 | (should-not ;; Due to `:read' access type. | ||
| 277 | (dbus-set-property | ||
| 278 | :session dbus--test-service dbus--test-path | ||
| 279 | dbus--test-interface property1 "foofoo")) | ||
| 280 | (should | ||
| 281 | (string-equal | ||
| 282 | (dbus-get-property | ||
| 283 | :session dbus--test-service dbus--test-path | ||
| 284 | dbus--test-interface property1) | ||
| 285 | "foo")) | ||
| 286 | |||
| 287 | ;; `:write' property. | ||
| 288 | (should | ||
| 289 | (equal | ||
| 290 | (dbus-register-property | ||
| 291 | :session dbus--test-service dbus--test-path | ||
| 292 | dbus--test-interface property2 :write "bar") | ||
| 293 | `((:property :session "org.gnu.Emacs.TestDBus" ,property2) | ||
| 294 | (,dbus--test-service ,dbus--test-path)))) | ||
| 295 | (should-not ;; Due to `:write' access type. | ||
| 296 | (dbus-get-property | ||
| 297 | :session dbus--test-service dbus--test-path | ||
| 298 | dbus--test-interface property2)) | ||
| 299 | (should | ||
| 300 | (string-equal | ||
| 301 | (dbus-set-property | ||
| 302 | :session dbus--test-service dbus--test-path | ||
| 303 | dbus--test-interface property2 "barbar") | ||
| 304 | "barbar")) | ||
| 305 | (should-not ;; Due to `:write' access type. | ||
| 306 | (dbus-get-property | ||
| 307 | :session dbus--test-service dbus--test-path | ||
| 308 | dbus--test-interface property2)) | ||
| 309 | |||
| 310 | ;; `:readwrite' property. | ||
| 311 | (should | ||
| 312 | (equal | ||
| 313 | (dbus-register-property | ||
| 314 | :session dbus--test-service dbus--test-path | ||
| 315 | dbus--test-interface property3 :readwrite "baz") | ||
| 316 | `((:property :session "org.gnu.Emacs.TestDBus" ,property3) | ||
| 317 | (,dbus--test-service ,dbus--test-path)))) | ||
| 318 | (should | ||
| 319 | (string-equal | ||
| 320 | (dbus-get-property | ||
| 321 | :session dbus--test-service dbus--test-path | ||
| 322 | dbus--test-interface property3) | ||
| 323 | "baz")) | ||
| 324 | (should | ||
| 325 | (string-equal | ||
| 326 | (dbus-set-property | ||
| 327 | :session dbus--test-service dbus--test-path | ||
| 328 | dbus--test-interface property3 "bazbaz") | ||
| 329 | "bazbaz")) | ||
| 330 | (should | ||
| 331 | (string-equal | ||
| 332 | (dbus-get-property | ||
| 333 | :session dbus--test-service dbus--test-path | ||
| 334 | dbus--test-interface property3) | ||
| 335 | "bazbaz")) | ||
| 336 | |||
| 337 | ;; `dbus-get-all-properties'. We cannot retrieve a value for | ||
| 338 | ;; the property with `:write' access type. | ||
| 339 | (let ((result | ||
| 340 | (dbus-get-all-properties | ||
| 341 | :session dbus--test-service dbus--test-path | ||
| 342 | dbus--test-interface))) | ||
| 343 | (should (string-equal (cdr (assoc property1 result)) "foo")) | ||
| 344 | (should (string-equal (cdr (assoc property3 result)) "bazbaz")) | ||
| 345 | (should-not (assoc property2 result)))) | ||
| 346 | |||
| 347 | ;; FIXME: This is wrong! The properties are missing. | ||
| 348 | ;; (should | ||
| 349 | ;; (equal | ||
| 350 | ;; (dbus-get-all-managed-objects | ||
| 351 | ;; :session dbus--test-service dbus--test-path) | ||
| 352 | ;; `((,dbus--test-path | ||
| 353 | ;; ((,dbus-interface-peer) | ||
| 354 | ;; (,dbus-interface-objectmanager) | ||
| 355 | ;; (,dbus-interface-properties))))))) | ||
| 356 | |||
| 357 | ;; Cleanup. | ||
| 358 | (dbus-unregister-service :session dbus--test-service))) | ||
| 175 | 359 | ||
| 176 | (defun dbus-test-all (&optional interactive) | 360 | (defun dbus-test-all (&optional interactive) |
| 177 | "Run all tests for \\[dbus]." | 361 | "Run all tests for \\[dbus]." |