add functions to return string's internal pointers
[folly.git] / folly / test / FBVectorTest.cpp
index 68380279916cd0b76f542a181d75357141ec81c7..d3747fcd39f6a70e1ac7233534cf49316b32ae57 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <gtest/gtest.h>
 #include <list>
+#include <map>
 #include <memory>
 #include <boost/random.hpp>
 
@@ -245,6 +246,34 @@ TEST(FBVector, move_iterator) {
   EXPECT_EQ(fbvi3, base);
 }
 
+TEST(FBVector, reserve_consistency) {
+  struct S { int64_t a, b, c, d; };
+
+  fbvector<S> fb1;
+  for (size_t i = 0; i < 1000; ++i) {
+    fb1.reserve(1);
+    EXPECT_EQ(fb1.size(), 0);
+    fb1.shrink_to_fit();
+  }
+}
+
+TEST(FBVector, vector_of_maps) {
+  fbvector<std::map<std::string, std::string>> v;
+
+  v.push_back(std::map<std::string, std::string>());
+  v.push_back(std::map<std::string, std::string>());
+
+  EXPECT_EQ(2, v.size());
+
+  v[1]["hello"] = "world";
+  EXPECT_EQ(0, v[0].size());
+  EXPECT_EQ(1, v[1].size());
+
+  v[0]["foo"] = "bar";
+  EXPECT_EQ(1, v[0].size());
+  EXPECT_EQ(1, v[1].size());
+}
+
 int main(int argc, char** argv) {
   testing::InitGoogleTest(&argc, argv);
   google::ParseCommandLineFlags(&argc, &argv, true);