]> code.delx.au - gnu-emacs-elpa/blob - packages/dbus-codegen/tests/dbus-codegen-tests.el
Merge commit '0cda39255827f283e7578cd469ae42daad9556a2' from js2-mode
[gnu-emacs-elpa] / packages / dbus-codegen / tests / dbus-codegen-tests.el
1 ;; Copyright (C) 2015 Free Software Foundation, Inc.
2
3 ;; This file is part of GNU Emacs.
4
5 ;; GNU Emacs is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; GNU Emacs 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
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19
20 ;;; Code:
21
22 (require 'ert)
23 (require 'dbus-codegen)
24
25 (ert-deftest dbus-codegen--read-signature ()
26 (should (equal '(1 . :int32) (dbus-codegen--read-signature "i" 0)))
27 (should-error (dbus-codegen--read-signature "a" 0))
28 (should (equal '(2 :array :int32) (dbus-codegen--read-signature "ai" 0)))
29 (should (equal '(4 :array (:dict-entry :string :int32))
30 (dbus-codegen--read-signature "a{si}" 0)))
31 (should (equal '(4 :array (:dict-entry :string (:variant)))
32 (dbus-codegen--read-signature "a{sv}" 0)))
33 (should-error (dbus-codegen--read-signature "a{sii}" 0))
34 (should (equal '(5 :array (:struct (:string :int32 :int32)))
35 (dbus-codegen--read-signature "a(sii)" 0))))
36
37 (ert-deftest dbus-codegen--object-path-p ()
38 (should (dbus-codegen--object-path-p "/"))
39 (should (not (dbus-codegen--object-path-p "//")))
40 (should (not (dbus-codegen--object-path-p "/a/")))
41 (should (dbus-codegen--object-path-p "/a/b"))
42 (should (not (dbus-codegen--object-path-p "/a!")))
43 (should (dbus-codegen--object-path-p "/a")))
44
45 (ert-deftest dbus-codegen--annotate-arg ()
46 (should (equal '(:int32 1)
47 (dbus-codegen--annotate-arg ':int32 1)))
48 (should-error (dbus-codegen--annotate-arg '(:array :int32) 1))
49 (should (equal '((:array :int32 1 :int32 2 :int32 3))
50 (dbus-codegen--annotate-arg '(:array :int32) '(1 2 3))))
51 ;; Type mismatch of the first element of a struct.
52 (should-error (dbus-codegen--annotate-arg '(:struct :string :int32 :int32)
53 '(1 2 3)))
54 (should (equal '((:array (:dict-entry :string "a" :int32 1)
55 (:dict-entry :string "b" :int32 2)
56 (:dict-entry :string "c" :int32 3)))
57 (dbus-codegen--annotate-arg
58 '(:array (:dict-entry :string :int32))
59 '(("a" . 1) ("b" . 2) ("c" . 3))))))
60
61 (defconst dbus-codegen-tests-introspection-data "\
62 <node>
63 <interface name='org.gtk.GDBus.PeerTestInterface'>
64 <method name='HelloPeer'>
65 <arg type='s' name='greeting' direction='in'/>
66 <arg type='s' name='response' direction='out'/>
67 </method>
68 <method name='EmitSignal'/>
69 <method name='EmitSignalWithNameSet'/>
70 <method name='OpenFile'>
71 <arg type='s' name='path' direction='in'/>
72 </method>
73 <signal name='PeerSignal'>
74 <arg type='s' name='a_string'/>
75 </signal>
76 <property type='s' name='PeerProperty' access='read'/>
77 <property type='s' name='PeerPropertyAnnotated' access='read'>
78 <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal'
79 value='false'/>
80 </property>
81 </interface>
82 </node>")
83
84 (ert-deftest dbus-codegen-define-proxy ()
85 (dbus-codegen-define-proxy test-proxy
86 dbus-codegen-tests-introspection-data
87 "org.gtk.GDBus.PeerTestInterface")
88 (should (fboundp 'test-proxy-create))
89 (should (fboundp 'test-proxy-destroy))
90 (should (fboundp 'test-proxy-hello-peer))
91 (should (fboundp 'test-proxy-hello-peer-asynchronously))
92 (should (fboundp 'test-proxy-emit-signal))
93 (should (fboundp 'test-proxy-emit-signal-asynchronously))
94 (should (fboundp 'test-proxy-emit-signal-with-name-set))
95 (should (fboundp 'test-proxy-emit-signal-with-name-set-asynchronously))
96 (should (fboundp 'test-proxy-open-file))
97 (should (fboundp 'test-proxy-open-file-asynchronously))
98 (should (fboundp 'test-proxy-register-peer-signal-signal))
99 (should (fboundp 'test-proxy-send-peer-signal-signal))
100 (should (fboundp 'test-proxy-handle-peer-signal-signal))
101 (should (fboundp 'test-proxy-peer-property))
102 (should (fboundp 'test-proxy-retrieve-peer-property-property))
103 (should (fboundp 'test-proxy-peer-property-annotated))
104 (should (fboundp 'test-proxy-retrieve-peer-property-annotated-property)))
105
106 (ert-deftest dbus-codegen-define-skeleton ()
107 (dbus-codegen-define-skeleton test-skeleton
108 dbus-codegen-tests-introspection-data
109 "org.gtk.GDBus.PeerTestInterface")
110 (should (fboundp 'test-skeleton-create))
111 (should (fboundp 'test-skeleton-destroy))
112 (should (fboundp 'test-skeleton-register-hello-peer-method))
113 (should (fboundp 'test-skeleton-handle-hello-peer-method))
114 (should (fboundp 'test-skeleton-register-emit-signal-method))
115 (should (fboundp 'test-skeleton-handle-emit-signal-method))
116 (should (fboundp 'test-skeleton-register-emit-signal-with-name-set-method))
117 (should (fboundp 'test-skeleton-handle-emit-signal-with-name-set-method))
118 (should (fboundp 'test-skeleton-register-open-file-method))
119 (should (fboundp 'test-skeleton-handle-open-file-method))
120 (should (fboundp 'test-skeleton-register-peer-signal-signal))
121 (should (fboundp 'test-skeleton-send-peer-signal-signal))
122 (should (fboundp 'test-skeleton-handle-peer-signal-signal))
123 (should (fboundp 'test-skeleton-register-peer-property-property))
124 (should (fboundp 'test-proxy-peer-property-annotated))
125 (should (fboundp 'test-proxy-retrieve-peer-property-annotated-property)))
126
127 (provide 'dbus-codegen-tests)
128
129 ;;; dbus-codegen-tests.el ends here