Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements. See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership. The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License. You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied. See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19
 
20
<?php
21
 
22
if (!isset($GEN_DIR)) {
23
  $GEN_DIR = 'gen-php';
24
}
25
if (!isset($MODE)) {
26
  $MODE = 'normal';
27
}
28
 
29
/** Set the Thrift root */
30
$GLOBALS['THRIFT_ROOT'] = '../../lib/php/src';
31
 
32
/** Include the Thrift base */
33
require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
34
 
35
/** Include the binary protocol */
36
require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
37
 
38
/** Include the socket layer */
39
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocketPool.php';
40
 
41
/** Include the socket layer */
42
require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
43
 
44
echo '==============================='."\n";
45
echo ' SAFE TO IGNORE THESE IN TEST'."\n";
46
echo '==============================='."\n";
47
 
48
/** Include the generated code */
49
require_once $GEN_DIR.'/ThriftTest.php';
50
require_once $GEN_DIR.'/ThriftTest_types.php';
51
 
52
echo '==============================='."\n";
53
echo ' END OF SAFE ERRORS SECTION'."\n";
54
echo '==============================='."\n\n";
55
 
56
$host = 'localhost';
57
$port = 9090;
58
 
59
if ($argc > 1) {
60
  $host = $argv[0];
61
}
62
 
63
if ($argc > 2) {
64
  $host = $argv[1];
65
}
66
 
67
$hosts = array('localhost');
68
 
69
$socket = new TSocket($host, $port);
70
$socket = new TSocketPool($hosts, $port);
71
$socket->setDebug(TRUE);
72
 
73
if ($MODE == 'inline') {
74
  $transport = $socket;
75
  $testClient = new ThriftTestClient($transport);
76
} else {
77
  $bufferedSocket = new TBufferedTransport($socket, 1024, 1024);
78
  $transport = $bufferedSocket;
79
  $protocol = new TBinaryProtocol($transport);
80
  $testClient = new ThriftTestClient($protocol);
81
}
82
 
83
$transport->open();
84
 
85
$start = microtime(true);
86
 
87
/**
88
 * VOID TEST
89
 */
90
print_r("testVoid()");
91
$testClient->testVoid();
92
print_r(" = void\n");
93
 
94
/**
95
 * STRING TEST
96
 */
97
print_r("testString(\"Test\")");
98
$s = $testClient->testString("Test");
99
print_r(" = \"$s\"\n");
100
 
101
/**
102
 * BYTE TEST
103
 */
104
print_r("testByte(1)");
105
$u8 = $testClient->testByte(1);
106
print_r(" = $u8\n");
107
 
108
/**
109
 * I32 TEST
110
 */
111
print_r("testI32(-1)");
112
$i32 = $testClient->testI32(-1);
113
print_r(" = $i32\n");
114
 
115
/**
116
 * I64 TEST
117
 */
118
print_r("testI64(-34359738368)");
119
$i64 = $testClient->testI64(-34359738368);
120
print_r(" = $i64\n");
121
 
122
/**
123
 * DOUBLE TEST
124
 */
125
print_r("testDouble(-852.234234234)");
126
$dub = $testClient->testDouble(-852.234234234);
127
print_r(" = $dub\n");
128
 
129
/**
130
 * STRUCT TEST
131
 */
132
print_r("testStruct({\"Zero\", 1, -3, -5})");
133
$out = new Xtruct();
134
$out->string_thing = "Zero";
135
$out->byte_thing = 1;
136
$out->i32_thing = -3;
137
$out->i64_thing = -5;
138
$in = $testClient->testStruct($out);
139
print_r(" = {\"".$in->string_thing."\", ".
140
        $in->byte_thing.", ".
141
        $in->i32_thing.", ".
142
        $in->i64_thing."}\n");
143
 
144
/**
145
 * NESTED STRUCT TEST
146
 */
147
print_r("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
148
$out2 = new Xtruct2();
149
$out2->byte_thing = 1;
150
$out2->struct_thing = $out;
151
$out2->i32_thing = 5;
152
$in2 = $testClient->testNest($out2);
153
$in = $in2->struct_thing;
154
print_r(" = {".$in2->byte_thing.", {\"".
155
        $in->string_thing."\", ".
156
        $in->byte_thing.", ".
157
        $in->i32_thing.", ".
158
        $in->i64_thing."}, ".
159
        $in2->i32_thing."}\n");
160
 
161
/**
162
 * MAP TEST
163
 */
164
$mapout = array();
165
for ($i = 0; $i < 5; ++$i) {
166
  $mapout[$i] = $i-10;
167
}
168
print_r("testMap({");
169
$first = true;
170
foreach ($mapout as $key => $val) {
171
  if ($first) {
172
    $first = false;
173
  } else {
174
    print_r(", ");
175
  }
176
  print_r("$key => $val");
177
}
178
print_r("})");
179
 
180
$mapin = $testClient->testMap($mapout);
181
print_r(" = {");
182
$first = true;
183
foreach ($mapin as $key => $val) {
184
  if ($first) {
185
    $first = false;
186
  } else {
187
    print_r(", ");
188
  }
189
  print_r("$key => $val");
190
}
191
print_r("}\n");
192
 
193
/**
194
 * SET TEST
195
 */
196
$setout = array();;
197
for ($i = -2; $i < 3; ++$i) {
198
  $setout []= $i;
199
}
200
print_r("testSet({");
201
$first = true;
202
foreach ($setout as $val) {
203
  if ($first) {
204
    $first = false;
205
  } else {
206
    print_r(", ");
207
  }
208
  print_r($val);
209
}
210
print_r("})");
211
$setin = $testClient->testSet($setout);
212
print_r(" = {");
213
$first = true;
214
foreach ($setin as $val) {
215
  if ($first) {
216
    $first = false;
217
  } else {
218
    print_r(", ");
219
  }
220
  print_r($val);
221
}
222
print_r("}\n");
223
 
224
/**
225
 * LIST TEST
226
 */
227
$listout = array();
228
for ($i = -2; $i < 3; ++$i) {
229
  $listout []= $i;
230
}
231
print_r("testList({");
232
$first = true;
233
foreach ($listout as $val) {
234
  if ($first) {
235
    $first = false;
236
  } else {
237
    print_r(", ");
238
  }
239
  print_r($val);
240
}
241
print_r("})");
242
$listin = $testClient->testList($listout);
243
print_r(" = {");
244
$first = true;
245
foreach ($listin as $val) {
246
  if ($first) {
247
    $first = false;
248
  } else {
249
    print_r(", ");
250
  }
251
  print_r($val);
252
}
253
print_r("}\n");
254
 
255
/**
256
 * ENUM TEST
257
 */
258
print_r("testEnum(ONE)");
259
$ret = $testClient->testEnum(Numberz::ONE);
260
print_r(" = $ret\n");
261
 
262
print_r("testEnum(TWO)");
263
$ret = $testClient->testEnum(Numberz::TWO);
264
print_r(" = $ret\n");
265
 
266
print_r("testEnum(THREE)");
267
$ret = $testClient->testEnum(Numberz::THREE);
268
print_r(" = $ret\n");
269
 
270
print_r("testEnum(FIVE)");
271
$ret = $testClient->testEnum(Numberz::FIVE);
272
print_r(" = $ret\n");
273
 
274
print_r("testEnum(EIGHT)");
275
$ret = $testClient->testEnum(Numberz::EIGHT);
276
print_r(" = $ret\n");
277
 
278
/**
279
 * TYPEDEF TEST
280
 */
281
print_r("testTypedef(309858235082523)");
282
$uid = $testClient->testTypedef(309858235082523);
283
print_r(" = $uid\n");
284
 
285
/**
286
 * NESTED MAP TEST
287
 */
288
print_r("testMapMap(1)");
289
$mm = $testClient->testMapMap(1);
290
print_r(" = {");
291
foreach ($mm as $key => $val) {
292
  print_r("$key => {");
293
  foreach ($val as $k2 => $v2) {
294
    print_r("$k2 => $v2, ");
295
  }
296
  print_r("}, ");
297
}
298
print_r("}\n");
299
 
300
/**
301
 * INSANITY TEST
302
 */
303
$insane = new Insanity();
304
$insane->userMap[Numberz::FIVE] = 5000;
305
$truck = new Xtruct();
306
$truck->string_thing = "Truck";
307
$truck->byte_thing = 8;
308
$truck->i32_thing = 8;
309
$truck->i64_thing = 8;
310
$insane->xtructs []= $truck;
311
print_r("testInsanity()");
312
$whoa = $testClient->testInsanity($insane);
313
print_r(" = {");
314
foreach ($whoa as $key => $val) {
315
  print_r("$key => {");
316
  foreach ($val as $k2 => $v2) {
317
    print_r("$k2 => {");
318
    $userMap = $v2->userMap;
319
    print_r("{");
320
    if (is_array($usermap)) {
321
      foreach ($userMap as $k3 => $v3) {
322
        print_r("$k3 => $v3, ");
323
      }
324
    }
325
    print_r("}, ");
326
 
327
    $xtructs = $v2->xtructs;
328
    print_r("{");
329
    if (is_array($xtructs)) {
330
      foreach ($xtructs as $x) {
331
        print_r("{\"".$x->string_thing."\", ".
332
                $x->byte_thing.", ".$x->i32_thing.", ".$x->i64_thing."}, ");
333
      }
334
    }
335
    print_r("}");
336
 
337
    print_r("}, ");
338
  }
339
  print_r("}, ");
340
}
341
print_r("}\n");
342
 
343
/**
344
 * EXCEPTION TEST
345
 */
346
print_r("testException('Xception')");
347
try {
348
  $testClient->testException('Xception');
349
  print_r("  void\nFAILURE\n");
350
} catch (Xception $x) {
351
  print_r(' caught xception '.$x->errorCode.': '.$x->message."\n");
352
}
353
 
354
 
355
/**
356
 * Normal tests done.
357
 */
358
 
359
$stop = microtime(true);
360
$elp = round(1000*($stop - $start), 0);
361
print_r("Total time: $elp ms\n");
362
 
363
/**
364
 * Extraneous "I don't trust PHP to pack/unpack integer" tests
365
 */
366
 
367
// Max I32
368
$num = pow(2, 30) + (pow(2, 30) - 1);
369
$num2 = $testClient->testI32($num);
370
if ($num != $num2) {
371
  print "Missed $num = $num2\n";
372
}
373
 
374
// Min I32
375
$num = 0 - pow(2, 31);
376
$num2 = $testClient->testI32($num);
377
if ($num != $num2) {
378
  print "Missed $num = $num2\n";
379
}
380
 
381
// Max I64
382
$num = pow(2, 62) + (pow(2, 62) - 1);
383
$num2 = $testClient->testI64($num);
384
if ($num != $num2) {
385
  print "Missed $num = $num2\n";
386
}
387
 
388
// Min I64
389
$num = 0 - pow(2, 63);
390
$num2 = $testClient->testI64($num);
391
if ($num != $num2) {
392
  print "Missed $num = $num2\n";
393
}
394
 
395
$transport->close();
396
return;
397
 
398
?>