2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/futures/Future.h>
18 #include <folly/portability/GTest.h>
20 using namespace folly;
22 TEST(WillEqual, basic) {
23 // both p1 and p2 already fulfilled
29 auto f1 = p1.getFuture();
30 auto f2 = p2.getFuture();
31 EXPECT_TRUE(f1.willEqual(f2).get());
38 auto f1 = p1.getFuture();
39 auto f2 = p2.getFuture();
40 EXPECT_FALSE(f1.willEqual(f2).get());
42 // both p1 and p2 not yet fulfilled
46 auto f1 = p1.getFuture();
47 auto f2 = p2.getFuture();
48 auto f3 = f1.willEqual(f2);
51 EXPECT_TRUE(f3.get());
56 auto f1 = p1.getFuture();
57 auto f2 = p2.getFuture();
58 auto f3 = f1.willEqual(f2);
61 EXPECT_FALSE(f3.get());
63 // p1 already fulfilled, p2 not yet fulfilled
68 auto f1 = p1.getFuture();
69 auto f2 = p2.getFuture();
70 auto f3 = f1.willEqual(f2);
72 EXPECT_TRUE(f3.get());
78 auto f1 = p1.getFuture();
79 auto f2 = p2.getFuture();
80 auto f3 = f1.willEqual(f2);
82 EXPECT_FALSE(f3.get());
84 // p2 already fulfilled, p1 not yet fulfilled
89 auto f1 = p1.getFuture();
90 auto f2 = p2.getFuture();
91 auto f3 = f1.willEqual(f2);
93 EXPECT_TRUE(f3.get());
99 auto f1 = p1.getFuture();
100 auto f2 = p2.getFuture();
101 auto f3 = f1.willEqual(f2);
103 EXPECT_FALSE(f3.get());