proxygen
WindowTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (WindowTest, Basic)
 
 TEST (WindowTest, ChangeCapacity)
 
 TEST (WindowTest, ExceedWindow)
 
 TEST (WindowTest, Overflow)
 
 TEST (WindowTest, Underflow)
 
 TEST (WindowTest, HugeReserve)
 
 TEST (WindowTest, HugeFree)
 
 TEST (WindowTest, HugeFree2)
 
 TEST (WindowTest, BytesOutstanding)
 
 TEST (WindowTest, BytesOutstandingAfterFail)
 
 TEST (WindowTest, NonStrict)
 
 TEST (WindowTest, NewCapacityOverflow)
 

Function Documentation

TEST ( WindowTest  ,
Basic   
)

Definition at line 15 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, proxygen::Window::free(), proxygen::Window::getCapacity(), proxygen::Window::getSize(), and proxygen::Window::reserve().

15  {
16  Window w(100);
17  ASSERT_TRUE(w.free(10));
18  ASSERT_EQ(w.getSize(), 110);
19  ASSERT_EQ(w.getCapacity(), 100);
20  ASSERT_TRUE(w.reserve(20));
21  ASSERT_EQ(w.getSize(), 90);
22  ASSERT_TRUE(w.reserve(90));
23  ASSERT_EQ(w.getSize(), 0);
24  ASSERT_TRUE(w.free(5));
25  ASSERT_EQ(w.getSize(), 5);
26  ASSERT_TRUE(w.free(0));
27  ASSERT_EQ(w.getSize(), 5);
28 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
ChangeCapacity   
)

Definition at line 30 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, proxygen::Window::free(), proxygen::Window::getCapacity(), proxygen::Window::getOutstanding(), proxygen::Window::getSize(), proxygen::Window::reserve(), and proxygen::Window::setCapacity().

30  {
31  Window w(100);
32  ASSERT_TRUE(w.setCapacity(10));
33  ASSERT_EQ(w.getSize(), 10);
34  ASSERT_EQ(w.getCapacity(), 10);
35  ASSERT_TRUE(w.reserve(7));
36  ASSERT_TRUE(w.setCapacity(5));
37  ASSERT_EQ(w.getCapacity(), 5);
38  ASSERT_EQ(w.getSize(), -2);
39  ASSERT_TRUE(w.free(1));
40  ASSERT_EQ(w.getSize(), -1);
41  ASSERT_TRUE(w.setCapacity(6));
42  ASSERT_EQ(w.getSize(), 0);
43  ASSERT_EQ(w.getCapacity(), 6);
44  ASSERT_TRUE(w.setCapacity(7));
45  ASSERT_EQ(w.getSize(), 1);
46  ASSERT_EQ(w.getCapacity(), 7);
47  ASSERT_EQ(w.getOutstanding(), 6);
48 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
ExceedWindow   
)

Definition at line 50 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, ASSERT_TRUE, proxygen::Window::getSize(), and proxygen::Window::reserve().

50  {
51  Window w(100);
52  ASSERT_TRUE(w.reserve(50));
53  ASSERT_TRUE(w.reserve(40));
54  ASSERT_EQ(w.getSize(), 10);
55  ASSERT_FALSE(w.reserve(20));
56 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
Overflow   
)

Definition at line 58 of file WindowTest.cpp.

References ASSERT_FALSE, max, and proxygen::Window::reserve().

58  {
59  Window w(0);
61 }
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
TEST ( WindowTest  ,
Underflow   
)

Definition at line 63 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, ASSERT_TRUE, proxygen::Window::free(), proxygen::Window::getSize(), and max.

63  {
64  Window w(100);
65  ASSERT_TRUE(w.free(100)); // You can manually bump up the window
66  ASSERT_TRUE(w.free(100)); // You can manually bump up the window
67  ASSERT_EQ(w.getSize(), 300);
68  ASSERT_FALSE(w.free(std::numeric_limits<int32_t>::max())); // to a point
69 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
HugeReserve   
)

Definition at line 71 of file WindowTest.cpp.

References ASSERT_FALSE, max, and proxygen::Window::reserve().

71  {
72  Window w(100);
74 }
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
TEST ( WindowTest  ,
HugeFree   
)

Definition at line 76 of file WindowTest.cpp.

References ASSERT_FALSE, ASSERT_TRUE, proxygen::Window::free(), and max.

76  {
77  Window w1(0);
79  Window w2(1);
81 }
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
HugeFree2   
)

Definition at line 83 of file WindowTest.cpp.

References ASSERT_FALSE, ASSERT_TRUE, proxygen::Window::free(), i, and max.

83  {
84  for (unsigned i = 0; i < 10; ++i) {
85  Window w(i);
87  ASSERT_FALSE(w.free(1));
88  }
89 }
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
BytesOutstanding   
)

Definition at line 91 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, proxygen::Window::free(), proxygen::Window::getOutstanding(), and proxygen::Window::reserve().

91  {
92  Window w(100);
93  ASSERT_EQ(w.getOutstanding(), 0);
94  ASSERT_TRUE(w.reserve(20));
95  ASSERT_EQ(w.getOutstanding(), 20);
96  ASSERT_TRUE(w.free(30));
97  // outstanding bytes is -10, but the API clamps this to 0
98  ASSERT_EQ(w.getOutstanding(), 0);
99 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
BytesOutstandingAfterFail   
)

Definition at line 101 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, proxygen::Window::getOutstanding(), and proxygen::Window::reserve().

101  {
102  Window w(100);
103  ASSERT_EQ(w.getOutstanding(), 0);
104  ASSERT_FALSE(w.reserve(110));
105  ASSERT_EQ(w.getOutstanding(), 0);
106 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
TEST ( WindowTest  ,
NonStrict   
)

Definition at line 108 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_TRUE, proxygen::Window::getOutstanding(), proxygen::Window::getSize(), and proxygen::Window::reserve().

108  {
109  Window w(100);
110  ASSERT_TRUE(w.reserve(110, false));
111  ASSERT_EQ(w.getOutstanding(), 110);
112  ASSERT_EQ(w.getSize(), -10);
113 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( WindowTest  ,
NewCapacityOverflow   
)

Definition at line 115 of file WindowTest.cpp.

References ASSERT_EQ, ASSERT_FALSE, ASSERT_TRUE, proxygen::Window::free(), proxygen::Window::getOutstanding(), proxygen::Window::getSize(), max, and proxygen::Window::setCapacity().

115  {
116  Window w(0);
117  ASSERT_TRUE(w.free(10));
118  ASSERT_EQ(w.getOutstanding(), 0);
119  ASSERT_EQ(w.getSize(), 10);
120  ASSERT_TRUE(w.setCapacity(std::numeric_limits<int32_t>::max() - 10));
122  ASSERT_FALSE(w.setCapacity(std::numeric_limits<int32_t>::max() - 9));
123 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogLevel max
Definition: LogLevel.cpp:31
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865