| 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 Ahven; |
| 30 |
|
| 31 |
with D_Bus.Service; |
| 32 |
with D_Bus.Messages; |
| 33 |
|
| 34 |
package body Service_Tests is |
| 35 |
|
| 36 |
use Ahven; |
| 37 |
use D_Bus; |
| 38 |
use D_Bus.Service; |
| 39 |
|
| 40 |
type Test_Object is new Object with null record; |
| 41 |
|
| 42 |
procedure Initialize (Obj : in out Test_Object); |
| 43 |
-- Initialize test object. |
| 44 |
|
| 45 |
procedure Test_Method |
| 46 |
(Request : Messages.Message_Type; |
| 47 |
Reply : out Messages.Message_Type); |
| 48 |
-- Method used for testing the service object. |
| 49 |
|
| 50 |
Called_Counter : Natural := 0; |
| 51 |
|
| 52 |
------------------------------------------------------------------------- |
| 53 |
|
| 54 |
procedure Duplicate_Methods |
| 55 |
is |
| 56 |
Obj : Test_Object; |
| 57 |
begin |
| 58 |
Obj.Register (Name => "TestMethod", |
| 59 |
Method => Test_Method'Access); |
| 60 |
|
| 61 |
begin |
| 62 |
Obj.Register (Name => "TestMethod", |
| 63 |
Method => Test_Method'Access); |
| 64 |
Fail (Message => "Exception expected"); |
| 65 |
|
| 66 |
exception |
| 67 |
when Duplicate_Method => null; |
| 68 |
end; |
| 69 |
end Duplicate_Methods; |
| 70 |
|
| 71 |
------------------------------------------------------------------------- |
| 72 |
|
| 73 |
procedure Initialize (Obj : in out Test_Object) |
| 74 |
is |
| 75 |
begin |
| 76 |
Obj.Register (Name => "TestMethod", |
| 77 |
Method => Test_Method'Access); |
| 78 |
end Initialize; |
| 79 |
|
| 80 |
------------------------------------------------------------------------- |
| 81 |
|
| 82 |
procedure Initialize (T : in out Testcase) is |
| 83 |
begin |
| 84 |
T.Set_Name (Name => "Service objects"); |
| 85 |
T.Add_Test_Routine |
| 86 |
(Routine => Register_Method'Access, |
| 87 |
Name => "Register service method"); |
| 88 |
T.Add_Test_Routine |
| 89 |
(Routine => Unknown_Method'Access, |
| 90 |
Name => "Call unknown method"); |
| 91 |
T.Add_Test_Routine |
| 92 |
(Routine => Duplicate_Methods'Access, |
| 93 |
Name => "Register same method twice"); |
| 94 |
end Initialize; |
| 95 |
|
| 96 |
------------------------------------------------------------------------- |
| 97 |
|
| 98 |
procedure Register_Method |
| 99 |
is |
| 100 |
Obj : Test_Object; |
| 101 |
Req : Messages.Message_Type; |
| 102 |
Rep : Messages.Message_Type; |
| 103 |
begin |
| 104 |
Obj.Initialize; |
| 105 |
Obj.Call (Name => "TestMethod", |
| 106 |
Request => Req, |
| 107 |
Reply => Rep); |
| 108 |
|
| 109 |
Assert (Condition => Called_Counter = 1, |
| 110 |
Message => "Method not called"); |
| 111 |
end Register_Method; |
| 112 |
|
| 113 |
------------------------------------------------------------------------- |
| 114 |
|
| 115 |
procedure Test_Method |
| 116 |
(Request : Messages.Message_Type; |
| 117 |
Reply : out Messages.Message_Type) |
| 118 |
is |
| 119 |
pragma Unreferenced (Request, Reply); |
| 120 |
begin |
| 121 |
Called_Counter := Called_Counter + 1; |
| 122 |
end Test_Method; |
| 123 |
|
| 124 |
------------------------------------------------------------------------- |
| 125 |
|
| 126 |
procedure Unknown_Method |
| 127 |
is |
| 128 |
Obj : Test_Object; |
| 129 |
Req : Messages.Message_Type; |
| 130 |
Rep : Messages.Message_Type; |
| 131 |
begin |
| 132 |
Obj.Call (Name => "Unknown", |
| 133 |
Request => Req, |
| 134 |
Reply => Rep); |
| 135 |
|
| 136 |
exception |
| 137 |
when Service.Unknown_Method => null; |
| 138 |
end Unknown_Method; |
| 139 |
|
| 140 |
end Service_Tests; |