Debian Codegraph @

tests/messagebox_tests.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 2020 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 dbus_message_h;
32
33 with D_Bus.Messages;
34 with D_Bus.Messagebox;
35
36 package body Messagebox_Tests is
37
38 use Ahven;
39 use D_Bus;
40
41 -------------------------------------------------------------------------
42
43 procedure Enqueue_Consume_Messages
44 is
45 use type D_Bus.Messages.Message_Type;
46
47 Box : Messagebox.Msg_Box_Type;
48 M : Messages.Message_Type;
49 Thin : constant access dbus_message_h.DBusMessage
50 := dbus_message_h.dbus_message_new (message_type => 2);
51 Ref : Messages.Message_Type := Messages.To_Thick
52 (Thin => Thin);
53 begin
54 Assert (Condition => not Messages.Is_Null (Msg => Ref),
55 Message => "Ref message nil");
56
57 Box.Consume (M => M);
58 Assert (Condition => M = Messages.Null_Message,
59 Message => "Null_Message expected (1)");
60
61 Box.Enqueue (M => Ref);
62 Box.Enqueue (M => Ref);
63
64 Box.Consume (M => M);
65 Assert (Condition => M = Ref,
66 Message => "Ref message expected (1)");
67 Box.Consume (M => M);
68 Assert (Condition => M = Ref,
69 Message => "Ref message expected (2)");
70 Box.Consume (M => M);
71 Assert (Condition => M = Messages.Null_Message,
72 Message => "Null_Message expected (2)");
73
74 Messages.Unref (Msg => Ref);
75 end Enqueue_Consume_Messages;
76
77 -------------------------------------------------------------------------
78
79 procedure Initialize (T : in out Testcase) is
80 begin
81 T.Set_Name (Name => "Messagebox");
82 T.Add_Test_Routine
83 (Routine => Enqueue_Consume_Messages'Access,
84 Name => "Enqueue/consume messages");
85 end Initialize;
86
87 end Messagebox_Tests;