proxygen
StampedPtrTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (StampedPtr, Basic)
 
 TEST (StampedPtr, Zero)
 
 TEST (StampedPtr, Void)
 
 TEST (StampedPtr, Make)
 
 TEST (StampedPtr, Const)
 
 TEST (StampedPtr, BitExtension)
 

Function Documentation

TEST ( StampedPtr  ,
Basic   
)

Definition at line 21 of file StampedPtrTest.cpp.

References EXPECT_EQ, EXPECT_NE, folly::StampedPtr< T >::ptr(), folly::StampedPtr< T >::raw, folly::StampedPtr< T >::set(), folly::StampedPtr< T >::setPtr(), folly::StampedPtr< T >::setStamp(), folly::StampedPtr< T >::stamp(), and uint64_t.

21  {
23  char target[10];
24  sp.set(target, 10);
25  EXPECT_EQ(sp.ptr(), target);
26  EXPECT_EQ(sp.stamp(), 10);
27  sp.setStamp(sp.stamp() + 1);
28  EXPECT_EQ(sp.stamp(), 11);
29  sp.setPtr(target + 1);
30  EXPECT_EQ(sp.ptr(), target + 1);
31 
32  uint64_t raw = sp.raw;
33  sp.raw = 0;
34  EXPECT_NE(sp.stamp(), 11);
35  sp.raw = raw;
36  EXPECT_EQ(sp.stamp(), 11);
37  EXPECT_EQ(sp.ptr(), target + 1);
38 }
void setPtr(T *ptr)
Definition: StampedPtr.h:84
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
uint16_t stamp() const
Definition: StampedPtr.h:76
T * ptr() const
Definition: StampedPtr.h:72
void set(T *ptr, uint16_t stamp)
Definition: StampedPtr.h:80
#define EXPECT_NE(val1, val2)
Definition: gtest.h:1926
void setStamp(uint16_t stamp)
Definition: StampedPtr.h:88
TEST ( StampedPtr  ,
Zero   
)

Definition at line 40 of file StampedPtrTest.cpp.

References EXPECT_EQ, and EXPECT_TRUE.

40  {
42  EXPECT_TRUE(sp.ptr() == nullptr);
43  EXPECT_EQ(sp.stamp(), 0);
44 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
TEST ( StampedPtr  ,
Void   
)

Definition at line 46 of file StampedPtrTest.cpp.

References EXPECT_EQ, folly::StampedPtr< T >::ptr(), and folly::StampedPtr< T >::set().

46  {
48  char target[10];
49  sp.set(target, 10);
50  EXPECT_EQ(sp.ptr(), target);
51 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
T * ptr() const
Definition: StampedPtr.h:72
void set(T *ptr, uint16_t stamp)
Definition: StampedPtr.h:80
TEST ( StampedPtr  ,
Make   
)

Definition at line 53 of file StampedPtrTest.cpp.

References EXPECT_EQ, folly::makeStampedPtr(), and x.

53  {
54  auto sp = folly::makeStampedPtr("abc", 0xffff);
55  EXPECT_EQ(*sp.ptr(), 'a');
56  EXPECT_EQ(sp.stamp(), 0xffff);
57 
58  double x;
59  auto sp2 = folly::makeStampedPtr(&x, 0);
60  EXPECT_EQ(sp2.ptr(), &x);
61  EXPECT_EQ(sp2.stamp(), 0);
62 }
StampedPtr< T > makeStampedPtr(T *ptr, uint16_t stamp)
Definition: StampedPtr.h:124
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const int x
TEST ( StampedPtr  ,
Const   
)

Definition at line 64 of file StampedPtrTest.cpp.

References folly::StampedPtr< T >::setPtr().

64  {
66  char target;
67  sp.setPtr(&target);
68 }
void setPtr(T *ptr)
Definition: StampedPtr.h:84
TEST ( StampedPtr  ,
BitExtension   
)

Definition at line 70 of file StampedPtrTest.cpp.

References ASSERT_TRUE, EXPECT_EQ, and folly::StampedPtr< T >::setPtr().

70  {
71  // fedcba9876543210
72  auto lo = static_cast<uintptr_t>(0x00007fff672333ecLL);
73  auto hi = static_cast<uintptr_t>(0xfffffffff72333ecLL);
74  ASSERT_TRUE(static_cast<intptr_t>(lo) > 0);
75  ASSERT_TRUE(static_cast<intptr_t>(hi) < 0);
76 
78  sp.setPtr(reinterpret_cast<char*>(lo));
79  EXPECT_EQ(sp.ptr(), reinterpret_cast<char*>(lo));
80  sp.setPtr(reinterpret_cast<char*>(hi));
81  EXPECT_EQ(sp.ptr(), reinterpret_cast<char*>(hi));
82 }
void setPtr(T *ptr)
Definition: StampedPtr.h:84
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865