Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "absl/strings/internal/resize_uninitialized.h"
00016
00017 #include "gtest/gtest.h"
00018
00019 namespace {
00020
00021 int resize_call_count = 0;
00022
00023 struct resizable_string {
00024 void resize(size_t) { resize_call_count += 1; }
00025 };
00026
00027 int resize_default_init_call_count = 0;
00028
00029 struct resize_default_init_string {
00030 void resize(size_t) { resize_call_count += 1; }
00031 void __resize_default_init(size_t) { resize_default_init_call_count += 1; }
00032 };
00033
00034 TEST(ResizeUninit, WithAndWithout) {
00035 resize_call_count = 0;
00036 resize_default_init_call_count = 0;
00037 {
00038 resizable_string rs;
00039
00040 EXPECT_EQ(resize_call_count, 0);
00041 EXPECT_EQ(resize_default_init_call_count, 0);
00042 EXPECT_FALSE(
00043 absl::strings_internal::STLStringSupportsNontrashingResize(&rs));
00044 EXPECT_EQ(resize_call_count, 0);
00045 EXPECT_EQ(resize_default_init_call_count, 0);
00046 absl::strings_internal::STLStringResizeUninitialized(&rs, 237);
00047 EXPECT_EQ(resize_call_count, 1);
00048 EXPECT_EQ(resize_default_init_call_count, 0);
00049 }
00050
00051 resize_call_count = 0;
00052 resize_default_init_call_count = 0;
00053 {
00054 resize_default_init_string rus;
00055
00056 EXPECT_EQ(resize_call_count, 0);
00057 EXPECT_EQ(resize_default_init_call_count, 0);
00058 EXPECT_TRUE(
00059 absl::strings_internal::STLStringSupportsNontrashingResize(&rus));
00060 EXPECT_EQ(resize_call_count, 0);
00061 EXPECT_EQ(resize_default_init_call_count, 0);
00062 absl::strings_internal::STLStringResizeUninitialized(&rus, 237);
00063 EXPECT_EQ(resize_call_count, 0);
00064 EXPECT_EQ(resize_default_init_call_count, 1);
00065 }
00066 }
00067
00068 }