00001 // Copyright 2017 The Abseil Authors. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // https://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 // Testing utilities for ABSL types which throw exceptions. 00016 00017 #ifndef ABSL_BASE_INTERNAL_EXCEPTION_TESTING_H_ 00018 #define ABSL_BASE_INTERNAL_EXCEPTION_TESTING_H_ 00019 00020 #include "gtest/gtest.h" 00021 #include "absl/base/config.h" 00022 00023 // ABSL_BASE_INTERNAL_EXPECT_FAIL tests either for a specified thrown exception 00024 // if exceptions are enabled, or for death with a specified text in the error 00025 // message 00026 #ifdef ABSL_HAVE_EXCEPTIONS 00027 00028 #define ABSL_BASE_INTERNAL_EXPECT_FAIL(expr, exception_t, text) \ 00029 EXPECT_THROW(expr, exception_t) 00030 00031 #elif defined(__ANDROID__) 00032 // Android asserts do not log anywhere that gtest can currently inspect. 00033 // So we expect exit, but cannot match the message. 00034 #define ABSL_BASE_INTERNAL_EXPECT_FAIL(expr, exception_t, text) \ 00035 EXPECT_DEATH(expr, ".*") 00036 #else 00037 #define ABSL_BASE_INTERNAL_EXPECT_FAIL(expr, exception_t, text) \ 00038 EXPECT_DEATH_IF_SUPPORTED(expr, text) 00039 00040 #endif 00041 00042 #endif // ABSL_BASE_INTERNAL_EXCEPTION_TESTING_H_