Thrift now works in PHP, hot stuff
Summary: End to end communication working in Thrift with PHP
Problem: It's a bit slower than pillar still. Need to find out why.
Reviewed By: aditya
Test Plan: Unit tests are in the test directory. Get lucas on the PHP case...
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664720 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index 6999f4e..6f72216 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -8,15 +8,13 @@
EIGHT = 8
}
-typedef u64 UserId
+typedef i64 UserId
struct Xtruct
{
string string_thing = 0,
byte byte_thing = 1,
- u32 u32_thing = 2,
i32 i32_thing = 3,
- u64 u64_thing = 4,
i64 i64_thing = 5
}
@@ -38,9 +36,7 @@
void testVoid()
string testString(string thing = 0)
byte testByte(byte thing = 0)
- u32 testU32(u32 thing = 0)
i32 testI32(i32 thing = 0)
- u64 testU64(u64 thing = 0)
i64 testI64(i64 thing = 0)
Xtruct testStruct(Xtruct thing = 0)
Xtruct2 testNest(Xtruct2 thing = 0)
diff --git a/test/cpp/Makefile b/test/cpp/Makefile
index 21c09ec..36abb43 100644
--- a/test/cpp/Makefile
+++ b/test/cpp/Makefile
@@ -12,19 +12,28 @@
LD = g++
# Compiler flags
-LIBS = ../../lib/cpp/server/TSimpleServer.cc \
- ../../lib/cpp/protocol/TBinaryProtocol.cc \
- ../../lib/cpp/transport/TBufferedTransport.cc \
- ../../lib/cpp/transport/TServerSocket.cc \
- ../../lib/cpp/transport/TSocket.cc
-CFL = -Wall -O3 -Igen-cpp -I../../lib/cpp $(LIBS)
-CFL = -Wall -O3 -Igen-cpp -I../../lib/cpp -lthrift
+LIBS = ../../lib/cpp/src/server/TSimpleServer.cc \
+ ../../lib/cpp/src/protocol/TBinaryProtocol.cc \
+ ../../lib/cpp/src/transport/TBufferedTransport.cc \
+ ../../lib/cpp/src/transport/TChunkedTransport.cc \
+ ../../lib/cpp/src/transport/TServerSocket.cc \
+ ../../lib/cpp/src/transport/TSocket.cc
+DCFL = -Wall -O3 -g -Igen-cpp -I../../lib/cpp/src $(LIBS)
+CFL = -Wall -O3 -Igen-cpp -I../../lib/cpp/src -lthrift
all: server client
+debug: server-debug client-debug
+
stubs: ../ThriftTest.thrift
$(THRIFT) -cpp ../ThriftTest.thrift
+server-debug: stubs
+ g++ -o TestServer $(DCFL) src/TestServer.cc gen-cpp/ThriftTest.cc
+
+client-debug: stubs
+ g++ -o TestClient $(DCFL) src/TestClient.cc gen-cpp/ThriftTest.cc
+
server: stubs
g++ -o TestServer $(CFL) src/TestServer.cc gen-cpp/ThriftTest.cc
diff --git a/test/cpp/src/TestClient.cc b/test/cpp/src/TestClient.cc
index 6bd06b9..083661f 100644
--- a/test/cpp/src/TestClient.cc
+++ b/test/cpp/src/TestClient.cc
@@ -77,14 +77,7 @@
printf("testByte(1)");
uint8_t u8 = testClient.testByte(1);
printf(" = %d\n", (int)u8);
-
- /**
- * U32 TEST
- */
- printf("testU32(1)");
- uint32_t u32 = testClient.testU32(1);
- printf(" = %u\n", u32);
-
+
/**
* I32 TEST
*/
@@ -93,13 +86,6 @@
printf(" = %d\n", i32);
/**
- * U64 TEST
- */
- printf("testU64(34359738368)");
- uint64_t u64 = testClient.testU64(34359738368);
- printf(" = %lu\n", u64);
-
- /**
* I64 TEST
*/
printf("testI64(-34359738368)");
@@ -109,40 +95,34 @@
/**
* STRUCT TEST
*/
- printf("testStruct({\"Zero\", 1, 2, -3, 4, -5})");
+ printf("testStruct({\"Zero\", 1, -3, -5})");
Xtruct out;
out.string_thing = "Zero";
out.byte_thing = 1;
- out.u32_thing = 2;
out.i32_thing = -3;
- out.u64_thing = 4;
out.i64_thing = -5;
Xtruct in = testClient.testStruct(out);
- printf(" = {\"%s\", %d, %u, %d, %lu, %ld}\n",
+ printf(" = {\"%s\", %d, %d, %ld}\n",
in.string_thing.c_str(),
(int)in.byte_thing,
- in.u32_thing,
in.i32_thing,
- in.u64_thing,
in.i64_thing);
/**
* NESTED STRUCT TEST
*/
- printf("testNest({1, {\"Zero\", 1, 2, -3, 4, -5}), 5}");
+ printf("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Xtruct2 out2;
out2.byte_thing = 1;
out2.struct_thing = out;
out2.i32_thing = 5;
Xtruct2 in2 = testClient.testNest(out2);
in = in2.struct_thing;
- printf(" = {%d, {\"%s\", %d, %u, %d, %lu, %ld}, %d}\n",
+ printf(" = {%d, {\"%s\", %d, %d, %ld}, %d}\n",
in2.byte_thing,
in.string_thing.c_str(),
(int)in.byte_thing,
- in.u32_thing,
in.i32_thing,
- in.u64_thing,
in.i64_thing,
in2.i32_thing);
@@ -270,7 +250,7 @@
*/
printf("testTypedef(309858235082523)");
UserId uid = testClient.testTypedef(309858235082523);
- printf(" = %lu\n", uid);
+ printf(" = %ld\n", uid);
/**
* NESTED MAP TEST
@@ -297,9 +277,7 @@
Xtruct truck;
truck.string_thing = "Truck";
truck.byte_thing = 8;
- truck.u32_thing = 8;
truck.i32_thing = 8;
- truck.u64_thing = 8;
truck.i64_thing = 8;
insane.xtructs.push_back(truck);
printf("testInsanity()");
@@ -307,7 +285,7 @@
printf(" = {");
map<UserId, map<Numberz,Insanity> >::const_iterator i_iter;
for (i_iter = whoa.begin(); i_iter != whoa.end(); ++i_iter) {
- printf("%lu => {", i_iter->first);
+ printf("%ld => {", i_iter->first);
map<Numberz,Insanity>::const_iterator i2_iter;
for (i2_iter = i_iter->second.begin();
i2_iter != i_iter->second.end();
@@ -317,7 +295,7 @@
map<Numberz, UserId>::const_iterator um;
printf("{");
for (um = userMap.begin(); um != userMap.end(); ++um) {
- printf("%d => %lu, ", um->first, um->second);
+ printf("%d => %ld, ", um->first, um->second);
}
printf("}, ");
@@ -325,12 +303,10 @@
list<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
- printf("{\"%s\", %d, %u, %d, %lu, %ld}, ",
+ printf("{\"%s\", %d, %d, %ld}, ",
x->string_thing.c_str(),
(int)x->byte_thing,
- x->u32_thing,
x->i32_thing,
- x->u64_thing,
x->i64_thing);
}
printf("}");
diff --git a/test/cpp/src/TestServer.cc b/test/cpp/src/TestServer.cc
index 206b6f5..c0df233 100644
--- a/test/cpp/src/TestServer.cc
+++ b/test/cpp/src/TestServer.cc
@@ -24,46 +24,32 @@
return thing;
}
- uint32_t testU32(uint32_t thing) {
- printf("testU32(%u)\n", thing);
- return thing;
- }
-
int32_t testI32(int32_t thing) {
printf("testI32(%d)\n", thing);
return thing;
}
- uint64_t testU64(uint64_t thing) {
- printf("testU64(%lu)\n", thing);
- return thing;
- }
-
int64_t testI64(int64_t thing) {
printf("testI64(%ld)\n", thing);
return thing;
}
Xtruct testStruct(Xtruct thing) {
- printf("testStruct({\"%s\", %d, %u, %d, %lu, %ld})\n",
+ printf("testStruct({\"%s\", %d, %d, %ld})\n",
thing.string_thing.c_str(),
(int)thing.byte_thing,
- thing.u32_thing,
thing.i32_thing,
- thing.u64_thing,
thing.i64_thing);
return thing;
}
Xtruct2 testNest(Xtruct2 nest) {
Xtruct thing = nest.struct_thing;
- printf("testNest({%d, {\"%s\", %d, %u, %d, %lu, %ld}, %d})\n",
+ printf("testNest({%d, {\"%s\", %d, %d, %ld}, %d})\n",
(int)nest.byte_thing,
thing.string_thing.c_str(),
(int)thing.byte_thing,
- thing.u32_thing,
thing.i32_thing,
- thing.u64_thing,
thing.i64_thing,
nest.i32_thing);
return nest;
@@ -123,7 +109,7 @@
}
UserId testTypedef(UserId thing) {
- printf("testTypedef(%lu)\n", thing);
+ printf("testTypedef(%ld)\n", thing);
return thing;
}
@@ -150,17 +136,13 @@
Xtruct hello;
hello.string_thing = "Hello2";
hello.byte_thing = 2;
- hello.u32_thing = 2;
hello.i32_thing = 2;
- hello.u64_thing = 2;
hello.i64_thing = 2;
Xtruct goodbye;
goodbye.string_thing = "Goodbye4";
goodbye.byte_thing = 4;
- goodbye.u32_thing = 4;
goodbye.i32_thing = 4;
- goodbye.u64_thing = 4;
goodbye.i64_thing = 4;
Insanity crazy;
@@ -187,7 +169,7 @@
printf(" = {");
map<UserId, map<Numberz,Insanity> >::const_iterator i_iter;
for (i_iter = insane.begin(); i_iter != insane.end(); ++i_iter) {
- printf("%lu => {", i_iter->first);
+ printf("%ld => {", i_iter->first);
map<Numberz,Insanity>::const_iterator i2_iter;
for (i2_iter = i_iter->second.begin();
i2_iter != i_iter->second.end();
@@ -197,7 +179,7 @@
map<Numberz, UserId>::const_iterator um;
printf("{");
for (um = userMap.begin(); um != userMap.end(); ++um) {
- printf("%d => %lu, ", um->first, um->second);
+ printf("%d => %ld, ", um->first, um->second);
}
printf("}, ");
@@ -205,12 +187,10 @@
list<Xtruct>::const_iterator x;
printf("{");
for (x = xtructs.begin(); x != xtructs.end(); ++x) {
- printf("{\"%s\", %d, %u, %d, %lu, %ld}, ",
+ printf("{\"%s\", %d, %d, %ld}, ",
x->string_thing.c_str(),
(int)x->byte_thing,
- x->u32_thing,
x->i32_thing,
- x->u64_thing,
x->i64_thing);
}
printf("}");
diff --git a/test/java/src/TestClient.java b/test/java/src/TestClient.java
index 70cf826..cbcd802 100644
--- a/test/java/src/TestClient.java
+++ b/test/java/src/TestClient.java
@@ -78,14 +78,7 @@
System.out.print("testByte(1)");
UInt8 u8 = testClient.testByte(new UInt8((short)1));
System.out.print(" = " + u8.get() + "\n");
-
- /**
- * U32 TEST
- */
- System.out.print("testU32(1)");
- UInt32 u32 = testClient.testU32(new UInt32(1));
- System.out.print(" = " + u32.get() + "\n");
-
+
/**
* I32 TEST
*/
@@ -94,13 +87,6 @@
System.out.print(" = " + i32.get() + "\n");
/**
- * U64 TEST
- */
- System.out.print("testU64(34359738368)");
- UInt64 u64 = testClient.testU64(new UInt64(34359738368L));
- System.out.print(" = " + u64.toLong() + "\n");
-
- /**
* I64 TEST
*/
System.out.print("testI64(-34359738368)");
@@ -110,27 +96,23 @@
/**
* STRUCT TEST
*/
- System.out.print("testStruct({\"Zero\", 1, 2, -3, 4, -5})");
+ System.out.print("testStruct({\"Zero\", 1, -3, -5})");
Xtruct out = new Xtruct();
out.string_thing.value = "Zero";
out.byte_thing.set((short)1);
- out.u32_thing.set(2);
out.i32_thing.set(-3);
- out.u64_thing.set(4);
out.i64_thing.set(-5);
Xtruct in = testClient.testStruct(out);
System.out.print(" = {" +
"\"" + in.string_thing.value + "\", " +
in.byte_thing.get() + ", " +
- in.u32_thing.get() + ", " +
in.i32_thing.get() + ", " +
- in.u64_thing.toLong() + ", " +
in.i64_thing.get() + "}\n");
/**
* NESTED STRUCT TEST
*/
- System.out.print("testNest({1, {\"Zero\", 1, 2, -3, 4, -5}), 5}");
+ System.out.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
Xtruct2 out2 = new Xtruct2();
out2.byte_thing.set((short)1);
out2.struct_thing = out;
@@ -141,9 +123,7 @@
in2.byte_thing.get() + ", {" +
"\"" + in.string_thing.value + "\", " +
in.byte_thing.get() + ", " +
- in.u32_thing.get() + ", " +
in.i32_thing.get() + ", " +
- in.u64_thing.toLong() + ", " +
in.i64_thing.get() + "}, " +
in2.i32_thing.get() + "}\n");
@@ -267,8 +247,8 @@
* TYPEDEF TEST
*/
System.out.print("testTypedef(309858235082523)");
- UInt64 uid = testClient.testTypedef(new UInt64(309858235082523L));
- System.out.print(" = " + uid.toLong() + "\n");
+ Int64 uid = testClient.testTypedef(new Int64(309858235082523L));
+ System.out.print(" = " + uid.get() + "\n");
/**
* NESTED MAP TEST
@@ -291,31 +271,29 @@
* INSANITY TEST
*/
Insanity insane = new Insanity();
- insane.userMap.put(Numberz.FIVE, new UInt64(5000));
+ insane.userMap.put(Numberz.FIVE, new Int64(5000));
Xtruct truck = new Xtruct();
truck.string_thing.value = "Truck";
truck.byte_thing.set((short)8);
- truck.u32_thing.set(8);
truck.i32_thing.set(8);
- truck.u64_thing.set(8);
truck.i64_thing.set(8);
insane.xtructs.add(truck);
System.out.print("testInsanity()");
- HashMap<UInt64,HashMap<Int32,Insanity>> whoa =
+ HashMap<Int64,HashMap<Int32,Insanity>> whoa =
testClient.testInsanity(insane);
System.out.print(" = {");
- for (UInt64 key : whoa.keySet()) {
+ for (Int64 key : whoa.keySet()) {
HashMap<Int32,Insanity> val = whoa.get(key);
- System.out.print(key.toLong() + " => {");
+ System.out.print(key.get() + " => {");
for (Int32 k2 : val.keySet()) {
Insanity v2 = val.get(k2);
System.out.print(k2.get() + " => {");
- HashMap<Int32, UInt64> userMap = v2.userMap;
+ HashMap<Int32, Int64> userMap = v2.userMap;
System.out.print("{");
for (Int32 k3 : userMap.keySet()) {
System.out.print(k3.get() + " => " +
- userMap.get(k3).toLong() + ", ");
+ userMap.get(k3).get() + ", ");
}
System.out.print("}, ");
@@ -325,9 +303,7 @@
System.out.print("{" +
"\"" + x.string_thing.value + "\", " +
x.byte_thing.get() + ", " +
- x.u32_thing.get() + ", "+
x.i32_thing.get() + ", "+
- x.u64_thing.toLong() + ", "+
x.i64_thing.get() + "}, ");
}
System.out.print("}");
diff --git a/test/java/src/TestServer.java b/test/java/src/TestServer.java
index c5edca4..0acc8a2 100644
--- a/test/java/src/TestServer.java
+++ b/test/java/src/TestServer.java
@@ -35,21 +35,11 @@
return thing;
}
- public UInt32 testU32(UInt32 thing) {
- System.out.print("testU32(" + thing.get() + ")\n");
- return thing;
- }
-
public Int32 testI32(Int32 thing) {
System.out.print("testI32(" + thing.get() + ")\n");
return thing;
}
- public UInt64 testU64(UInt64 thing) {
- System.out.print("testU64(" + thing.toLong() + ")\n");
- return thing;
- }
-
public Int64 testI64(Int64 thing) {
System.out.print("testI64(" + thing.get() + ")\n");
return thing;
@@ -59,9 +49,7 @@
System.out.print("testStruct({" +
"\"" + thing.string_thing.value + "\", " +
thing.byte_thing.get() + ", " +
- thing.u32_thing.get() + ", " +
thing.i32_thing.get() + ", " +
- thing.u64_thing.toLong() + ", " +
thing.i64_thing.get() + "})\n");
return thing;
}
@@ -72,9 +60,7 @@
nest.byte_thing.get() + ", {" +
"\"" + thing.string_thing.value + "\", " +
thing.byte_thing.get() + ", " +
- thing.u32_thing.get() + ", " +
thing.i32_thing.get() + ", " +
- thing.u64_thing.toLong() + ", " +
thing.i64_thing.get() + "}, " +
nest.i32_thing.get() + "})\n");
return nest;
@@ -130,8 +116,8 @@
return thing;
}
- public UInt64 testTypedef(UInt64 thing) {
- System.out.print("testTypedef(" + thing.toLong() + ")\n");
+ public Int64 testTypedef(Int64 thing) {
+ System.out.print("testTypedef(" + thing.get() + ")\n");
return thing;
}
@@ -153,31 +139,27 @@
return mapmap;
}
- public HashMap<UInt64, HashMap<Int32,Insanity>> testInsanity(Insanity argument) {
+ public HashMap<Int64, HashMap<Int32,Insanity>> testInsanity(Insanity argument) {
System.out.print("testInsanity()\n");
Xtruct hello = new Xtruct();
hello.string_thing.value = "Hello2";
hello.byte_thing.set((short)2);
- hello.u32_thing.set(2);
hello.i32_thing.set(2);
- hello.u64_thing.set(2);
hello.i64_thing.set(2);
Xtruct goodbye = new Xtruct();
goodbye.string_thing.value = "Goodbye4";
goodbye.byte_thing.set((short)4);
- goodbye.u32_thing.set(4);
goodbye.i32_thing.set(4);
- goodbye.u64_thing.set(4);
goodbye.i64_thing.set(4);
Insanity crazy = new Insanity();
- crazy.userMap.put(Numberz.EIGHT, new UInt64(8));
+ crazy.userMap.put(Numberz.EIGHT, new Int64(8));
crazy.xtructs.add(goodbye);
Insanity looney = new Insanity();
- crazy.userMap.put(Numberz.FIVE, new UInt64(5));
+ crazy.userMap.put(Numberz.FIVE, new Int64(5));
crazy.xtructs.add(hello);
HashMap<Int32,Insanity> first_map = new HashMap<Int32, Insanity>();
@@ -188,10 +170,10 @@
second_map.put(Numberz.SIX, looney);
- HashMap<UInt64,HashMap<Int32,Insanity>> insane =
- new HashMap<UInt64, HashMap<Int32,Insanity>>();
- insane.put(new UInt64(1), first_map);
- insane.put(new UInt64(2), second_map);
+ HashMap<Int64,HashMap<Int32,Insanity>> insane =
+ new HashMap<Int64, HashMap<Int32,Insanity>>();
+ insane.put(new Int64(1), first_map);
+ insane.put(new Int64(2), second_map);
return insane;
}
diff --git a/test/php/Makefile b/test/php/Makefile
new file mode 100644
index 0000000..2e6bec5
--- /dev/null
+++ b/test/php/Makefile
@@ -0,0 +1,27 @@
+# Makefile for Thrift test project.
+#
+# Author:
+# Mark Slee <mcslee@facebook.com>
+
+# Default target is everything
+target: all
+
+# Tools
+THRIFT = thrift
+
+# Compiler flags
+LIBS = ../../lib/cpp/server/TSimpleServer.cc \
+ ../../lib/cpp/protocol/TBinaryProtocol.cc \
+ ../../lib/cpp/transport/TBufferedTransport.cc \
+ ../../lib/cpp/transport/TServerSocket.cc \
+ ../../lib/cpp/transport/TSocket.cc
+CFL = -Wall -O3 -Igen-cpp -I../../lib/cpp $(LIBS)
+CFL = -Wall -O3 -Igen-cpp -I../../lib/cpp -lthrift
+
+all: stubs
+
+stubs: ../ThriftTest.thrift
+ $(THRIFT) -php ../ThriftTest.thrift
+
+clean:
+ rm -fr gen-php
diff --git a/test/php/TestClient.php b/test/php/TestClient.php
new file mode 100644
index 0000000..8f765fa
--- /dev/null
+++ b/test/php/TestClient.php
@@ -0,0 +1,327 @@
+<?php
+
+/** Include the Thrift base */
+require_once '/home/mcslee/code/projects/thrift/lib/php/src/Thrift.php';
+
+/** Include the binary protocol */
+require_once THRIFT_ROOT.'/protocol/TBinaryProtocol.php';
+
+/** Include the socket layer */
+require_once THRIFT_ROOT.'/transport/TSocket.php';
+
+/** Include the socket layer */
+require_once THRIFT_ROOT.'/transport/TBufferedTransport.php';
+
+/** Include the generated code */
+require_once '/home/mcslee/code/projects/thrift/test/php/gen-php/ThriftTest.php';
+
+$host = 'localhost';
+$port = 9090;
+
+if ($argc > 1) {
+ $host = $argv[0];
+}
+
+if ($argc > 2) {
+ $host = $argv[1];
+}
+
+$socket = new TSocket($host, $port);
+$bufferedSocket = new TBufferedTransport($socket, 1024, 1024);
+$binary = new TBinaryProtocol();
+
+$testClient = new ThriftTestClient($bufferedSocket, $binary);
+$bufferedSocket->open();
+
+$start = microtime(true);
+
+/**
+ * VOID TEST
+ */
+print_r("testVoid()");
+$testClient->testVoid();
+print_r(" = void\n");
+
+/**
+ * STRING TEST
+ */
+print_r("testString(\"Test\")");
+$s = $testClient->testString("Test");
+print_r(" = \"$s\"\n");
+
+/**
+ * BYTE TEST
+ */
+print_r("testByte(1)");
+$u8 = $testClient->testByte(1);
+print_r(" = $u8\n");
+
+/**
+ * I32 TEST
+ */
+print_r("testI32(-1)");
+$i32 = $testClient->testI32(-1);
+print_r(" = $i32\n");
+
+/**
+ * I64 TEST
+ */
+print_r("testI64(-34359738368)");
+$i64 = $testClient->testI64(-34359738368);
+print_r(" = $i64\n");
+
+/**
+ * STRUCT TEST
+ */
+print_r("testStruct({\"Zero\", 1, -3, -5})");
+$out = new Xtruct();
+$out->string_thing = "Zero";
+$out->byte_thing = 1;
+$out->i32_thing = -3;
+$out->i64_thing = -5;
+$in = $testClient->testStruct($out);
+print_r(" = {\"".$in->string_thing."\", ".
+ $in->byte_thing.", ".
+ $in->i32_thing.", ".
+ $in->i64_thing."}\n");
+
+/**
+ * NESTED STRUCT TEST
+ */
+print_r("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
+$out2 = new Xtruct2();
+$out2->byte_thing = 1;
+$out2->struct_thing = $out;
+$out2->i32_thing = 5;
+$in2 = $testClient->testNest($out2);
+$in = $in2->struct_thing;
+print_r(" = {".$in2->byte_thing.", {\"".
+ $in->string_thing."\", ".
+ $in->byte_thing.", ".
+ $in->i32_thing.", ".
+ $in->i64_thing."}, ".
+ $in2->i32_thing."}\n");
+
+/**
+ * MAP TEST
+ */
+$mapout = array();
+for ($i = 0; $i < 5; ++$i) {
+ $mapout[$i] = $i-10;
+}
+print_r("testMap({");
+$first = true;
+foreach ($mapout as $key => $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r("$key => $val");
+}
+print_r("})");
+
+$mapin = $testClient->testMap($mapout);
+print_r(" = {");
+$first = true;
+foreach ($mapin as $key => $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r("$key => $val");
+}
+print_r("}\n");
+
+/**
+ * SET TEST
+ */
+$setout = array();;
+for ($i = -2; $i < 3; ++$i) {
+ $setout []= $i;
+}
+print_r("testSet({");
+$first = true;
+foreach ($setout as $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r($val);
+}
+print_r("})");
+$setin = $testClient->testSet($setout);
+print_r(" = {");
+$first = true;
+foreach ($setin as $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r($val);
+}
+print_r("}\n");
+
+/**
+ * LIST TEST
+ */
+$listout = array();
+for ($i = -2; $i < 3; ++$i) {
+ $listout []= $i;
+}
+print_r("testList({");
+$first = true;
+foreach ($listout as $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r($val);
+}
+print_r("})");
+$listin = $testClient->testList($listout);
+print_r(" = {");
+$first = true;
+foreach ($listin as $val) {
+ if ($first) {
+ $first = false;
+ } else {
+ print_r(", ");
+ }
+ print_r($val);
+}
+print_r("}\n");
+
+/**
+ * ENUM TEST
+ */
+print_r("testEnum(ONE)");
+$ret = $testClient->testEnum(Numberz::ONE);
+print_r(" = $ret\n");
+
+print_r("testEnum(TWO)");
+$ret = $testClient->testEnum(Numberz::TWO);
+print_r(" = $ret\n");
+
+print_r("testEnum(THREE)");
+$ret = $testClient->testEnum(Numberz::THREE);
+print_r(" = $ret\n");
+
+print_r("testEnum(FIVE)");
+$ret = $testClient->testEnum(Numberz::FIVE);
+print_r(" = $ret\n");
+
+print_r("testEnum(EIGHT)");
+$ret = $testClient->testEnum(Numberz::EIGHT);
+print_r(" = $ret\n");
+
+/**
+ * TYPEDEF TEST
+ */
+print_r("testTypedef(309858235082523)");
+$uid = $testClient->testTypedef(309858235082523);
+print_r(" = $uid\n");
+
+/**
+ * NESTED MAP TEST
+ */
+print_r("testMapMap(1)");
+$mm = $testClient->testMapMap(1);
+print_r(" = {");
+foreach ($mm as $key => $val) {
+ print_r("$key => {");
+ foreach ($val as $k2 => $v2) {
+ print_r("$k2 => $v2, ");
+ }
+ print_r("}, ");
+}
+print_r("}\n");
+
+/**
+ * INSANITY TEST
+ */
+$insane = new Insanity();
+$insane->userMap[Numberz::FIVE] = 5000;
+$truck = new Xtruct();
+$truck->string_thing = "Truck";
+$truck->byte_thing = 8;
+$truck->i32_thing = 8;
+$truck->i64_thing = 8;
+$insane->xtructs []= $truck;
+print_r("testInsanity()");
+$whoa = $testClient->testInsanity($insane);
+print_r(" = {");
+foreach ($whoa as $key => $val) {
+ print_r("$key => {");
+ foreach ($val as $k2 => $v2) {
+ print_r("$k2 => {");
+ $userMap = $v2->userMap;
+ print_r("{");
+ foreach ($userMap as $k3 => $v3) {
+ print_r("$k3 => $v3, ");
+ }
+ print_r("}, ");
+
+ $xtructs = $v2->xtructs;
+ print_r("{");
+ foreach ($xtructs as $x) {
+ print_r("{\"".$x->string_thing."\", ".
+ $x->byte_thing.", ".$x->i32_thing.", ".$x->i64_thing."}, ");
+ }
+ print_r("}");
+
+ print_r("}, ");
+ }
+ print_r("}, ");
+}
+print_r("}\n");
+
+
+/**
+ * Normal tests done.
+ */
+
+$stop = microtime(true);
+$elp = round(1000*($stop - $start), 0);
+print_r("Total time: $elp ms\n");
+
+/**
+ * Extraneous "I don't trust PHP to pack/unpack integer" tests
+ */
+
+// Max I32
+$num = pow(2, 30) + (pow(2, 30) - 1);
+$num2 = $testClient->testI32($num);
+if ($num != $num2) {
+ print "Missed $num = $num2\n";
+}
+
+// Min I32
+$num = 0 - pow(2, 31);
+$num2 = $testClient->testI32($num);
+if ($num != $num2) {
+ print "Missed $num = $num2\n";
+}
+
+// Max I64
+$num = pow(2, 62) + (pow(2, 62) - 1);
+$num2 = $testClient->testI64($num);
+if ($num != $num2) {
+ print "Missed $num = $num2\n";
+}
+
+// Min I64
+$num = 0 - pow(2, 63);
+$num2 = $testClient->testI64($num);
+if ($num != $num2) {
+ print "Missed $num = $num2\n";
+}
+
+$bufferedSocket->close();
+return;
+
+?>