Debian Codegraph @

tests/arguments_basic_tests.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 2011, 2012 Reto Buerki <[email protected]>
5 --
6 -- This program is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU General Public License
8 -- as published by the Free Software Foundation; either version 2
9 -- of the License, or (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 -- USA.
20 --
21 -- As a special exception, if other files instantiate generics from this
22 -- unit, or you link this unit with other files to produce an
23 -- executable this unit does not by itself cause the resulting
24 -- executable to be covered by the GNU General Public License. This
25 -- exception does not however invalidate any other reasons why the
26 -- executable file might be covered by the GNU Public License.
27 --
28
29 with Ahven;
30
31 with Config;
32
33 with D_Bus.Types;
34 with D_Bus.Connection;
35 with D_Bus.Arguments.Basic;
36
37 package body Arguments_Basic_Tests is
38
39 use Ahven;
40 use D_Bus;
41 use D_Bus.Arguments;
42 use D_Bus.Arguments.Basic;
43 use type D_Bus.Types.Obj_Path;
44
45 -------------------------------------------------------------------------
46
47 procedure Initialize (T : in out Testcase) is
48 begin
49 T.Set_Name (Name => "Basic arguments handling");
50 T.Add_Test_Routine
51 (Routine => Marshal_String_Type'Access,
52 Name => "Marshal/unmarshal string type");
53 T.Add_Test_Routine
54 (Routine => Marshal_Object_Path_Type'Access,
55 Name => "Marshal/unmarshal object path type");
56 T.Add_Test_Routine
57 (Routine => Marshal_Boolean_Type'Access,
58 Name => "Marshal/unmarshal boolean type");
59 T.Add_Test_Routine
60 (Routine => Marshal_U_Int64_Type'Access,
61 Name => "Marshal/unmarshal uint64 type");
62 T.Add_Test_Routine
63 (Routine => Marshal_Int64_Type'Access,
64 Name => "Marshal/unmarshal int64 type");
65 T.Add_Test_Routine
66 (Routine => Marshal_U_Int32_Type'Access,
67 Name => "Marshal/unmarshal uint32 type");
68 T.Add_Test_Routine
69 (Routine => Marshal_Int32_Type'Access,
70 Name => "Marshal/unmarshal int32 type");
71 T.Add_Test_Routine
72 (Routine => Marshal_U_Int16_Type'Access,
73 Name => "Marshal/unmarshal uint16 type");
74 T.Add_Test_Routine
75 (Routine => Marshal_Int16_Type'Access,
76 Name => "Marshal/unmarshal int16 type");
77 T.Add_Test_Routine
78 (Routine => Marshal_Byte_Type'Access,
79 Name => "Marshal/unmarshal byte type");
80 end Initialize;
81
82 -------------------------------------------------------------------------
83
84 procedure Marshal_Boolean_Type
85 is
86 Conn : constant Connection.Connection_Type
87 := Connection.Connect (Address => Config.Service_Addr);
88 Result : Arguments.Argument_List_Type;
89 begin
90 Result := Connection.Call_Blocking
91 (Connection => Conn,
92 Destination => "dbus.ada.server",
93 Path => +"/",
94 Iface => "dbus.ada.server.type",
95 Method => "rebound",
96 Args => +True);
97
98 declare
99 Bool : constant Boolean_Type := Boolean_Type (Result.First_Element);
100 begin
101 Assert (Condition => Bool.To_Ada,
102 Message => "Result not True");
103 end;
104 end Marshal_Boolean_Type;
105
106 -------------------------------------------------------------------------
107
108 procedure Marshal_Byte_Type
109 is
110 Conn : constant Connection.Connection_Type
111 := Connection.Connect (Address => Config.Service_Addr);
112 Result : Argument_List_Type;
113 begin
114 Result := Connection.Call_Blocking
115 (Connection => Conn,
116 Destination => "dbus.ada.server",
117 Path => +"/",
118 Iface => "dbus.ada.server.type",
119 Method => "rebound",
120 Args => +Byte'Last);
121
122 declare
123 B : constant Byte_Type := Byte_Type (Result.First_Element);
124 begin
125 Assert (Condition => B.To_Ada = Byte'Last,
126 Message => "Incorrect upper bound");
127 end;
128
129 Result := Connection.Call_Blocking
130 (Connection => Conn,
131 Destination => "dbus.ada.server",
132 Path => +"/",
133 Iface => "dbus.ada.server.type",
134 Method => "rebound",
135 Args => +Byte'First);
136
137 declare
138 B : constant Byte_Type := Byte_Type (Result.First_Element);
139 begin
140 Assert (Condition => B.To_Ada = Byte'First,
141 Message => "Incorrect lower bound");
142 end;
143 end Marshal_Byte_Type;
144
145 -------------------------------------------------------------------------
146
147 procedure Marshal_Int16_Type
148 is
149 Conn : constant Connection.Connection_Type
150 := Connection.Connect (Address => Config.Service_Addr);
151 Result : Argument_List_Type;
152 begin
153 Result := Connection.Call_Blocking
154 (Connection => Conn,
155 Destination => "dbus.ada.server",
156 Path => +"/",
157 Iface => "dbus.ada.server.type",
158 Method => "rebound",
159 Args => +Signed_16'Last);
160
161 declare
162 Int16 : constant Int16_Type
163 := Int16_Type (Result.First_Element);
164 begin
165 Assert (Condition => Int16.To_Ada = Signed_16'Last,
166 Message => "Incorrect upper bound");
167 end;
168
169 Result := Connection.Call_Blocking
170 (Connection => Conn,
171 Destination => "dbus.ada.server",
172 Path => +"/",
173 Iface => "dbus.ada.server.type",
174 Method => "rebound",
175 Args => +Signed_16'First);
176
177 declare
178 Int16 : constant Int16_Type
179 := Int16_Type (Result.First_Element);
180 begin
181 Assert (Condition => Int16.To_Ada = Signed_16'First,
182 Message => "Incorrect lower bound");
183 end;
184 end Marshal_Int16_Type;
185
186 -------------------------------------------------------------------------
187
188 procedure Marshal_Int32_Type
189 is
190 Conn : constant Connection.Connection_Type
191 := Connection.Connect (Address => Config.Service_Addr);
192 Result : Argument_List_Type;
193 begin
194 Result := Connection.Call_Blocking
195 (Connection => Conn,
196 Destination => "dbus.ada.server",
197 Path => +"/",
198 Iface => "dbus.ada.server.type",
199 Method => "rebound",
200 Args => +Signed_32'Last);
201
202 declare
203 Int32 : constant Int32_Type := Int32_Type (Result.First_Element);
204 begin
205 Assert (Condition => Int32.To_Ada = Signed_32'Last,
206 Message => "Incorrect upper bound");
207 end;
208
209 Result := Connection.Call_Blocking
210 (Connection => Conn,
211 Destination => "dbus.ada.server",
212 Path => +"/",
213 Iface => "dbus.ada.server.type",
214 Method => "rebound",
215 Args => +Signed_32'First);
216
217 declare
218 Int32 : constant Int32_Type := Int32_Type (Result.First_Element);
219 begin
220 Assert (Condition => Int32.To_Ada = Signed_32'First,
221 Message => "Incorrect lower bound");
222 end;
223 end Marshal_Int32_Type;
224
225 -------------------------------------------------------------------------
226
227 procedure Marshal_Int64_Type
228 is
229 Conn : constant Connection.Connection_Type
230 := Connection.Connect (Address => Config.Service_Addr);
231 Result : Argument_List_Type;
232 begin
233 Result := Connection.Call_Blocking
234 (Connection => Conn,
235 Destination => "dbus.ada.server",
236 Path => +"/",
237 Iface => "dbus.ada.server.type",
238 Method => "rebound",
239 Args => +Signed_64'Last);
240
241 declare
242 Int64 : constant Int64_Type := Int64_Type (Result.First_Element);
243 begin
244 Assert (Condition => Int64.To_Ada = Signed_64'Last,
245 Message => "Incorrect upper bound");
246 end;
247
248 Result := Connection.Call_Blocking
249 (Connection => Conn,
250 Destination => "dbus.ada.server",
251 Path => +"/",
252 Iface => "dbus.ada.server.type",
253 Method => "rebound",
254 Args => +Signed_64'First);
255
256 declare
257 Int64 : constant Int64_Type := Int64_Type (Result.First_Element);
258 begin
259 Assert (Condition => Int64.To_Ada = Signed_64'First,
260 Message => "Incorrect lower bound");
261 end;
262 end Marshal_Int64_Type;
263
264 -------------------------------------------------------------------------
265
266 procedure Marshal_Object_Path_Type
267 is
268 Ref_Path : constant Types.Obj_Path := +"/com/example/MusicPlayer1";
269 Conn : constant Connection.Connection_Type
270 := Connection.Connect (Address => Config.Service_Addr);
271 Result : Argument_List_Type;
272 begin
273 Result := Connection.Call_Blocking
274 (Connection => Conn,
275 Destination => "dbus.ada.server",
276 Path => +"/",
277 Iface => "dbus.ada.server.type",
278 Method => "rebound",
279 Args => +Ref_Path);
280
281 declare
282 Path_Arg : constant Object_Path_Type
283 := Object_Path_Type (Result.First_Element);
284 begin
285 Assert (Condition => Path_Arg.To_Ada = Ref_Path,
286 Message => "Object path mismatch");
287 end;
288 end Marshal_Object_Path_Type;
289
290 -------------------------------------------------------------------------
291
292 procedure Marshal_String_Type
293 is
294 Ref_Str : constant String := "this is a teststring";
295 Conn : constant Connection.Connection_Type
296 := Connection.Connect (Address => Config.Service_Addr);
297 Result : Argument_List_Type;
298 begin
299 Result := Connection.Call_Blocking
300 (Connection => Conn,
301 Destination => "dbus.ada.server",
302 Path => +"/",
303 Iface => "dbus.ada.server.type",
304 Method => "rebound",
305 Args => +Ref_Str);
306
307 Assert (Condition => Ref_Str = Result.First_Element.To_String,
308 Message => "String type mismatch");
309 end Marshal_String_Type;
310
311 -------------------------------------------------------------------------
312
313 procedure Marshal_U_Int16_Type
314 is
315 Conn : constant Connection.Connection_Type
316 := Connection.Connect (Address => Config.Service_Addr);
317 Result : Argument_List_Type;
318 begin
319 Result := Connection.Call_Blocking
320 (Connection => Conn,
321 Destination => "dbus.ada.server",
322 Path => +"/",
323 Iface => "dbus.ada.server.type",
324 Method => "rebound",
325 Args => +Unsigned_16'Last);
326
327 declare
328 U_Int16 : constant U_Int16_Type
329 := U_Int16_Type (Result.First_Element);
330 begin
331 Assert (Condition => U_Int16.To_Ada = Unsigned_16'Last,
332 Message => "Incorrect upper bound");
333 end;
334
335 Result := Connection.Call_Blocking
336 (Connection => Conn,
337 Destination => "dbus.ada.server",
338 Path => +"/",
339 Iface => "dbus.ada.server.type",
340 Method => "rebound",
341 Args => +Unsigned_16'First);
342
343 declare
344 U_Int16 : constant U_Int16_Type
345 := U_Int16_Type (Result.First_Element);
346 begin
347 Assert (Condition => U_Int16.To_Ada = Unsigned_16'First,
348 Message => "Incorrect lower bound");
349 end;
350 end Marshal_U_Int16_Type;
351
352 -------------------------------------------------------------------------
353
354 procedure Marshal_U_Int32_Type
355 is
356 Conn : constant Connection.Connection_Type
357 := Connection.Connect (Address => Config.Service_Addr);
358 Result : Argument_List_Type;
359 begin
360 Result := Connection.Call_Blocking
361 (Connection => Conn,
362 Destination => "dbus.ada.server",
363 Path => +"/",
364 Iface => "dbus.ada.server.type",
365 Method => "rebound",
366 Args => +Unsigned_32'Last);
367
368 declare
369 U_Int32 : constant U_Int32_Type
370 := U_Int32_Type (Result.First_Element);
371 begin
372 Assert (Condition => U_Int32.To_Ada = Unsigned_32'Last,
373 Message => "Incorrect upper bound");
374 end;
375
376 Result := Connection.Call_Blocking
377 (Connection => Conn,
378 Destination => "dbus.ada.server",
379 Path => +"/",
380 Iface => "dbus.ada.server.type",
381 Method => "rebound",
382 Args => +Unsigned_32'First);
383
384 declare
385 U_Int32 : constant U_Int32_Type
386 := U_Int32_Type (Result.First_Element);
387 begin
388 Assert (Condition => U_Int32.To_Ada = Unsigned_32'First,
389 Message => "Incorrect lower bound");
390 end;
391 end Marshal_U_Int32_Type;
392
393 -------------------------------------------------------------------------
394
395 procedure Marshal_U_Int64_Type
396 is
397 Conn : constant Connection.Connection_Type
398 := Connection.Connect (Address => Config.Service_Addr);
399 Result : Argument_List_Type;
400 begin
401 Result := Connection.Call_Blocking
402 (Connection => Conn,
403 Destination => "dbus.ada.server",
404 Path => +"/",
405 Iface => "dbus.ada.server.type",
406 Method => "rebound",
407 Args => +Unsigned_64'Last);
408
409 declare
410 U_Int64 : constant U_Int64_Type
411 := U_Int64_Type (Result.First_Element);
412 begin
413 Assert (Condition => U_Int64.To_Ada = Unsigned_64'Last,
414 Message => "Incorrect upper bound");
415 end;
416
417 Result := Connection.Call_Blocking
418 (Connection => Conn,
419 Destination => "dbus.ada.server",
420 Path => +"/",
421 Iface => "dbus.ada.server.type",
422 Method => "rebound",
423 Args => +Unsigned_64'First);
424
425 declare
426 U_Int64 : constant U_Int64_Type
427 := U_Int64_Type (Result.First_Element);
428 begin
429 Assert (Condition => U_Int64.To_Ada = Unsigned_64'First,
430 Message => "Incorrect lower bound");
431 end;
432 end Marshal_U_Int64_Type;
433
434 end Arguments_Basic_Tests;