fix build when sanitizers are enabled and jemalloc is disabled
[folly.git] / folly / test / PaddedTest.cpp
index 1fd751375bffbbc556cfbca320382687c5cbb395..7cbcb7296c8880f727450f6741e66a89732e34fe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#include "folly/Padded.h"
+#include <folly/Padded.h>
 
 #include <glog/logging.h>
-#include <gtest/gtest.h>
+
+#include <folly/portability/GTest.h>
 
 using namespace folly;
 
@@ -84,11 +85,11 @@ class IntPaddedTestBase : public ::testing::Test {
 
 class IntPaddedConstTest : public IntPaddedTestBase {
  protected:
-  void SetUp() {
+  void SetUp() override {
     v_.resize(4);
     n_ = 0;
     for (int i = 0; i < 4; i++) {
-      for (int j = 0; j < IntNode::kElementCount; ++j, ++n_) {
+      for (size_t j = 0; j < IntNode::kElementCount; ++j, ++n_) {
         v_[i].data()[j] = n_;
       }
     }
@@ -160,7 +161,7 @@ TEST_F(IntPaddedNonConstTest, Iteration) {
 
   k = 0;
   for (int i = 0; i < 4; i++) {
-    for (int j = 0; j < IntNode::kElementCount; ++j, ++k) {
+    for (size_t j = 0; j < IntNode::kElementCount; ++j, ++k) {
       EXPECT_EQ(k, v_[i].data()[j]);
     }
   }
@@ -181,11 +182,11 @@ class StructPaddedTestBase : public ::testing::Test {
 
 class StructPaddedConstTest : public StructPaddedTestBase {
  protected:
-  void SetUp() {
+  void SetUp() override {
     v_.resize(4);
     n_ = 0;
     for (int i = 0; i < 4; i++) {
-      for (int j = 0; j < PointNode::kElementCount; ++j, ++n_) {
+      for (size_t j = 0; j < PointNode::kElementCount; ++j, ++n_) {
         auto& point = v_[i].data()[j];
         point.x = n_;
         point.y = n_ + 1;
@@ -240,3 +241,23 @@ TEST_F(IntAdaptorTest, ResizeConstructor) {
   }
 }
 
+TEST_F(IntAdaptorTest, SimpleEmplaceBack) {
+  for (int i = 0; i < n_; ++i) {
+    EXPECT_EQ((i == 0), a_.empty());
+    EXPECT_EQ(i, a_.size());
+    a_.emplace_back(i);
+  }
+  EXPECT_EQ(n_, a_.size());
+
+  int k = 0;
+  for (auto it = a_.begin(); it != a_.end(); ++it, ++k) {
+    EXPECT_EQ(k, a_[k]);
+    EXPECT_EQ(k, *it);
+  }
+  EXPECT_EQ(n_, k);
+
+  auto p = a_.move();
+  EXPECT_TRUE(a_.empty());
+  EXPECT_EQ(16, p.second);
+  EXPECT_TRUE(v_ == p.first);
+}