/php/test/Ice/slicing/objects/Client.php

https://bitbucket.org/cleto/zeroc-ice-package · PHP · 1067 lines · 831 code · 124 blank · 112 comment · 212 complexity · 6ba9cb260bfda5896846f202e93c6422 MD5 · raw file

  1. <?
  2. error_reporting(E_ALL | E_STRICT);
  3. if(!extension_loaded("ice"))
  4. {
  5. echo "\nerror: Ice extension is not loaded.\n\n";
  6. exit(1);
  7. }
  8. $NS = function_exists("Ice\\initialize");
  9. require_once ($NS ? 'Ice_ns.php' : 'Ice.php');
  10. require_once 'Forward.php';
  11. require_once 'ClientPrivate.php';
  12. function test($b)
  13. {
  14. if(!$b)
  15. {
  16. $bt = debug_backtrace();
  17. die("\ntest failed in ".$bt[0]["file"]." line ".$bt[0]["line"]."\n");
  18. }
  19. }
  20. function allTests($communicator)
  21. {
  22. global $NS;
  23. global $Ice_Encoding_1_0;
  24. $d1cls = $NS ? "Test\\D1" : "Test_D1";
  25. $d3cls = $NS ? "Test\\D3" : "Test_D3";
  26. $obj = $communicator->stringToProxy("Test:default -p 12010");
  27. $test = $obj->ice_checkedCast("::Test::TestIntf");
  28. echo "base as Object... ";
  29. flush();
  30. {
  31. $o = $test->SBaseAsObject();
  32. test($o != null);
  33. test(get_class($o) == ($NS ? "Test\\SBase" : "Test_SBase"));
  34. test($o->sb == "SBase.sb");
  35. }
  36. echo "ok\n";
  37. echo "base as base... ";
  38. flush();
  39. {
  40. $o = $test->SBaseAsSBase();
  41. test($o->sb == "SBase.sb");
  42. }
  43. echo "ok\n";
  44. echo "base with known derived as base... ";
  45. flush();
  46. {
  47. $sb = $test->SBSKnownDerivedAsSBase();
  48. test($sb->sb == "SBSKnownDerived.sb");
  49. test(get_class($sb) == ($NS ? "Test\\SBSKnownDerived" : "Test_SBSKnownDerived"));
  50. test($sb->sbskd == "SBSKnownDerived.sbskd");
  51. }
  52. echo "ok\n";
  53. echo "base with known derived as known derived... ";
  54. flush();
  55. {
  56. $sbksd = $test->SBSKnownDerivedAsSBSKnownDerived();
  57. test($sbksd->sbskd == "SBSKnownDerived.sbskd");
  58. }
  59. echo "ok\n";
  60. echo "base with unknown derived as base... ";
  61. flush();
  62. {
  63. $sb = $test->SBSUnknownDerivedAsSBase();
  64. test($sb->sb == "SBSUnknownDerived.sb");
  65. }
  66. if($test->ice_getEncodingVersion() == $Ice_Encoding_1_0)
  67. {
  68. try
  69. {
  70. //
  71. // This test succeeds for the 1.0 encoding.
  72. //
  73. $sb = $test->SBSUnknownDerivedAsSBaseCompact();
  74. test($sb->sb == "SBSUnknownDerived.sb");
  75. }
  76. catch(Exception $ex)
  77. {
  78. test(false);
  79. }
  80. }
  81. else
  82. {
  83. try
  84. {
  85. //
  86. // This test fails when using the compact format because the instance cannot
  87. // be sliced to a known type.
  88. //
  89. $sb = $test->SBSUnknownDerivedAsSBaseCompact();
  90. test(false);
  91. }
  92. catch(Exception $ex)
  93. {
  94. test(get_class($ex) == ($NS ? "Ice\\NoObjectFactoryException" : "Ice_NoObjectFactoryException"));
  95. }
  96. }
  97. echo "ok\n";
  98. echo "unknown with Object as Object... ";
  99. flush();
  100. {
  101. $usocls = $NS ? "Ice\\UnknownSlicedObject" : "Ice_UnknownSlicedObject";
  102. try
  103. {
  104. $o = $test->SUnknownAsObject();
  105. test($test->ice_getEncodingVersion() != $Ice_Encoding_1_0);
  106. test($o instanceof $usocls);
  107. test($o->unknownTypeId == "::Test::SUnknown");
  108. test($o->_ice_slicedData != null);
  109. $test->checkSUnknown($o);
  110. }
  111. catch(Exception $b)
  112. {
  113. $excls = $NS ? "Ice\\NoObjectFactoryException" : "Ice_NoObjectFactoryException";
  114. if($b instanceof $excls)
  115. {
  116. test($test->ice_getEncodingVersion() == $Ice_Encoding_1_0);
  117. }
  118. else
  119. {
  120. throw $ex;
  121. }
  122. }
  123. }
  124. echo "ok\n";
  125. echo "one-element cycle... ";
  126. flush();
  127. {
  128. $b = $test->oneElementCycle();
  129. test($b != null);
  130. test(get_class($b) == ($NS ? "Test\\B" : "Test_B"));
  131. test($b->sb == "B1.sb");
  132. test($b->pb === $b); // Object identity comparison
  133. //
  134. // Break cyclic dependencies - helps in detecting leaks.
  135. //
  136. $b->pb = null;
  137. }
  138. echo "ok\n";
  139. echo "two-element cycle... ";
  140. flush();
  141. {
  142. $b1 = $test->twoElementCycle();
  143. test($b1 != null);
  144. test(get_class($b1) == ($NS ? "Test\\B" : "Test_B"));
  145. test($b1->sb == "B1.sb");
  146. $b2 = $b1->pb;
  147. test($b2 != null);
  148. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B"));
  149. test($b2->sb == "B2.sb");
  150. test($b2->pb === $b1); // Object identity comparison
  151. //
  152. // Break cyclic dependencies - helps in detecting leaks.
  153. //
  154. $b1->pb = null;
  155. }
  156. echo "ok\n";
  157. echo "known derived pointer slicing as base... ";
  158. flush();
  159. {
  160. $b1 = $test->D1AsB();
  161. test($b1 != null);
  162. test(get_class($b1) == ($NS ? "Test\\D1" : "Test_D1"));
  163. test($b1->sb == "D1.sb");
  164. test($b1->pb != null);
  165. test($b1->pb !== $b1); // Object identity comparison
  166. $d1 = $b1;
  167. test($d1->sd1 == "D1.sd1");
  168. test($d1->pd1 != null);
  169. test($d1->pd1 !== $b1); // Object identity comparison
  170. test($b1->pb === $d1->pd1); // Object identity comparison
  171. $b2 = $b1->pb;
  172. test($b2 != null);
  173. test($b2->pb === $b1); // Object identity comparison
  174. test($b2->sb == "D2.sb");
  175. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B"));
  176. //
  177. // Break cyclic dependencies - helps in detecting leaks.
  178. //
  179. $b2->pb = null;
  180. }
  181. echo "ok\n";
  182. echo "known derived pointer slicing as derived... ";
  183. flush();
  184. {
  185. $d1 = $test->D1AsD1();
  186. test($d1 != null);
  187. test(get_class($d1) == ($NS ? "Test\\D1" : "Test_D1"));
  188. test($d1->sb == "D1.sb");
  189. test($d1->pb != null);
  190. test($d1->pb !== $d1); // Object identity comparison
  191. $b2 = $d1->pb;
  192. test($b2 != null);
  193. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B"));
  194. test($b2->sb == "D2.sb");
  195. test($b2->pb === $d1); // Object identity comparison
  196. //
  197. // Break cyclic dependencies - helps in detecting leaks.
  198. //
  199. $b2->pb = null;
  200. }
  201. echo "ok\n";
  202. echo "unknown derived pointer slicing as base... ";
  203. flush();
  204. {
  205. $b2 = $test->D2AsB();
  206. test($b2 != null);
  207. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B"));
  208. test($b2->sb == "D2.sb");
  209. test($b2->pb != null);
  210. test($b2->pb !== $b2); // Object identity comparison
  211. $b1 = $b2->pb;
  212. test($b1 != null);
  213. test(get_class($b1) == ($NS ? "Test\\D1" : "Test_D1"));
  214. test($b1->sb == "D1.sb");
  215. test($b1->pb === $b2); // Object identity comparison
  216. $d1 = $b1;
  217. test($d1 != null);
  218. test($d1->sd1 == "D1.sd1");
  219. test($d1->pd1 === $b2); // Object identity comparison
  220. //
  221. // Break cyclic dependencies - helps in detecting leaks.
  222. //
  223. $b1->pb = null;
  224. $d1->pd1 = null;
  225. }
  226. echo "ok\n";
  227. echo "parameter pointer slicing with known first... ";
  228. flush();
  229. {
  230. $test->paramTest1($b1, $b2);
  231. test($b1 != null);
  232. test(get_class($b1) == ($NS ? "Test\\D1" : "Test_D1"));
  233. test($b1->sb == "D1.sb");
  234. test($b1->pb === $b2); // Object identity comparison
  235. $d1 = $b1;
  236. test($d1 != null);
  237. test($d1->sd1 == "D1.sd1");
  238. test($d1->pd1 === $b2); // Object identity comparison
  239. test($b2 != null);
  240. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B")); // No factory, must be sliced
  241. test($b2->sb == "D2.sb");
  242. test($b2->pb === $b1); // Object identity comparison
  243. //
  244. // Break cyclic dependencies - helps in detecting leaks.
  245. //
  246. $b2->pb = null;
  247. }
  248. echo "ok\n";
  249. echo "parameter pointer slicing with unknown first... ";
  250. flush();
  251. {
  252. $test->paramTest2($b2, $b1);
  253. test($b1 != null);
  254. test(get_class($b1) == ($NS ? "Test\\D1" : "Test_D1"));
  255. test($b1->sb == "D1.sb");
  256. test($b1->pb === $b2); // Object identity comparison
  257. $d1 = $b1;
  258. test($d1 != null);
  259. test($d1->sd1 == "D1.sd1");
  260. test($d1->pd1 === $b2); // Object identity comparison
  261. test($b2 != null);
  262. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B")); // No factory, must be sliced
  263. test($b2->sb == "D2.sb");
  264. test($b2->pb === $b1); // Object identity comparison
  265. //
  266. // Break cyclic dependencies - helps in detecting leaks.
  267. //
  268. $b2->pb = null;
  269. }
  270. echo "ok\n";
  271. echo "return value identity with known first... ";
  272. flush();
  273. {
  274. $r = $test->returnTest1($p1, $p2);
  275. test($r === $p1);
  276. //
  277. // Break cyclic dependencies - helps in detecting leaks.
  278. //
  279. $p2->pb = null;
  280. }
  281. echo "ok\n";
  282. echo "return value identity with unknown first... ";
  283. flush();
  284. {
  285. $r = $test->returnTest2($p1, $p2);
  286. test($r === $p1);
  287. //
  288. // Break cyclic dependencies - helps in detecting leaks.
  289. //
  290. $p1->pb = null;
  291. }
  292. echo "ok\n";
  293. echo "return value identity for input params known first... ";
  294. flush();
  295. {
  296. $d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  297. $d1->sb = "D1.sb";
  298. $d1->sd1 = "D1.sd1";
  299. $d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  300. $d3->pb = $d1;
  301. $d3->sb = "D3.sb";
  302. $d3->sd3 = "D3.sd3";
  303. $d3->pd3 = $d1;
  304. $d1->pb = $d3;
  305. $d1->pd1 = $d3;
  306. $b1 = $test->returnTest3($d1, $d3);
  307. test($b1 != null);
  308. test($b1->sb == "D1.sb");
  309. test(get_class($b1) == ($NS ? "Test\\D1" : "Test_D1"));
  310. $p1 = $b1;
  311. test($p1 != null);
  312. test($p1->sd1 == "D1.sd1");
  313. test($p1->pd1 === $b1->pb); // Object identity comparison
  314. $b2 = $b1->pb;
  315. test($b2 != null);
  316. test($b2->sb == "D3.sb");
  317. test(get_class($b2) == ($NS ? "Test\\B" : "Test_B")); // Sliced by server
  318. test($b2->pb === $b1); // Object identity comparison
  319. test(!($b2 instanceof $d3cls));
  320. test($b1 !== $d1);
  321. test($b1 !== $d3);
  322. test($b2 !== $d1);
  323. test($b2 !== $d3);
  324. //
  325. // Break cyclic dependencies - helps in detecting leaks.
  326. //
  327. $d1->pb = null;
  328. $d1->pd1 = null;
  329. $b1->pb = null;
  330. $p1->pd1 = null;
  331. }
  332. echo "ok\n";
  333. echo "return value identity for input params unknown first... ";
  334. flush();
  335. {
  336. $d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  337. $d1->sb = "D1.sb";
  338. $d1->sd1 = "D1.sd1";
  339. $d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  340. $d3->pb = $d1;
  341. $d3->sb = "D3.sb";
  342. $d3->sd3 = "D3.sd3";
  343. $d3->pd3 = $d1;
  344. $d1->pb = $d3;
  345. $d1->pd1 = $d3;
  346. $b1 = $test->returnTest3($d3, $d1);
  347. test($b1 != null);
  348. test($b1->sb == "D3.sb");
  349. test(get_class($b1) == ($NS ? "Test\\B" : "Test_B")); // Sliced by server
  350. test(!($b1 instanceof $d3cls));
  351. $b2 = $b1->pb;
  352. test($b2 != null);
  353. test($b2->sb == "D1.sb");
  354. test(get_class($b2) == ($NS ? "Test\\D1" : "Test_D1"));
  355. test($b2->pb === $b1); // Object identity comparison
  356. $p3 = $b2;
  357. test($p3 instanceof $d1cls);
  358. test($p3->sd1 == "D1.sd1");
  359. test($p3->pd1 === $b1); // Object identity comparison
  360. test($b1 !== $d1);
  361. test($b1 !== $d3);
  362. test($b2 !== $d1);
  363. test($b2 !== $d3);
  364. //
  365. // Break cyclic dependencies - helps in detecting leaks.
  366. //
  367. $d1->pb = null;
  368. $d1->pd1 = null;
  369. $b1->pb = null;
  370. $p1->pd1 = null;
  371. }
  372. echo "ok\n";
  373. echo "return value identity for input params unknown first... ";
  374. flush();
  375. {
  376. $d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  377. $d1->sb = "D1.sb";
  378. $d1->sd1 = "D1.sd1";
  379. $d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  380. $d3->pb = $d1;
  381. $d3->sb = "D3.sb";
  382. $d3->sd3 = "D3.sd3";
  383. $d3->pd3 = $d1;
  384. $d1->pb = $d3;
  385. $d1->pd1 = $d3;
  386. $b1 = $test->returnTest3($d3, $d1);
  387. test($b1 != null);
  388. test($b1->sb == "D3.sb");
  389. test(get_class($b1) == ($NS ? "Test\\B" : "Test_B")); // Sliced by server
  390. test(!($b1 instanceof $d3cls));
  391. $b2 = $b1->pb;
  392. test($b2 != null);
  393. test($b2->sb == "D1.sb");
  394. test(get_class($b2) == ($NS ? "Test\\D1" : "Test_D1"));
  395. test($b2->pb === $b1); // Object identity comparison
  396. $p3 = $b2;
  397. test($p3 instanceof $d1cls);
  398. test($p3->sd1 == "D1.sd1");
  399. test($p3->pd1 === $b1); // Object identity comparison
  400. test($b1 !== $d1);
  401. test($b1 !== $d3);
  402. test($b2 !== $d1);
  403. test($b2 !== $d3);
  404. //
  405. // Break cyclic dependencies - helps in detecting leaks.
  406. //
  407. $d3->pb = null;
  408. $d3->pd3 = null;
  409. $d3->pb = null;
  410. $d3->pd3 = null;
  411. $b1->pb = null;
  412. $b2->pb = null;
  413. }
  414. echo "ok\n";
  415. echo "remainder unmarshaling (3 instances)... ";
  416. flush();
  417. {
  418. $ret = $test->paramTest3($p1, $p2);
  419. test($p1 != null);
  420. test($p1->sb == "D2.sb (p1 1)");
  421. test($p1->pb == null);
  422. test(get_class($p1) == ($NS ? "Test\\B" : "Test_B"));
  423. test($p2 != null);
  424. test($p2->sb == "D2.sb (p2 1)");
  425. test($p2->pb == null);
  426. test(get_class($p2) == ($NS ? "Test\\B" : "Test_B"));
  427. test($ret != null);
  428. test($ret->sb == "D1.sb (p2 2)");
  429. test($ret->pb === null);
  430. test(get_class($ret) == ($NS ? "Test\\D1" : "Test_D1"));
  431. }
  432. echo "ok\n";
  433. echo "remainder unmarshaling (4 instances)... ";
  434. flush();
  435. {
  436. $ret = $test->paramTest4($b);
  437. test($b != null);
  438. test($b->sb == "D4.sb (1)");
  439. test($b->pb == null);
  440. test(get_class($b) == ($NS ? "Test\\B" : "Test_B"));
  441. test($ret != null);
  442. test($ret->sb == "B.sb (2)");
  443. test($ret->pb === null);
  444. test(get_class($ret) == ($NS ? "Test\\B" : "Test_B"));
  445. }
  446. echo "ok\n";
  447. echo "parameter pointer slicing with first instance marshaled in unknown derived as base... ";
  448. flush();
  449. {
  450. $b1 = $NS ? eval("return new Test\\B;") : eval("return new Test_B;");
  451. $b1->sb = "B.sb(1)";
  452. $b1->pb = $b1;
  453. $d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  454. $d3->sb = "D3.sb";
  455. $d3->pb = $d3;
  456. $d3->sd3 = "D3.sd3";
  457. $d3->pd3 = $b1;
  458. $b2 = $NS ? eval("return new Test\\B;") : eval("return new Test_B;");
  459. $b2->sb = "B.sb(2)";
  460. $b2->pb = $b1;
  461. $r = $test->returnTest3($d3, $b2);
  462. test($r != null);
  463. test(get_class($r) == ($NS ? "Test\\B" : "Test_B"));
  464. test($r->sb == "D3.sb");
  465. test($r->pb === $r);
  466. //
  467. // Break cyclic dependencies - helps in detecting leaks.
  468. //
  469. $b1->pb = null;
  470. $d3->pb = null;
  471. $d3->pd3 = null;
  472. $r->pb = null;
  473. }
  474. echo "ok\n";
  475. echo "parameter pointer slicing with first instance marshaled in unknown derived as derived... ";
  476. flush();
  477. {
  478. $d11 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  479. $d11->sb = "D1.sb(1)";
  480. $d11->pb = $d11;
  481. $d11->pd1 = null;
  482. $d11->sd1 = "D1.sd1(1)";
  483. $d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  484. $d3->sb = "D3.sb";
  485. $d3->pb = $d3;
  486. $d3->sd3 = "D3.sd3";
  487. $d3->pd1 = null;
  488. $d3->pd3 = $d11;
  489. $d12 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  490. $d12->sb = "D1.sb(2)";
  491. $d12->pb = $d12;
  492. $d12->sd1 = "D1.sd1(2)";
  493. $d12->pd1 = $d11;
  494. $r = $test->returnTest3($d3, $d12);
  495. test($r != null);
  496. test(get_class($r) == ($NS ? "Test\\B" : "Test_B"));
  497. test($r->sb == "D3.sb");
  498. test($r->pb === $r);
  499. //
  500. // Break cyclic dependencies - helps in detecting leaks.
  501. //
  502. $d11->pb = null;
  503. $d3->pb = null;
  504. $d3->pd3 = null;
  505. $r->pb = null;
  506. $d12->pb = null;
  507. }
  508. echo "ok\n";
  509. echo "sequence slicing... ";
  510. flush();
  511. {
  512. $ss = null;
  513. {
  514. $ss1b = $NS ? eval("return new Test\\B;") : eval("return new Test_B;");
  515. $ss1b->sb = "B.sb";
  516. $ss1b->pb = $ss1b;
  517. $ss1d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  518. $ss1d1->sb = "D1.sb";
  519. $ss1d1->sd1 = "D1.sd1";
  520. $ss1d1->pb = $ss1b;
  521. $ss1d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  522. $ss1d3->sb = "D3.sb";
  523. $ss1d3->sd3 = "D3.sd3";
  524. $ss1d3->pb = $ss1b;
  525. $ss1d3->pd3 = null;
  526. $ss2b = $NS ? eval("return new Test\\B;") : eval("return new Test_B;");
  527. $ss2b->sb = "B.sb";
  528. $ss2b->pb = $ss1b;
  529. $ss2d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  530. $ss2d1->sb = "D1.sb";
  531. $ss2d1->sd1 = "D1.sd1";
  532. $ss2d1->pb = $ss2b;
  533. $ss2d3 = $NS ? eval("return new Test\\D3;") : eval("return new Test_D3;");
  534. $ss2d3->sb = "D3.sb";
  535. $ss2d3->sd3 = "D3.sd3";
  536. $ss2d3->pb = $ss2b;
  537. $ss2d3->pd1 = null;
  538. $ss1d1->pd1 = $ss2b;
  539. $ss1d3->pd3 = $ss2d1;
  540. $ss2d1->pd1 = $ss1d3;
  541. $ss2d3->pd3 = $ss1d1;
  542. $ss1 = $NS ? eval("return new Test\\SS1;") : eval("return new Test_SS1;");
  543. $ss1->s = array($ss1b, $ss1d1, $ss1d3);
  544. $ss2 = $NS ? eval("return new Test\\SS2;") : eval("return new Test_SS2;");
  545. $ss2->s = array($ss2b, $ss2d1, $ss2d3);
  546. $ss = $test->sequenceTest($ss1, $ss2);
  547. //
  548. // Break cyclic dependencies - helps in detecting leaks.
  549. //
  550. $ss1b->pb = null;
  551. $ss1d1->pd1 = null;
  552. $ss1d3->pd3 = null;
  553. $ss2d1->pd1 = null;
  554. $ss2d3->pd3 = null;
  555. }
  556. test($ss->c1 != null);
  557. $ss1b = $ss->c1->s[0];
  558. $ss1d1 = $ss->c1->s[1];
  559. $ss1d3 = $ss->c1->s[2];
  560. test($ss->c2 != null);
  561. $ss2b = $ss->c2->s[0];
  562. $ss2d1 = $ss->c2->s[1];
  563. $ss2d3 = $ss->c2->s[2];
  564. test($ss1b->pb === $ss1b);
  565. test($ss1d1->pb === $ss1b);
  566. test($ss1d3->pb === $ss1b);
  567. test($ss2b->pb === $ss1b);
  568. test($ss2d1->pb === $ss2b);
  569. test($ss2d3->pb === $ss2b);
  570. test(get_class($ss1b) == ($NS ? "Test\\B" : "Test_B"));
  571. test(get_class($ss1d1) == ($NS ? "Test\\D1" : "Test_D1"));
  572. test(get_class($ss1d3) == ($NS ? "Test\\B" : "Test_B"));
  573. test(get_class($ss2b) == ($NS ? "Test\\B" : "Test_B"));
  574. test(get_class($ss2d1) == ($NS ? "Test\\D1" : "Test_D1"));
  575. test(get_class($ss2d3) == ($NS ? "Test\\B" : "Test_B"));
  576. //
  577. // Break cyclic dependencies - helps in detecting leaks.
  578. //
  579. $ss1b->pb = null;
  580. }
  581. echo "ok\n";
  582. echo "dictionary slicing... ";
  583. flush();
  584. {
  585. $bin = array();
  586. for($i = 0; $i < 10; $i++)
  587. {
  588. $d1 = $NS ? eval("return new Test\\D1;") : eval("return new Test_D1;");
  589. $d1->sb = sprintf("D1.%d", $i);
  590. $d1->pb = $d1;
  591. $d1->sd1 = $d1->sb;
  592. $d1->pd1 = null;
  593. $bin[$i] = $d1;
  594. }
  595. $r = $test->dictionaryTest($bin, $bout);
  596. test(count($bout) == 10);
  597. for($i = 0; $i < 10; $i++)
  598. {
  599. $b = $bout[$i * 10];
  600. $s = sprintf("D1.%d", $i);
  601. test($b != null);
  602. test($b->sb == $s);
  603. test($b->pb != null);
  604. test($b->pb !== $b);
  605. test($b->pb->sb == $s);
  606. test($b->pb->pb === $b->pb);
  607. }
  608. test(count($r) == 10);
  609. for($i = 0; $i < 10; $i++)
  610. {
  611. $b = $r[$i * 20];
  612. $s = sprintf("D1.%d", $i * 20);
  613. test($b != null);
  614. test($b->sb == $s);
  615. if($i == 0)
  616. {
  617. test($b->pb == null);
  618. }
  619. else
  620. {
  621. test($b->pb === $r[($i - 1) * 20]);
  622. }
  623. test($b instanceof $d1cls);
  624. $d1 = $b;
  625. test($d1->sd1 == $s);
  626. test($d1->pd1 === $d1);
  627. }
  628. //
  629. // Break cyclic dependencies - helps in detecting leaks.
  630. //
  631. for($i = 0; $i < 10; $i++)
  632. {
  633. $bin[$i]->pb = null;
  634. $bout[$i * 10]->pb->pb = null;
  635. $r[$i * 20]->pb = null;
  636. $r[$i * 20]->pd1 = null;
  637. }
  638. }
  639. echo "ok\n";
  640. echo "base exception thrown as base exception... ";
  641. flush();
  642. {
  643. try
  644. {
  645. $test->throwBaseAsBase();
  646. test(false);
  647. }
  648. catch(Exception $e)
  649. {
  650. $excls = $NS ? "Test\\BaseException" : "Test_BaseException";
  651. if(!($e instanceof $excls))
  652. {
  653. throw $ex;
  654. }
  655. test(get_class($e) == ($NS ? "Test\\BaseException" : "Test_BaseException"));
  656. test($e->sbe == "sbe");
  657. test($e->pb != null);
  658. test($e->pb->sb == "sb");
  659. test($e->pb->pb === $e->pb);
  660. //
  661. // Break cyclic dependencies - helps in detecting leaks.
  662. //
  663. $e->pb->pb = null;
  664. }
  665. }
  666. echo "ok\n";
  667. echo "derived exception thrown as base exception... ";
  668. flush();
  669. {
  670. try
  671. {
  672. $test->throwDerivedAsBase();
  673. test(false);
  674. }
  675. catch(Exception $e)
  676. {
  677. $excls = $NS ? "Test\\DerivedException" : "Test_DerivedException";
  678. if(!($e instanceof $excls))
  679. {
  680. throw $ex;
  681. }
  682. test(get_class($e) == ($NS ? "Test\\DerivedException" : "Test_DerivedException"));
  683. test($e->sbe == "sbe");
  684. test($e->pb != null);
  685. test($e->pb->sb == "sb1");
  686. test($e->pb->pb === $e->pb);
  687. test($e->sde == "sde1");
  688. test($e->pd1 != null);
  689. test($e->pd1->sb == "sb2");
  690. test($e->pd1->pb === $e->pd1);
  691. test($e->pd1->sd1 == "sd2");
  692. test($e->pd1->pd1 === $e->pd1);
  693. //
  694. // Break cyclic dependencies - helps in detecting leaks.
  695. //
  696. $e->pb->pb = null;
  697. $e->pd1->pb = null;
  698. $e->pd1->pd1 = null;
  699. }
  700. }
  701. echo "ok\n";
  702. echo "derived exception thrown as derived exception... ";
  703. flush();
  704. {
  705. try
  706. {
  707. $test->throwDerivedAsDerived();
  708. test(false);
  709. }
  710. catch(Exception $e)
  711. {
  712. $excls = $NS ? "Test\\DerivedException" : "Test_DerivedException";
  713. if(!($e instanceof $excls))
  714. {
  715. throw $ex;
  716. }
  717. test(get_class($e) == ($NS ? "Test\\DerivedException" : "Test_DerivedException"));
  718. test($e->sbe == "sbe");
  719. test($e->pb != null);
  720. test($e->pb->sb == "sb1");
  721. test($e->pb->pb === $e->pb);
  722. test($e->sde == "sde1");
  723. test($e->pd1 != null);
  724. test($e->pd1->sb == "sb2");
  725. test($e->pd1->pb === $e->pd1);
  726. test($e->pd1->sd1 == "sd2");
  727. test($e->pd1->pd1 === $e->pd1);
  728. //
  729. // Break cyclic dependencies - helps in detecting leaks.
  730. //
  731. $e->pb->pb = null;
  732. $e->pd1->pb = null;
  733. $e->pd1->pd1 = null;
  734. }
  735. }
  736. echo "ok\n";
  737. echo "unknown derived exception thrown as base exception... ";
  738. flush();
  739. {
  740. try
  741. {
  742. $test->throwUnknownDerivedAsBase();
  743. test(false);
  744. }
  745. catch(Exception $e)
  746. {
  747. $excls = $NS ? "Test\\BaseException" : "Test_BaseException";
  748. if(!($e instanceof $excls))
  749. {
  750. throw $ex;
  751. }
  752. test(get_class($e) == ($NS ? "Test\\BaseException" : "Test_BaseException"));
  753. test($e->sbe == "sbe");
  754. test($e->pb != null);
  755. test($e->pb->sb == "sb d2");
  756. test($e->pb->pb === $e->pb);
  757. //
  758. // Break cyclic dependencies - helps in detecting leaks.
  759. //
  760. $e->pb->pb = null;
  761. }
  762. }
  763. echo "ok\n";
  764. echo "forward-declared class... ";
  765. flush();
  766. {
  767. try
  768. {
  769. $f = null;
  770. $test->useForward($f);
  771. test($f != null);
  772. }
  773. catch(Exception $e)
  774. {
  775. test(false);
  776. }
  777. }
  778. echo "ok\n";
  779. echo "preserved classes... ";
  780. flush();
  781. {
  782. //
  783. // Server knows the most-derived class PDerived.
  784. //
  785. $pd = $NS ? eval("return new Test\\PDerived;") : eval("return new Test_PDerived;");
  786. $pd->pi = 3;
  787. $pd->ps = "preserved";
  788. $pd->pb = $pd;
  789. $r = $test->exchangePBase($pd);
  790. test(get_class($r) == ($NS ? "Test\\PDerived" : "Test_PDerived"));
  791. test($r->pi == 3);
  792. test($r->ps == "preserved");
  793. test($r->pb === $r); // Object identity comparison
  794. //
  795. // Server only knows the base (non-preserved) type, so the object is sliced.
  796. //
  797. $pu = $NS ? eval("return new Test\\PCUnknown;") : eval("return new Test_PCUnknown;");
  798. $pu->pi = 3;
  799. $pu->pu = "preserved";
  800. $r = $test->exchangePBase($pu);
  801. test(get_class($r) != ($NS ? "Test\\PCUnknown" : "Test_PCUnknown"));
  802. test($r->pi == 3);
  803. //
  804. // Server only knows the intermediate type Preserved. The object will be sliced to
  805. // Preserved for the 1.0 encoding; otherwise it should be returned intact.
  806. //
  807. $pcd = $NS ? eval("return new Test\\PCDerived;") : eval("return new Test_PCDerived;");
  808. $pcd->pi = 3;
  809. $pcd->pbs = array($pcd);
  810. $r = $test->exchangePBase($pcd);
  811. if($test->ice_getEncodingVersion() == $Ice_Encoding_1_0)
  812. {
  813. test(get_class($r) != ($NS ? "Test\\PCDerived" : "Test_PCDerived"));
  814. test($r->pi == 3);
  815. }
  816. else
  817. {
  818. test(get_class($r) == ($NS ? "Test\\PCDerived" : "Test_PCDerived"));
  819. test($r->pi == 3);
  820. test($r->pbs[0] === $r); // Object identity comparison
  821. }
  822. //
  823. // Server only knows the intermediate type CompactPDerived. The object will be sliced to
  824. // CompactPDerived for the 1.0 encoding; otherwise it should be returned intact.
  825. //
  826. $pcd = $NS ? eval("return new Test\\CompactPCDerived;") : eval("return new Test_CompactPCDerived;");
  827. $pcd->pi = 3;
  828. $pcd->pbs = array($pcd);
  829. $r = $test->exchangePBase($pcd);
  830. if($test->ice_getEncodingVersion() == $Ice_Encoding_1_0)
  831. {
  832. test(get_class($r) != ($NS ? "Test\\CompactPCDerived" : "Test_CompactPCDerived"));
  833. test($r->pi == 3);
  834. }
  835. else
  836. {
  837. test(get_class($r) == ($NS ? "Test\\CompactPCDerived" : "Test_CompactPCDerived"));
  838. test($r->pi == 3);
  839. test($r->pbs[0] === $r); // Object identity comparison
  840. }
  841. //
  842. // Send an object that will have multiple preserved slices in the server.
  843. // The object will be sliced to Preserved for the 1.0 encoding.
  844. //
  845. $pcd = $NS ? eval("return new Test\\PCDerived3;") : eval("return new Test_PCDerived3;");
  846. $pcd->pi = 3;
  847. //
  848. // Sending more than 254 objects exercises the encoding for object ids.
  849. //
  850. $pcd->pbs = array();
  851. for($i = 0; $i < 300; ++$i)
  852. {
  853. $p2 = $NS ? eval("return new Test\\PCDerived2;") : eval("return new Test_PCDerived2;");
  854. $p2->pi = $i;
  855. $p2->pbs = array(null); // Nil reference. This slice should not have an indirection table.
  856. $p2->pcd2 = $i;
  857. array_push($pcd->pbs, $p2);
  858. }
  859. $pcd->pcd2 = $pcd->pi;
  860. $pcd->pcd3 = $pcd->pbs[10];
  861. $r = $test->exchangePBase($pcd);
  862. if($test->ice_getEncodingVersion() == $Ice_Encoding_1_0)
  863. {
  864. test(get_class($r) != ($NS ? "Test\\PCDerived3" : "Test_PCDerived3"));
  865. test(get_class($r) == ($NS ? "Test\\PDerived" : "Test_PDerived"));
  866. test($r->pi == 3);
  867. }
  868. else
  869. {
  870. test(get_class($r) == ($NS ? "Test\\PCDerived3" : "Test_PCDerived3"));
  871. test($r->pi == 3);
  872. for($i = 0; $i < 300; ++$i)
  873. {
  874. $p2 = $r->pbs[$i];
  875. test(get_class($p2) == ($NS ? "Test\\PCDerived2" : "Test_PCDerived2"));
  876. test($p2->pi == $i);
  877. test(count($p2->pbs) == 1);
  878. test($p2->pbs[0] == null);
  879. test($p2->pcd2 == $i);
  880. }
  881. test($r->pcd2 == $r->pi);
  882. test($r->pcd3 === $r->pbs[10]); // Object identity comparison
  883. }
  884. //
  885. // Obtain an object with preserved slices and send it back to the server.
  886. // The preserved slices should be excluded for the 1.0 encoding, otherwise
  887. // they should be included.
  888. //
  889. $p = $test->PBSUnknownAsPreserved();
  890. $test->checkPBSUnknown($p);
  891. if($test->ice_getEncodingVersion() != $Ice_Encoding_1_0)
  892. {
  893. $test->ice_encodingVersion($Ice_Encoding_1_0)->checkPBSUnknown($p);
  894. }
  895. //
  896. // Relay a graph through the server. This test uses a preserved class
  897. // with a class member.
  898. //
  899. $c = $NS ? eval("return new Test\\PNode;") : eval("return new Test_PNode;");
  900. $c->next = $NS ? eval("return new Test\\PNode;") : eval("return new Test_PNode;");
  901. $c->next->next = $NS ? eval("return new Test\\PNode;") : eval("return new Test_PNode;");
  902. $c->next->next->next = $c; // Create a cyclic graph.
  903. $n = $test->exchangePNode($c);
  904. test($n->next != null);
  905. test($n->next !== $n->next->next); // Object identity comparison
  906. test($n->next->next !== $n->next->next->next); // Object identity comparison
  907. test($n->next->next->next === $n); // Object identity comparison
  908. $n = null; // Release reference.
  909. //
  910. // Obtain a preserved object from the server where the most-derived
  911. // type is unknown. The preserved slice refers to a graph of PNode
  912. // objects.
  913. //
  914. $p = $test->PBSUnknownAsPreservedWithGraph();
  915. test($p != null);
  916. $test->checkPBSUnknownWithGraph($p);
  917. $p = null; // Release reference.
  918. //
  919. // Obtain a preserved object from the server where the most-derived
  920. // type is unknown. A data member in the preserved slice refers to the
  921. // outer object, so the chain of references looks like this:
  922. //
  923. // outer->slicedData->outer
  924. //
  925. $p = $test->PBSUnknown2AsPreservedWithGraph();
  926. test($p != null);
  927. if($test->ice_getEncodingVersion() != $Ice_Encoding_1_0)
  928. {
  929. test($p->_ice_slicedData != null);
  930. }
  931. $test->checkPBSUnknown2WithGraph($p);
  932. $p->_ice_slicedData = null; // Break the cycle.
  933. $p = null; // Release reference.
  934. }
  935. echo "ok\n";
  936. return $test;
  937. }
  938. $communicator = Ice_initialize($argv);
  939. $test = allTests($communicator);
  940. $test->shutdown();
  941. $communicator->destroy();
  942. exit();
  943. ?>