|
|
|
@ -21,10 +21,8 @@ |
|
|
|
|
#include "google/protobuf/compiler/hpb/tests/child_model.upb.proto.h" |
|
|
|
|
#include "google/protobuf/compiler/hpb/tests/no_package.upb.proto.h" |
|
|
|
|
#include "google/protobuf/compiler/hpb/tests/test_model.upb.proto.h" |
|
|
|
|
#include "google/protobuf/hpb/hpb.h" |
|
|
|
|
#include "google/protobuf/hpb/requires.h" |
|
|
|
|
#include "protos/protos.h" |
|
|
|
|
#include "protos/repeated_field.h" |
|
|
|
|
#include "protos/repeated_field_iterator.h" |
|
|
|
|
#include "upb/mem/arena.h" |
|
|
|
|
#include "upb/mem/arena.hpp" |
|
|
|
|
|
|
|
|
@ -67,13 +65,13 @@ TEST(CppGeneratedCode, MessageEnumValue) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ArenaConstructor) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(false, testModel.has_b1()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, Booleans) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_FALSE(testModel.b1()); |
|
|
|
|
testModel.set_b1(true); |
|
|
|
@ -87,7 +85,7 @@ TEST(CppGeneratedCode, Booleans) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ScalarInt32) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
// Test int32 defaults.
|
|
|
|
|
EXPECT_EQ(testModel.value(), 0); |
|
|
|
@ -130,7 +128,7 @@ TEST(CppGeneratedCode, Strings) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ScalarUInt32) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
// Test defaults.
|
|
|
|
|
EXPECT_EQ(testModel.optional_uint32(), 0); |
|
|
|
@ -150,7 +148,7 @@ TEST(CppGeneratedCode, ScalarUInt32) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ScalarInt64) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
// Test defaults.
|
|
|
|
|
EXPECT_EQ(testModel.optional_int64(), 0); |
|
|
|
@ -174,7 +172,7 @@ TEST(CppGeneratedCode, ScalarInt64) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ScalarFloat) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
// Test defaults.
|
|
|
|
|
EXPECT_EQ(testModel.optional_float(), 0.0f); |
|
|
|
@ -202,7 +200,7 @@ TEST(CppGeneratedCode, ScalarFloat) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, ScalarDouble) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
// Test defaults.
|
|
|
|
|
EXPECT_EQ(testModel.optional_double(), 0.0); |
|
|
|
@ -226,7 +224,7 @@ TEST(CppGeneratedCode, ScalarDouble) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, Enums) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
|
|
|
|
|
// Check enum default value.
|
|
|
|
@ -254,7 +252,7 @@ TEST(CppGeneratedCode, Enums) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, FieldWithDefaultValue) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto testModel = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(testModel.has_int_value_with_default()); |
|
|
|
@ -269,7 +267,7 @@ TEST(CppGeneratedCode, FieldWithDefaultValue) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, OneOfFields) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(test_model.has_oneof_member1()); |
|
|
|
@ -297,7 +295,7 @@ TEST(CppGeneratedCode, OneOfFields) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, Messages) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(false, test_model.has_child_model_1()); |
|
|
|
|
auto child_model = test_model.child_model_1(); |
|
|
|
@ -321,7 +319,7 @@ TEST(CppGeneratedCode, Messages) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, NestedMessages) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
auto nested_child = test_model.nested_child_1(); |
|
|
|
|
EXPECT_EQ(0, nested_child->nested_child_name().size()); |
|
|
|
@ -332,7 +330,7 @@ TEST(CppGeneratedCode, NestedMessages) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedMessages) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.child_models_size()); |
|
|
|
|
// Should be able to clear repeated field when empty.
|
|
|
|
@ -361,7 +359,7 @@ TEST(CppGeneratedCode, RepeatedMessages) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedScalar) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.value_array_size()); |
|
|
|
|
// Should be able to clear repeated field when empty.
|
|
|
|
@ -382,7 +380,7 @@ TEST(CppGeneratedCode, RepeatedScalar) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedFieldClear) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
test_model.mutable_value_array()->push_back(5); |
|
|
|
|
test_model.mutable_value_array()->push_back(16); |
|
|
|
@ -393,7 +391,7 @@ TEST(CppGeneratedCode, RepeatedFieldClear) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedFieldProxyForScalars) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.value_array().size()); |
|
|
|
|
EXPECT_EQ(0, test_model.mutable_value_array()->size()); |
|
|
|
@ -426,7 +424,7 @@ TEST(CppGeneratedCode, RepeatedFieldProxyForScalars) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedScalarIterator) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
test_model.mutable_value_array()->push_back(5); |
|
|
|
|
test_model.mutable_value_array()->push_back(16); |
|
|
|
@ -493,7 +491,7 @@ TEST(CppGeneratedCode, RepeatedScalarIterator) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedFieldProxyForStrings) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.repeated_string().size()); |
|
|
|
|
EXPECT_EQ(0, test_model.mutable_repeated_string()->size()); |
|
|
|
@ -528,7 +526,7 @@ TEST(CppGeneratedCode, RepeatedFieldProxyForStrings) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedFieldProxyForMessages) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.child_models().size()); |
|
|
|
|
ChildModel1 child1; |
|
|
|
@ -573,7 +571,7 @@ TEST(CppGeneratedCode, RepeatedFieldProxyForMessages) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, EmptyRepeatedFieldProxyForMessages) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.child_models().size()); |
|
|
|
|
ChildModel1 child1; |
|
|
|
@ -586,7 +584,7 @@ TEST(CppGeneratedCode, EmptyRepeatedFieldProxyForMessages) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedFieldProxyForMessagesIndexOperator) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.child_models().size()); |
|
|
|
|
ChildModel1 child1; |
|
|
|
@ -604,7 +602,7 @@ TEST(CppGeneratedCode, RepeatedFieldProxyForMessagesIndexOperator) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, RepeatedStrings) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.repeated_string_size()); |
|
|
|
|
// Should be able to clear repeated field when empty.
|
|
|
|
@ -626,8 +624,8 @@ TEST(CppGeneratedCode, RepeatedStrings) { |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, MessageMapInt32KeyMessageValue) { |
|
|
|
|
const int key_test_value = 3; |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::protos::Arena child_arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
::hpb::Arena child_arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.child_map_size()); |
|
|
|
|
test_model.clear_child_map(); |
|
|
|
@ -648,7 +646,7 @@ TEST(CppGeneratedCode, MessageMapInt32KeyMessageValue) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, MessageMapStringKeyAndStringValue) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.str_to_str_map_size()); |
|
|
|
|
test_model.clear_str_to_str_map(); |
|
|
|
@ -664,7 +662,7 @@ TEST(CppGeneratedCode, MessageMapStringKeyAndStringValue) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, MessageMapStringKeyAndInt32Value) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
auto test_model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
EXPECT_EQ(0, test_model.str_to_int_map_size()); |
|
|
|
|
test_model.clear_str_to_int_map(); |
|
|
|
@ -725,13 +723,13 @@ TEST(CppGeneratedCode, SetExtension) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, SetExtensionWithPtr) { |
|
|
|
|
::protos::Arena arena_model; |
|
|
|
|
::hpb::Arena arena_model; |
|
|
|
|
::protos::Ptr<TestModel> model = |
|
|
|
|
::protos::CreateMessage<TestModel>(arena_model); |
|
|
|
|
void* prior_message; |
|
|
|
|
{ |
|
|
|
|
// Use a nested scope to make sure the arenas are fused correctly.
|
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
::protos::Ptr<ThemeExtension> extension1 = |
|
|
|
|
::protos::CreateMessage<ThemeExtension>(arena); |
|
|
|
|
extension1->set_ext_name("Hello World"); |
|
|
|
@ -748,7 +746,7 @@ TEST(CppGeneratedCode, SetExtensionWithPtr) { |
|
|
|
|
|
|
|
|
|
#ifndef _MSC_VER |
|
|
|
|
TEST(CppGeneratedCode, SetExtensionShouldNotCompileForWrongType) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
::protos::Ptr<TestModel> model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
ThemeExtension extension1; |
|
|
|
|
ContainerExtension extension2; |
|
|
|
@ -769,7 +767,7 @@ TEST(CppGeneratedCode, SetExtensionShouldNotCompileForWrongType) { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
TEST(CppGeneratedCode, SetExtensionWithPtrSameArena) { |
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
::protos::Ptr<TestModel> model = ::protos::CreateMessage<TestModel>(arena); |
|
|
|
|
void* prior_message; |
|
|
|
|
{ |
|
|
|
@ -1227,7 +1225,7 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) { |
|
|
|
|
ASSERT_TRUE(::protos::SetExtension(&source, theme, extension1).ok()); |
|
|
|
|
|
|
|
|
|
// Now that we have a source model with extension data, serialize.
|
|
|
|
|
::protos::Arena arena; |
|
|
|
|
::hpb::Arena arena; |
|
|
|
|
std::string data = std::string(::protos::Serialize(&source, arena).value()); |
|
|
|
|
|
|
|
|
|
// Test with ExtensionRegistry
|
|
|
|
|