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 #define __TBB_NO_IMPLICIT_LINKAGE 1 25 26 #include "../../src/tbb/assert_impl.h" // Out-of-line TBB assertion handling routines are instantiated here. 27 #include "common/test.h" 28 #include "oneapi/tbb/detail/_exception.h" 29 #include "../../src/tbb/exception.cpp" 30 #include <stdexcept> 31 #include <cerrno> 32 #include <iostream> 33 34 namespace tbb { 35 namespace detail { 36 namespace r1 { terminate_on_exception()37bool terminate_on_exception() { 38 return false; 39 } 40 } 41 } 42 } 43 44 #if TBB_USE_EXCEPTIONS 45 46 //! \brief \ref error_guessing 47 TEST_CASE("test tbb::detail::r1::handle_perror") { 48 bool caught = false; 49 50 try { 51 tbb::detail::r1::handle_perror(EAGAIN, "apple"); 52 } catch( std::runtime_error& e ) { 53 REQUIRE(std::memcmp(e.what(), "apple: ", 7) == 0); 54 REQUIRE_MESSAGE(std::strlen(std::strstr(e.what(), std::strerror(EAGAIN))), "Bad error message"); 55 caught = true; 56 } 57 REQUIRE(caught); 58 } 59 60 #endif // TBB_USE_EXCEPTIONS 61