resize_uninitialized_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
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 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15