1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 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 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 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. 15 */ 16 17 //! \file test_handle_perror.cpp 18 //! \brief Test for [internal] functionality 19 20 #if _WIN32 || _WIN64 21 #define _CRT_SECURE_NO_WARNINGS 22 #endif 23 24 #include "common/test.h" 25 #include "oneapi/tbb/detail/_exception.h" 26 #include "../../src/tbb/exception.cpp" 27 #include <stdexcept> 28 #include <cerrno> 29 #include <iostream> 30 31 namespace tbb { 32 namespace detail { 33 namespace r1 { 34 bool terminate_on_exception() { 35 return false; 36 } 37 } 38 } 39 } 40 41 #if TBB_USE_EXCEPTIONS 42 43 //! \brief \ref error_guessing 44 TEST_CASE("test tbb::detail::r1::handle_perror") { 45 bool caught = false; 46 47 try { 48 tbb::detail::r1::handle_perror(EAGAIN, "apple"); 49 } catch( std::runtime_error& e ) { 50 REQUIRE(std::memcmp(e.what(), "apple: ", 7) == 0); 51 REQUIRE_MESSAGE(std::strlen(std::strstr(e.what(), std::strerror(EAGAIN))), "Bad error message"); 52 caught = true; 53 } 54 REQUIRE(caught); 55 } 56 57 #endif // TBB_USE_EXCEPTIONS 58