// 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 #include #include #ifndef _SHARED_PTR_H #include #endif #include #include #include #include #include #include #include #include #include #include #include namespace google { namespace protobuf { namespace util { namespace { using google::protobuf::Type; using google::protobuf::Enum; using google::protobuf::Field; using google::protobuf::Option; using google::protobuf::BoolValue; static const char kUrlPrefix[] = "type.googleapis.com"; class DescriptorPoolTypeResolverTest : public testing::Test { public: DescriptorPoolTypeResolverTest() { resolver_.reset(NewTypeResolverForDescriptorPool( kUrlPrefix, DescriptorPool::generated_pool())); } const Field* FindField(const Type& type, const string& name) { for (int i = 0; i < type.fields_size(); ++i) { const Field& field = type.fields(i); if (field.name() == name) { return &field; } } return NULL; } bool HasField(const Type& type, const string& name) { return FindField(type, name) != NULL; } bool HasField(const Type& type, Field::Cardinality cardinality, Field::Kind kind, const string& name, int number) { const Field* field = FindField(type, name); if (field == NULL) { return false; } return field->cardinality() == cardinality && field->kind() == kind && field->number() == number; } bool CheckFieldTypeUrl(const Type& type, const string& name, const string& type_url) { const Field* field = FindField(type, name); if (field == NULL) { return false; } return field->type_url() == type_url; } bool FieldInOneof(const Type& type, const string& name, const string& oneof_name) { const Field* field = FindField(type, name); if (field == NULL || field->oneof_index() <= 0 || field->oneof_index() > type.oneofs_size()) { return false; } return type.oneofs(field->oneof_index() - 1) == oneof_name; } bool IsPacked(const Type& type, const string& name) { const Field* field = FindField(type, name); if (field == NULL) { return false; } return field->packed(); } bool EnumHasValue(const Enum& type, const string& name, int number) { for (int i = 0; i < type.enumvalue_size(); ++i) { if (type.enumvalue(i).name() == name && type.enumvalue(i).number() == number) { return true; } } return false; } bool HasBoolOption(const RepeatedPtrField