aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_unittest.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_unittest.cc45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
index 61cc32a4..2ad7ea4e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc
@@ -995,75 +995,76 @@ TEST(GeneratedMessageTest, TestEmbedOptimizedForSize) {
TEST(GeneratedMessageTest, TestSpaceUsed) {
unittest::TestAllTypes message1;
- // sizeof provides a lower bound on SpaceUsed().
- EXPECT_LE(sizeof(unittest::TestAllTypes), message1.SpaceUsed());
- const int empty_message_size = message1.SpaceUsed();
+ // sizeof provides a lower bound on SpaceUsedLong().
+ EXPECT_LE(sizeof(unittest::TestAllTypes), message1.SpaceUsedLong());
+ const size_t empty_message_size = message1.SpaceUsedLong();
// Setting primitive types shouldn't affect the space used.
message1.set_optional_int32(123);
message1.set_optional_int64(12345);
message1.set_optional_uint32(123);
message1.set_optional_uint64(12345);
- EXPECT_EQ(empty_message_size, message1.SpaceUsed());
+ EXPECT_EQ(empty_message_size, message1.SpaceUsedLong());
// On some STL implementations, setting the string to a small value should
- // only increase SpaceUsed() by the size of a string object, though this is
- // not true everywhere.
+ // only increase SpaceUsedLong() by the size of a string object, though this
+ // is not true everywhere.
message1.set_optional_string("abc");
- EXPECT_LE(empty_message_size + sizeof(string), message1.SpaceUsed());
+ EXPECT_LE(empty_message_size + sizeof(string), message1.SpaceUsedLong());
// Setting a string to a value larger than the string object itself should
- // increase SpaceUsed(), because it cannot store the value internally.
+ // increase SpaceUsedLong(), because it cannot store the value internally.
message1.set_optional_string(string(sizeof(string) + 1, 'x'));
int min_expected_increase = message1.optional_string().capacity() +
sizeof(string);
EXPECT_LE(empty_message_size + min_expected_increase,
- message1.SpaceUsed());
+ message1.SpaceUsedLong());
- int previous_size = message1.SpaceUsed();
+ size_t previous_size = message1.SpaceUsedLong();
// Adding an optional message should increase the size by the size of the
// nested message type. NestedMessage is simple enough (1 int field) that it
// is equal to sizeof(NestedMessage)
message1.mutable_optional_nested_message();
ASSERT_EQ(sizeof(unittest::TestAllTypes::NestedMessage),
- message1.optional_nested_message().SpaceUsed());
+ message1.optional_nested_message().SpaceUsedLong());
EXPECT_EQ(previous_size +
sizeof(unittest::TestAllTypes::NestedMessage),
- message1.SpaceUsed());
+ message1.SpaceUsedLong());
}
TEST(GeneratedMessageTest, TestOneofSpaceUsed) {
unittest::TestOneof2 message1;
- EXPECT_LE(sizeof(unittest::TestOneof2), message1.SpaceUsed());
+ EXPECT_LE(sizeof(unittest::TestOneof2), message1.SpaceUsedLong());
- const int empty_message_size = message1.SpaceUsed();
+ const size_t empty_message_size = message1.SpaceUsedLong();
// Setting primitive types shouldn't affect the space used.
message1.set_foo_int(123);
message1.set_bar_int(12345);
- EXPECT_EQ(empty_message_size, message1.SpaceUsed());
+ EXPECT_EQ(empty_message_size, message1.SpaceUsedLong());
- // Setting a string in oneof to a small value should only increase SpaceUsed()
- // by the size of a string object.
+ // Setting a string in oneof to a small value should only increase
+ // SpaceUsedLong() by the size of a string object.
message1.set_foo_string("abc");
- EXPECT_LE(empty_message_size + sizeof(string), message1.SpaceUsed());
+ EXPECT_LE(empty_message_size + sizeof(string), message1.SpaceUsedLong());
// Setting a string in oneof to a value larger than the string object itself
- // should increase SpaceUsed(), because it cannot store the value internally.
+ // should increase SpaceUsedLong(), because it cannot store the value
+ // internally.
message1.set_foo_string(string(sizeof(string) + 1, 'x'));
int min_expected_increase = message1.foo_string().capacity() +
sizeof(string);
EXPECT_LE(empty_message_size + min_expected_increase,
- message1.SpaceUsed());
+ message1.SpaceUsedLong());
// Setting a message in oneof should delete the other fields and increase the
// size by the size of the nested message type. NestedMessage is simple enough
// that it is equal to sizeof(NestedMessage)
message1.mutable_foo_message();
ASSERT_EQ(sizeof(unittest::TestOneof2::NestedMessage),
- message1.foo_message().SpaceUsed());
+ message1.foo_message().SpaceUsedLong());
EXPECT_EQ(empty_message_size +
sizeof(unittest::TestOneof2::NestedMessage),
- message1.SpaceUsed());
+ message1.SpaceUsedLong());
}
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS