Debian Codegraph @

tests/arguments_tests.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 2011 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 Ada.Exceptions;
30
31 with Ahven;
32
33 with D_Bus.Arguments.Basic;
34
35 package body Arguments_Tests is
36
37 use Ahven;
38 use D_Bus;
39 use D_Bus.Arguments;
40
41 -------------------------------------------------------------------------
42
43 procedure Get_Elements
44 is
45 use D_Bus.Arguments.Basic;
46
47 L : Argument_List_Type;
48 begin
49 L.Append (New_Item => +"first");
50 L.Append (New_Item => +"second");
51 L.Append (New_Item => +"third");
52
53 Assert (Condition => String_Type (L.Get_Element (Pos => 1)) = +"first",
54 Message => "First mismatch");
55 Assert (Condition => String_Type (L.Get_Element (Pos => 3)) = +"third",
56 Message => "Third mismatch");
57 Assert (Condition => String_Type (L.Get_Element (Pos => 2)) = +"second",
58 Message => "Second mismatch");
59
60 begin
61 declare
62 Dummy : constant Argument_Type'Class
63 := String_Type (L.Get_Element (Pos => 4));
64 begin
65 Fail (Message => "Exception expected");
66 end;
67
68 exception
69 when E : Arguments_Error =>
70 Assert (Condition => Ada.Exceptions.Exception_Message (X => E)
71 = "No element at position 4",
72 Message => "Exception mismatch");
73 end;
74 end Get_Elements;
75
76 -------------------------------------------------------------------------
77
78 procedure Initialize (T : in out Testcase) is
79 begin
80 T.Set_Name (Name => "Arguments handling");
81 T.Add_Test_Routine
82 (Routine => List_Append'Access,
83 Name => "Append arguments to list");
84 T.Add_Test_Routine
85 (Routine => Get_Elements'Access,
86 Name => "Get elements from list");
87 end Initialize;
88
89 -------------------------------------------------------------------------
90
91 procedure List_Append
92 is
93 L : Argument_List_Type;
94 B : Basic.String_Type;
95 begin
96 Assert (Condition => L.Is_Empty,
97 Message => "New list not empty1");
98 Assert (Condition => L.Get_Count = 0,
99 Message => "New list not empty2");
100
101 L.Append (New_Item => B);
102 L.Append (New_Item => B);
103 Assert (Condition => L.Get_Count = 2,
104 Message => "Count not 2");
105 Assert (Condition => not L.Is_Empty,
106 Message => "List is empty");
107 end List_Append;
108
109 end Arguments_Tests;