File: service_tests.adb

package info (click to toggle)
dbusada 0.6.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 748 kB
  • sloc: ada: 5,892; ansic: 98; makefile: 81; sh: 47
file content (140 lines) | stat: -rw-r--r-- 4,265 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--
--  D_Bus/Ada - An Ada binding to D-Bus
--
--  Copyright (C) 2011  Reto Buerki <reet@codelabs.ch>
--
--  This program is free software; you can redistribute it and/or
--  modify it under the terms of the GNU General Public License
--  as published by the Free Software Foundation; either version 2
--  of the License, or (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program; if not, write to the Free Software
--  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
--  USA.
--
--  As a special exception, if other files instantiate generics from this
--  unit,  or  you  link  this  unit  with  other  files  to  produce  an
--  executable   this  unit  does  not  by  itself  cause  the  resulting
--  executable to  be  covered by the  GNU General  Public License.  This
--  exception does  not  however  invalidate  any  other reasons why  the
--  executable file might be covered by the GNU Public License.
--

with Ahven;

with D_Bus.Service;
with D_Bus.Messages;

package body Service_Tests is

   use Ahven;
   use D_Bus;
   use D_Bus.Service;

   type Test_Object is new Object with null record;

   procedure Initialize (Obj : in out Test_Object);
   --  Initialize test object.

   procedure Test_Method
     (Request :     Messages.Message_Type;
      Reply   : out Messages.Message_Type);
   --  Method used for testing the service object.

   Called_Counter : Natural := 0;

   -------------------------------------------------------------------------

   procedure Duplicate_Methods
   is
      Obj : Test_Object;
   begin
      Obj.Register (Name   => "TestMethod",
                    Method => Test_Method'Access);

      begin
         Obj.Register (Name   => "TestMethod",
                       Method => Test_Method'Access);
         Fail (Message => "Exception expected");

      exception
         when Duplicate_Method => null;
      end;
   end Duplicate_Methods;

   -------------------------------------------------------------------------

   procedure Initialize (Obj : in out Test_Object)
   is
   begin
      Obj.Register (Name   => "TestMethod",
                    Method => Test_Method'Access);
   end Initialize;

   -------------------------------------------------------------------------

   procedure Initialize (T : in out Testcase) is
   begin
      T.Set_Name (Name => "Service objects");
      T.Add_Test_Routine
        (Routine => Register_Method'Access,
         Name    => "Register service method");
      T.Add_Test_Routine
        (Routine => Unknown_Method'Access,
         Name    => "Call unknown method");
      T.Add_Test_Routine
        (Routine => Duplicate_Methods'Access,
         Name    => "Register same method twice");
   end Initialize;

   -------------------------------------------------------------------------

   procedure Register_Method
   is
      Obj : Test_Object;
      Req : Messages.Message_Type;
      Rep : Messages.Message_Type;
   begin
      Obj.Initialize;
      Obj.Call (Name    => "TestMethod",
                Request => Req,
                Reply   => Rep);

      Assert (Condition => Called_Counter = 1,
              Message   => "Method not called");
   end Register_Method;

   -------------------------------------------------------------------------

   procedure Test_Method
     (Request :     Messages.Message_Type;
      Reply   : out Messages.Message_Type)
   is
      pragma Unreferenced (Request, Reply);
   begin
      Called_Counter := Called_Counter + 1;
   end Test_Method;

   -------------------------------------------------------------------------

   procedure Unknown_Method
   is
      Obj : Test_Object;
      Req : Messages.Message_Type;
      Rep : Messages.Message_Type;
   begin
      Obj.Call (Name    => "Unknown",
                Request => Req,
                Reply   => Rep);

   exception
      when Service.Unknown_Method => null;
   end Unknown_Method;

end Service_Tests;