proxygen
FBVectorTest.cpp File Reference
#include <folly/FBVector.h>
#include <list>
#include <map>
#include <memory>
#include <boost/random.hpp>
#include <folly/FBString.h>
#include <folly/Random.h>
#include <folly/Traits.h>
#include <folly/container/Foreach.h>
#include <folly/portability/GTest.h>
#include <folly/test/FBVectorTestUtil.h>
#include <folly/test/FBVectorTests.cpp.h>

Go to the source code of this file.

Macros

#define VECTOR   IntFBVector
 
#define VECTOR   FBStringFBVector
 

Typedefs

using IntFBVector = fbvector< int >
 
using FBStringFBVector = fbvector< fbstring >
 

Functions

 TEST (fbvector, clause_23_3_6_1_3_ambiguity)
 
 TEST (fbvector, clause_23_3_6_1_11_ambiguity)
 
 TEST (fbvector, clause_23_3_6_2_6)
 
 TEST (fbvector, clause_23_3_6_4_ambiguity)
 
 TEST (fbvector, composition)
 
 TEST (fbvector, works_with_std_string)
 
 TEST (fbvector, works_with_user_defined_type)
 
 TEST (fbvector, move_construction)
 
 TEST (fbvector, emplace)
 
 TEST (fbvector, initializer_lists)
 
 TEST (fbvector, unique_ptr)
 
 TEST (FBVector, task858056)
 
 TEST (FBVector, move_iterator)
 
 TEST (FBVector, reserve_consistency)
 
 TEST (FBVector, vector_of_maps)
 
 TEST (FBVector, shrink_to_fit_after_clear)
 
 TEST (FBVector, zero_len)
 

Macro Definition Documentation

#define VECTOR   IntFBVector

Definition at line 45 of file FBVectorTest.cpp.

#define VECTOR   FBStringFBVector

Definition at line 45 of file FBVectorTest.cpp.

Typedef Documentation

Definition at line 40 of file FBVectorTest.cpp.

using IntFBVector = fbvector<int>

Definition at line 39 of file FBVectorTest.cpp.

Function Documentation

TEST ( fbvector  ,
clause_23_3_6_1_3_ambiguity   
)

Definition at line 49 of file FBVectorTest.cpp.

References EXPECT_EQ, FOR_EACH, i, folly::fbvector< T, Allocator >::size(), and v.

