2 * Copyright 2015 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 <gtest/gtest.h>
19 #include <folly/futures/Future.h>
21 using namespace folly;
23 TEST(WillEqual, basic) {
24 // both p1 and p2 already fulfilled
30 auto f1 = p1.getFuture();
31 auto f2 = p2.getFuture();
32 EXPECT_TRUE(f1.willEqual(f2).get());
39 auto f1 = p1.getFuture();
40 auto f2 = p2.getFuture();
41 EXPECT_FALSE(f1.willEqual(f2).get());
43 // both p1 and p2 not yet fulfilled
47 auto f1 = p1.getFuture();
48 auto f2 = p2.getFuture();
49 auto f3 = f1.willEqual(f2);
52 EXPECT_TRUE(f3.get());
57 auto f1 = p1.getFuture();
58 auto f2 = p2.getFuture();
59 auto f3 = f1.willEqual(f2);
62 EXPECT_FALSE(f3.get());
64 // p1 already fulfilled, p2 not yet fulfilled
69 auto f1 = p1.getFuture();
70 auto f2 = p2.getFuture();
71 auto f3 = f1.willEqual(f2);
73 EXPECT_TRUE(f3.get());
79 auto f1 = p1.getFuture();
80 auto f2 = p2.getFuture();
81 auto f3 = f1.willEqual(f2);
83 EXPECT_FALSE(f3.get());
85 // p2 already fulfilled, p1 not yet fulfilled
90 auto f1 = p1.getFuture();
91 auto f2 = p2.getFuture();
92 auto f3 = f1.willEqual(f2);
94 EXPECT_TRUE(f3.get());
100 auto f1 = p1.getFuture();
101 auto f2 = p2.getFuture();
102 auto f3 = f1.willEqual(f2);
104 EXPECT_FALSE(f3.get());