2017-02-01 20:47:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("Conformance/WireFormat.php");
|
|
|
|
require_once("Conformance/ConformanceResponse.php");
|
|
|
|
require_once("Conformance/ConformanceRequest.php");
|
2018-08-09 00:00:41 +00:00
|
|
|
require_once("Conformance/TestCategory.php");
|
2017-02-01 20:47:58 +00:00
|
|
|
require_once("Protobuf_test_messages/Proto3/ForeignMessage.php");
|
|
|
|
require_once("Protobuf_test_messages/Proto3/ForeignEnum.php");
|
2017-07-01 00:22:32 +00:00
|
|
|
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php");
|
2018-07-09 21:29:23 +00:00
|
|
|
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php");
|
|
|
|
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php");
|
2017-02-01 20:47:58 +00:00
|
|
|
|
|
|
|
require_once("GPBMetadata/Conformance.php");
|
|
|
|
require_once("GPBMetadata/Google/Protobuf/TestMessagesProto3.php");
|
|
|
|
|
2018-08-09 00:00:41 +00:00
|
|
|
use \Conformance\TestCategory;
|
2017-02-01 20:47:58 +00:00
|
|
|
use \Conformance\WireFormat;
|
|
|
|
|
2017-09-10 22:17:50 +00:00
|
|
|
if (!ini_get("date.timezone")) {
|
|
|
|
ini_set("date.timezone", "UTC");
|
|
|
|
}
|
|
|
|
|
2017-02-01 20:47:58 +00:00
|
|
|
$test_count = 0;
|
|
|
|
|
|
|
|
function doTest($request)
|
|
|
|
{
|
2017-07-01 00:22:32 +00:00
|
|
|
$test_message = new \Protobuf_test_messages\Proto3\TestAllTypesProto3();
|
2017-02-01 20:47:58 +00:00
|
|
|
$response = new \Conformance\ConformanceResponse();
|
|
|
|
if ($request->getPayload() == "protobuf_payload") {
|
2017-07-01 00:22:32 +00:00
|
|
|
if ($request->getMessageType() == "protobuf_test_messages.proto3.TestAllTypesProto3") {
|
2017-06-28 01:24:15 +00:00
|
|
|
try {
|
2017-03-08 22:31:34 +00:00
|
|
|
$test_message->mergeFromString($request->getProtobufPayload());
|
2017-06-28 01:24:15 +00:00
|
|
|
} catch (Exception $e) {
|
2017-02-08 18:27:54 +00:00
|
|
|
$response->setParseError($e->getMessage());
|
|
|
|
return $response;
|
2017-06-28 01:24:15 +00:00
|
|
|
}
|
2017-06-29 22:04:50 +00:00
|
|
|
} elseif ($request->getMessageType() == "protobuf_test_messages.proto2.TestAllTypesProto2") {
|
2017-10-26 21:41:43 +00:00
|
|
|
$response->setSkipped("PHP doesn't support proto2");
|
|
|
|
return $response;
|
2017-06-28 01:24:15 +00:00
|
|
|
} else {
|
2017-10-26 21:41:43 +00:00
|
|
|
trigger_error("Protobuf request doesn't have specific payload type", E_USER_ERROR);
|
2017-02-08 18:27:54 +00:00
|
|
|
}
|
2017-02-01 20:47:58 +00:00
|
|
|
} elseif ($request->getPayload() == "json_payload") {
|
2018-08-09 00:00:41 +00:00
|
|
|
$ignore_json_unknown =
|
|
|
|
($request->getTestCategory() ==
|
|
|
|
TestCategory::JSON_IGNORE_UNKNOWN_PARSING_TEST);
|
2017-02-08 18:27:54 +00:00
|
|
|
try {
|
2018-07-09 21:29:23 +00:00
|
|
|
$test_message->mergeFromJsonString($request->getJsonPayload(),
|
|
|
|
$ignore_json_unknown);
|
2017-02-08 18:27:54 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$response->setParseError($e->getMessage());
|
|
|
|
return $response;
|
|
|
|
}
|
2017-02-01 20:47:58 +00:00
|
|
|
} 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) {
|
2017-03-08 22:31:34 +00:00
|
|
|
$response->setProtobufPayload($test_message->serializeToString());
|
2017-02-01 20:47:58 +00:00
|
|
|
} elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) {
|
2017-11-03 19:30:09 +00:00
|
|
|
try {
|
|
|
|
$response->setJsonPayload($test_message->serializeToJsonString());
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$response->setSerializeError($e->getMessage());
|
|
|
|
return $response;
|
|
|
|
}
|
2017-02-01 20:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doTestIO()
|
|
|
|
{
|
|
|
|
$length_bytes = fread(STDIN, 4);
|
|
|
|
if (strlen($length_bytes) == 0) {
|
|
|
|
return false; # EOF
|
|
|
|
} elseif (strlen($length_bytes) != 4) {
|
2017-06-30 19:14:09 +00:00
|
|
|
fwrite(STDERR, "I/O error\n");
|
|
|
|
return false;
|
2017-02-01 20:47:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
2017-03-08 22:31:34 +00:00
|
|
|
$request->mergeFromString($serialized_request);
|
2017-02-01 20:47:58 +00:00
|
|
|
|
|
|
|
$response = doTest($request);
|
|
|
|
|
2017-03-08 22:31:34 +00:00
|
|
|
$serialized_response = $response->serializeToString();
|
2017-02-01 20:47:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|