1 /* 2 * Copyright 2019 Google LLC. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * https://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /* 17 * Copyright 2020 Google LLC 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an "AS IS" BASIS, 27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 */ 31 32 #ifndef PRIVATE_JOIN_AND_COMPUTE_UTIL_STATUS_TESTING_H_ 33 #define PRIVATE_JOIN_AND_COMPUTE_UTIL_STATUS_TESTING_H_ 34 35 #include <gmock/gmock.h> 36 37 #include "private_join_and_compute/util/status.inc" 38 39 #ifndef GTEST_HAS_STATUS_MATCHERS 40 41 #define ASSERT_OK(expr) \ 42 PRIVATE_JOIN_AND_COMPUTE_ASSERT_OK_IMPL_( \ 43 PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_(_status, __LINE__), \ 44 expr) 45 46 #define PRIVATE_JOIN_AND_COMPUTE_ASSERT_OK_IMPL_(status, expr) \ 47 auto status = (expr); \ 48 ASSERT_THAT(status.ok(), ::testing::Eq(true)); 49 50 #define EXPECT_OK(expr) \ 51 PRIVATE_JOIN_AND_COMPUTE_EXPECT_OK_IMPL_( \ 52 PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_(_status, __LINE__), \ 53 expr) 54 55 #define PRIVATE_JOIN_AND_COMPUTE_EXPECT_OK_IMPL_(status, expr) \ 56 auto status = (expr); \ 57 EXPECT_THAT(status.ok(), ::testing::Eq(true)); 58 59 #define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \ 60 PRIVATE_JOIN_AND_COMPUTE_ASSERT_OK_AND_ASSIGN_IMPL_( \ 61 PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_(_status_or_value, \ 62 __LINE__), \ 63 lhs, rexpr) 64 65 #define PRIVATE_JOIN_AND_COMPUTE_ASSERT_OK_AND_ASSIGN_IMPL_(statusor, lhs, \ 66 rexpr) \ 67 auto statusor = (rexpr); \ 68 ASSERT_THAT(statusor.ok(), ::testing::Eq(true)); \ 69 lhs = std::move(statusor).value() 70 71 // Internal helper for concatenating macro values. 72 #define PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_INNER_(x, y) x##y 73 #define PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_(x, y) \ 74 PRIVATE_JOIN_AND_COMPUTE_STATUS_TESTING_IMPL_CONCAT_INNER_(x, y) 75 76 #endif // GTEST_HAS_STATUS_MATCHERS 77 78 #endif // PRIVATE_JOIN_AND_COMPUTE_UTIL_STATUS_TESTING_H_ 79