2 // **********************************************************************
4 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
6 // This copy of Ice is licensed to you under the terms described in the
7 // ICE_LICENSE file included in this distribution.
9 // **********************************************************************
11 error_reporting(E_ALL | E_STRICT
);
13 if(!extension_loaded("ice"))
15 echo "\nerror: Ice extension is not loaded.\n\n";
19 $NS = function_exists("Ice\\initialize");
20 require_once ($NS ?
'Ice_ns.php' : 'Ice.php');
21 require_once 'Test.php';
27 $bt = debug_backtrace();
28 die("\ntest failed in ".$bt[0]["file"]." line ".$bt[0]["line"]."\n");
32 function allTests($communicator)
36 $ipEndpointInfoClass = $NS ?
"Ice\\IPEndpointInfo" : "Ice_IPEndpointInfo";
37 $tcpEndpointType = $NS ?
constant("Ice\\TCPEndpointType") : constant("Ice_TCPEndpointType");
38 $tcpEndpointInfoClass = $NS ?
"Ice\\TCPEndpointInfo" : "Ice_TCPEndpointInfo";
39 $udpEndpointType = $NS ?
constant("Ice\\UDPEndpointType") : constant("Ice_UDPEndpointType");
40 $udpEndpointInfoClass = $NS ?
"Ice\\UDPEndpointInfo" : "Ice_UDPEndpointInfo";
43 echo "testing proxy endpoint information... ";
46 $p1 = $communicator->stringToProxy("test -t:default -h tcphost -p 10000 -t 1200 -z:" .
47 "udp -h udphost -p 10001 --interface eth0 --ttl 5:" .
48 "opaque -t 100 -v ABCD");
50 $endps = $p1->ice_getEndpoints();
52 $ipEndpoint = $endps[0]->getInfo();
53 test($ipEndpoint instanceof $ipEndpointInfoClass);
54 test($ipEndpoint->host
== "tcphost");
55 test($ipEndpoint->port
== 10000);
56 test($ipEndpoint->timeout
== 1200);
57 test($ipEndpoint->compress
);
58 test(!$ipEndpoint->datagram());
59 test($ipEndpoint->type() == $tcpEndpointType && !$ipEndpoint->secure() ||
60 $ipEndpoint->type() == $sslEndpointType && $ipEndpoint->secure());
61 test($ipEndpoint->type() == $tcpEndpointType && ($ipEndpoint instanceof $tcpEndpointInfoClass) ||
62 $ipEndpoint->type() == $sslEndpointType);
64 $udpEndpoint = $endps[1]->getInfo();
65 test($udpEndpoint instanceof $udpEndpointInfoClass);
66 test($udpEndpoint->host
== "udphost");
67 test($udpEndpoint->port
== 10001);
68 test($udpEndpoint->mcastInterface
== "eth0");
69 test($udpEndpoint->mcastTtl
== 5);
70 test($udpEndpoint->timeout
== -1);
71 test(!$udpEndpoint->compress
);
72 test(!$udpEndpoint->secure());
73 test($udpEndpoint->datagram());
74 test($udpEndpoint->type() == $udpEndpointType);
76 $opaqueEndpoint = $endps[2]->getInfo();
77 test($opaqueEndpoint);
81 $defaultHost = $communicator->getProperties()->getProperty("Ice.Default.Host");
82 $base = $communicator->stringToProxy("test:default -p 12010:udp -p 12010");
83 $testIntf = $base->ice_checkedCast("::Test::TestIntf");
85 echo "test connection endpoint information... ";
88 $ipinfo = $base->ice_getConnection()->getEndpoint()->getInfo();
89 test($ipinfo instanceof $ipEndpointInfoClass);
90 test($ipinfo->port
== 12010);
91 test(!$ipinfo->compress
);
92 test($ipinfo->host
== $defaultHost);
94 $ctx = $testIntf->getEndpointInfoAsContext();
95 test($ctx["host"] == $ipinfo->host
);
96 test($ctx["compress"] == "false");
97 test($ctx["port"] > 0);
99 $udpinfo = $base->ice_datagram()->ice_getConnection()->getEndpoint()->getInfo();
100 test($udpinfo instanceof $udpEndpointInfoClass);
101 test($udpinfo->port
== 12010);
102 test($udpinfo->host
== $defaultHost);
106 echo "testing connection information... ";
109 $ipConnectionInfoClass = $NS ?
"Ice\\IPConnectionInfo" : "Ice_IPConnectionInfo";
111 $info = $base->ice_getConnection()->getInfo();
112 test($info instanceof $ipConnectionInfoClass);
113 test(!$info->incoming
);
114 test(strlen($info->adapterName
) == 0);
115 test($info->remotePort
== 12010);
116 test($info->remoteAddress
== $defaultHost);
117 test($info->localAddress
== $defaultHost);
119 $ctx = $testIntf->getConnectionInfoAsContext();
120 test($ctx["incoming"] == "true");
121 test($ctx["adapterName"] == "TestAdapter");
122 test($ctx["remoteAddress"] == $info->localAddress
);
123 test($ctx["localAddress"] == $info->remoteAddress
);
124 test($ctx["remotePort"] == $info->localPort
);
125 test($ctx["localPort"] == $info->remotePort
);
132 $communicator = Ice_initialize(&$argv);
133 $server = allTests($communicator);
135 $communicator->destroy();