From 39756643df2f88805649595e651b719c8f5a4dea Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 1 Feb 2017 12:47:58 -0800 Subject: Add conformance test for php (#2655) --- conformance/conformance_php.php | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 conformance/conformance_php.php (limited to 'conformance/conformance_php.php') diff --git a/conformance/conformance_php.php b/conformance/conformance_php.php new file mode 100755 index 00000000..c2314001 --- /dev/null +++ b/conformance/conformance_php.php @@ -0,0 +1,102 @@ +getPayload() == "protobuf_payload") { + $test_message->encode($request->getProtobufPayload()); + } elseif ($request->getPayload() == "json_payload") { + // TODO(teboring): Implmement json decoding. + } else { + trigger_error("Request didn't have payload.", E_USER_ERROR); + } + + if ($request->getRequestedOutputFormat() == WireFormat::UNSPECIFIED) { + trigger_error("Unspecified output format.", E_USER_ERROR); + } elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) { + $response->setProtobufPayload($test_message->encode()); + } elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) { + // TODO(teboring): Implmement json encoding. + } + + return $response; +} + +function doTestIO() +{ + $length_bytes = fread(STDIN, 4); + if (strlen($length_bytes) == 0) { + return false; # EOF + } elseif (strlen($length_bytes) != 4) { + trigger_error("I/O error", E_USER_ERROR); + } + + $length = unpack("V", $length_bytes)[1]; + $serialized_request = fread(STDIN, $length); + if (strlen($serialized_request) != $length) { + trigger_error("I/O error", E_USER_ERROR); + } + + $request = new \Conformance\ConformanceRequest(); + $request->decode($serialized_request); + + $response = doTest($request); + + $serialized_response = $response->encode(); + fwrite(STDOUT, pack("V", strlen($serialized_response))); + fwrite(STDOUT, $serialized_response); + + $GLOBALS['test_count'] += 1; + + return true; +} + +while(true){ + if (!doTestIO()) { + fprintf(STDERR, + "conformance_php: received EOF from test runner " + + "after %d tests, exiting\n", $test_count); + exit; + } +} -- cgit v1.2.3