Debian Codegraph @

tests/types_tests.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 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 D_Bus.Types;
32
33 package body Types_Tests is
34
35 use Ahven;
36 use D_Bus;
37
38 -------------------------------------------------------------------------
39
40 procedure Initialize (T : in out Testcase) is
41 begin
42 T.Set_Name (Name => "Types");
43 T.Add_Test_Routine
44 (Routine => Validate_Paths'Access,
45 Name => "Validate object paths");
46 T.Add_Test_Routine
47 (Routine => Path_To_String'Access,
48 Name => "Convert path to string");
49 end Initialize;
50
51 -------------------------------------------------------------------------
52
53 procedure Path_To_String
54 is
55 use type Types.Obj_Path;
56
57 Str : constant String := "/com/example/MusicPlayer1";
58 Path : constant Types.Obj_Path := +Str;
59 begin
60 Assert (Condition => Types.To_String (Path => Path) = Str,
61 Message => "String mismatch");
62 end Path_To_String;
63
64 -------------------------------------------------------------------------
65
66 procedure Validate_Paths
67 is
68 begin
69 Assert (Condition => Types.Is_Valid (Path => "/"),
70 Message => "Root not valid");
71 Assert (Condition => not Types.Is_Valid (Path => "/obj/"),
72 Message => "Trailing slash valid");
73 Assert (Condition => not Types.Is_Valid (Path => "/obj//obj2"),
74 Message => "Multiple slashes valid");
75 Assert (Condition => not Types.Is_Valid (Path => "/obj/o*"),
76 Message => "Invalid char not detected");
77
78 declare
79 use type D_Bus.Types.Obj_Path;
80
81 Path : Types.Obj_Path;
82 pragma Unreferenced (Path);
83 begin
84 Path := +"not a path";
85 Fail (Message => "Exception expected");
86
87 exception
88 when D_Bus_Error => null;
89 end;
90 end Validate_Paths;
91
92 end Types_Tests;