Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
1. Fix C++ tests.
  * Add missing files to Makefile.am and fix distcheck in tests.sh
  * Remove BUILT_SOURCES from conformance/Makefile.am.
  * Add some missing override keyword.
  * Add a type cast to int64 because our StrCat() in stubs can't handle size_t.
2. Fix Java tests.
  * Add missing test dependency on guava in pom.xml.
  * Include newly referenced test data in test resources.
  * Manually fix map_lite_test.proto which is overwritten because it's mapped
    from map_test.proto in google3.
  * Add back "optimize_for = LITE_RUNTIME" which is still needed to keep the
    opensource test passing as it's still running lite tests.
  * Add a type cast in newBuilder() because without it the code doesn't compile
    with openjdk javac 1.8 (the compiler can't figure if it's the right type
    due to complex generic typing).
3. Fix Python tests.
  * Remove/replace references to <hash_map>.
  * Suppress more warnings in setup.py.
  * Replace incorrect header inclusion for google/protobuf/proto_api.h.
  * Add strings::EndsWith to google/protobuf/stubs/strutil.h because it's
    referenced in the updated python C extension code.
  * Replace proto2 with google::protobuf. The proto2 name is leaked to
    opensource because we removed the subsitition rule for proto2 namespace
    but only fixed C++ source code and forgot to update python C extension code.
  • Loading branch information
xfxyjwf committed Aug 10, 2018
1 parent 8e4fd1b commit acd5b05
Show file tree
Hide file tree
Showing 22 changed files with 728 additions and 34 deletions.
17 changes: 16 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,18 @@ php_EXTRA_DIST= \
php/src/Google/Protobuf/Internal/SourceCodeInfo/Location.php \
php/src/Google/Protobuf/Internal/UninterpretedOption.php \
php/src/Google/Protobuf/Internal/UninterpretedOption/NamePart.php \
php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php \
php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php \
php/src/Google/Protobuf/Internal/EnumDescriptorProto_EnumReservedRange.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php \
php/src/Google/Protobuf/Internal/FieldOptions_CType.php \
php/src/Google/Protobuf/Internal/FieldOptions_JSType.php \
php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php \
php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php \
php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php \
php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php \
php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php \
php/src/Google/Protobuf/ListValue.php \
php/src/Google/Protobuf/Method.php \
php/src/Google/Protobuf/Mixin.php \
Expand Down Expand Up @@ -804,7 +816,6 @@ python_EXTRA_DIST= \
python/google/protobuf/json_format.py \
python/google/protobuf/message.py \
python/google/protobuf/message_factory.py \
python/google/protobuf/python_api.h \
python/google/protobuf/python_protobuf.h \
python/google/protobuf/proto_api.h \
python/google/protobuf/proto_builder.py \
Expand All @@ -825,6 +836,10 @@ python_EXTRA_DIST= \
python/google/protobuf/pyext/map_container.h \
python/google/protobuf/pyext/message.cc \
python/google/protobuf/pyext/message.h \
python/google/protobuf/pyext/field.cc \
python/google/protobuf/pyext/field.h \
python/google/protobuf/pyext/unknown_fields.cc \
python/google/protobuf/pyext/unknown_fields.h \
python/google/protobuf/pyext/message_factory.cc \
python/google/protobuf/pyext/message_factory.h \
python/google/protobuf/pyext/message_module.cc \
Expand Down
2 changes: 0 additions & 2 deletions conformance/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ $(protoc_outputs): protoc_middleman

$(other_language_protoc_outputs): protoc_middleman

BUILT_SOURCES = $(protoc_outputs) $(other_language_protoc_outputs)

CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java javac_middleman_lite conformance-java-lite conformance-csharp conformance-php conformance-php-c $(other_language_protoc_outputs)

