|
|
|
@ -20,6 +20,7 @@ |
|
|
|
|
#include "google/protobuf/dynamic_message.h" |
|
|
|
|
|
|
|
|
|
#include <memory> |
|
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
#include "google/protobuf/descriptor.pb.h" |
|
|
|
|
#include "google/protobuf/testing/googletest.h" |
|
|
|
@ -29,8 +30,43 @@ |
|
|
|
|
#include "google/protobuf/unittest.pb.h" |
|
|
|
|
#include "google/protobuf/unittest_no_field_presence.pb.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace google { |
|
|
|
|
namespace protobuf { |
|
|
|
|
namespace { |
|
|
|
|
|
|
|
|
|
void AddUnittestDescriptors( |
|
|
|
|
DescriptorPool& pool, std::vector<const FileDescriptor*>* files = nullptr) { |
|
|
|
|
// We want to make sure that DynamicMessage works (particularly with
|
|
|
|
|
// extensions) even if we use descriptors that are *not* from compiled-in
|
|
|
|
|
// types, so we make copies of the descriptors for unittest.proto and
|
|
|
|
|
// unittest_import.proto.
|
|
|
|
|
FileDescriptorProto unittest_file; |
|
|
|
|
FileDescriptorProto unittest_import_file; |
|
|
|
|
FileDescriptorProto unittest_import_public_file; |
|
|
|
|
FileDescriptorProto unittest_no_field_presence_file; |
|
|
|
|
|
|
|
|
|
unittest::TestAllTypes::descriptor()->file()->CopyTo(&unittest_file); |
|
|
|
|
unittest_import::ImportMessage::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_import_file); |
|
|
|
|
unittest_import::PublicImportMessage::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_import_public_file); |
|
|
|
|
proto2_nofieldpresence_unittest::TestAllTypes::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_no_field_presence_file); |
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(pool.BuildFile(unittest_import_public_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool.BuildFile(unittest_import_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool.BuildFile(unittest_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool.BuildFile(unittest_no_field_presence_file) != nullptr); |
|
|
|
|
|
|
|
|
|
if (files) { |
|
|
|
|
files->push_back(pool.FindFileByName(unittest_file.name())); |
|
|
|
|
files->push_back(pool.FindFileByName(unittest_import_file.name())); |
|
|
|
|
files->push_back(pool.FindFileByName(unittest_import_public_file.name())); |
|
|
|
|
files->push_back( |
|
|
|
|
pool.FindFileByName(unittest_no_field_presence_file.name())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class DynamicMessageTest : public ::testing::TestWithParam<bool> { |
|
|
|
|
protected: |
|
|
|
@ -50,27 +86,7 @@ class DynamicMessageTest : public ::testing::TestWithParam<bool> { |
|
|
|
|
DynamicMessageTest() : factory_(&pool_) {} |
|
|
|
|
|
|
|
|
|
void SetUp() override { |
|
|
|
|
// We want to make sure that DynamicMessage works (particularly with
|
|
|
|
|
// extensions) even if we use descriptors that are *not* from compiled-in
|
|
|
|
|
// types, so we make copies of the descriptors for unittest.proto and
|
|
|
|
|
// unittest_import.proto.
|
|
|
|
|
FileDescriptorProto unittest_file; |
|
|
|
|
FileDescriptorProto unittest_import_file; |
|
|
|
|
FileDescriptorProto unittest_import_public_file; |
|
|
|
|
FileDescriptorProto unittest_no_field_presence_file; |
|
|
|
|
|
|
|
|
|
unittest::TestAllTypes::descriptor()->file()->CopyTo(&unittest_file); |
|
|
|
|
unittest_import::ImportMessage::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_import_file); |
|
|
|
|
unittest_import::PublicImportMessage::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_import_public_file); |
|
|
|
|
proto2_nofieldpresence_unittest::TestAllTypes::descriptor()->file()->CopyTo( |
|
|
|
|
&unittest_no_field_presence_file); |
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(pool_.BuildFile(unittest_import_public_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool_.BuildFile(unittest_import_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool_.BuildFile(unittest_file) != nullptr); |
|
|
|
|
ASSERT_TRUE(pool_.BuildFile(unittest_no_field_presence_file) != nullptr); |
|
|
|
|
AddUnittestDescriptors(pool_); |
|
|
|
|
|
|
|
|
|
descriptor_ = pool_.FindMessageTypeByName("protobuf_unittest.TestAllTypes"); |
|
|
|
|
ASSERT_TRUE(descriptor_ != nullptr); |
|
|
|
@ -298,5 +314,7 @@ TEST_F(DynamicMessageTest, Proto3) { |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_SUITE_P(UseArena, DynamicMessageTest, ::testing::Bool()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
} // namespace protobuf
|
|
|
|
|
} // namespace google
|
|
|
|
|