Guest User

Untitled

a guest
Dec 31st, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. <?php
  2.  
  3. $GLOBALS['THRIFT_ROOT'] = '/usr/lib/php';
  4.  
  5. require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
  6. require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TJSONProtocol.php';
  7. require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
  8. #require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';
  9. require_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
  10. require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
  11. require_once '/var/www/html/tjs/web/gen-php/ThriftTest/ThriftTest.php';
  12.  
  13. /****
  14.  * stuff for binary tests
  15.  ***/
  16. require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
  17. require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
  18.  
  19.  
  20. class ThriftTestHandler
  21. {
  22.   function testVoid() {
  23.   }
  24.  
  25.   function testString($s) {
  26.     return $s;
  27.   }
  28.  
  29.   function testDouble($d) {
  30.     return $d;
  31.   }
  32.  
  33.   function testByte($b) {
  34.     return $b;
  35.   }
  36.  
  37.   function testI32($i) {
  38.     return $i;
  39.   }
  40.  
  41.   function testI64($i) {
  42.     return $i;
  43.   }
  44.  
  45.   function testStruct($s) {
  46.     return $s;
  47.   }
  48.  
  49.   function testNest($s) {
  50.     return $s;
  51.   }
  52.  
  53.   function testMap($m) {
  54.     return $m;
  55.   }
  56.  
  57.   function testStringMap($m) {
  58.     return $m;
  59.   }
  60.  
  61.   function testSet($s) {
  62.     return $s;
  63.   }
  64.  
  65.   function testList($l) {
  66.     return $l;
  67.   }
  68.  
  69.   function testEnum($e) {
  70.     return $e;
  71.   }
  72.  
  73.   function testTypeDef($t) {
  74.     return $t;
  75.   }
  76.  
  77.   function testMapMap($m) {
  78.     #  map<i32,map<i32,i32>>
  79.    $expectedResult = array(
  80.                 "4" => array(
  81.                      "1" => 1,
  82.                      "2" => 2,
  83.                      "3" => 3,
  84.                      "4" => 4
  85.                      ),
  86.                 "-4" => array(
  87.                       "-4" => -4,
  88.                       "-3" => -3,
  89.                       "-2" => -2,
  90.                       "-1" => -1
  91.                       )
  92.                 );
  93.     return $expectedResult;
  94.  
  95.   }
  96.  
  97.   function testException($m) {
  98.     switch ($m) {
  99.     case 'Xception':
  100.     case 'ApplicationException':
  101.       throw new ThriftTest_Xception(
  102.                     array(
  103.                       'errorCode' => 1001,
  104.                       'message' => "$m"
  105.                       )
  106.                     );
  107.       break;
  108.     default:
  109.       break;
  110.     }
  111.   }
  112.  
  113.   function testInsanity() {
  114.     $xtruct1 = new ThriftTest_Xtruct(
  115.                      array(
  116.                        'string_thing' => 'Goodbye4',
  117.                        'byte_thing' => 4,
  118.                        'i32_thing' => 4,
  119.                        'i64_thing' => 4
  120.                        )
  121.                      );
  122.  
  123.     $xtruct2 = new ThriftTest_Xtruct(
  124.                      array(
  125.                        'string_thing' => 'Hello2',
  126.                        'byte_thing' =>2,
  127.                        'i32_thing' => 2,
  128.                        'i64_thing' => 2
  129.                        )
  130.                      );
  131.  
  132.     $userMap = array(
  133.              Numberz::FIVE => 5,
  134.              Numberz::EIGHT => 8
  135.              );
  136.  
  137.     $insanity2 = new ThriftTest_Insanity(
  138.                      array(
  139.                            'userMap' => $userMap,
  140.                            'xtructs' => array($xtruct1,$xtruct2)
  141.                            )
  142.                      );
  143.     $insanity3 = $insanity2;
  144.  
  145.     $insanity6 = new ThriftTest_Insanity(
  146.                      array(
  147.                            'userMap' => null,
  148.                            'xtructs' => null
  149.                            )
  150.                      );
  151.  
  152.     return array(
  153.          "1" => array(
  154.                   Numberz::TWO => $insanity2,
  155.                   Numberz::THREE => $insanity3
  156.                   ),
  157.          "2" => array(
  158.                   Numberz::SIX => $insanity6
  159.                   )
  160.          );
  161.  
  162.   }
  163.  
  164. }
  165.  
  166. $handler = new ThriftTestHandler();
  167. $processor = new ThriftTestProcessor($handler);
  168. $tinput = new TPhpStream(TPhpStream::MODE_R);
  169. $toutput = new TPhpStream(TPhpStream::MODE_W);
  170. $tinput->open();
  171. $toutput->open();
  172. $pinput = new TJSONProtocol($tinput);
  173. $poutput = new TJSONProtocol($toutput);
  174.  
  175. /***
  176.  * for binary tests
  177.  */
  178. //$pinput = new TBinaryProtocol($tinput);
  179. //$poutput = new TBinaryProtocol($toutput);
  180.  
  181. $processor->process($pinput,$poutput);
Advertisement
Add Comment
Please, Sign In to add comment