MAINTAINERCLEANFILES = \
Expand Down
14 changes: 14 additions & 0 deletions java/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -57,6 +62,15 @@
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${protobuf.source.dir}</directory>
<includes>
<include>google/protobuf/testdata/golden_message_oneof_implemented</include>
<include>google/protobuf/testdata/golden_packed_fields_message</include>
</includes>
</testResource>
</testResources>

<plugins>
<!-- Use Antrun plugin to generate sources with protoc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@

syntax = "proto3";

package map_test;
package map_lite_test;

option java_package = "map_test";
option optimize_for = LITE_RUNTIME;
option java_package = "map_lite_test";
option java_outer_classname = "MapTestProto";

message TestMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ syntax = "proto2";

package protobuf_unittest;

option optimize_for = LITE_RUNTIME;

import "com/google/protobuf/non_nested_extension_lite.proto";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ syntax = "proto2";

package protobuf_unittest;

option optimize_for = LITE_RUNTIME;

message MessageLiteToBeExtended {
extensions 1 to max;
Expand Down
1 change: 0 additions & 1 deletion python/google/protobuf/pyext/extension_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <Python.h>

#include <memory>
#include <hash_map>

#include <google/protobuf/pyext/message.h>

Expand Down
142 changes: 142 additions & 0 deletions python/google/protobuf/pyext/field.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <google/protobuf/pyext/field.h>

#include <google/protobuf/descriptor.h>
#include <google/protobuf/pyext/descriptor.h>
#include <google/protobuf/pyext/message.h>

#if PY_MAJOR_VERSION >= 3
#define PyString_FromFormat PyUnicode_FromFormat
#endif

namespace google {
namespace protobuf {
namespace python {

namespace field {

static PyObject* Repr(PyMessageFieldProperty* self) {
return PyString_FromFormat("<field property '%s'>",
self->field_descriptor->full_name().c_str());
}

static PyObject* DescrGet(PyMessageFieldProperty* self, PyObject* obj,
PyObject* type) {
if (obj == NULL) {
Py_INCREF(self);
return reinterpret_cast<PyObject*>(self);
}
return cmessage::GetFieldValue(reinterpret_cast<CMessage*>(obj),
self->field_descriptor);
}

static int DescrSet(PyMessageFieldProperty* self, PyObject* obj,
PyObject* value) {
if (value == NULL) {
PyErr_SetString(PyExc_AttributeError, "Cannot delete field attribute");
return -1;
}
return cmessage::SetFieldValue(reinterpret_cast<CMessage*>(obj),
self->field_descriptor, value);
}

static PyObject* GetDescriptor(PyMessageFieldProperty* self, void* closure) {
return PyFieldDescriptor_FromDescriptor(self->field_descriptor);
}

static PyObject* GetDoc(PyMessageFieldProperty* self, void* closure) {
return PyString_FromFormat("Field %s",
self->field_descriptor->full_name().c_str());
}

static PyGetSetDef Getters[] = {
{"DESCRIPTOR", (getter)GetDescriptor, NULL, "Field descriptor"},
{"__doc__", (getter)GetDoc, NULL, NULL},
{NULL}};
} // namespace field

static PyTypeObject _CFieldProperty_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) // head
FULL_MODULE_NAME ".FieldProperty", // tp_name
sizeof(PyMessageFieldProperty), // tp_basicsize
0, // tp_itemsize
0, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
(reprfunc)field::Repr, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
"Field property of a Message", // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
field::Getters, // tp_getset
0, // tp_base
0, // tp_dict
(descrgetfunc)field::DescrGet, // tp_descr_get
(descrsetfunc)field::DescrSet, // tp_descr_set
0, // tp_dictoffset
0, // tp_init
0, // tp_alloc
0, // tp_new
};
PyTypeObject* CFieldProperty_Type = &_CFieldProperty_Type;

PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor) {
// Create a new descriptor object
PyMessageFieldProperty* property =
PyObject_New(PyMessageFieldProperty, CFieldProperty_Type);
if (property == NULL) {
return NULL;
}
property->field_descriptor = field_descriptor;
return reinterpret_cast<PyObject*>(property);
}

} // namespace python
} // namespace protobuf
} // namespace google
59 changes: 59 additions & 0 deletions python/google/protobuf/pyext/field.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
#define GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__

