florist_blady_6.1.0_05ac0091/gnatsocks/test_sockets.adb

 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
------------------------------------------------------------------------
--  file : test_sockets.adb  [$Revision: 110555 $]
------------------------------------------------------------------------

--  The bare bones of a test for packages Sockets and Sockets.Internet.

with Ada.Characters.Latin_1,
     POSIX_Report,
     Sockets,
     Sockets.Internet;
procedure Test_Sockets is

   use POSIX_Report,
       Sockets,
       Sockets.Internet;

   Stream_Sock : Sockets.Stream_Socket;
   Server_Sock : Sockets.Server_Socket;
   In_Stream   : Input_Stream_Ptr;
   Out_Strem   : Output_Stream_Ptr;

   Lf : constant Character := Ada.Characters.Latin_1.Lf;
   Cr : constant Character := Ada.Characters.Latin_1.Cr;

   Localhost : Internet_Address;
   Telnet_Port : constant Port_Number := 23;
   Sockaddr : Internet_Socket_Address;

begin
   Header ("Test_Sockets");
   Test ("package Sockets");

   declare
      Addr : Internet_Address;
   begin
      Test ("Local_Host");
      Localhost := Local_Host;
      Test ("Get_Hostname");
      declare
         Address : constant String := Get_AddressString (Localhost);
      begin
         Comment ("address = " & Address);
         declare
            Hostname : constant String := Get_HostByAddr (Localhost);
         begin
            Comment ("hostname = " & Hostname);
            Test ("Get_AddrByName");
            Addr := Get_AddrByName (Hostname);
            Assert (Localhost = Addr, "A000: Get_AddrByName, Get_HostName");
         end;
      end;
      Comment ("name of All_Local_Addresses = "
        & Get_HostByAddr (All_Local_Addresses));
   exception when E : others => Fail (E, "A001");
   end;

--     declare
--        Ch : Character;
   begin
      Test ("open stream socket to telnet port of local host");
      Sockets.Open (Stream_Sock,
        Sockets.Internet.New_Address (Telnet_Port, Localhost));
      In_Stream := Sockets.Get_Input_Stream (Stream_Sock);
      Test ("close");
      Close (Stream_Sock);
   exception when E : others => Fail (E, "A002");
   end;

   begin
      null;
   exception when E : others => Fail (E, "A003");
   end;

   Done;
exception when E : others => Fatal_Exception (E, "A004");
end Test_Sockets;