This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
namespace google {
namespace protobuf {
class DynamicMessageTest : public testing::Test {
protected:
DescriptorPool pool_;
DynamicMessageFactory factory_;
const Descriptor* descriptor_;
const Message* prototype_;
const Descriptor* extensions_descriptor_;
const Message* extensions_prototype_;
const Descriptor* packed_descriptor_;
const Message* packed_prototype_;
DynamicMessageTest(): factory_(&pool_) {}
virtual void SetUp() {
FileDescriptorProto unittest_file;
FileDescriptorProto unittest_import_file;
FileDescriptorProto unittest_import_public_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);
ASSERT_TRUE(pool_.BuildFile(unittest_import_public_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_import_file) != NULL);
ASSERT_TRUE(pool_.BuildFile(unittest_file) != NULL);
descriptor_ = pool_.FindMessageTypeByName("protobuf_unittest.TestAllTypes");
ASSERT_TRUE(descriptor_ != NULL);
prototype_ = factory_.GetPrototype(descriptor_);
extensions_descriptor_ =
pool_.FindMessageTypeByName("protobuf_unittest.TestAllExtensions");
ASSERT_TRUE(extensions_descriptor_ != NULL);
extensions_prototype_ = factory_.GetPrototype(extensions_descriptor_);
packed_descriptor_ =
pool_.FindMessageTypeByName("protobuf_unittest.TestPackedTypes");
ASSERT_TRUE(packed_descriptor_ != NULL);
packed_prototype_ = factory_.GetPrototype(packed_descriptor_);
}
};
TEST_F(DynamicMessageTest, Descriptor) {
EXPECT_EQ(prototype_->GetDescriptor(), descriptor_);
}
TEST_F(DynamicMessageTest, OnePrototype) {
EXPECT_EQ(prototype_, factory_.GetPrototype(descriptor_));
}
TEST_F(DynamicMessageTest, Defaults) {
TestUtil::ReflectionTester reflection_tester(descriptor_);
reflection_tester.ExpectClearViaReflection(*prototype_);
}
TEST_F(DynamicMessageTest, IndependentOffsets) {
scoped_ptr<Message> message(prototype_->New());
TestUtil::ReflectionTester reflection_tester(descriptor_);
reflection_tester.SetAllFieldsViaReflection(message.get());
reflection_tester.ExpectAllFieldsSetViaReflection(*message);
}
TEST_F(DynamicMessageTest, Extensions) {
scoped_ptr<Message> message(extensions_prototype_->New());
TestUtil::ReflectionTester reflection_tester(extensions_descriptor_);
reflection_tester.SetAllFieldsViaReflection(message.get());
reflection_tester.ExpectAllFieldsSetViaReflection(*message);
}
TEST_F(DynamicMessageTest, PackedFields) {
scoped_ptr<Message> message(packed_prototype_->New());
TestUtil::ReflectionTester reflection_tester(packed_descriptor_);
reflection_tester.SetPackedFieldsViaReflection(message.get());
reflection_tester.ExpectPackedFieldsSetViaReflection(*message);
}
TEST_F(DynamicMessageTest, SpaceUsed) {
scoped_ptr<Message> message(prototype_->New());
TestUtil::ReflectionTester reflection_tester(descriptor_);
int initial_space_used = message->SpaceUsed();
reflection_tester.SetAllFieldsViaReflection(message.get());
EXPECT_LT(initial_space_used, message->SpaceUsed());
}
}
}