#include <Python.h>

namespace google {
namespace protobuf {

class FieldDescriptor;

namespace python {

// A data descriptor that represents a field in a Message class.
struct PyMessageFieldProperty {
PyObject_HEAD;

// This pointer is owned by the same pool as the Message class it belongs to.
const FieldDescriptor* field_descriptor;
};

extern PyTypeObject* CFieldProperty_Type;

PyObject* NewFieldProperty(const FieldDescriptor* field_descriptor);

} // namespace python
} // namespace protobuf
} // namespace google

#endif // GOOGLE_PROTOBUF_PYTHON_CPP_FIELD_H__
14 changes: 7 additions & 7 deletions python/google/protobuf/pyext/map_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MapReflectionFriend {
struct MapIterator {
PyObject_HEAD;

std::unique_ptr<::proto2::MapIterator> iter;
std::unique_ptr<google::protobuf::MapIterator> iter;

// A pointer back to the container, so we can notice changes to the version.
// We own a ref on this.
Expand Down Expand Up @@ -314,7 +314,7 @@ static MapContainer* GetMap(PyObject* obj) {

Py_ssize_t MapReflectionFriend::Length(PyObject* _self) {
MapContainer* self = GetMap(_self);
const proto2::Message* message = self->message;
const Message* message = self->message;
return message->GetReflection()->MapSize(*message,
self->parent_field_descriptor);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ int MapContainer::Release() {
// ScalarMap ///////////////////////////////////////////////////////////////////

PyObject *NewScalarMapContainer(
CMessage* parent, const proto2::FieldDescriptor* parent_field_descriptor) {
CMessage* parent, const FieldDescriptor* parent_field_descriptor) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
return NULL;
}
Expand Down Expand Up @@ -548,7 +548,7 @@ PyObject* MapReflectionFriend::ScalarMapToStr(PyObject* _self) {
MapContainer* self = GetMap(_self);
Message* message = self->GetMutableMessage();
const Reflection* reflection = message->GetReflection();
for (proto2::MapIterator it = reflection->MapBegin(
for (google::protobuf::MapIterator it = reflection->MapBegin(
message, self->parent_field_descriptor);
it != reflection->MapEnd(message, self->parent_field_descriptor);
++it) {
Expand Down Expand Up @@ -704,7 +704,7 @@ static PyObject* GetCMessage(MessageMapContainer* self, Message* message,
}

PyObject* NewMessageMapContainer(
CMessage* parent, const proto2::FieldDescriptor* parent_field_descriptor,
CMessage* parent, const FieldDescriptor* parent_field_descriptor,
CMessageClass* message_class) {
if (!CheckFieldBelongsToMessage(parent_field_descriptor, parent->message)) {
return NULL;
Expand Down Expand Up @@ -837,7 +837,7 @@ PyObject* MapReflectionFriend::MessageMapToStr(PyObject* _self) {
MessageMapContainer* self = GetMessageMap(_self);
Message* message = self->GetMutableMessage();
const Reflection* reflection = message->GetReflection();
for (proto2::MapIterator it = reflection->MapBegin(
for (google::protobuf::MapIterator it = reflection->MapBegin(
message, self->parent_field_descriptor);
it != reflection->MapEnd(message, self->parent_field_descriptor);
++it) {
Expand Down Expand Up @@ -1011,7 +1011,7 @@ PyObject* MapReflectionFriend::GetIterator(PyObject *_self) {
Message* message = self->GetMutableMessage();
const Reflection* reflection = message->GetReflection();

iter->iter.reset(new ::proto2::MapIterator(
iter->iter.reset(new google::protobuf::MapIterator(
reflection->MapBegin(message, self->parent_field_descriptor)));
}

Expand Down
Loading

0 comments on commit acd5b05

Please sign in to comment.