49  {
50  fbvector<int> v(10, 20);
51  EXPECT_EQ(v.size(), 10);
52  FOR_EACH (i, v) { EXPECT_EQ(*i, 20); }
53 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define FOR_EACH(i, c)
Definition: Foreach.h:143
TEST ( fbvector  ,
clause_23_3_6_1_11_ambiguity   
)

Definition at line 55 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::assign(), EXPECT_EQ, FOR_EACH, i, folly::fbvector< T, Allocator >::size(), and v.

55  {
57  v.assign(10, 20);
58  EXPECT_EQ(v.size(), 10);
59  FOR_EACH (i, v) { EXPECT_EQ(*i, 20); }
60 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void assign(It first, It last)
Definition: FBVector.h:800
#define FOR_EACH(i, c)
Definition: Foreach.h:143
size_type size() const noexcept
Definition: FBVector.h:964
TEST ( fbvector  ,
clause_23_3_6_2_6   
)

Definition at line 62 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::assign(), random(), folly::test::detail::randomObject< int >(), folly::fbvector< T, Allocator >::reserve(), folly::fbvector< T, Allocator >::shrink_to_fit(), and v.

62  {
64  auto const n = random(0U, 10000U);
65  v.reserve(n);
66  auto const n1 = random(0U, 10000U);
67  auto const obj = randomObject<int>();
68  v.assign(n1, obj);
69  v.shrink_to_fit();
70  // Nothing to verify except that the call made it through
71 }
Integral2 random(Integral1 low, Integral2 up)
auto v
void assign(It first, It last)
Definition: FBVector.h:800
void reserve(size_type n)
Definition: FBVector.h:1003
void shrink_to_fit() noexcept
Definition: FBVector.h:1027
TEST ( fbvector  ,
clause_23_3_6_4_ambiguity   
)

Definition at line 73 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::end(), EXPECT_EQ, i, folly::fbvector< T, Allocator >::insert(), folly::fbvector< T, Allocator >::size(), and v.

73  {
76  v.insert(it, 10, 20);
77  EXPECT_EQ(v.size(), 10);
78  for (auto i : v) {
79  EXPECT_EQ(i, 20);
80  }
81 }
iterator end() noexcept
Definition: FBVector.h:928
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const T * const_iterator
Definition: FBVector.h:206
size_type size() const noexcept
Definition: FBVector.h:964
iterator insert(const_iterator cpos, const T &value)
Definition: FBVector.h:1500
TEST ( fbvector  ,
composition   
)

Definition at line 83 of file FBVectorTest.cpp.

83  {
85 }
TEST ( fbvector  ,
works_with_std_string   
)

Definition at line 87 of file FBVectorTest.cpp.

References EXPECT_EQ, FOLLY_ASSUME_FBVECTOR_COMPATIBLE(), folly::fbvector< T, Allocator >::push_back(), folly::fbvector< T, Allocator >::size(), and v.

87  {
88  fbvector<std::string> v(10, "hello");
89  EXPECT_EQ(v.size(), 10);
90  v.push_back("world");
91 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( fbvector  ,
works_with_user_defined_type   
)

Definition at line 101 of file FBVectorTest.cpp.

References EXPECT_EQ, folly::fbvector< T, Allocator >::push_back(), folly::fbvector< T, Allocator >::size(), and v.

101  {
103  EXPECT_EQ(v.size(), 10);
104  v.push_back(UserDefinedType());
105 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
TEST ( fbvector  ,
move_construction   
)

Definition at line 107 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::assign(), EXPECT_EQ, folly::fbvector< T, Allocator >::front(), folly::gen::move, and folly::fbvector< T, Allocator >::size().

107  {
108  fbvector<int> v1(100, 100);
109  fbvector<int> v2;
110  EXPECT_EQ(v1.size(), 100);
111  EXPECT_EQ(v1.front(), 100);
112  EXPECT_EQ(v2.size(), 0);
113  v2 = std::move(v1);
114  EXPECT_EQ(v1.size(), 0);
115  EXPECT_EQ(v2.size(), 100);
116  EXPECT_EQ(v2.front(), 100);
117 
118  v1.assign(100, 100);
119  auto other = std::move(v1);
120  EXPECT_EQ(v1.size(), 0);
121  EXPECT_EQ(other.size(), 100);
122  EXPECT_EQ(other.front(), 100);
123 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_type size() const noexcept
Definition: FBVector.h:964
TEST ( fbvector  ,
emplace   
)

Definition at line 125 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::back(), folly::fbvector< T, Allocator >::emplace_back(), EXPECT_EQ, folly::fbvector< T, Allocator >::front(), s, and folly::fbvector< T, Allocator >::size().

125  {
126  fbvector<std::string> s(12, "asd");
127  EXPECT_EQ(s.size(), 12);
128  EXPECT_EQ(s.front(), "asd");
129  s.emplace_back("funk");
130  EXPECT_EQ(s.back(), "funk");
131 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static set< string > s
TEST ( fbvector  ,
initializer_lists   
)

Definition at line 133 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::begin(), EXPECT_EQ, folly::fbvector< T, Allocator >::insert(), and folly::fbvector< T, Allocator >::size().

133  {
134  fbvector<int> vec = {1, 2, 3};
135  EXPECT_EQ(vec.size(), 3);
136  EXPECT_EQ(vec[0], 1);
137  EXPECT_EQ(vec[1], 2);
138  EXPECT_EQ(vec[2], 3);
139 
140  vec = {0, 0, 12, 16};
141  EXPECT_EQ(vec.size(), 4);
142  EXPECT_EQ(vec[0], 0);
143  EXPECT_EQ(vec[1], 0);
144  EXPECT_EQ(vec[2], 12);
145  EXPECT_EQ(vec[3], 16);
146 
147  vec.insert(vec.begin() + 1, {23, 23});
148  EXPECT_EQ(vec.size(), 6);
149  EXPECT_EQ(vec[0], 0);
150  EXPECT_EQ(vec[1], 23);
151  EXPECT_EQ(vec[2], 23);
152  EXPECT_EQ(vec[3], 0);
153  EXPECT_EQ(vec[4], 12);
154  EXPECT_EQ(vec[5], 16);
155 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
iterator begin() noexcept
Definition: FBVector.h:922
Definition: Traits.h:588
size_type size() const noexcept
Definition: FBVector.h:964
iterator insert(const_iterator cpos, const T &value)
Definition: FBVector.h:1500
TEST ( fbvector  ,
unique_ptr   
)

Definition at line 157 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::back(), EXPECT_EQ, EXPECT_FALSE, folly::gen::move, folly::fbvector< T, Allocator >::push_back(), and v.

157  {
159  std::unique_ptr<int> p(new int(12));
160  v.push_back(std::move(p));
161  EXPECT_EQ(*v.back(), 12);
162 
163  v[0] = std::move(p);
164  EXPECT_FALSE(v[0].get());
165  v[0] = std::make_unique<int>(32);
166  std::unique_ptr<int> somePtr;
167  v.insert(v.begin(), std::move(somePtr));
168  EXPECT_EQ(*v[1], 32);
169 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( FBVector  ,
task858056   
)

Definition at line 171 of file FBVectorTest.cpp.

References folly::gen::cycle, EXPECT_EQ, FOR_EACH_R, message, and folly::fbvector< T, Allocator >::push_back().

171  {
173  cycle.push_back("foo");
174  cycle.push_back("bar");
175  cycle.push_back("baz");
176  fbstring message("Cycle detected: ");
177  FOR_EACH_R (node_name, cycle) {
178  message += "[";
179  message += *node_name;
180  message += "] ";
181  }
182  EXPECT_EQ("Cycle detected: [baz] [bar] [foo] ", message);
183 }
Definition: test.c:42
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define FOR_EACH_R(i, c)
Definition: Foreach.h:156
void push_back(const T &value)
Definition: FBVector.h:1156
std::string message
Definition: SPDYCodec.cpp:133
constexpr detail::Cycle< true > cycle
Definition: Base-inl.h:2573
TEST ( FBVector  ,
move_iterator   
)

Definition at line 185 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::assign(), folly::fbvector< T, Allocator >::end(), EXPECT_EQ, and folly::fbvector< T, Allocator >::insert().

185  {
186  fbvector<int> base = {0, 1, 2};
187 
188  auto cp1 = base;
189  fbvector<int> fbvi1(
190  std::make_move_iterator(cp1.begin()), std::make_move_iterator(cp1.end()));
191  EXPECT_EQ(fbvi1, base);
192 
193  auto cp2 = base;
194  fbvector<int> fbvi2;
195  fbvi2.assign(
196  std::make_move_iterator(cp2.begin()), std::make_move_iterator(cp2.end()));
197  EXPECT_EQ(fbvi2, base);
198 
199  auto cp3 = base;
200  fbvector<int> fbvi3;
201  fbvi3.insert(
202  fbvi3.end(),
203  std::make_move_iterator(cp3.begin()),
204  std::make_move_iterator(cp3.end()));
205  EXPECT_EQ(fbvi3, base);
206 }
iterator end() noexcept
Definition: FBVector.h:928
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void assign(It first, It last)
Definition: FBVector.h:800
iterator insert(const_iterator cpos, const T &value)
Definition: FBVector.h:1500
TEST ( FBVector  ,
reserve_consistency   
)

Definition at line 208 of file FBVectorTest.cpp.

References a, b, c, EXPECT_EQ, i, int64_t, folly::fbvector< T, Allocator >::reserve(), folly::fbvector< T, Allocator >::shrink_to_fit(), and folly::fbvector< T, Allocator >::size().

208  {
209  struct S {
210  int64_t a, b, c, d;
211  };
212 
213  fbvector<S> fb1;
214  for (size_t i = 0; i < 1000; ++i) {
215  fb1.reserve(1);
216  EXPECT_EQ(fb1.size(), 0);
217  fb1.shrink_to_fit();
218  }
219 }
char b
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void reserve(size_type n)
Definition: FBVector.h:1003
char a
void shrink_to_fit() noexcept
Definition: FBVector.h:1027
size_type size() const noexcept
Definition: FBVector.h:964
char c
TEST ( FBVector  ,
vector_of_maps   
)

Definition at line 221 of file FBVectorTest.cpp.

References EXPECT_EQ, folly::fbvector< T, Allocator >::push_back(), folly::size(), folly::fbvector< T, Allocator >::size(), and v.

221  {
223 
224  v.push_back(std::map<std::string, std::string>());
225  v.push_back(std::map<std::string, std::string>());
226 
227  EXPECT_EQ(2, v.size());
228 
229  v[1]["hello"] = "world";
230  EXPECT_EQ(0, v[0].size());
231  EXPECT_EQ(1, v[1].size());
232 
233  v[0]["foo"] = "bar";
234  EXPECT_EQ(1, v[0].size());
235  EXPECT_EQ(1, v[1].size());
236 }
auto v
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void push_back(const T &value)
Definition: FBVector.h:1156
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
size_type size() const noexcept
Definition: FBVector.h:964
TEST ( FBVector  ,
shrink_to_fit_after_clear   
)

Definition at line 238 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::capacity(), folly::fbvector< T, Allocator >::clear(), EXPECT_EQ, folly::fbvector< T, Allocator >::push_back(), folly::fbvector< T, Allocator >::shrink_to_fit(), and folly::fbvector< T, Allocator >::size().

238  {
239  fbvector<int> fb1;
240  fb1.push_back(42);
241  fb1.push_back(1337);
242  fb1.clear();
243  fb1.shrink_to_fit();
244  EXPECT_EQ(fb1.size(), 0);
245  EXPECT_EQ(fb1.capacity(), 0);
246 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void push_back(const T &value)
Definition: FBVector.h:1156
void shrink_to_fit() noexcept
Definition: FBVector.h:1027
size_type capacity() const noexcept
Definition: FBVector.h:995
void clear() noexcept
Definition: FBVector.h:1188
size_type size() const noexcept
Definition: FBVector.h:964
TEST ( FBVector  ,
zero_len   
)

Definition at line 248 of file FBVectorTest.cpp.

References folly::fbvector< T, Allocator >::begin(), folly::fbvector< T, Allocator >::end(), and folly::gen::move.

248  {
249  fbvector<int> fb1(0);
250  fbvector<int> fb2(0, 10);
251  fbvector<int> fb3(std::move(fb1));
252  fbvector<int> fb4;
253  fb4 = std::move(fb2);
254  fbvector<int> fb5 = fb3;
255  fbvector<int> fb6;
256  fb6 = fb4;
257  std::initializer_list<int> il = {};
258  fb6 = il;
259  fbvector<int> fb7(fb6.begin(), fb6.end());
260 }
iterator end() noexcept
Definition: FBVector.h:928
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
iterator begin() noexcept
Definition: FBVector.h:922